Skip to content

Commit d0b7cba

Browse files
committed
feat: add vertical/horizontal to mark mode for four range
1 parent 962b841 commit d0b7cba

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

src/block-components/button/edit.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
AdvancedSelectControl,
1313
} from '~stackable/components'
1414
import { i18n } from 'stackable'
15-
import { useBlockAttributesContext, useBlockLayoutDefaults } from '~stackable/hooks'
15+
import {
16+
useBlockAttributesContext, useBlockLayoutDefaults, usePresetControls,
17+
} from '~stackable/hooks'
1618

1719
/**
1820
* WordPress dependencies
@@ -185,6 +187,9 @@ const SizeControls = props => {
185187
const { getPlaceholder } = useBlockLayoutDefaults()
186188

187189
const buttonPaddingPlaceholder = getPlaceholder( paddingPlaceholderName, { single: false } )
190+
191+
const presetMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
192+
188193
return ( <>
189194
{ props.hasFullWidth && (
190195
<AdvancedToggleControl
@@ -228,6 +233,8 @@ const SizeControls = props => {
228233
title: __( 'Button padding', i18n ),
229234
description: __( 'Adjusts the space between the button text and button borders', i18n ),
230235
} }
236+
marks={ presetMarks }
237+
hasCSSVariableValue={ true }
231238
/>
232239
</> )
233240
}

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ const FourRangeControl = memo( props => {
347347
]
348348
}
349349

350+
// Create step supports for each side
350351
const [ propsToPassFirst, rangeValueFirst, rangeOnChangeFirst ] = stepSupport(
351352
isFourMarkMode.first,
352353
firstValue,
@@ -377,6 +378,18 @@ const FourRangeControl = memo( props => {
377378
onChangeLeft,
378379
)
379380

381+
const [ propsToPassVertical, rangeValueVertical, rangeOnChangeVertical ] = stepSupport(
382+
isFourMarkMode.top,
383+
value.top,
384+
onChangeVertical,
385+
)
386+
387+
const [ propsToPassHorizontal, rangeValueHorizontal, rangeOnChangeHorizontal ] = stepSupport(
388+
isFourMarkMode.left,
389+
value.left,
390+
onChangeHorizontal,
391+
)
392+
380393
return (
381394
<AdvancedControl { ...controlProps }>
382395
{ isLocked && ! props.vhMode && (
@@ -442,9 +455,9 @@ const FourRangeControl = memo( props => {
442455
<span className="ugb-four-range-control__icon"><SVGVerticalImage /></span>
443456
</Tooltip>
444457
<RangeControl
445-
{ ...propsToPass }
446-
value={ value.top }
447-
onChange={ onChangeVertical }
458+
{ ...propsToPassVertical }
459+
value={ rangeValueVertical }
460+
onChange={ rangeOnChangeVertical }
448461
allowReset={ false }
449462
initialPosition={ ( () => {
450463
if ( currentHoverState !== 'normal' ) {
@@ -472,7 +485,21 @@ const FourRangeControl = memo( props => {
472485

473486
return typeof props.placeholderTop === 'undefined' ? propsToPass.placeholder : props.placeholderTop
474487
} )() }
475-
/>
488+
__nextHasNoMarginBottom
489+
>
490+
{ props.allowCustom && props.marks && (
491+
<Button
492+
className="stk-range-control__custom-button"
493+
size="small"
494+
variant="tertiary"
495+
onClick={ () => setIsFourMarkMode( prev => {
496+
return { ...prev, top: ! prev.top }
497+
} ) }
498+
icon={ settings }
499+
>
500+
</Button>
501+
) }
502+
</RangeControl>
476503
<ResetButton
477504
allowReset={ props.allowReset }
478505
value={ value.top }
@@ -485,9 +512,9 @@ const FourRangeControl = memo( props => {
485512
<span className="ugb-four-range-control__icon"><SVGHorizontalImage /></span>
486513
</Tooltip>
487514
<RangeControl
488-
{ ...propsToPass }
489-
value={ value.left }
490-
onChange={ onChangeHorizontal }
515+
{ ...propsToPassHorizontal }
516+
value={ rangeValueHorizontal }
517+
onChange={ rangeOnChangeHorizontal }
491518
allowReset={ false }
492519
initialPosition={ ( () => {
493520
if ( currentHoverState !== 'normal' ) {
@@ -514,7 +541,21 @@ const FourRangeControl = memo( props => {
514541
}
515542
return typeof props.placeholderLeft === 'undefined' ? propsToPass.placeholder : props.placeholderLeft
516543
} )() }
517-
/>
544+
__nextHasNoMarginBottom
545+
>
546+
{ props.allowCustom && props.marks && (
547+
<Button
548+
className="stk-range-control__custom-button"
549+
size="small"
550+
variant="tertiary"
551+
onClick={ () => setIsFourMarkMode( prev => {
552+
return { ...prev, left: ! prev.left }
553+
} ) }
554+
icon={ settings }
555+
>
556+
</Button>
557+
) }
558+
</RangeControl>
518559
<ResetButton
519560
allowReset={ props.allowReset }
520561
value={ value.left }

0 commit comments

Comments
 (0)