Skip to content

Commit fccd644

Browse files
added 'fillMissing' prop for 'SelectItemControl' component
1 parent fd15a93 commit fccd644

6 files changed

Lines changed: 32 additions & 10 deletions

File tree

dist/zukit-blocks.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zukit-blocks.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zukit.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zukit.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sass/components/_select-item-control.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ $select-item-basic-border-color: rgb(25, 30, 35);
8080
color: $select-item-disabled-color;
8181
}
8282
}
83+
&.is-slot {
84+
.components-button {
85+
width: 100%;
86+
height: 100%;
87+
pointer-events: none;
88+
background-color: transparent;
89+
border-color: rgba($wp-gray-200, 0.4);
90+
color: transparent;
91+
}
92+
}
8393

8494
@include in('<.__2columns') { width: calc(50% - #{twice($admin-button-wrapper-padding)}); }
8595
@include in('<.__3columns') { width: calc(33% - #{twice($admin-button-wrapper-padding)}); }

src/scripts/components/select-item-control.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)