-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathsettings-drawer.js
45 lines (39 loc) · 986 Bytes
/
settings-drawer.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
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { ToggleControl, VisuallyHidden } from '@wordpress/components';
const noop = () => {};
const LinkControlSettingsDrawer = ( {
value,
settings,
setNewValue = noop,
} ) => {
if ( ! settings || ! settings.length ) {
return null;
}
const handleSettingChange = ( setting ) => ( newValue ) => {
setNewValue( {
...value,
[ setting.id ]: newValue,
} );
};
const theSettings = settings.map( ( setting ) => (
<ToggleControl
className="block-editor-link-control__setting"
key={ setting.id }
label={ setting.title }
onChange={ handleSettingChange( setting ) }
checked={ value ? !! value[ setting.id ] : false }
/>
) );
return (
<fieldset className="block-editor-link-control__settings">
<VisuallyHidden as="legend">
{ __( 'Currently selected link settings' ) }
</VisuallyHidden>
{ theSettings }
</fieldset>
);
};
export default LinkControlSettingsDrawer;