Skip to content

Commit f74c488

Browse files
committed
fix: FourRangeControl synchronization of markmode; default markmode
1 parent 558d0fe commit f74c488

File tree

1 file changed

+32
-25
lines changed
  • src/components/four-range-control

1 file changed

+32
-25
lines changed

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

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const FourRangeControl = memo( props => {
204204
bottom: !! props.marks,
205205
left: !! props.marks,
206206
}
207-
if ( props.marks && value ) {
207+
if ( props.marks && firstValue ) {
208208
// Check if the current value exsits in the marks
209209
const marksUnit = ( props.hasCSSVariableValue ? '' : unit )
210210
isMarkValue.first = isMarkValue.first && props.marks.some( mark => mark.value === firstValue + marksUnit )
@@ -222,6 +222,13 @@ const FourRangeControl = memo( props => {
222222
bottom: props.enableBottom ? newValue : value.bottom,
223223
left: props.enableLeft ? newValue : value.left,
224224
} )
225+
setIsFourMarkMode( prev => ( {
226+
...prev,
227+
top: prev.first,
228+
right: prev.first,
229+
bottom: prev.first,
230+
left: prev.first,
231+
} ) )
225232
}
226233

227234
const onChangeTop = newValue => {
@@ -231,6 +238,7 @@ const FourRangeControl = memo( props => {
231238
bottom: value.bottom,
232239
left: value.left,
233240
} )
241+
setIsFourMarkMode( prev => ( { ...prev, first: prev.top } ) )
234242
}
235243

236244
const onChangeRight = newValue => {
@@ -240,6 +248,7 @@ const FourRangeControl = memo( props => {
240248
bottom: value.bottom,
241249
left: value.left,
242250
} )
251+
setIsFourMarkMode( prev => ( { ...prev, first: prev.right } ) )
243252
}
244253

245254
const onChangeBottom = newValue => {
@@ -249,6 +258,7 @@ const FourRangeControl = memo( props => {
249258
bottom: newValue,
250259
left: value.left,
251260
} )
261+
setIsFourMarkMode( prev => ( { ...prev, first: prev.bottom } ) )
252262
}
253263

254264
const onChangeLeft = newValue => {
@@ -258,6 +268,7 @@ const FourRangeControl = memo( props => {
258268
bottom: value.bottom,
259269
left: newValue,
260270
} )
271+
setIsFourMarkMode( prev => ( { ...prev, first: prev.left } ) )
261272
}
262273

263274
const onChangeVertical = newValue => {
@@ -267,6 +278,11 @@ const FourRangeControl = memo( props => {
267278
bottom: newValue,
268279
left: value.left,
269280
} )
281+
setIsFourMarkMode( prev => ( {
282+
...prev,
283+
top: prev.top,
284+
bottom: prev.top,
285+
} ) )
270286
}
271287

272288
const onChangeHorizontal = newValue => {
@@ -276,6 +292,11 @@ const FourRangeControl = memo( props => {
276292
bottom: value.bottom,
277293
left: newValue,
278294
} )
295+
setIsFourMarkMode( prev => ( {
296+
...prev,
297+
right: prev.right,
298+
left: prev.right,
299+
} ) )
279300
}
280301
// Support for steps. Modify the props to make the range control show steps.
281302
const stepSupport = ( isMarkMode, initialValue, initialOnChange ) => {
@@ -351,7 +372,7 @@ const FourRangeControl = memo( props => {
351372
controlProps.units = isFourMarkMode.first
352373
? false : controlProps.units
353374
} else if ( isLocked && props.vhMode ) {
354-
controlProps.units = isFourMarkMode.top && isFourMarkMode.left
375+
controlProps.units = isFourMarkMode.top && isFourMarkMode.right
355376
? false : controlProps.units
356377
} else {
357378
controlProps.units = isFourMarkMode.top && isFourMarkMode.right && isFourMarkMode.bottom && isFourMarkMode.left
@@ -396,8 +417,8 @@ const FourRangeControl = memo( props => {
396417
)
397418

398419
const [ propsToPassHorizontal, rangeValueHorizontal, rangeOnChangeHorizontal ] = stepSupport(
399-
isFourMarkMode.left,
400-
value.left,
420+
isFourMarkMode.right,
421+
value.right,
401422
onChangeHorizontal,
402423
)
403424

@@ -443,9 +464,7 @@ const FourRangeControl = memo( props => {
443464
className="stk-range-control__custom-button"
444465
size="small"
445466
variant="tertiary"
446-
onClick={ () => setIsFourMarkMode( prev => {
447-
return { ...prev, first: ! prev.first }
448-
} ) }
467+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, first: ! prev.first } ) ) }
449468
icon={ settings }
450469
>
451470
</Button>
@@ -503,9 +522,7 @@ const FourRangeControl = memo( props => {
503522
className="stk-range-control__custom-button"
504523
size="small"
505524
variant="tertiary"
506-
onClick={ () => setIsFourMarkMode( prev => {
507-
return { ...prev, top: ! prev.top }
508-
} ) }
525+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, top: ! prev.top } ) ) }
509526
icon={ settings }
510527
>
511528
</Button>
@@ -559,9 +576,7 @@ const FourRangeControl = memo( props => {
559576
className="stk-range-control__custom-button"
560577
size="small"
561578
variant="tertiary"
562-
onClick={ () => setIsFourMarkMode( prev => {
563-
return { ...prev, left: ! prev.left }
564-
} ) }
579+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, left: ! prev.left } ) ) }
565580
icon={ settings }
566581
>
567582
</Button>
@@ -621,9 +636,7 @@ const FourRangeControl = memo( props => {
621636
className="stk-range-control__custom-button"
622637
size="small"
623638
variant="tertiary"
624-
onClick={ () => setIsFourMarkMode( prev => {
625-
return { ...prev, top: ! prev.top }
626-
} ) }
639+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, top: ! prev.top } ) ) }
627640
icon={ settings }
628641
>
629642
</Button>
@@ -680,9 +693,7 @@ const FourRangeControl = memo( props => {
680693
className="stk-range-control__custom-button"
681694
size="small"
682695
variant="tertiary"
683-
onClick={ () => setIsFourMarkMode( prev => {
684-
return { ...prev, right: ! prev.right }
685-
} ) }
696+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, right: ! prev.right } ) ) }
686697
icon={ settings }
687698
>
688699
</Button>
@@ -739,9 +750,7 @@ const FourRangeControl = memo( props => {
739750
className="stk-range-control__custom-button"
740751
size="small"
741752
variant="tertiary"
742-
onClick={ () => setIsFourMarkMode( prev => {
743-
return { ...prev, bottom: ! prev.bottom }
744-
} ) }
753+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, bottom: ! prev.bottom } ) ) }
745754
icon={ settings }
746755
>
747756
</Button>
@@ -798,9 +807,7 @@ const FourRangeControl = memo( props => {
798807
className="stk-range-control__custom-button"
799808
size="small"
800809
variant="tertiary"
801-
onClick={ () => setIsFourMarkMode( prev => {
802-
return { ...prev, left: ! prev.left }
803-
} ) }
810+
onClick={ () => setIsFourMarkMode( prev => ( { ...prev, left: ! prev.left } ) ) }
804811
icon={ settings }
805812
>
806813
</Button>

0 commit comments

Comments
 (0)