react-select-search
Advanced tools
Comparing version 3.0.9 to 3.0.10
@@ -18,3 +18,3 @@ "use strict"; | ||
var Option = function Option(_ref) { | ||
function Option(_ref) { | ||
var _classes; | ||
@@ -50,3 +50,3 @@ | ||
}, option.value); | ||
}; | ||
} | ||
@@ -53,0 +53,0 @@ Option.defaultProps = { |
@@ -18,3 +18,3 @@ "use strict"; | ||
var Options = function Options(_ref) { | ||
function Options(_ref) { | ||
var options = _ref.options, | ||
@@ -79,3 +79,3 @@ optionProps = _ref.optionProps, | ||
); | ||
}; | ||
} | ||
@@ -82,0 +82,0 @@ Options.defaultProps = { |
@@ -20,3 +20,3 @@ "use strict"; | ||
var OptionsList = function OptionsList(_ref) { | ||
function OptionsList(_ref) { | ||
var options = _ref.options, | ||
@@ -65,4 +65,8 @@ optionProps = _ref.optionProps, | ||
}); | ||
} | ||
OptionsList.defaultProps = { | ||
renderGroupHeader: null, | ||
renderOption: null | ||
}; | ||
OptionsList.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -69,0 +73,0 @@ options: _propTypes["default"].arrayOf(_types.optionType).isRequired, |
@@ -21,4 +21,7 @@ "use strict"; | ||
return fuse.search(value); | ||
return fuse.search(value).map(function (_ref) { | ||
var item = _ref.item; | ||
return item; | ||
}); | ||
}; | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
exports.fuzzySearch = exports["default"] = exports.useSelect = void 0; | ||
exports.useSelect = exports.fuzzySearch = exports["default"] = void 0; | ||
@@ -6,0 +6,0 @@ var _useSelect = _interopRequireDefault(require("./useSelect")); |
@@ -39,2 +39,3 @@ "use strict"; | ||
newOptions.forEach(function (newOption) { | ||
// eslint-disable-next-line eqeqeq | ||
var optionIndex = oldOptions.findIndex(function (o) { | ||
@@ -41,0 +42,0 @@ return o.value == newOption.value; |
@@ -11,4 +11,4 @@ "use strict"; | ||
return Array.isArray(selectedValue) ? // eslint-disable-next-line eqeqeq | ||
selectedValue.findIndex(function (item) { | ||
return Array.isArray(selectedValue) // eslint-disable-next-line eqeqeq | ||
? selectedValue.findIndex(function (item) { | ||
return item.value == itemValue.value; | ||
@@ -15,0 +15,0 @@ }) >= 0 // eslint-disable-next-line eqeqeq |
@@ -9,10 +9,12 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
const Option = ({ | ||
optionProps, | ||
highlighted, | ||
selected, | ||
option, | ||
cls, | ||
renderOption | ||
}) => { | ||
function Option(_ref) { | ||
let { | ||
optionProps, | ||
highlighted, | ||
selected, | ||
option, | ||
cls, | ||
renderOption | ||
} = _ref; | ||
const props = _extends({}, optionProps, { | ||
@@ -43,3 +45,3 @@ value: option.value, | ||
}, option.value); | ||
}; | ||
} | ||
@@ -46,0 +48,0 @@ Option.defaultProps = { |
@@ -7,11 +7,12 @@ import { memo, useCallback, useEffect, useRef } from 'react'; | ||
const Options = ({ | ||
options, | ||
optionProps, | ||
snapshot, | ||
cls, | ||
renderGroupHeader, | ||
renderOption, | ||
emptyMessage | ||
}) => { | ||
function Options(_ref) { | ||
let { | ||
options, | ||
optionProps, | ||
snapshot, | ||
cls, | ||
renderGroupHeader, | ||
renderOption, | ||
emptyMessage | ||
} = _ref; | ||
const selectRef = useRef(null); | ||
@@ -71,3 +72,3 @@ const { | ||
); | ||
}; | ||
} | ||
@@ -74,0 +75,0 @@ Options.defaultProps = { |
@@ -9,47 +9,54 @@ import { memo } from 'react'; | ||
const OptionsList = ({ | ||
options, | ||
optionProps, | ||
snapshot, | ||
renderOption, | ||
renderGroupHeader, | ||
cls | ||
}) => /*#__PURE__*/_jsx("ul", { | ||
className: cls('options'), | ||
children: options.map(o => { | ||
if (o.type === 'group') { | ||
return /*#__PURE__*/_jsx("li", { | ||
role: "none", | ||
className: cls('row'), | ||
children: /*#__PURE__*/_jsxs("div", { | ||
className: cls('group'), | ||
children: [/*#__PURE__*/_jsx("div", { | ||
className: cls('group-header'), | ||
children: renderGroupHeader ? renderGroupHeader(o.name) : o.name | ||
}), /*#__PURE__*/_jsx("ul", { | ||
className: cls('options'), | ||
children: /*#__PURE__*/_jsx(OptionsList, { | ||
optionProps: optionProps, | ||
snapshot: snapshot, | ||
options: o.items, | ||
renderOption: renderOption, | ||
renderGroupHeader: renderGroupHeader, | ||
cls: cls | ||
}) | ||
})] | ||
}) | ||
}, o.groupId); | ||
} | ||
function OptionsList(_ref) { | ||
let { | ||
options, | ||
optionProps, | ||
snapshot, | ||
renderOption, | ||
renderGroupHeader, | ||
cls | ||
} = _ref; | ||
return /*#__PURE__*/_jsx("ul", { | ||
className: cls('options'), | ||
children: options.map(o => { | ||
if (o.type === 'group') { | ||
return /*#__PURE__*/_jsx("li", { | ||
role: "none", | ||
className: cls('row'), | ||
children: /*#__PURE__*/_jsxs("div", { | ||
className: cls('group'), | ||
children: [/*#__PURE__*/_jsx("div", { | ||
className: cls('group-header'), | ||
children: renderGroupHeader ? renderGroupHeader(o.name) : o.name | ||
}), /*#__PURE__*/_jsx("ul", { | ||
className: cls('options'), | ||
children: /*#__PURE__*/_jsx(OptionsList, { | ||
optionProps: optionProps, | ||
snapshot: snapshot, | ||
options: o.items, | ||
renderOption: renderOption, | ||
renderGroupHeader: renderGroupHeader, | ||
cls: cls | ||
}) | ||
})] | ||
}) | ||
}, o.groupId); | ||
} | ||
return /*#__PURE__*/_jsx(Option, { | ||
selected: isSelected(o, snapshot.option), | ||
highlighted: snapshot.highlighted === o.index, | ||
option: o, | ||
optionProps: optionProps, | ||
cls: cls, | ||
renderOption: renderOption | ||
}, o.value); | ||
}) | ||
}); | ||
return /*#__PURE__*/_jsx(Option, { | ||
selected: isSelected(o, snapshot.option), | ||
highlighted: snapshot.highlighted === o.index, | ||
option: o, | ||
optionProps: optionProps, | ||
cls: cls, | ||
renderOption: renderOption | ||
}, o.value); | ||
}) | ||
}); | ||
} | ||
OptionsList.defaultProps = { | ||
renderGroupHeader: null, | ||
renderOption: null | ||
}; | ||
OptionsList.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -56,0 +63,0 @@ options: PropTypes.arrayOf(optionType).isRequired, |
@@ -13,4 +13,9 @@ // eslint-disable-next-line import/no-extraneous-dependencies | ||
return fuse.search(value); | ||
return fuse.search(value).map(_ref => { | ||
let { | ||
item | ||
} = _ref; | ||
return item; | ||
}); | ||
}; | ||
} |
@@ -1,5 +0,6 @@ | ||
export default function highlightReducer(highlighted, { | ||
key, | ||
options | ||
}) { | ||
export default function highlightReducer(highlighted, _ref) { | ||
let { | ||
key, | ||
options | ||
} = _ref; | ||
const max = options.length - 1; | ||
@@ -6,0 +7,0 @@ let newHighlighted = key === 'ArrowDown' ? highlighted + 1 : highlighted - 1; |
@@ -1,3 +0,4 @@ | ||
export { default as useSelect } from './useSelect'; | ||
export { default as useSelect } from './useSelect'; // eslint-disable-next-line no-restricted-exports | ||
export { default } from './SelectSearch'; | ||
export { default as fuzzySearch } from './fuzzySearch'; |
export default function classes(classNames) { | ||
return Object.entries(classNames).filter(([cls, display]) => cls && display).map(([cls]) => cls).join(' '); | ||
return Object.entries(classNames).filter(_ref => { | ||
let [cls, display] = _ref; | ||
return cls && display; | ||
}).map(_ref2 => { | ||
let [cls] = _ref2; | ||
return cls; | ||
}).join(' '); | ||
} |
export default function debounce(func, wait) { | ||
let timeout; | ||
return (...args) => { | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(timeout); | ||
@@ -5,0 +9,0 @@ timeout = setTimeout(() => { |
@@ -26,2 +26,3 @@ import valueToArray from './valuteToArray'; | ||
newOptions.forEach(newOption => { | ||
// eslint-disable-next-line eqeqeq | ||
const optionIndex = oldOptions.findIndex(o => o.value == newOption.value); | ||
@@ -28,0 +29,0 @@ |
@@ -6,5 +6,5 @@ export default function isSelected(itemValue, selectedValue) { | ||
return Array.isArray(selectedValue) ? // eslint-disable-next-line eqeqeq | ||
selectedValue.findIndex(item => item.value == itemValue.value) >= 0 // eslint-disable-next-line eqeqeq | ||
return Array.isArray(selectedValue) // eslint-disable-next-line eqeqeq | ||
? selectedValue.findIndex(item => item.value == itemValue.value) >= 0 // eslint-disable-next-line eqeqeq | ||
: selectedValue.value == itemValue.value; | ||
} |
@@ -12,26 +12,27 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import { jsxs as _jsxs } from "react/jsx-runtime"; | ||
const SelectSearch = /*#__PURE__*/forwardRef(({ | ||
value: defaultValue, | ||
disabled, | ||
placeholder, | ||
multiple, | ||
search, | ||
autoFocus, | ||
autoComplete, | ||
options: defaultOptions, | ||
id, | ||
onChange, | ||
onFocus, | ||
onBlur, | ||
printOptions, | ||
closeOnSelect, | ||
className, | ||
renderValue, | ||
renderOption, | ||
renderGroupHeader, | ||
getOptions, | ||
filterOptions, | ||
debounce, | ||
emptyMessage | ||
}, ref) => { | ||
const SelectSearch = /*#__PURE__*/forwardRef((_ref, ref) => { | ||
let { | ||
value: defaultValue, | ||
disabled, | ||
placeholder, | ||
multiple, | ||
search, | ||
autoFocus, | ||
autoComplete, | ||
options: defaultOptions, | ||
id, | ||
onChange, | ||
onFocus, | ||
onBlur, | ||
printOptions, | ||
closeOnSelect, | ||
className, | ||
renderValue, | ||
renderOption, | ||
renderGroupHeader, | ||
getOptions, | ||
filterOptions, | ||
debounce, | ||
emptyMessage | ||
} = _ref; | ||
const cls = useClassName(className); | ||
@@ -38,0 +39,0 @@ const [snapshot, valueProps, optionProps] = useSelect({ |
import { useEffect, useMemo, useState } from 'react'; | ||
import debounce from './lib/debounce'; | ||
import flattenOptions from './lib/flattenOptions'; | ||
export default function useFetch(q, defaultOptions, { | ||
debounceTime, | ||
filterOptions, | ||
getOptions | ||
}) { | ||
export default function useFetch(q, defaultOptions, _ref) { | ||
let { | ||
debounceTime, | ||
filterOptions, | ||
getOptions | ||
} = _ref; | ||
const [fetching, setFetching] = useState(false); | ||
@@ -10,0 +11,0 @@ const [options, setOptions] = useState(() => flattenOptions(defaultOptions)); |
@@ -10,16 +10,17 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import useHighlight from './useHighlight'; | ||
export default function useSelect({ | ||
value: defaultValue = null, | ||
options: defaultOptions = [], | ||
search: canSearch = false, | ||
multiple = false, | ||
disabled = false, | ||
closeOnSelect = true, | ||
getOptions: getOptionsFn = null, | ||
filterOptions = null, | ||
onChange = () => {}, | ||
onFocus = () => {}, | ||
onBlur = () => {}, | ||
debounce = 0 | ||
}) { | ||
export default function useSelect(_ref) { | ||
let { | ||
value: defaultValue = null, | ||
options: defaultOptions = [], | ||
search: canSearch = false, | ||
multiple = false, | ||
disabled = false, | ||
closeOnSelect = true, | ||
getOptions: getOptionsFn = null, | ||
filterOptions = null, | ||
onChange = () => {}, | ||
onFocus = () => {}, | ||
onBlur = () => {}, | ||
debounce = 0 | ||
} = _ref; | ||
const ref = useRef(null); | ||
@@ -77,5 +78,8 @@ const [value, setValue] = useState(null); | ||
onBlur: onBlurCb, | ||
onChange: canSearch ? ({ | ||
target | ||
}) => setSearch(target.value) : null, | ||
onChange: canSearch ? _ref2 => { | ||
let { | ||
target | ||
} = _ref2; | ||
return setSearch(target.value); | ||
} : null, | ||
disabled, | ||
@@ -82,0 +86,0 @@ ref |
{ | ||
"name": "react-select-search", | ||
"version": "3.0.9", | ||
"version": "3.0.10", | ||
"description": "Lightweight select component for React", | ||
@@ -12,2 +12,3 @@ "main": "dist/cjs/index.js", | ||
"test": "jest", | ||
"test:react16": "npm i --legacy-peer-deps --no-save react-16@npm:react@^16.14.0 react-dom-16@npm:react-dom@^16.14.0 && REACT_16=yup jest", | ||
"test:watch": "npm test -- --watch", | ||
@@ -39,38 +40,38 @@ "test:coverage": "npm test -- --coverage --silent", | ||
"peerDependencies": { | ||
"prop-types": "^15.7.2", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1" | ||
"prop-types": "^15.8.1", | ||
"react": "^18.0.1 || ^17.0.1 || ^16.14.0", | ||
"react-dom": "^18.0.1 || ^17.0.1 || ^16.14.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.12.1", | ||
"@babel/core": "^7.12.9", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.12.1", | ||
"@babel/plugin-transform-react-pure-annotations": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/preset-react": "^7.12.7", | ||
"@babel/register": "^7.12.1", | ||
"@storybook/addon-actions": "^6.2.9", | ||
"@storybook/addon-essentials": "^6.2.9", | ||
"@storybook/addon-links": "^6.2.9", | ||
"@storybook/addon-storyshots": "^6.2.9", | ||
"@storybook/addon-storysource": "^6.2.9", | ||
"@storybook/addons": "^6.2.9", | ||
"@storybook/react": "^6.2.9", | ||
"babel-eslint": "^10.1.0", | ||
"babel-loader": "^8.1.0", | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.17.10", | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@babel/plugin-proposal-class-properties": "^7.16.7", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.17.3", | ||
"@babel/plugin-transform-react-pure-annotations": "^7.16.7", | ||
"@babel/preset-env": "^7.17.10", | ||
"@babel/preset-react": "^7.16.7", | ||
"@babel/register": "^7.17.7", | ||
"@storybook/addon-actions": "^6.4.22", | ||
"@storybook/addon-essentials": "^6.4.22", | ||
"@storybook/addon-links": "^6.4.22", | ||
"@storybook/addon-storyshots": "^6.4.22", | ||
"@storybook/addon-storysource": "^6.4.22", | ||
"@storybook/addons": "^6.4.22", | ||
"@storybook/react": "^6.4.22", | ||
"babel-loader": "^8.2.5", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24", | ||
"browser-env": "^3.3.0", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.14.0", | ||
"eslint-config-airbnb": "^18.2.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"eslint-plugin-jsx-a11y": "^6.3.1", | ||
"eslint-plugin-react": "^7.21.5", | ||
"eslint-plugin-react-hooks": "^4.1.2", | ||
"fuse.js": "^3.4.5", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.14.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-react": "^7.29.4", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"fuse.js": "^6.6.0", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest": "^26.6.3", | ||
"jest": "^28.0.3", | ||
"pretty": "^2.0.0", | ||
"prop-types": "^15.7.2", | ||
"prop-types": "^15.8.1", | ||
"react": "^17.0.1", | ||
@@ -80,7 +81,7 @@ "react-dom": "^17.0.1", | ||
"react-test-renderer": "^17.0.1", | ||
"react-transition-group": "^4.4.1" | ||
"react-transition-group": "^4.4.2" | ||
}, | ||
"optionalDependencies": { | ||
"fuse.js": "^3.4.5" | ||
"fuse.js": "^6.6.0" | ||
} | ||
} |
@@ -121,3 +121,3 @@ <p align="center"> | ||
| ---- | ---- | ------- | ----------- | | ||
| options | array | | Se the [options documentation](#the-options-object) below | | ||
| options | array | | See the [options documentation](#the-options-object) below | | ||
| getOptions | function | null | Get options through a function call, can return a promise for async usage. See [get options](#get-options) for more. | | ||
@@ -124,0 +124,0 @@ | filterOptions | function | null | Takes the current options list and should return a function that handles the filtering. Runs after getOptions. See [fuzzySearch.js](src/fuzzySearch.js) for example. | |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80437
1918