* Add isCompact prop to SearchListControl

* Add left and right borders to search list

* Remove box-shadow when search list items are focused/active

* Add Changelog notice

* Update snapshots
This commit is contained in:
Albert Juhé Lluveras 2020-12-22 15:32:24 +01:00 committed by GitHub
parent 2db701b5f3
commit 080271fb27
5 changed files with 31 additions and 19 deletions

View File

@ -4,6 +4,7 @@
- Add new `<Accordion>` component. - Add new `<Accordion>` component.
- Remove the `showCount` prop from `<SearchListItem>`. Count will always be displayed if any of those props is not undefined/null: `countLabel` and `item.count`. - Remove the `showCount` prop from `<SearchListItem>`. Count will always be displayed if any of those props is not undefined/null: `countLabel` and `item.count`.
- Fix alignment of `<SearchListItem>` count bubble in newest versions of `@wordpress/components`. - Fix alignment of `<SearchListItem>` count bubble in newest versions of `@wordpress/components`.
- `<SearchListControl>` no longer has different styles when it's used inside a panel. Those styles are available now with the `isCompact` prop.
- Support custom attributes in `<AttributeFilter />`. - Support custom attributes in `<AttributeFilter />`.
- Add product attributes support to `<Search />`. - Add product attributes support to `<Search />`.
- Allow single-selection support to `<Search />`. - Allow single-selection support to `<Search />`.

View File

@ -14,6 +14,7 @@ import { compose, withInstanceId, withState } from '@wordpress/compose';
import { escapeRegExp, findIndex } from 'lodash'; import { escapeRegExp, findIndex } from 'lodash';
import NoticeOutlineIcon from 'gridicons/dist/notice-outline'; import NoticeOutlineIcon from 'gridicons/dist/notice-outline';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames';
/** /**
* Internal dependencies * Internal dependencies
@ -226,11 +227,15 @@ export class SearchListControl extends Component {
} }
render() { render() {
const { className = '', search, setState } = this.props; const { className = '', isCompact, search, setState } = this.props;
const messages = { ...defaultMessages, ...this.props.messages }; const messages = { ...defaultMessages, ...this.props.messages };
return ( return (
<div className={ `woocommerce-search-list ${ className }` }> <div
className={ classnames( 'woocommerce-search-list', className, {
'is-compact': isCompact,
} ) }
>
{ this.renderSelectedSection() } { this.renderSelectedSection() }
<div className="woocommerce-search-list__search"> <div className="woocommerce-search-list__search">
@ -253,6 +258,10 @@ SearchListControl.propTypes = {
* Additional CSS classes. * Additional CSS classes.
*/ */
className: PropTypes.string, className: PropTypes.string,
/**
* Whether it should be displayed in a compact way, so it occupies less space.
*/
isCompact: PropTypes.bool,
/** /**
* Whether the list of items is hierarchical or not. If true, each list item is expected to * Whether the list of items is hierarchical or not. If true, each list item is expected to
* have a parent property. * have a parent property.

View File

@ -10,6 +10,7 @@ const SearchListControlExample = withState( {
loading: true, loading: true,
} )( ( { selected, loading, setState } ) => { } )( ( { selected, loading, setState } ) => {
const showCount = boolean( 'Show count', false ); const showCount = boolean( 'Show count', false );
const isCompact = boolean( 'Compact', false );
let list = [ let list = [
{ id: 1, name: 'Apricots' }, { id: 1, name: 'Apricots' },
{ id: 2, name: 'Clementine' }, { id: 2, name: 'Clementine' },
@ -31,6 +32,7 @@ const SearchListControlExample = withState( {
</button> </button>
<SearchListControl <SearchListControl
list={ list } list={ list }
isCompact={ isCompact }
isLoading={ loading } isLoading={ loading }
selected={ selected } selected={ selected }
onChange={ ( items ) => setState( { selected: items } ) } onChange={ ( items ) => setState( { selected: items } ) }

View File

@ -43,12 +43,11 @@
} }
.woocommerce-search-list__list { .woocommerce-search-list__list {
border: 1px solid $gray-100;
padding: 0; padding: 0;
max-height: 17em; max-height: 17em;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
border-top: 1px solid $gray-100;
border-bottom: 1px solid $gray-100;
&.is-loading { &.is-loading {
padding: $gap-small 0; padding: $gap-small 0;
@ -104,6 +103,11 @@
background: $gray-100; background: $gray-100;
} }
&:active,
&:focus {
box-shadow: none;
}
&:last-child { &:last-child {
border-bottom: none !important; border-bottom: none !important;
} }
@ -202,11 +206,7 @@
} }
} }
.components-panel { .woocommerce-search-list.is-compact {
.woocommerce-search-list {
padding: 0;
}
.woocommerce-search-list__selected { .woocommerce-search-list__selected {
margin: 0 0 $gap; margin: 0 0 $gap;
padding: 0; padding: 0;

View File

@ -2,7 +2,7 @@
exports[`SearchListControl should render a search box and list of hierarchical options 1`] = ` exports[`SearchListControl should render a search box and list of hierarchical options 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -303,7 +303,7 @@ exports[`SearchListControl should render a search box and list of hierarchical o
exports[`SearchListControl should render a search box and list of options 1`] = ` exports[`SearchListControl should render a search box and list of options 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -875,7 +875,7 @@ exports[`SearchListControl should render a search box and list of options with a
exports[`SearchListControl should render a search box and list of options, with a custom render callback for each item 1`] = ` exports[`SearchListControl should render a search box and list of options, with a custom render callback for each item 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -957,7 +957,7 @@ exports[`SearchListControl should render a search box and list of options, with
exports[`SearchListControl should render a search box and list of options, with a custom search input message 1`] = ` exports[`SearchListControl should render a search box and list of options, with a custom search input message 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1243,7 +1243,7 @@ exports[`SearchListControl should render a search box and list of options, with
exports[`SearchListControl should render a search box and no options 1`] = ` exports[`SearchListControl should render a search box and no options 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1314,7 +1314,7 @@ exports[`SearchListControl should render a search box and no options 1`] = `
exports[`SearchListControl should render a search box with a search term, and no matching options 1`] = ` exports[`SearchListControl should render a search box with a search term, and no matching options 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1386,7 +1386,7 @@ exports[`SearchListControl should render a search box with a search term, and no
exports[`SearchListControl should render a search box with a search term, and only matching options 1`] = ` exports[`SearchListControl should render a search box with a search term, and only matching options 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1521,7 +1521,7 @@ exports[`SearchListControl should render a search box with a search term, and on
exports[`SearchListControl should render a search box with a search term, and only matching options, regardless of case sensitivity 1`] = ` exports[`SearchListControl should render a search box with a search term, and only matching options, regardless of case sensitivity 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1656,7 +1656,7 @@ exports[`SearchListControl should render a search box with a search term, and on
exports[`SearchListControl should render a search box, a list of options, and 1 selected item 1`] = ` exports[`SearchListControl should render a search box, a list of options, and 1 selected item 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"
@ -1995,7 +1995,7 @@ exports[`SearchListControl should render a search box, a list of options, and 1
exports[`SearchListControl should render a search box, a list of options, and 2 selected item 1`] = ` exports[`SearchListControl should render a search box, a list of options, and 2 selected item 1`] = `
<div <div
className="woocommerce-search-list " className="woocommerce-search-list"
> >
<div <div
className="woocommerce-search-list__selected" className="woocommerce-search-list__selected"