Skip to content

Commit 01d221a

Browse files
committed
feat: add row and column gap
1 parent 754bfcb commit 01d221a

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/block-components/columns/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export const addAttributes = attrObject => {
99
},
1010
columnGap: {
1111
stkResponsive: true,
12-
type: 'number',
12+
type: 'string',
1313
default: '',
1414
},
1515
rowGap: {
1616
stkResponsive: true,
17-
type: 'number',
17+
type: 'string',
1818
default: '',
1919
},
2020
columnWrapDesktop: { // Only applies to desktops

src/block-components/columns/edit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
useBlockSetAttributesContext,
2424
useDeviceType,
2525
useBlockLayoutDefaults,
26+
usePresetControls,
2627
} from '~stackable/hooks'
2728
import { range } from 'lodash'
2829

@@ -124,6 +125,8 @@ export const Controls = props => {
124125
: deviceType === 'Tablet' ? ( attributes.columnArrangementTablet || defaultArrangement )
125126
: ( attributes.columnArrangementMobile || defaultArrangement )
126127

128+
const presetMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
129+
127130
return (
128131
<>
129132
{ props.hasColumnsControl && <ColumnsControl /> }
@@ -284,6 +287,8 @@ export const Controls = props => {
284287
video: 'column-gap',
285288
description: __( 'Sets the distance between two or more columns', i18n ),
286289
} }
290+
marks={ presetMarks }
291+
hasCSSVariableValue={ true }
287292
/>
288293
<AdvancedRangeControl
289294
label={ __( 'Row Gap', i18n ) }
@@ -296,6 +301,8 @@ export const Controls = props => {
296301
// TODO: Add a working video
297302
description: __( 'Sets the distance between two or more columns', i18n ),
298303
} }
304+
marks={ presetMarks }
305+
hasCSSVariableValue={ true }
299306
/>
300307
</>
301308
) }

src/block-components/columns/style.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,27 @@ export const addStyles = ( blockStyleGenerator, props = {} ) => {
3030
selector: '.%s-column',
3131
styleRule: '--stk-column-gap',
3232
attrName: 'columnGap',
33-
format: '%spx',
3433
responsive: 'all',
34+
valueCallback: value => {
35+
// Substitute with using format to work with preset controls
36+
if ( value.startsWith( 'var(--stk' ) ) {
37+
return value
38+
}
39+
return value + 'px'
40+
},
3541
}, {
3642
...propsToPass,
3743
renderIn: 'edit',
3844
selector: '.%s-column > .block-editor-inner-blocks > .block-editor-block-list__layout',
3945
styleRule: '--stk-column-gap',
4046
attrName: 'columnGap',
41-
format: '%spx',
4247
responsive: 'all',
48+
valueCallback: value => {
49+
if ( value.startsWith( 'var(--stk' ) ) {
50+
return value
51+
}
52+
return value + 'px'
53+
},
4354
} ] )
4455

4556
blockStyleGenerator.addBlockStyles( 'columnWrapDesktop', [ {
@@ -78,16 +89,26 @@ export const addStyles = ( blockStyleGenerator, props = {} ) => {
7889
selector: '.%s-column',
7990
styleRule: 'rowGap',
8091
attrName: 'rowGap',
81-
format: '%spx',
8292
responsive: 'all',
93+
valueCallback: value => {
94+
if ( value.startsWith( 'var(--stk' ) ) {
95+
return value
96+
}
97+
return value + 'px'
98+
},
8399
}, {
84100
...propsToPass,
85101
renderIn: 'edit',
86102
selector: '.%s-column > .block-editor-inner-blocks > .block-editor-block-list__layout',
87103
styleRule: 'rowGap',
88104
attrName: 'rowGap',
89-
format: '%spx',
90105
responsive: 'all',
106+
valueCallback: value => {
107+
if ( value.startsWith( 'var(--stk' ) ) {
108+
return value
109+
}
110+
return value + 'px'
111+
},
91112
} ] )
92113
}
93114

0 commit comments

Comments
 (0)