@@ -31,6 +31,7 @@ const SelectItemControl = ({
3131 isSecondary = true ,
3232 isSmall = true ,
3333 withoutControl, // if true the control will be wrapped in regular <div>, otherwise in <BaseControl>
34+ fillMissing, // if true then 'empty & disabled' items will be added to the required number based on the number of columns
3435 recap, // maybe true (then default options will be used) or object with options (label, value, style, isDisabled)
3536 options, // array of object with keys 'value' and 'label' [{ label: 'Name', value: 2 }]
3637 // could be array of values - then it will be transformed to array of objects
@@ -48,7 +49,11 @@ const SelectItemControl = ({
4849 ...additionalProps // all additional props go to Button
4950} ) => {
5051
51- const makeItem = ( { label, value, style, isDisabled } ) => (
52+ // fill 'missing' items with 'empty' slots if requested
53+ const missingCount = fillMissing ? Math . ceil ( options . length / columns ) * columns - options . length : 0 ;
54+ const missing = Array ( missingCount ) . fill ( ) . map ( ( _ , i ) => ( { value : `slot${ i } ` , isDisabled : true , isSlot : true } ) ) ;
55+
56+ const makeItem = ( { label, value, style, isDisabled, isSlot } ) => (
5257 < ConditionalWrap
5358 condition = { withTooltip }
5459 wrap = { Tooltip }
@@ -61,19 +66,25 @@ const SelectItemControl = ({
6166 {
6267 'is-selected' : selectedItem === value && ! isDisabled ,
6368 'is-disabled' : isDisabled ,
69+ 'is-slot' : isSlot ,
6470 } )
6571 } >
6672 < Button
67- className = { mergeClasses ( `${ cname } __button` , buttonClass , `${ cname } __${ value } ` , { [ 'is-selected' ] : selectedItem === value && ! isDisabled } ) }
73+ className = { mergeClasses (
74+ `${ cname } __button` ,
75+ buttonClass ,
76+ `${ cname } __${ value } ` ,
77+ { [ 'is-selected' ] : selectedItem === value && ! isDisabled }
78+ ) }
6879 isSecondary = { isSecondary }
6980 isSmall = { isSmall }
7081 onClick = { ( ) => isDisabled ? false : onClick ( value ) }
7182 style = { style || buttonStyle }
7283 { ...pick ( additionalProps , buttonPossibleProps ) }
7384 >
74- { isFunction ( transformValue ) ? transformValue ( value , label , style ) : value }
85+ { isSlot ? null : ( isFunction ( transformValue ) ? transformValue ( value , label , style ) : value ) }
7586 </ Button >
76- { withLabels &&
87+ { ! isSlot && withLabels &&
7788 < div className = "block-editor-block-styles__item-label" >
7889 { label }
7990 </ div >
@@ -99,6 +110,7 @@ const SelectItemControl = ({
99110 { beforeItem }
100111 { recap && makeItem ( recapOptions ) }
101112 { map ( selectOptions , makeItem ) }
113+ { map ( missing , makeItem ) }
102114 { afterItem }
103115 </ ButtonGroup >
104116 </ ConditionalWrap >
0 commit comments