-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
64 lines (57 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* WordPress dependencies
*/
import { ToolbarButton, DuotoneSwatch } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { DOWN } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
import DuotonePickerPopover from './duotone-picker-popover';
function DuotoneControl( {
colorPalette,
duotonePalette,
disableCustomColors,
value,
onChange,
} ) {
const [ isOpen, setIsOpen ] = useState( false );
if ( ! duotonePalette ) {
return null;
}
const onToggle = () => {
setIsOpen( ( prev ) => ! prev );
};
const openOnArrowDown = ( event ) => {
if ( ! isOpen && event.keyCode === DOWN ) {
event.preventDefault();
event.stopPropagation();
onToggle();
}
};
return (
<>
<ToolbarButton
showTooltip
onClick={ onToggle }
aria-haspopup="true"
aria-expanded={ isOpen }
onKeyDown={ openOnArrowDown }
label={ __( 'Apply duotone filter' ) }
icon={ <DuotoneSwatch values={ value } /> }
/>
{ isOpen && (
<DuotonePickerPopover
value={ value }
onChange={ onChange }
onToggle={ onToggle }
duotonePalette={ duotonePalette }
colorPalette={ colorPalette }
disableCustomColors={ disableCustomColors }
/>
) }
</>
);
}
export default DuotoneControl;