-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
image-settings-panel.js
71 lines (65 loc) · 1.77 KB
/
image-settings-panel.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
65
66
67
68
69
70
71
/**
* WordPress dependencies
*/
import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
ToggleControl,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
export function useHasImageSettingsPanel( name, settings, userSettings ) {
// Note: If lightbox userSettings exists, that means
// they were defined via the Global Styles UI and
// will NOT be a boolean value or contain the `allowEditing`
// property, so we should show the settings panel in those cases.
return (
( name === 'core/image' && settings?.lightbox?.allowEditing ) ||
!! userSettings?.lightbox
);
}
export default function ImageSettingsPanel( {
onChange,
userSettings,
settings,
panelId,
} ) {
const resetLightbox = () => {
onChange( undefined );
};
const onChangeLightbox = ( newSetting ) => {
onChange( {
enabled: newSetting,
} );
};
let lightboxChecked = false;
if ( settings?.lightbox?.enabled ) {
lightboxChecked = settings.lightbox.enabled;
}
return (
<>
<ToolsPanel
label={ _x( 'Settings', 'Image settings' ) }
resetAll={ resetLightbox }
panelId={ panelId }
>
<ToolsPanelItem
// We use the `userSettings` prop instead of `settings`, because `settings`
// contains the core/theme values for the lightbox and we want to show the
// "RESET" button ONLY when the user has explicitly set a value in the
// Global Styles.
hasValue={ () => !! userSettings?.lightbox }
label={ __( 'Expand on Click' ) }
onDeselect={ resetLightbox }
isShownByDefault={ true }
panelId={ panelId }
>
<ToggleControl
label={ __( 'Expand on Click' ) }
checked={ lightboxChecked }
onChange={ onChangeLightbox }
/>
</ToolsPanelItem>
</ToolsPanel>
</>
);
}