Skip to content

Commit 811e0b2

Browse files
committed
feat: apply preset controls to fontSize, padding, margin, height
1 parent 53ec598 commit 811e0b2

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,77 @@ import { useAttributeEditHandlers, useDeviceType } from '~stackable/hooks'
1414
*/
1515
import { __ } from '@wordpress/i18n'
1616
import { getAttributeNameFunc } from '~stackable/util'
17+
import { useSetting } from '@wordpress/block-editor'
18+
19+
const HEIGHT_PRESET = [
20+
{
21+
value: '64px',
22+
label: 'XS',
23+
},
24+
{
25+
value: '128px',
26+
label: 'S',
27+
},
28+
{
29+
value: '192px',
30+
label: 'M',
31+
},
32+
{
33+
value: '256px',
34+
label: 'L',
35+
},
36+
{
37+
value: '384px',
38+
label: 'XL',
39+
},
40+
{
41+
value: '512px',
42+
label: '2XL',
43+
},
44+
{
45+
value: '640px',
46+
label: '3XL',
47+
},
48+
{
49+
value: '100vh',
50+
label: 'Full',
51+
},
52+
]
53+
54+
const SPACING_PRESET = [
55+
{
56+
label: 'XS',
57+
value: '4px',
58+
},
59+
{
60+
label: 'S',
61+
value: '8px',
62+
},
63+
{
64+
label: 'M',
65+
value: '16px',
66+
},
67+
{
68+
label: 'L',
69+
value: '24px',
70+
},
71+
{
72+
label: 'XL',
73+
value: '32px',
74+
},
75+
{
76+
label: '2XL',
77+
value: '48px',
78+
},
79+
{
80+
label: '3XL',
81+
value: '64px',
82+
},
83+
{
84+
label: '4XL',
85+
value: '96px',
86+
},
87+
]
1788

1889
const Layout = props => {
1990
const deviceType = useDeviceType()
@@ -30,6 +101,8 @@ const Layout = props => {
30101
labelVerticalAlign = __( 'Content Vertical Align', i18n ),
31102
} = props.labels
32103

104+
const heightMarks = HEIGHT_PRESET
105+
33106
return (
34107
<>
35108
{ props.hasMinHeight && <AdvancedRangeControl
@@ -47,6 +120,7 @@ const Layout = props => {
47120
description: __( 'Adjusts the minimum allowable height of the block', i18n ),
48121
} }
49122
visualGuide={ props.visualGuide }
123+
marks={ heightMarks }
50124
/> }
51125

52126
{ props.hasContentVerticalAlign &&
@@ -132,6 +206,15 @@ const Spacing = props => {
132206
...props.visualGuide,
133207
highlight: 'margin',
134208
}
209+
let spacingMarks = SPACING_PRESET
210+
const spacingSizes = useSetting( 'spacing.spacingSizes' )
211+
212+
if ( Array.isArray( spacingSizes ) && spacingSizes.length > 0 ) {
213+
spacingMarks = spacingSizes.map( size => ( {
214+
value: size.size,
215+
label: size.name,
216+
} ) )
217+
}
135218

136219
return (
137220
<>
@@ -150,6 +233,7 @@ const Spacing = props => {
150233
} }
151234
visualGuide={ paddingVisualGuide }
152235
placeholder={ props.paddingPlaceholder }
236+
marks={ spacingMarks }
153237
/>
154238

155239
{ props.enableMargin &&
@@ -167,6 +251,7 @@ const Spacing = props => {
167251
description: __( 'Sets the block margin, i.e. the space outside the block between the block border and the next block.', i18n ),
168252
} }
169253
visualGuide={ marginVisualGuide }
254+
marks={ spacingMarks }
170255
/>
171256
}
172257
</>

src/block-components/typography/edit.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from '@wordpress/element'
3131
import { __ } from '@wordpress/i18n'
3232
import { applyFilters } from '@wordpress/hooks'
33+
import { useSelect } from '@wordpress/data'
3334

3435
const TYPOGRAPHY_SHADOWS = [
3536
'none',
@@ -57,6 +58,45 @@ const GRADIENT_OPTIONS = [
5758
},
5859
]
5960

61+
const SIZE_PRESET = [
62+
{
63+
value: '0.75rem',
64+
label: 'XS',
65+
},
66+
{
67+
value: '0.875rem',
68+
label: 'S',
69+
},
70+
{
71+
value: '1rem',
72+
label: 'M',
73+
},
74+
{
75+
value: '1.125rem',
76+
label: 'L',
77+
},
78+
{
79+
value: '1.5rem',
80+
label: 'XL',
81+
},
82+
{
83+
value: '2rem',
84+
label: '2XL',
85+
},
86+
{
87+
value: '2.5rem',
88+
label: '3XL',
89+
},
90+
{
91+
value: '3rem',
92+
label: '4XL',
93+
},
94+
{
95+
value: '4rem',
96+
label: '5XL',
97+
},
98+
]
99+
60100
export const Controls = props => {
61101
const {
62102
hasAlign,
@@ -100,6 +140,15 @@ export const Controls = props => {
100140

101141
const onChangeContent = useCallback( text => setDebouncedText( escapeHTMLIfInvalid( text ) ), [] )
102142

143+
const themeSettings = useSelect( select => select( 'core/block-editor' ).getSettings(), [] )
144+
let sizeMarks = SIZE_PRESET
145+
if ( Array.isArray( themeSettings?.fontSizes ) && themeSettings.fontSizes.length > 0 ) {
146+
sizeMarks = themeSettings.fontSizes.map( size => ( {
147+
value: size.size,
148+
label: size.name,
149+
} ) )
150+
}
151+
103152
return (
104153
<>
105154
{ applyFilters( 'stackable.block-component.typography.before', null, props ) }
@@ -269,6 +318,7 @@ export const Controls = props => {
269318
title: __( 'Font size', i18n ),
270319
description: __( 'Sets the size of text characters', i18n ),
271320
} }
321+
marks={ sizeMarks }
272322
/>
273323

274324
{ hasColor && (

0 commit comments

Comments
 (0)