From eb622395917b9f3156af5cdb0da92a19086080a1 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Wed, 20 Dec 2017 08:51:07 +0200 Subject: [PATCH 01/11] arrowRenderer changed to arrow function --- src/utils/defaultArrowRenderer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/defaultArrowRenderer.js b/src/utils/defaultArrowRenderer.js index 3fee9f0ec4..b72ae139ad 100644 --- a/src/utils/defaultArrowRenderer.js +++ b/src/utils/defaultArrowRenderer.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default function arrowRenderer ({ onMouseDown }) { +const arrowRenderer = ({ onMouseDown }) => { return ( Date: Wed, 20 Dec 2017 08:53:33 +0200 Subject: [PATCH 02/11] clearRenderer changed to arrow function --- src/utils/defaultClearRenderer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/defaultClearRenderer.js b/src/utils/defaultClearRenderer.js index 3f25e85d7d..66885dcb88 100644 --- a/src/utils/defaultClearRenderer.js +++ b/src/utils/defaultClearRenderer.js @@ -1,6 +1,6 @@ import React from 'react'; -export default function clearRenderer () { +const clearRenderer = () => { return ( ); }; + +export default clearRenderer; From 5791fb97344819add6839961667607e784d6c5b3 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Wed, 20 Dec 2017 08:57:49 +0200 Subject: [PATCH 03/11] Refactored defaultFilterOptions file --- src/utils/defaultFilterOptions.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/defaultFilterOptions.js b/src/utils/defaultFilterOptions.js index 5ae9b72410..9d92331e8c 100644 --- a/src/utils/defaultFilterOptions.js +++ b/src/utils/defaultFilterOptions.js @@ -1,11 +1,11 @@ import stripDiacritics from './stripDiacritics'; import trim from './trim'; -function isValid(value) { +const isValid = value => { return typeof (value) !== 'undefined' && value !== null && value !== ''; -} +}; -function filterOptions (options, filterValue, excludeOptions, props) { +const filterOptions = (options, filterValue, excludeOptions, props) => { if (props.ignoreAccents) { filterValue = stripDiacritics(filterValue); } @@ -25,17 +25,17 @@ function filterOptions (options, filterValue, excludeOptions, props) { if (props.filterOption) return props.filterOption.call(this, option, filterValue); if (!filterValue) return true; - var value = option[props.valueKey]; - var label = option[props.labelKey]; - var hasValue = isValid(value); - var hasLabel = isValid(label); + const value = option[props.valueKey]; + const label = option[props.labelKey]; + const hasValue = isValid(value); + const hasLabel = isValid(label); if (!hasValue && !hasLabel) { return false; } - var valueTest = hasValue ? String(value) : null; - var labelTest = hasLabel ? String(label) : null; + let valueTest = hasValue ? String(value) : null; + let labelTest = hasLabel ? String(label) : null; if (props.ignoreAccents) { if (valueTest && props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); @@ -55,6 +55,6 @@ function filterOptions (options, filterValue, excludeOptions, props) { (labelTest && props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0) ); }); -} +}; export default filterOptions; From b35f8d055b45cc3b8a2d55b599b8d2acb4a2c4f7 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 01:58:36 +0200 Subject: [PATCH 04/11] Refactored defaultMenuRenderer file --- src/utils/defaultMenuRenderer.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/utils/defaultMenuRenderer.js b/src/utils/defaultMenuRenderer.js index 224a2376a5..d2fd6494ac 100644 --- a/src/utils/defaultMenuRenderer.js +++ b/src/utils/defaultMenuRenderer.js @@ -1,12 +1,12 @@ import classNames from 'classnames'; +import PropTypes from 'prop-types'; import React from 'react'; -function menuRenderer ({ +const menuRenderer = ({ focusedOption, focusOption, inputValue, instancePrefix, - labelKey, onFocus, onOptionRef, onSelect, @@ -18,11 +18,11 @@ function menuRenderer ({ selectValue, valueArray, valueKey, -}) { +}) => { let Option = optionComponent; return options.map((option, i) => { - let isSelected = valueArray && valueArray.some(x => x[valueKey] == option[valueKey]); + let isSelected = valueArray && valueArray.some(x => x[valueKey] === option[valueKey]); let isFocused = option === focusedOption; let optionClass = classNames(optionClassName, { 'Select-option': true, @@ -53,6 +53,24 @@ function menuRenderer ({ ); }); -} +}; + +menuRenderer.propTypes = { + focusOption: PropTypes.func, + focusedOption: PropTypes.object, + inputValue: PropTypes.string, + instancePrefix: PropTypes.string, + onFocus: PropTypes.func, + onOptionRef: PropTypes.func, + onSelect: PropTypes.func, + optionClassName: PropTypes.string, + optionComponent: PropTypes.func, + optionRenderer: PropTypes.func, + options: PropTypes.array, + removeValue: PropTypes.func, + selectValue: PropTypes.func, + valueArray: PropTypes.array, + valueKey: PropTypes.string, +}; export default menuRenderer; From 880a473430b5474a3768dbdbc5e7d56647083440 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:03:32 +0200 Subject: [PATCH 05/11] Refactored stripDiacritics file --- src/utils/stripDiacritics.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/stripDiacritics.js b/src/utils/stripDiacritics.js index 478d26e6b9..d6456ddc91 100644 --- a/src/utils/stripDiacritics.js +++ b/src/utils/stripDiacritics.js @@ -1,4 +1,4 @@ -var map = [ +const map = [ { 'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g }, { 'base':'AA','letters':/[\uA732]/g }, { 'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g }, @@ -85,9 +85,11 @@ var map = [ { 'base':'z', 'letters':/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g }, ]; -export default function stripDiacritics (str) { - for (var i = 0; i < map.length; i++) { +const stripDiacritics = str => { + for (let i = 0; i < map.length; i++) { str = str.replace(map[i].letters, map[i].base); } return str; }; + +export default stripDiacritics; From f7a17a6053b50ed89652341a2b86a90c5d5f1ef0 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:06:24 +0200 Subject: [PATCH 06/11] Refactored trim file --- src/utils/trim.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/trim.js b/src/utils/trim.js index 56aef05bd2..4f0172a419 100644 --- a/src/utils/trim.js +++ b/src/utils/trim.js @@ -1,3 +1,3 @@ -export default function trim(str) { - return str.replace(/^\s+|\s+$/g, ''); -} +const trim = str => str.replace(/^\s+|\s+$/g, ''); + +export default trim; From 4fa40cbb6f54860e28dc8e9f8615ba1beed85fc3 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:17:07 +0200 Subject: [PATCH 07/11] Refactored Async.js --- src/Async.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 => - ); -} From d205e64c6d7edb57274d56c154ca70abae0ab8b9 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:20:33 +0200 Subject: [PATCH 08/11] Refactored AsyncCreatable.js --- src/AsyncCreatable.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 ( - ; AsyncCreatableSelect.propTypes = { children: PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element From 69868a09842bdf468b07314ab170a20282b9cd5f Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:01:34 +0200 Subject: [PATCH 09/11] Refactored Creatable.js --- src/Creatable.js | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) 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 ( - ; -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; From d923fb6a0a4eb6ed15be3299239da141d0004cce Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:08:11 +0200 Subject: [PATCH 10/11] Refactored Option.js --- src/Option.js | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) 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 ? (
+ onMouseDown={blockEvent} + onClick={blockEvent}> {this.props.children}
) : ( @@ -95,7 +94,7 @@ class Option extends React.Component { ); } -}; +} Option.propTypes = { children: PropTypes.node, From 9185809c5d61700f33fee9be0edb3b08c6594603 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:11:15 +0200 Subject: [PATCH 11/11] Refactored Value.js --- src/Value.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Value.js b/src/Value.js index e282fd18ca..d405e78dfc 100644 --- a/src/Value.js +++ b/src/Value.js @@ -1,6 +1,6 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; +import React from 'react'; class Value extends React.Component { @@ -43,12 +43,12 @@ class Value extends React.Component { this.onRemove(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; } @@ -91,8 +91,7 @@ class Value extends React.Component { ); } -}; - +} Value.propTypes = { children: PropTypes.node,