Skip to content

Commit ea5101e

Browse files
committed
fix: add rem support to allow custom mode to have values when switching, convert from rem if only has px support
1 parent 888ad9b commit ea5101e

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ const Layout = props => {
4040
label={ labelHeight }
4141
attribute={ getAttrName( 'height' ) }
4242
responsive="all"
43-
units={ [ 'px', 'vh' ] }
44-
min={ [ 0, 0 ] }
45-
sliderMax={ [ 1000, 100 ] }
46-
step={ [ 1, 1 ] }
43+
units={ [ 'px', 'rem', 'vh' ] }
44+
min={ [ 0, 0, 0 ] }
45+
sliderMax={ [ 1000, 60, 100 ] }
46+
step={ [ 1, 1, 1 ] }
4747
allowReset={ true }
4848
placeholder="0"
4949
helpTooltip={ {
@@ -155,10 +155,10 @@ const Spacing = props => {
155155
attribute={ getAttrName( 'padding' ) }
156156
responsive="all"
157157
hover="all"
158-
units={ [ 'px', 'em', '%' ] }
158+
units={ [ 'px', 'em', 'rem', '%' ] }
159159
defaultLocked={ true }
160-
min={ [ 0, 0, 0 ] }
161-
sliderMax={ [ 200, 30, 100 ] }
160+
min={ [ 0, 0, 0, 0 ] }
161+
sliderMax={ [ 200, 30, 30, 100 ] }
162162
helpTooltip={ {
163163
video: 'inner-block-padding',
164164
description: __( 'Sets the block paddings, i.e the space between the inner columns and the block border', i18n ),
@@ -174,10 +174,10 @@ const Spacing = props => {
174174
label={ labelMargins }
175175
attribute={ getAttrName( 'margin' ) }
176176
responsive="all"
177-
units={ [ 'px', '%' ] }
177+
units={ [ 'px', 'rem', '%' ] }
178178
defaultLocked={ false }
179-
sliderMin={ [ -200, -100 ] }
180-
sliderMax={ [ 200, 100 ] }
179+
sliderMin={ [ -200, -15, -100 ] }
180+
sliderMax={ [ 200, 15, 100 ] }
181181
placeholder="0"
182182
helpTooltip={ {
183183
video: 'advanced-block-margin',

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,14 @@ const AdvancedRangeControl = props => {
196196
}
197197
// Extract the unit and value.
198198
const markValue = props.marks[ value ]?.[ property ] || '0'
199-
const [ _newValue, unit ] = extractNumbersAndUnits( markValue )[ 0 ]
200-
const newValue = _newValue
199+
let [ newValue, unit ] = extractNumbersAndUnits( markValue )[ 0 ]
200+
201+
// If the attribute has no units (only support px), and the
202+
// preset units are rem or em, convert to px
203+
if ( ! hasUnits && ( unit === 'rem' || unit === 'em' ) ) {
204+
newValue = `${ parseFloat( newValue ) * 16 }`
205+
unit = 'px'
206+
}
201207

202208
// Update the unit.
203209
if ( unit ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const FourRangeControl = memo( props => {
327327
}
328328

329329
// We need to change the way we handle the value and onChange if we're doing marks
330-
let rangeValue = initialValue
330+
let rangeValue = props.hasCSSVariableValue ? parseFloat( initialValue ) : initialValue
331331
let rangeOnChange = initialOnChange
332332
if ( props.marks && isMarkMode ) {
333333
rangeValue = props.marks.findIndex( mark => {

0 commit comments

Comments
 (0)