Skip to content

Commit c957630

Browse files
committed
feat: add blockHeight and borderRadius
1 parent 01d221a commit c957630

File tree

7 files changed

+140
-45
lines changed

7 files changed

+140
-45
lines changed

src/block-components/helpers/borders/edit.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { Fragment } from '@wordpress/element'
1616
import { __ } from '@wordpress/i18n'
1717
import {
18-
useAttributeEditHandlers, useBlockLayoutDefaults, useBlockSetAttributesContext,
18+
useAttributeEditHandlers, useBlockLayoutDefaults, useBlockSetAttributesContext, usePresetControls,
1919
} from '~stackable/hooks'
2020
import { applyFilters } from '@wordpress/hooks'
2121

@@ -71,6 +71,8 @@ export const BorderControls = props => {
7171

7272
applyFilters( 'stackable.block-component.helpers.borders', null, getAttribute, updateAttributes )
7373

74+
const presetMarks = usePresetControls( 'borderRadius' )?.getPresetMarks() || null
75+
7476
return (
7577
<Fragment>
7678
{ props.hasBorderType &&
@@ -132,6 +134,8 @@ export const BorderControls = props => {
132134
isCorner={ true }
133135
sliderMax={ props.borderSliderMax }
134136
placeholder={ props.borderRadiusPlaceholder }
137+
marks={ presetMarks }
138+
hasCSSVariableValue={ true }
135139
/>
136140
}
137141
<ShadowControl

src/block-components/helpers/borders/style.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
3636
attrName: 'borderRadius2',
3737
key: 'borderTopLeftRadius2',
3838
attrNameTemplate,
39-
format: '%spx',
39+
valueCallback: value => {
40+
// Substitute with using format to work with preset controls
41+
value = typeof value === 'number' ? value.toString() : value
42+
if ( value.startsWith( 'var(--stk' ) ) {
43+
return value
44+
}
45+
return value + 'px'
46+
},
4047
responsive: 'all',
4148
hover: 'all',
4249
valuePreCallback: value => value?.top,
@@ -48,7 +55,13 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
4855
attrName: 'borderRadius2',
4956
key: 'borderTopRightRadius2',
5057
attrNameTemplate,
51-
format: '%spx',
58+
valueCallback: value => {
59+
value = typeof value === 'number' ? value.toString() : value
60+
if ( value.startsWith( 'var(--stk' ) ) {
61+
return value
62+
}
63+
return value + 'px'
64+
},
5265
responsive: 'all',
5366
hover: 'all',
5467
valuePreCallback: value => value?.right,
@@ -60,7 +73,13 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
6073
attrName: 'borderRadius2',
6174
key: 'borderBottomRightRadius2',
6275
attrNameTemplate,
63-
format: '%spx',
76+
valueCallback: value => {
77+
value = typeof value === 'number' ? value.toString() : value
78+
if ( value.startsWith( 'var(--stk' ) ) {
79+
return value
80+
}
81+
return value + 'px'
82+
},
6483
responsive: 'all',
6584
hover: 'all',
6685
valuePreCallback: value => value?.left,
@@ -72,7 +91,13 @@ export const addBorderStyles = ( blockStyleGenerator, props = {} ) => {
7291
attrName: 'borderRadius2',
7392
key: 'borderBottomLeftRadius2',
7493
attrNameTemplate,
75-
format: '%spx',
94+
valueCallback: value => {
95+
value = typeof value === 'number' ? value.toString() : value
96+
if ( value.startsWith( 'var(--stk' ) ) {
97+
return value
98+
}
99+
return value + 'px'
100+
},
76101
responsive: 'all',
77102
hover: 'all',
78103
valuePreCallback: value => value?.bottom,

src/block-components/helpers/size/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const sizeAttributes = {
22
height: {
33
stkResponsive: true,
44
stkUnits: 'px',
5-
type: 'number',
5+
type: 'string',
66
default: '',
77
},
88
width: {

src/block-components/helpers/size/edit.js

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,6 @@ import {
1717
import { __ } from '@wordpress/i18n'
1818
import { getAttributeNameFunc } from '~stackable/util'
1919

20-
const HEIGHT_PRESET = [
21-
{
22-
value: '64px',
23-
label: 'XS',
24-
},
25-
{
26-
value: '128px',
27-
label: 'S',
28-
},
29-
{
30-
value: '192px',
31-
label: 'M',
32-
},
33-
{
34-
value: '256px',
35-
label: 'L',
36-
},
37-
{
38-
value: '384px',
39-
label: 'XL',
40-
},
41-
{
42-
value: '512px',
43-
label: '2XL',
44-
},
45-
{
46-
value: '640px',
47-
label: '3XL',
48-
},
49-
{
50-
value: '100vh',
51-
label: 'Full',
52-
},
53-
]
54-
5520
const Layout = props => {
5621
const deviceType = useDeviceType()
5722

@@ -67,7 +32,7 @@ const Layout = props => {
6732
labelVerticalAlign = __( 'Content Vertical Align', i18n ),
6833
} = props.labels
6934

70-
const heightMarks = HEIGHT_PRESET
35+
const presetMarks = usePresetControls( 'blockHeights' )?.getPresetMarks() || null
7136

7237
return (
7338
<>
@@ -86,7 +51,8 @@ const Layout = props => {
8651
description: __( 'Adjusts the minimum allowable height of the block', i18n ),
8752
} }
8853
visualGuide={ props.visualGuide }
89-
marks={ heightMarks }
54+
marks={ presetMarks }
55+
hasCSSVariableValue={ true }
9056
/> }
9157

9258
{ props.hasContentVerticalAlign &&

src/hooks/use-preset-controls.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ const PRESET_MAPPING = {
1111
settings: [ 'spacing', 'spacingSizes' ],
1212
prefix: 'spacing-size',
1313
},
14+
blockHeights: {
15+
settings: [ 'blockHeights' ],
16+
prefix: 'block-height',
17+
},
18+
borderRadius: {
19+
settings: [ 'borderRadius' ],
20+
prefix: 'border-radius',
21+
},
1422
}
1523

1624
export const usePresetControls = property => {

src/plugins/global-settings/preset-controls/index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class Stackable_Size_And_Spacing_Preset_Controls {
2323
'settings' => array( 'spacing', 'spacingSizes' ),
2424
'prefix' => 'spacing-size',
2525
),
26+
'blockHeights' => array(
27+
'settings' => array( 'blockHeights' ),
28+
'prefix' => 'block-height',
29+
),
30+
'borderRadius' => array(
31+
'settings' => array( 'borderRadius' ),
32+
'prefix' => 'border-radius',
33+
),
2634
);
2735

2836
public $custom_presets;

src/plugins/global-settings/preset-controls/presets.json

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,90 @@
9292
"slug": "xxxxx-large"
9393
}
9494
]
95-
}
96-
}
95+
},
96+
"blockHeights": [
97+
{
98+
"name": "XS",
99+
"size": "4rem",
100+
"slug": "x-small"
101+
},
102+
{
103+
"name": "S",
104+
"size": "8rem",
105+
"slug": "small"
106+
},
107+
{
108+
"name": "M",
109+
"size": "12rem",
110+
"slug": "medium"
111+
},
112+
{
113+
"name": "L",
114+
"size": "16rem",
115+
"slug": "large"
116+
},
117+
{
118+
"name": "XL",
119+
"size": "24rem",
120+
"slug": "x-large"
121+
},
122+
{
123+
"name": "2XL",
124+
"size": "32rem",
125+
"slug": "xx-large"
126+
},
127+
{
128+
"name": "3XL",
129+
"size": "40rem",
130+
"slug": "xxx-large"
131+
},
132+
{
133+
"name": "Full",
134+
"size": "100vh",
135+
"slug": "full"
136+
}
137+
],
138+
"borderRadius": [
139+
{
140+
"name": "None",
141+
"size": "0px",
142+
"slug": "none"
143+
},
144+
{
145+
"name": "XS",
146+
"size": "2px",
147+
"slug": "x-small"
148+
},
149+
{
150+
"name": "S",
151+
"size": "4px",
152+
"slug": "small"
153+
},
154+
{
155+
"name": "M",
156+
"size": "8px",
157+
"slug": "medium"
158+
},
159+
{
160+
"name": "L",
161+
"size": "16px",
162+
"slug": "large"
163+
},
164+
{
165+
"name": "XL",
166+
"size": "24px",
167+
"slug": "x-large"
168+
},
169+
{
170+
"name": "2XL",
171+
"size": "32px",
172+
"slug": "xx-large"
173+
},
174+
{
175+
"name": "Full",
176+
"size": "9999px",
177+
"slug": "full"
178+
}
179+
]
180+
}
97181
}

0 commit comments

Comments
 (0)