PluginProbe
ElasticPress / 4.2.1
ElasticPress v4.2.1
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / assets / js / instant-results / components / tools / active-constraints.js

active-constraints.js in ElasticPress 4.2.1, at assets/js/instant-results/components/tools/active-constraints.js

56 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies.
3 */
4 import { createPortal, createRef, WPElement } from '@wordpress/element';
5 import { closeSmall, Icon } from '@wordpress/icons';
6 import { __, sprintf } from '@wordpress/i18n';
7
8 /**
9 * Internal dependencies.
10 */
11 import SmallButton from '../common/small-button';
12
13 /**
14 * Create ref for portal.
15 */
16 const ref = createRef();
17
18 /**
19 * Active filter component.
20 *
21 * @param {object} props Props.
22 * @param {string} props.label Constraint label.
23 * @param {Function} props.onClick Click handler.
24 * @returns {WPElement} Element.
25 */
26 export const ActiveContraint = ({ label, onClick }) => {
27 if (!ref.current) {
28 return null;
29 }
30
31 return createPortal(
32 <SmallButton
33 aria-label={sprintf(
34 /* translators: %s: Constraint label. */
35 __('Remove filter: %s', 'elasticpress'),
36 label,
37 )}
38 className="ep-search-icon-button"
39 onClick={onClick}
40 >
41 <Icon icon={closeSmall} />
42 {label}
43 </SmallButton>,
44 ref.current,
45 );
46 };
47
48 /**
49 * Active constraints component.
50 *
51 * @returns {WPElement} Element.
52 */
53 export default () => {
54 return <div className="ep-search-tokens" ref={ref} />;
55 };
56