Skip to content

Commit 20e53a1

Browse files
committed
Merge branch 'develop' into fix/3504-responsive-typescale
2 parents 4973b69 + 05d4066 commit 20e53a1

File tree

13 files changed

+44
-49
lines changed

13 files changed

+44
-49
lines changed

src/block-components/alignment/edit.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ export const Edit = memo( props => {
8787
enableContentAlign = true,
8888
} = props
8989

90-
const blockHeightMarks = usePresetControls( 'blockHeights' )?.getPresetMarks() || null
91-
const spacingSizeMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
90+
const blockHeightMarks = usePresetControls( 'blockHeights' )
91+
?.getPresetMarks( { addNonePreset: true } ) || null
92+
const spacingSizeMarks = usePresetControls( 'spacingSizes' )
93+
?.getPresetMarks( { addNonePreset: true } ) || null
9294

9395
const containerSize = props.hasContainerSize && <>
9496
<ControlSeparator />

src/block-components/button/edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ const SizeControls = props => {
188188

189189
const buttonPaddingPlaceholder = getPlaceholder( paddingPlaceholderName, { single: false } )
190190

191-
const presetMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
191+
const presetMarks = usePresetControls( 'spacingSizes' )
192+
?.getPresetMarks( { addNonePreset: true } ) || null
192193

193194
return ( <>
194195
{ props.hasFullWidth && (

src/block-components/columns/edit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export const Controls = props => {
125125
: deviceType === 'Tablet' ? ( attributes.columnArrangementTablet || defaultArrangement )
126126
: ( attributes.columnArrangementMobile || defaultArrangement )
127127

128-
const presetMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
129-
128+
const presetMarks = usePresetControls( 'spacingSizes' )
129+
?.getPresetMarks( { addNonePreset: true } ) || null
130130
return (
131131
<>
132132
{ props.hasColumnsControl && <ColumnsControl /> }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +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
74+
const presetMarks = usePresetControls( 'borderRadius' )
75+
?.getPresetMarks( { addNonePreset: true } ) || null
7576

7677
return (
7778
<Fragment>

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const Layout = props => {
3232
labelVerticalAlign = __( 'Content Vertical Align', i18n ),
3333
} = props.labels
3434

35-
const presetMarks = usePresetControls( 'blockHeights' )?.getPresetMarks() || null
35+
const presetMarks = usePresetControls( 'blockHeights' )
36+
?.getPresetMarks( { addNonePreset: true } ) || null
3637

3738
return (
3839
<>
@@ -139,13 +140,8 @@ const Spacing = props => {
139140
}
140141

141142
// Add additional presets for setting margins and paddings to None
142-
const nonePreset = {
143-
name: __( 'None', i18n ),
144-
size: '0rem',
145-
slug: 'none',
146-
}
147143
const presetMarks = usePresetControls( 'spacingSizes' )
148-
?.getPresetMarks( { additionalPresets: [ nonePreset ] } ) || null
144+
?.getPresetMarks( { addNonePreset: true } ) || null
149145

150146
return (
151147
<>

src/block/column/edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ const Edit = props => {
164164
// props used by controls to prevent rerenders of all the inspector controls.
165165
const InspectorControls = memo( props => {
166166
const { getPlaceholder } = useBlockLayoutDefaults()
167-
const presets = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
167+
const presets = usePresetControls( 'spacingSizes' )
168+
?.getPresetMarks( { addNonePreset: true } ) || null
168169

169170
return (
170171
<>

src/components/advanced-range-control/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ const AdvancedRangeControl = props => {
216216
}
217217
return _value === derivedValue && ( _unit === '' || _unit === unit )
218218
} )
219+
rangeValue = rangeValue === -1 ? '' : rangeValue
220+
219221
rangeOnChange = ( value, property = 'value' ) => {
220222
if ( value === '' ) {
221223
return _onChange( value )

src/components/font-size-control/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { __ } from '@wordpress/i18n'
1010
import { i18n } from 'stackable'
1111

1212
const FontSizeControl = props => {
13-
let passedPlaceholder = props.placeholder
13+
const passedPlaceholder = props.placeholder
1414

1515
const pxToEm = ( value = '', baseValue = 21 ) => {
1616
if ( value === '' ) {
@@ -28,11 +28,6 @@ const FontSizeControl = props => {
2828
return Math.round( parseFloat( value ) * baseValue )
2929
}
3030

31-
if ( typeof passedPlaceholder === 'string' ) {
32-
// Add a converted EM unit whenever the user changes the unit.
33-
passedPlaceholder = [ passedPlaceholder, pxToEm( passedPlaceholder ) ]
34-
}
35-
3631
return (
3732
<AdvancedRangeControl
3833
{ ...props }

src/components/four-range-control/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ const FourRangeControl = memo( props => {
381381
}
382382
return _value === initialValue && ( _unit === '' || _unit === unit )
383383
} )
384+
rangeValue = rangeValue === -1 ? '' : rangeValue
384385
rangeOnChange = ( value, property = 'value' ) => {
385386
if ( value === '' ) {
386387
return initialOnChange( value )

src/hooks/use-preset-controls.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { i18n } from 'stackable'
2+
import DEFAULT_PRESETS from '~stackable/plugins/global-settings/preset-controls/presets.json'
13
import { useSettings } from '@wordpress/block-editor'
24
import { useSelect } from '@wordpress/data'
3-
import DEFAULT_PRESETS from '~stackable/plugins/global-settings/preset-controls/presets.json'
5+
import { __ } from '@wordpress/i18n'
46

57
const PRESET_MAPPING = {
68
fontSizes: {
@@ -21,6 +23,12 @@ const PRESET_MAPPING = {
2123
},
2224
}
2325

26+
const nonePreset = {
27+
name: __( 'None', i18n ),
28+
size: '0px',
29+
slug: 'none',
30+
}
31+
2432
export const usePresetControls = property => {
2533
// Get the theme presets for the property
2634
const [ themePresets ] = useSettings( PRESET_MAPPING[ property ].settings.join( '.' ) )
@@ -56,10 +64,12 @@ export const usePresetControls = property => {
5664

5765
// Get the merge preset marks with the CSS Variable value
5866
// Setting customOnly to true returns the preset marks for custom presets only
59-
const getPresetMarks = ( { customOnly = false, additionalPresets = [] } = {} ) => {
67+
// Setting addNonePreset to true adds a none preset with a value of 0
68+
const getPresetMarks = ( { customOnly = false, addNonePreset = false } = {} ) => {
6069
const prefix = PRESET_MAPPING[ property ].prefix
6170
let presets = customOnly ? allCustomPresets[ property ] ?? [] : getMergedPresets()
62-
presets = [ ...additionalPresets, ...presets ]
71+
// Add the none preset
72+
presets = [ ...( addNonePreset ? [ nonePreset ] : [] ), ...presets ]
6373

6474
return presets
6575
.filter( preset => ! ( preset?.isDiscarded ) )

0 commit comments

Comments
 (0)