Skip to content

Commit

Permalink
Re-organize file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgio committed Feb 27, 2019
1 parent d7513d0 commit 564fe95
Show file tree
Hide file tree
Showing 30 changed files with 454 additions and 428 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncContainer from './containers/asyncContainer';
import asyncContainer from '../containers/asyncContainer';
import Typeahead from './Typeahead.react';

export default asyncContainer(Typeahead);
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ const copyStyles = (styles, node) => {
/* eslint-enable no-param-reassign */
};

const propTypes = {
/**
* ClassName for the input element.
*/
inputClassName: PropTypes.string,
/**
* Ref callback for the input element.
*/
inputRef: PropTypes.func,
/**
* CSS styles for the input element.
*/
/* eslint-disable-next-line react/forbid-prop-types */
inputStyle: PropTypes.object,
};

class AutosizeInput extends React.Component {
state = {
inputWidth: MIN_WIDTH,
Expand Down Expand Up @@ -135,20 +151,6 @@ class AutosizeInput extends React.Component {
}
}

AutosizeInput.propTypes = {
/**
* ClassName for the input element.
*/
inputClassName: PropTypes.string,
/**
* Ref callback for the input element.
*/
inputRef: PropTypes.func,
/**
* CSS styles for the input element.
*/
/* eslint-disable-next-line react/forbid-prop-types */
inputStyle: PropTypes.object,
};
AutosizeInput.propTypes = propTypes;

export default AutosizeInput;
21 changes: 12 additions & 9 deletions src/ClearButton.react.js → src/components/ClearButton.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';

const propTypes = {
bsSize: PropTypes.oneOf(['large', 'lg', 'small', 'sm']),
label: PropTypes.string,
onClick: PropTypes.func.isRequired,
};

const defaultProps = {
label: 'Clear',
};

/**
* ClearButton
*
Expand All @@ -24,14 +34,7 @@ const ClearButton = ({ bsSize, className, label, onClick, ...props }) => (
</button>
);

ClearButton.propTypes = {
bsSize: PropTypes.oneOf(['large', 'lg', 'small', 'sm']),
label: PropTypes.string,
onClick: PropTypes.func.isRequired,
};

ClearButton.defaultProps = {
label: 'Clear',
};
ClearButton.propTypes = propTypes;
ClearButton.defaultProps = defaultProps;

export default ClearButton;
23 changes: 13 additions & 10 deletions src/Highlighter.react.js → src/components/Highlighter.react.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import PropTypes from 'prop-types';
import React from 'react';

import { getMatchBounds } from './utils';
import { getMatchBounds } from '../utils';

const propTypes = {
children: PropTypes.string.isRequired,
highlightClassName: PropTypes.string,
search: PropTypes.string.isRequired,
};

const defaultProps = {
highlightClassName: 'rbt-highlight-text',
};

/**
* Stripped-down version of https://github.com/helior/react-highlighter
Expand Down Expand Up @@ -67,14 +77,7 @@ class Highlighter extends React.PureComponent {
}
}

Highlighter.propTypes = {
children: PropTypes.string.isRequired,
highlightClassName: PropTypes.string,
search: PropTypes.string.isRequired,
};

Highlighter.defaultProps = {
highlightClassName: 'rbt-highlight-text',
};
Highlighter.propTypes = propTypes;
Highlighter.defaultProps = defaultProps;

export default Highlighter;
File renamed without changes.
37 changes: 20 additions & 17 deletions src/Menu.react.js → src/components/Menu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import React, { Children } from 'react';

import { BaseMenuItem } from './MenuItem.react';

const propTypes = {
/**
* Needed for accessibility.
*/
id: isRequiredForA11y(PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
])),
/**
* Maximum height of the dropdown menu.
*/
maxHeight: PropTypes.string,
};

const defaultProps = {
maxHeight: '300px',
};

/**
* Menu component that handles empty state when passed a set of results.
*/
Expand Down Expand Up @@ -59,23 +77,8 @@ class Menu extends React.Component {
}
}

Menu.propTypes = {
/**
* Needed for accessibility.
*/
id: isRequiredForA11y(PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
])),
/**
* Maximum height of the dropdown menu.
*/
maxHeight: PropTypes.string,
};

Menu.defaultProps = {
maxHeight: '300px',
};
Menu.propTypes = propTypes;
Menu.defaultProps = defaultProps;

Menu.Divider = (props) => (
<li className="divider dropdown-divider" role="separator" />
Expand Down
2 changes: 1 addition & 1 deletion src/MenuItem.react.js → src/components/MenuItem.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cx from 'classnames';
import { noop } from 'lodash';
import React from 'react';

import menuItemContainer from './containers/menuItemContainer';
import menuItemContainer from '../containers/menuItemContainer';

class BaseMenuItem extends React.Component {
render() {
Expand Down
36 changes: 19 additions & 17 deletions src/Token.react.js → src/components/Token.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@ import PropTypes from 'prop-types';

import ClearButton from './ClearButton.react';

import tokenContainer from './containers/tokenContainer';
import { RETURN } from './constants';
import tokenContainer from '../containers/tokenContainer';
import { RETURN } from '../constants';

const propTypes = {
active: PropTypes.bool,
/**
* Handler for removing/deleting the token. If not defined, the token will
* be rendered in a read-only state.
*/
onRemove: PropTypes.func,
tabIndex: PropTypes.number,
};

const defaultProps = {
active: false,
tabIndex: 0,
};

/**
* Token
Expand Down Expand Up @@ -73,20 +88,7 @@ class Token extends React.Component {
}
}

Token.propTypes = {
active: PropTypes.bool,
/**
* Handler for removing/deleting the token. If not defined, the token will
* be rendered in a read-only state.
*/
onRemove: PropTypes.func,
tabIndex: PropTypes.number,
};

Token.defaultProps = {
active: false,
tabIndex: 0,
};

Token.propTypes = propTypes;
Token.defaultProps = defaultProps;

export default tokenContainer(Token);
4 changes: 2 additions & 2 deletions src/Typeahead.react.js → src/components/Typeahead.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import Typeahead from './core/Typeahead';
import Typeahead from '../core/Typeahead';

import ClearButton from './ClearButton.react';
import Loader from './Loader.react';
import TypeaheadInputMulti from './TypeaheadInputMulti.react';
import TypeaheadInputSingle from './TypeaheadInputSingle.react';
import TypeaheadMenu from './TypeaheadMenu.react';

import { preventInputBlur } from './utils';
import { preventInputBlur } from '../utils';

const propTypes = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@ import React from 'react';
import AutosizeInput from './AutosizeInput.react';
import Token from './Token.react';

import { getOptionLabel, isSelectable } from './utils';
import hintContainer from './containers/hintContainer';
import withClassNames from './containers/withClassNames';
import { getOptionLabel, isSelectable } from '../utils';
import hintContainer from '../containers/hintContainer';
import withClassNames from '../containers/withClassNames';

import { BACKSPACE } from './constants';
import { BACKSPACE } from '../constants';

const HintedAutosizeInput = hintContainer(AutosizeInput);

const propTypes = {
/**
* Provides a hook for customized rendering of tokens when multiple
* selections are enabled.
*/
renderToken: PropTypes.func,
};

const defaultProps = {
renderToken: (option, props, idx) => (
<Token
disabled={props.disabled}
key={idx}
onRemove={props.onRemove}
tabIndex={props.tabIndex}>
{getOptionLabel(option, props.labelKey)}
</Token>
),
};

class TypeaheadInputMulti extends React.Component {
render() {
const {
Expand Down Expand Up @@ -114,24 +134,7 @@ class TypeaheadInputMulti extends React.Component {
}
}

TypeaheadInputMulti.propTypes = {
/**
* Provides a hook for customized rendering of tokens when multiple
* selections are enabled.
*/
renderToken: PropTypes.func,
};

TypeaheadInputMulti.defaultProps = {
renderToken: (option, props, idx) => (
<Token
disabled={props.disabled}
key={idx}
onRemove={props.onRemove}
tabIndex={props.tabIndex}>
{getOptionLabel(option, props.labelKey)}
</Token>
),
};
TypeaheadInputMulti.propTypes = propTypes;
TypeaheadInputMulti.defaultProps = defaultProps;

export default withClassNames(TypeaheadInputMulti);
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cx from 'classnames';
import React from 'react';

import hintContainer from './containers/hintContainer';
import withClassNames from './containers/withClassNames';
import hintContainer from '../containers/hintContainer';
import withClassNames from '../containers/withClassNames';

class TypeaheadInputSingle extends React.Component {
render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ import Highlighter from './Highlighter.react';
import Menu from './Menu.react';
import MenuItem from './MenuItem.react';

import { getOptionLabel } from './utils';
import { getOptionLabel } from '../utils';

const propTypes = {
/**
* Provides the ability to specify a prefix before the user-entered text to
* indicate that the selection will be new. No-op unless `allowNew={true}`.
*/
newSelectionPrefix: PropTypes.string,
/**
* Provides a hook for customized rendering of menu item contents.
*/
renderMenuItemChildren: PropTypes.func,
};

const defaultProps = {
newSelectionPrefix: 'New selection: ',
renderMenuItemChildren: (option, props, idx) => (
<Highlighter search={props.text}>
{getOptionLabel(option, props.labelKey)}
</Highlighter>
),
};

class TypeaheadMenu extends React.Component {
render() {
Expand Down Expand Up @@ -76,26 +97,7 @@ class TypeaheadMenu extends React.Component {
}
}

TypeaheadMenu.propTypes = {
/**
* Provides the ability to specify a prefix before the user-entered text to
* indicate that the selection will be new. No-op unless `allowNew={true}`.
*/
newSelectionPrefix: PropTypes.string,
/**
* Provides a hook for customized rendering of menu item contents.
*/
renderMenuItemChildren: PropTypes.func,
};

TypeaheadMenu.defaultProps = {
newSelectionPrefix: 'New selection: ',
renderMenuItemChildren: (option, props, idx) => (
<Highlighter search={props.text}>
{getOptionLabel(option, props.labelKey)}
</Highlighter>
),
};

TypeaheadMenu.propTypes = propTypes;
TypeaheadMenu.defaultProps = defaultProps;

export default TypeaheadMenu;
Loading

0 comments on commit 564fe95

Please sign in to comment.