feat: animated slider
This commit is contained in:
@@ -22,6 +22,11 @@ type SliderProps = Omit<ComponentPropsWithoutRef<typeof RSlider.Root>, 'classNam
|
|||||||
notches?: NotchPlacement;
|
notches?: NotchPlacement;
|
||||||
/** Thumb shape. `'square'` (default) has a small border-radius; `'round'` is a full circle. */
|
/** Thumb shape. `'square'` (default) has a small border-radius; `'round'` is a full circle. */
|
||||||
knobStyle?: KnobStyle;
|
knobStyle?: KnobStyle;
|
||||||
|
/**
|
||||||
|
* Enable step-glide animation. Defaults to `true` when `marks` is set, `false` otherwise.
|
||||||
|
* Explicitly setting this always overrides the default.
|
||||||
|
*/
|
||||||
|
animated?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,6 +78,7 @@ export const Slider = ({
|
|||||||
marks,
|
marks,
|
||||||
notches = 'bottom',
|
notches = 'bottom',
|
||||||
knobStyle = 'square',
|
knobStyle = 'square',
|
||||||
|
animated,
|
||||||
min = 0,
|
min = 0,
|
||||||
max = 100,
|
max = 100,
|
||||||
step = 1,
|
step = 1,
|
||||||
@@ -84,10 +90,12 @@ export const Slider = ({
|
|||||||
const hasLabels = resolved.some((m) => m.label != null);
|
const hasLabels = resolved.some((m) => m.label != null);
|
||||||
const showTop = hasMarks && (notches === 'top' || notches === 'both');
|
const showTop = hasMarks && (notches === 'top' || notches === 'both');
|
||||||
const showBottom = hasMarks && (notches === 'bottom' || notches === 'both');
|
const showBottom = hasMarks && (notches === 'bottom' || notches === 'both');
|
||||||
|
const isAnimated = animated !== undefined ? animated : hasMarks;
|
||||||
|
|
||||||
const cls = [
|
const cls = [
|
||||||
'modern-sk-slider',
|
'modern-sk-slider',
|
||||||
`modern-sk-slider--knob-${knobStyle}`,
|
`modern-sk-slider--knob-${knobStyle}`,
|
||||||
|
isAnimated && 'modern-sk-slider--animated',
|
||||||
hasMarks && 'modern-sk-slider--has-marks',
|
hasMarks && 'modern-sk-slider--has-marks',
|
||||||
hasLabels && 'modern-sk-slider--has-labels',
|
hasLabels && 'modern-sk-slider--has-labels',
|
||||||
showTop && 'modern-sk-slider--notch-top',
|
showTop && 'modern-sk-slider--notch-top',
|
||||||
|
|||||||
@@ -626,8 +626,10 @@ textarea.modern-sk-field {
|
|||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
background: linear-gradient(90deg, var(--lime-deep), var(--lime));
|
background: linear-gradient(90deg, var(--lime-deep), var(--lime));
|
||||||
box-shadow: 0 0 10px rgba(190, 242, 100, 0.4);
|
box-shadow: 0 0 10px rgba(190, 242, 100, 0.4);
|
||||||
|
}
|
||||||
/* Radix positions the range via left/right offsets (not width); ease those
|
/* Radix positions the range via left/right offsets (not width); ease those
|
||||||
so the fill glides between discrete steps while dragging. */
|
so the fill glides between discrete steps while dragging. */
|
||||||
|
.modern-sk-slider--animated .modern-sk-slider__range {
|
||||||
transition:
|
transition:
|
||||||
left 0.12s ease-out,
|
left 0.12s ease-out,
|
||||||
right 0.12s ease-out;
|
right 0.12s ease-out;
|
||||||
@@ -647,12 +649,12 @@ textarea.modern-sk-field {
|
|||||||
/* Radix sets the step position (left) on a WRAPPER span around the thumb, not on
|
/* Radix sets the step position (left) on a WRAPPER span around the thumb, not on
|
||||||
the thumb element itself — so the transition must live on that wrapper. The
|
the thumb element itself — so the transition must live on that wrapper. The
|
||||||
wrapper is the slider's direct child span that isn't the track. */
|
wrapper is the slider's direct child span that isn't the track. */
|
||||||
.modern-sk-slider > span:not(.modern-sk-slider__track) {
|
.modern-sk-slider--animated > span:not(.modern-sk-slider__track) {
|
||||||
transition: left 0.12s ease-out;
|
transition: left 0.12s ease-out;
|
||||||
}
|
}
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
.modern-sk-slider > span:not(.modern-sk-slider__track),
|
.modern-sk-slider--animated > span:not(.modern-sk-slider__track),
|
||||||
.modern-sk-slider__range {
|
.modern-sk-slider--animated .modern-sk-slider__range {
|
||||||
transition: none;
|
transition: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user