@@ -215,37 +234,4 @@ const ProductAttributeTermControl = ( {
);
};
-ProductAttributeTermControl.propTypes = {
- /**
- * Callback to update the selected product attributes.
- */
- onChange: PropTypes.func.isRequired,
- /**
- * Callback to update the category operator. If not passed in, setting is not used.
- */
- onOperatorChange: PropTypes.func,
- /**
- * Setting for whether products should match all or any selected categories.
- */
- operator: PropTypes.oneOf( [ 'all', 'any' ] ),
- /**
- * The list of currently selected attribute slug/ID pairs.
- */
- selected: PropTypes.array.isRequired,
- // from withAttributes
- attributes: PropTypes.array,
- error: PropTypes.object,
- expandedAttribute: PropTypes.number,
- onExpandAttribute: PropTypes.func,
- isCompact: PropTypes.bool,
- isLoading: PropTypes.bool,
- termsAreLoading: PropTypes.bool,
- termsList: PropTypes.object,
-};
-
-ProductAttributeTermControl.defaultProps = {
- isCompact: false,
- operator: 'any',
-};
-
-export default withAttributes( withInstanceId( ProductAttributeTermControl ) );
+export default withInstanceId( ProductAttributeTermControl );
diff --git a/assets/js/editor-components/product-attribute-term-control/style.scss b/assets/js/editor-components/product-attribute-term-control/style.scss
index b1741f8f89d..aa3d6878de0 100644
--- a/assets/js/editor-components/product-attribute-term-control/style.scss
+++ b/assets/js/editor-components/product-attribute-term-control/style.scss
@@ -32,25 +32,4 @@
margin-bottom: $gap-small;
}
}
-
- &.depth-0::after {
- margin-left: $gap-smaller;
- content: "";
- height: $gap-large;
- width: $gap-large;
- background-image: url('data:image/svg+xml;utf8,
');
- background-repeat: no-repeat;
- background-position: center right;
- background-size: contain;
- }
-
- &.depth-0.is-selected::after {
- background-image: url('data:image/svg+xml;utf8,
');
- }
-
- &[disabled].depth-0::after {
- margin-left: 0;
- width: auto;
- background: none;
- }
}
diff --git a/assets/js/editor-components/search-list-control/item.tsx b/assets/js/editor-components/search-list-control/item.tsx
index 0eed60a9eb8..a9ee2717578 100644
--- a/assets/js/editor-components/search-list-control/item.tsx
+++ b/assets/js/editor-components/search-list-control/item.tsx
@@ -1,9 +1,44 @@
+/**
+ * External dependencies
+ */
+import classNames from 'classnames';
+import { CheckboxControl } from '@wordpress/components';
+import { useCallback } from '@wordpress/element';
+import { arrayDifferenceBy, arrayUnionBy } from '@woocommerce/utils';
+
/**
* Internal dependencies
*/
-import type { renderItemArgs } from './types';
+import type {
+ renderItemArgs,
+ SearchListItem as SearchListItemProps,
+} from './types';
import { getHighlightedName, getBreadcrumbsForDisplay } from './utils';
+const Count = ( { label }: { label: string | React.ReactNode | number } ) => {
+ return (
+
{ label }
+ );
+};
+
+const ItemLabel = ( props: { item: SearchListItemProps; search: string } ) => {
+ const { item, search } = props;
+ const hasBreadcrumbs = item.breadcrumbs && item.breadcrumbs.length;
+
+ return (
+
+ { hasBreadcrumbs ? (
+
+ { getBreadcrumbsForDisplay( item.breadcrumbs ) }
+
+ ) : null }
+
+ { getHighlightedName( item.name, search ) }
+
+
+ );
+};
+
export const SearchListItem = ( {
countLabel,
className,
@@ -14,27 +49,115 @@ export const SearchListItem = ( {
isSingle,
onSelect,
search = '',
+ selected,
+ useExpandedPanelId,
...props
}: renderItemArgs ): JSX.Element => {
+ const [ expandedPanelId, setExpandedPanelId ] = useExpandedPanelId;
const showCount =
countLabel !== undefined &&
countLabel !== null &&
item.count !== undefined &&
item.count !== null;
- const classes = [ className, 'woocommerce-search-list__item' ];
- classes.push( `depth-${ depth }` );
- if ( isSingle ) {
- classes.push( 'is-radio-button' );
- }
- if ( showCount ) {
- classes.push( 'has-count' );
- }
- const hasBreadcrumbs = item.breadcrumbs && item.breadcrumbs.length;
+ const hasBreadcrumbs = !! item.breadcrumbs?.length;
+ const hasChildren = !! item.children?.length;
+ const isExpanded = expandedPanelId === item.id;
+ const classes = classNames(
+ [ 'woocommerce-search-list__item', `depth-${ depth }`, className ],
+ {
+ 'has-breadcrumbs': hasBreadcrumbs,
+ 'has-children': hasChildren,
+ 'has-count': showCount,
+ 'is-expanded': isExpanded,
+ 'is-radio-button': isSingle,
+ }
+ );
+
const name = props.name || `search-list-item-${ controlId }`;
const id = `${ name }-${ item.id }`;
- return (
-