diff --git a/src/Async.js b/src/Async.js index 8b7d8330d6..66810ee168 100644 --- a/src/Async.js +++ b/src/Async.js @@ -1,7 +1,9 @@ -import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import React, { Component } from 'react'; import Select from './Select'; + import stripDiacritics from './utils/stripDiacritics'; + const propTypes = { autoload: PropTypes.bool.isRequired, // automatically call the `loadOptions` prop on-mount; defaults to true cache: PropTypes.any, // object to use to cache results; set to null/false to disable caching @@ -34,6 +36,8 @@ const propTypes = { const defaultCache = {}; +const defaultChildren = props => ; + const defaultProps = { autoload: true, cache: defaultCache, @@ -183,7 +187,7 @@ export default class Async extends Component { } render () { - const { children, loadingPlaceholder, multi, onChange, placeholder, value } = this.props; + const { children, loadingPlaceholder, placeholder } = this.props; const { isLoading, options } = this.state; const props = { @@ -204,9 +208,3 @@ export default class Async extends Component { Async.propTypes = propTypes; Async.defaultProps = defaultProps; - -function defaultChildren (props) { - return ( - - ); -} diff --git a/src/AsyncCreatable.js b/src/AsyncCreatable.js index 55d064818c..cf3aa0ecae 100644 --- a/src/AsyncCreatable.js +++ b/src/AsyncCreatable.js @@ -1,8 +1,9 @@ -import React from 'react'; import PropTypes from 'prop-types'; -import Select from './Select'; +import React from 'react'; + import Async from './Async'; import Creatable from './Creatable'; +import Select from './Select'; class AsyncCreatableSelect extends React.Component { @@ -32,13 +33,9 @@ class AsyncCreatableSelect extends React.Component { ); } -}; +} -function defaultChildren (props) { - return ( - - ); -}; +const defaultChildren = props => ; AsyncCreatableSelect.propTypes = { children: PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element diff --git a/src/Creatable.js b/src/Creatable.js index 43b26ab5aa..ec1fc44163 100644 --- a/src/Creatable.js +++ b/src/Creatable.js @@ -1,8 +1,9 @@ -import React from 'react'; import PropTypes from 'prop-types'; -import Select from './Select'; +import React from 'react'; + import defaultFilterOptions from './utils/defaultFilterOptions'; import defaultMenuRenderer from './utils/defaultMenuRenderer'; +import Select from './Select'; class CreatableSelect extends React.Component { constructor (props, context) { @@ -21,7 +22,6 @@ class CreatableSelect extends React.Component { newOptionCreator, onNewOptionClick, options = [], - shouldKeyDownEventCreateNewOption } = this.props; if (isValidNewOption({ label: this.inputValue })) { @@ -140,7 +140,7 @@ class CreatableSelect extends React.Component { } } - onOptionSelect (option, event) { + onOptionSelect (option) { if (option === this._createPlaceholderOption) { this.createNewOption(); } else { @@ -154,8 +154,6 @@ class CreatableSelect extends React.Component { render () { const { - newOptionCreator, - shouldKeyDownEventCreateNewOption, ref: refProp, ...restProps } = this.props; @@ -192,19 +190,15 @@ class CreatableSelect extends React.Component { return children(props); } -}; +} -function defaultChildren (props) { - return ( - - ); -}; +const defaultChildren = props => ; -function isOptionUnique ({ option, options, labelKey, valueKey }) { +const isOptionUnique = ({ option, options, labelKey, valueKey }) => { if (!options || !options.length) { return true; } - + return options .filter((existingOption) => existingOption[labelKey] === option[labelKey] || @@ -213,23 +207,20 @@ function isOptionUnique ({ option, options, labelKey, valueKey }) { .length === 0; }; -function isValidNewOption ({ label }) { - return !!label; -}; +const isValidNewOption = ({ label }) => !!label; -function newOptionCreator ({ label, labelKey, valueKey }) { +const newOptionCreator = ({ label, labelKey, valueKey }) => { const option = {}; option[valueKey] = label; option[labelKey] = label; option.className = 'Select-create-option-placeholder'; + return option; }; -function promptTextCreator (label) { - return `Create option "${label}"`; -} +const promptTextCreator = label => `Create option "${label}"`; -function shouldKeyDownEventCreateNewOption ({ keyCode }) { +const shouldKeyDownEventCreateNewOption = ({ keyCode }) => { switch (keyCode) { case 9: // TAB case 13: // ENTER @@ -240,7 +231,7 @@ function shouldKeyDownEventCreateNewOption ({ keyCode }) { } }; - // Default prop methods +// Default prop methods CreatableSelect.isOptionUnique = isOptionUnique; CreatableSelect.isValidNewOption = isValidNewOption; CreatableSelect.newOptionCreator = newOptionCreator; @@ -305,5 +296,4 @@ CreatableSelect.propTypes = { shouldKeyDownEventCreateNewOption: PropTypes.func, }; - export default CreatableSelect; diff --git a/src/Option.js b/src/Option.js index 7a3de5da9a..4eb85818ad 100644 --- a/src/Option.js +++ b/src/Option.js @@ -1,6 +1,19 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; +import React from 'react'; + +const blockEvent = event => { + event.preventDefault(); + event.stopPropagation(); + if ((event.target.tagName !== 'A') || !('href' in event.target)) { + return; + } + if (event.target.target) { + window.open(event.target.href, event.target.target); + } else { + window.location.href = event.target.href; + } +}; class Option extends React.Component { @@ -16,20 +29,6 @@ class Option extends React.Component { this.onFocus = this.onFocus.bind(this); } - - blockEvent (event) { - event.preventDefault(); - event.stopPropagation(); - if ((event.target.tagName !== 'A') || !('href' in event.target)) { - return; - } - if (event.target.target) { - window.open(event.target.href, event.target.target); - } else { - window.location.href = event.target.href; - } - } - handleMouseDown (event) { event.preventDefault(); event.stopPropagation(); @@ -52,12 +51,12 @@ class Option extends React.Component { this.handleMouseDown(event); } - handleTouchMove (event) { + handleTouchMove () { // Set a flag that the view is being dragged this.dragging = true; } - handleTouchStart (event) { + handleTouchStart () { // Set a flag that the view is not being dragged this.dragging = false; } @@ -69,13 +68,13 @@ class Option extends React.Component { } render () { - var { option, instancePrefix, optionIndex } = this.props; - var className = classNames(this.props.className, option.className); + const { option, instancePrefix, optionIndex } = this.props; + const className = classNames(this.props.className, option.className); return option.disabled ? (