diff --git a/assets/js/base/components/dropdown-selector/index.js b/assets/js/base/components/dropdown-selector/index.js deleted file mode 100644 index 1a6080106bf..00000000000 --- a/assets/js/base/components/dropdown-selector/index.js +++ /dev/null @@ -1,231 +0,0 @@ -/** - * External dependencies - */ -import PropTypes from 'prop-types'; -import { useCallback, useRef } from '@wordpress/element'; -import classNames from 'classnames'; -import Downshift from 'downshift'; -import { __, sprintf } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import DropdownSelectorInput from './input'; -import DropdownSelectorInputWrapper from './input-wrapper'; -import DropdownSelectorMenu from './menu'; -import DropdownSelectorSelectedChip from './selected-chip'; -import DropdownSelectorSelectedValue from './selected-value'; -import './style.scss'; - -/** - * Component used to show an input box with a dropdown with suggestions. - * - * @param {Object} props Incoming props for the component. - * @param {string} props.attributeLabel Label for the attributes. - * @param {string} props.className CSS class used. - * @param {import('react').CSSProperties} props.style CSS style object used. - * @param {Array} props.checked Which items are checked. - * @param {string} props.inputLabel Label used for the input. - * @param {boolean} props.isDisabled Whether the input is disabled or not. - * @param {boolean} props.isLoading Whether the input is loading. - * @param {boolean} props.multiple Whether multi-select is allowed. - * @param {function():any} props.onChange Function to be called when onChange event fires. - * @param {Array} props.options The option values to show in the select. - * @param {boolean} [props.isCaseSensitive=false] Whether the dropdown search should be case-sensitive. - */ -const DropdownSelector = ( { - attributeLabel = '', - className, - style = {}, - checked = [], - inputLabel = '', - isDisabled = false, - isLoading = false, - multiple = false, - onChange = () => {}, - options = [], - isCaseSensitive = false, -} ) => { - const inputRef = useRef( null ); - - const classes = classNames( - className, - 'wc-block-dropdown-selector', - 'wc-block-components-dropdown-selector', - { - 'is-disabled': isDisabled, - 'is-loading': isLoading, - } - ); - - /** - * State reducer for the downshift component. - * See: https://github.com/downshift-js/downshift#statereducer - */ - const stateReducer = useCallback( - ( state, changes ) => { - switch ( changes.type ) { - case Downshift.stateChangeTypes.keyDownEnter: - case Downshift.stateChangeTypes.clickItem: - return { - ...changes, - highlightedIndex: state.highlightedIndex, - isOpen: multiple, - inputValue: '', - }; - case Downshift.stateChangeTypes.blurInput: - case Downshift.stateChangeTypes.mouseUp: - return { - ...changes, - inputValue: state.inputValue, - }; - default: - return changes; - } - }, - [ multiple ] - ); - - return ( - - { ( { - getInputProps, - getItemProps, - getLabelProps, - getMenuProps, - highlightedIndex, - inputValue, - isOpen, - openMenu, - } ) => ( -
0, - 'is-open': isOpen, - } ) } - style={ style } - > - { /* eslint-disable-next-line jsx-a11y/label-has-for */ } - - inputRef.current.focus() } - > - { checked.map( ( value ) => { - const option = options.find( - ( o ) => o.value === value - ); - - if ( ! option ) { - return null; - } - - const onRemoveItem = ( val ) => { - onChange( val ); - inputRef.current.focus(); - }; - - return multiple ? ( - - ) : ( - inputRef.current.focus() } - onRemoveItem={ onRemoveItem } - option={ option } - /> - ); - } ) } - { - onChange( val ); - inputRef.current.focus(); - } } - placeholder={ - checked.length > 0 && multiple - ? null - : sprintf( - /* translators: %s attribute name. */ - __( - 'Any %s', - 'woo-gutenberg-products-block' - ), - attributeLabel - ) - } - tabIndex={ - // When it's a single selector and there is one element selected, - // we make the input non-focusable with the keyboard because it's - // visually hidden. The input is still rendered, though, because it - // must be possible to focus it when pressing the select value chip. - ! multiple && checked.length > 0 ? '-1' : '0' - } - value={ inputValue } - /> - - { isOpen && ! isDisabled && ( - { - let optionName = option.name; - let nameQuery = inputValue?.trim(); - if ( ! isCaseSensitive ) { - optionName = optionName.toLowerCase(); - nameQuery = nameQuery?.toLowerCase(); - } - return ( - ! nameQuery || - optionName.includes( nameQuery ) - ); - } ) } - /> - ) } -
- ) } -
- ); -}; - -DropdownSelector.propTypes = { - attributeLabel: PropTypes.string, - checked: PropTypes.array, - className: PropTypes.string, - inputLabel: PropTypes.string, - isDisabled: PropTypes.bool, - isLoading: PropTypes.bool, - limit: PropTypes.number, - onChange: PropTypes.func, - options: PropTypes.arrayOf( - PropTypes.shape( { - label: PropTypes.node.isRequired, - value: PropTypes.string.isRequired, - } ) - ), - isCaseSensitive: PropTypes.bool, -}; - -export default DropdownSelector; diff --git a/assets/js/base/components/dropdown-selector/input-wrapper.js b/assets/js/base/components/dropdown-selector/input-wrapper.js deleted file mode 100644 index 4391c1e9bb9..00000000000 --- a/assets/js/base/components/dropdown-selector/input-wrapper.js +++ /dev/null @@ -1,13 +0,0 @@ -const DropdownSelectorInputWrapper = ( { children, onClick } ) => { - return ( - /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ -
- { children } -
- ); -}; - -export default DropdownSelectorInputWrapper; diff --git a/assets/js/base/components/dropdown-selector/input.js b/assets/js/base/components/dropdown-selector/input.js deleted file mode 100644 index abb3cd73101..00000000000 --- a/assets/js/base/components/dropdown-selector/input.js +++ /dev/null @@ -1,36 +0,0 @@ -const DropdownSelectorInput = ( { - checked, - getInputProps, - inputRef, - isDisabled, - onFocus, - onRemoveItem, - placeholder, - tabIndex, - value, -} ) => { - return ( - 0 - ) { - onRemoveItem( checked[ checked.length - 1 ] ); - } - }, - placeholder, - tabIndex, - } ) } - /> - ); -}; - -export default DropdownSelectorInput; diff --git a/assets/js/base/components/dropdown-selector/menu.js b/assets/js/base/components/dropdown-selector/menu.js deleted file mode 100644 index 43c4c25be39..00000000000 --- a/assets/js/base/components/dropdown-selector/menu.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * External dependencies - */ -import { __, sprintf } from '@wordpress/i18n'; -import classNames from 'classnames'; - -const DropdownSelectorMenu = ( { - checked, - getItemProps, - getMenuProps, - highlightedIndex, - options, -} ) => { - return ( - - ); -}; - -export default DropdownSelectorMenu; diff --git a/assets/js/base/components/dropdown-selector/selected-chip.js b/assets/js/base/components/dropdown-selector/selected-chip.js deleted file mode 100644 index 3510451292f..00000000000 --- a/assets/js/base/components/dropdown-selector/selected-chip.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * External dependencies - */ -import { __, sprintf } from '@wordpress/i18n'; -import { RemovableChip } from '@woocommerce/base-components/chip'; - -const DropdownSelectorSelectedChip = ( { onRemoveItem, option } ) => { - return ( - { - onRemoveItem( option.value ); - } } - ariaLabel={ sprintf( - /* translators: %s is referring to the filter option being removed. */ - __( 'Remove %s filter', 'woo-gutenberg-products-block' ), - option.name - ) } - text={ option.label } - radius="large" - /> - ); -}; - -export default DropdownSelectorSelectedChip; diff --git a/assets/js/base/components/dropdown-selector/selected-value.js b/assets/js/base/components/dropdown-selector/selected-value.js deleted file mode 100644 index 35c34146192..00000000000 --- a/assets/js/base/components/dropdown-selector/selected-value.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * External dependencies - */ -import { __, sprintf } from '@wordpress/i18n'; -import { useEffect, useRef } from '@wordpress/element'; -import { Icon, closeSmall } from '@wordpress/icons'; - -const DropdownSelectorSelectedValue = ( { onClick, onRemoveItem, option } ) => { - const labelRef = useRef( null ); - - useEffect( () => { - labelRef.current.focus(); - }, [ labelRef ] ); - - return ( -
- - -
- ); -}; - -export default DropdownSelectorSelectedValue; diff --git a/assets/js/base/components/dropdown-selector/style.scss b/assets/js/base/components/dropdown-selector/style.scss deleted file mode 100644 index 8e314e348f6..00000000000 --- a/assets/js/base/components/dropdown-selector/style.scss +++ /dev/null @@ -1,176 +0,0 @@ -// 18px is the minimum input field line-height and 14px is the font-size of -// the drop down selector elements. - -$dropdown-selector-line-height: math.div(18, 14); - -.wc-block-components-dropdown-selector { - max-width: 300px; - position: relative; - width: 100%; -} - -.wc-block-components-dropdown-selector__input-wrapper { - background: #fff; - border: 1px solid $input-border-gray; - color: $input-text-active; - align-items: center; - border-radius: 4px; - cursor: text; - display: flex; - flex-wrap: wrap; - padding: 2px $gap-smaller; - - .is-disabled & { - background-color: $gray-200; - } - - .is-multiple.has-checked > & { - padding: 2px $gap-smallest; - } - - .is-open > & { - border-radius: 4px 4px 0 0; - } -} - -.wc-block-components-dropdown-selector__input { - @include font-size(small); - line-height: $dropdown-selector-line-height; - margin: em($gap-small * 0.25) 0; - min-width: 0; - padding: em($gap-smallest * 0.75) 0 em($gap-smallest * 0.75); - - .is-single & { - width: 100%; - - &:hover, - &:focus, - &:active { - outline: 0; - } - } - - .is-single.has-checked.is-open & { - margin-bottom: 1.5px; - margin-top: 1.5px; - } - - .is-single.has-checked:not(.is-open) & { - @include visually-hidden(); - // Fixes an issue in Firefox that `flex: wrap` in the container was making - // this element to still occupy one line. - position: absolute; - } - - .is-multiple & { - flex: 1; - min-width: 0; - } -} - -// Visually hide the input -.is-single .wc-block-components-dropdown-selector__input:first-child, -.is-multiple .wc-block-components-dropdown-selector__input { - background: transparent; - border: 0; - - &:hover, - &:focus, - &:active { - outline: 0; - } -} - -.wc-block-components-dropdown-selector { - // Reset