@@ -8,12 +8,18 @@ import {
8
8
} from '@wordpress/block-editor' ;
9
9
import { __ } from '@wordpress/i18n' ;
10
10
import {
11
- PanelBody ,
12
11
ToggleControl ,
13
12
__experimentalToggleGroupControl as ToggleGroupControl ,
14
13
__experimentalToggleGroupControlOption as ToggleGroupControlOption ,
14
+ __experimentalToolsPanel as ToolsPanel ,
15
+ __experimentalToolsPanelItem as ToolsPanelItem ,
15
16
} from '@wordpress/components' ;
16
17
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+ import { useToolsPanelDropdownMenuProps } from '../utils/hooks' ;
22
+
17
23
const ACCORDION_BLOCK_NAME = 'core/accordion-item' ;
18
24
const ACCORDION_BLOCK = {
19
25
name : ACCORDION_BLOCK_NAME ,
@@ -24,6 +30,7 @@ export default function Edit( {
24
30
setAttributes,
25
31
} ) {
26
32
const blockProps = useBlockProps ( ) ;
33
+ const dropdownMenuProps = useToolsPanelDropdownMenuProps ( ) ;
27
34
28
35
const innerBlocksProps = useInnerBlocksProps ( blockProps , {
29
36
template : [ [ ACCORDION_BLOCK_NAME ] , [ ACCORDION_BLOCK_NAME ] ] ,
@@ -35,49 +42,90 @@ export default function Edit( {
35
42
return (
36
43
< >
37
44
< InspectorControls key = "setting" >
38
- < PanelBody title = { __ ( 'Settings' ) } initialOpen >
39
- < ToggleControl
40
- isBlock
41
- __nextHasNoMarginBottom
45
+ < ToolsPanel
46
+ label = { __ ( 'Settings' ) }
47
+ resetAll = { ( ) => {
48
+ setAttributes ( {
49
+ autoclose : false ,
50
+ showIcon : true ,
51
+ iconPosition : 'right' ,
52
+ } ) ;
53
+ } }
54
+ dropdownMenuProps = { dropdownMenuProps }
55
+ >
56
+ < ToolsPanelItem
42
57
label = { __ ( 'Auto-close' ) }
43
- onChange = { ( value ) => {
44
- setAttributes ( {
45
- autoclose : value ,
46
- } ) ;
47
- } }
48
- checked = { autoclose }
49
- help = { __ (
50
- 'Automatically close accordions when a new one is opened.'
51
- ) }
52
- />
53
- < ToggleControl
54
- isBlock
55
- __nextHasNoMarginBottom
58
+ isShownByDefault
59
+ hasValue = { ( ) => ! ! autoclose }
60
+ onDeselect = { ( ) =>
61
+ setAttributes ( { autoclose : false } )
62
+ }
63
+ >
64
+ < ToggleControl
65
+ isBlock
66
+ __nextHasNoMarginBottom
67
+ label = { __ ( 'Auto-close' ) }
68
+ onChange = { ( value ) => {
69
+ setAttributes ( {
70
+ autoclose : value ,
71
+ } ) ;
72
+ } }
73
+ checked = { autoclose }
74
+ help = { __ (
75
+ 'Automatically close accordions when a new one is opened.'
76
+ ) }
77
+ />
78
+ </ ToolsPanelItem >
79
+ < ToolsPanelItem
56
80
label = { __ ( 'Show icon' ) }
57
- onChange = { ( value ) => {
58
- setAttributes ( {
59
- showIcon : value ,
60
- } ) ;
61
- } }
62
- checked = { showIcon }
63
- help = { __ (
64
- 'Display a plus icon next to the accordion header.'
65
- ) }
66
- />
67
- < ToggleGroupControl
68
- __nextHasNoMarginBottom
69
- __next40pxDefaultSize
70
- isBlock
81
+ isShownByDefault
82
+ hasValue = { ( ) => ! showIcon }
83
+ onDeselect = { ( ) => setAttributes ( { showIcon : true } ) }
84
+ >
85
+ < ToggleControl
86
+ isBlock
87
+ __nextHasNoMarginBottom
88
+ label = { __ ( 'Show icon' ) }
89
+ onChange = { ( value ) => {
90
+ setAttributes ( {
91
+ showIcon : value ,
92
+ } ) ;
93
+ } }
94
+ checked = { showIcon }
95
+ help = { __ (
96
+ 'Display a plus icon next to the accordion header.'
97
+ ) }
98
+ />
99
+ </ ToolsPanelItem >
100
+ < ToolsPanelItem
71
101
label = { __ ( 'Icon Position' ) }
72
- value = { iconPosition }
73
- onChange = { ( value ) => {
74
- setAttributes ( { iconPosition : value } ) ;
75
- } }
102
+ isShownByDefault
103
+ hasValue = { ( ) => iconPosition !== 'right' }
104
+ onDeselect = { ( ) =>
105
+ setAttributes ( { iconPosition : 'right' } )
106
+ }
76
107
>
77
- < ToggleGroupControlOption label = "Left" value = "left" />
78
- < ToggleGroupControlOption label = "Right" value = "right" />
79
- </ ToggleGroupControl >
80
- </ PanelBody >
108
+ < ToggleGroupControl
109
+ __nextHasNoMarginBottom
110
+ __next40pxDefaultSize
111
+ isBlock
112
+ label = { __ ( 'Icon Position' ) }
113
+ value = { iconPosition }
114
+ onChange = { ( value ) => {
115
+ setAttributes ( { iconPosition : value } ) ;
116
+ } }
117
+ >
118
+ < ToggleGroupControlOption
119
+ label = { __ ( 'Left' ) }
120
+ value = "left"
121
+ />
122
+ < ToggleGroupControlOption
123
+ label = { __ ( 'Right' ) }
124
+ value = "right"
125
+ />
126
+ </ ToggleGroupControl >
127
+ </ ToolsPanelItem >
128
+ </ ToolsPanel >
81
129
</ InspectorControls >
82
130
< div { ...innerBlocksProps } />
83
131
</ >
0 commit comments