-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c635cd
commit 293140f
Showing
23 changed files
with
1,021 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ommerce-blocks/assets/js/blocks/collection-filters/inner-blocks/active-filters/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"name": "woocommerce/collection-active-filters", | ||
"version": "1.0.0", | ||
"title": "Collection Active Filters", | ||
"description": "Display the currently active filters.", | ||
"category": "woocommerce", | ||
"keywords": [ | ||
"WooCommerce" | ||
], | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"ancestor": [ | ||
"woocommerce/collection-filters" | ||
], | ||
"supports": { | ||
"interactivity": true | ||
}, | ||
"usesContext": [ | ||
"queryId" | ||
], | ||
"attributes": { | ||
"displayStyle": { | ||
"type": "string", | ||
"default": "list" | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
.../assets/js/blocks/collection-filters/inner-blocks/active-filters/components/inspector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
PanelBody, | ||
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { EditProps, BlockAttributes } from '../types'; | ||
|
||
export const Inspector = ( { attributes, setAttributes }: EditProps ) => { | ||
const { displayStyle } = attributes; | ||
|
||
return ( | ||
<InspectorControls> | ||
<PanelBody | ||
title={ __( | ||
'Display Settings', | ||
'woo-gutenberg-products-block' | ||
) } | ||
> | ||
<ToggleGroupControl | ||
label={ __( | ||
'Display Style', | ||
'woo-gutenberg-products-block' | ||
) } | ||
value={ displayStyle } | ||
onChange={ ( value: BlockAttributes[ 'displayStyle' ] ) => | ||
setAttributes( { | ||
displayStyle: value, | ||
} ) | ||
} | ||
className="wc-block-active-filter__style-toggle" | ||
> | ||
<ToggleGroupControlOption | ||
value="list" | ||
label={ __( 'List', 'woo-gutenberg-products-block' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="chips" | ||
label={ __( 'Chips', 'woo-gutenberg-products-block' ) } | ||
/> | ||
</ToggleGroupControl> | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
}; |
77 changes: 77 additions & 0 deletions
77
.../blocks/collection-filters/inner-blocks/active-filters/components/removable-list-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { Label, RemovableChip } from '@woocommerce/blocks-components'; | ||
import { Icon, closeSmall } from '@wordpress/icons'; | ||
|
||
interface RemovableListItemProps { | ||
type: string; | ||
name: string; | ||
prefix?: string | JSX.Element; | ||
showLabel?: boolean; | ||
isLoading?: boolean; | ||
displayStyle: string; | ||
removeCallback?: () => void; | ||
} | ||
|
||
export const RemovableListItem = ( { | ||
type, | ||
name, | ||
prefix = '', | ||
removeCallback = () => null, | ||
showLabel = true, | ||
displayStyle, | ||
}: RemovableListItemProps ) => { | ||
const prefixedName = prefix ? ( | ||
<> | ||
{ prefix } | ||
| ||
{ name } | ||
</> | ||
) : ( | ||
name | ||
); | ||
const removeText = sprintf( | ||
/* translators: %s attribute value used in the filter. For example: yellow, green, small, large. */ | ||
__( 'Remove %s filter', 'woo-gutenberg-products-block' ), | ||
name | ||
); | ||
|
||
return ( | ||
<li | ||
className="wc-block-active-filters__list-item" | ||
key={ type + ':' + name } | ||
> | ||
{ showLabel && ( | ||
<span className="wc-block-active-filters__list-item-type"> | ||
{ type + ': ' } | ||
</span> | ||
) } | ||
{ displayStyle === 'chips' ? ( | ||
<RemovableChip | ||
element="span" | ||
text={ prefixedName } | ||
onRemove={ removeCallback } | ||
radius="large" | ||
ariaLabel={ removeText } | ||
/> | ||
) : ( | ||
<span className="wc-block-active-filters__list-item-name"> | ||
<button | ||
className="wc-block-active-filters__list-item-remove" | ||
onClick={ removeCallback } | ||
> | ||
<Icon | ||
className="wc-block-components-chip__remove-icon" | ||
icon={ closeSmall } | ||
size={ 16 } | ||
/> | ||
<Label screenReaderLabel={ removeText } /> | ||
</button> | ||
{ prefixedName } | ||
</span> | ||
) } | ||
</li> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
...ocommerce-blocks/assets/js/blocks/collection-filters/inner-blocks/active-filters/edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import classNames from 'classnames'; | ||
import { Disabled } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { EditProps } from './types'; | ||
import { Inspector } from './components/inspector'; | ||
import { RemovableListItem } from './components/removable-list-item'; | ||
|
||
const Edit = ( props: EditProps ) => { | ||
const { displayStyle } = props.attributes; | ||
|
||
const blockProps = useBlockProps( { | ||
className: 'wc-block-active-filters', | ||
} ); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<Inspector { ...props } /> | ||
<Disabled> | ||
<ul | ||
className={ classNames( 'wc-block-active-filters__list', { | ||
'wc-block-active-filters__list--chips': | ||
displayStyle === 'chips', | ||
} ) } | ||
> | ||
<RemovableListItem | ||
type={ __( 'Size', 'woo-gutenberg-products-block' ) } | ||
name={ __( 'Small', 'woo-gutenberg-products-block' ) } | ||
displayStyle={ displayStyle } | ||
/> | ||
<RemovableListItem | ||
type={ __( 'Color', 'woo-gutenberg-products-block' ) } | ||
name={ __( 'Blue', 'woo-gutenberg-products-block' ) } | ||
displayStyle={ displayStyle } | ||
/> | ||
</ul> | ||
</Disabled> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Edit; |
22 changes: 22 additions & 0 deletions
22
...mmerce-blocks/assets/js/blocks/collection-filters/inner-blocks/active-filters/frontend.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { store, navigate, getContext } from '@woocommerce/interactivity'; | ||
|
||
type ActiveFiltersContext = { | ||
queryId: number; | ||
params: string[]; | ||
}; | ||
|
||
store( 'woocommerce/collection-active-filters', { | ||
actions: { | ||
clearAll: () => { | ||
const { params } = getContext< ActiveFiltersContext >(); | ||
const url = new URL( window.location.href ); | ||
const { searchParams } = url; | ||
|
||
params.forEach( ( param ) => searchParams.delete( param ) ); | ||
navigate( url.href ); | ||
}, | ||
}, | ||
} ); |
25 changes: 25 additions & 0 deletions
25
...commerce-blocks/assets/js/blocks/collection-filters/inner-blocks/active-filters/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { Icon } from '@wordpress/icons'; | ||
import { toggle } from '@woocommerce/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import Edit from './edit'; | ||
import './style.scss'; | ||
|
||
registerBlockType( metadata, { | ||
icon: { | ||
src: ( | ||
<Icon | ||
icon={ toggle } | ||
className="wc-block-editor-components-block-icon" | ||
/> | ||
), | ||
}, | ||
edit: Edit, | ||
} ); |
Oops, something went wrong.