Skip to content

Commit 531c3f5

Browse files
fix(UX-1136): Update slider colours to match Figma designs (#402)
fix: Slider - Make rounded boolean toggle on Widgetbook fix: Slider - Make circle and square slider thumb the same size fix: Slider - Make active and inactive track same size --------- Co-authored-by: thelukewalton <[email protected]>
1 parent d84e09b commit 531c3f5

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

packages/zeta_flutter/lib/src/components/slider/slider.dart

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ class _ZetaSliderState extends State<ZetaSlider> {
7373
label: widget.semanticLabel,
7474
child: SliderTheme(
7575
data: SliderThemeData(
76-
// TODO(UX-1136): Match with new colors
77-
7876
/// Active Track
7977
activeTrackColor: _activeColor,
80-
disabledActiveTrackColor: colors.surfaceDisabled,
78+
disabledActiveTrackColor: colors.mainDisabled,
8179

8280
/// Inactive Track
83-
inactiveTrackColor: colors.surfaceInfoSubtle,
81+
inactiveTrackColor: colors.mainLight,
8482

8583
/// Ticks
86-
activeTickMarkColor: colors.surfaceDefault,
87-
inactiveTickMarkColor: colors.surfaceDefault,
84+
activeTickMarkColor: colors.mainInverse,
85+
inactiveTickMarkColor: colors.mainInverse,
86+
disabledActiveTickMarkColor: colors.mainInverse,
87+
disabledInactiveTickMarkColor: colors.mainInverse,
8888

8989
/// Thumb
90-
thumbColor: colors.surfaceDefaultInverse,
91-
disabledThumbColor: colors.surfaceDisabled,
90+
thumbColor: colors.mainDefault,
91+
disabledThumbColor: colors.mainDisabled,
9292
overlayShape: _SliderThumb(
9393
size: Zeta.of(context).spacing.xl / 2,
9494
rounded: context.rounded,
@@ -99,6 +99,7 @@ class _ZetaSliderState extends State<ZetaSlider> {
9999
rounded: context.rounded,
100100
color: _activeColor,
101101
),
102+
trackShape: context.rounded ? _RoundedRectangleTrackShape() : const RectangularSliderTrackShape(),
102103
),
103104
child: Slider(
104105
value: widget.value,
@@ -125,9 +126,9 @@ class _ZetaSliderState extends State<ZetaSlider> {
125126
Color get _activeColor {
126127
final colors = Zeta.of(context).colors;
127128
if (widget.onChange == null) {
128-
return colors.surfaceDisabled;
129+
return colors.mainDisabled;
129130
}
130-
return _selected ? colors.mainPrimary : colors.surfaceDefaultInverse;
131+
return _selected ? colors.mainPrimary : colors.mainDefault;
131132
}
132133
}
133134

@@ -175,6 +176,37 @@ class _SliderThumb extends SliderComponentShape {
175176
// draw icon with text painter
176177
rounded
177178
? canvas.drawCircle(center, size, paint)
178-
: canvas.drawRect(Rect.fromCenter(center: center, width: size, height: size), paint);
179+
: canvas.drawRect(Rect.fromCenter(center: center, width: size * 2, height: size * 2), paint);
180+
}
181+
}
182+
183+
class _RoundedRectangleTrackShape extends RoundedRectSliderTrackShape {
184+
@override
185+
void paint(
186+
PaintingContext context,
187+
Offset offset, {
188+
required RenderBox parentBox,
189+
Offset? secondaryOffset,
190+
required SliderThemeData sliderTheme,
191+
required Animation<double> enableAnimation,
192+
required TextDirection textDirection,
193+
required Offset thumbCenter,
194+
bool isDiscrete = false,
195+
bool isEnabled = false,
196+
double additionalActiveTrackHeight = 0,
197+
}) {
198+
super.paint(
199+
context,
200+
offset,
201+
parentBox: parentBox,
202+
secondaryOffset: secondaryOffset,
203+
sliderTheme: sliderTheme,
204+
enableAnimation: enableAnimation,
205+
textDirection: textDirection,
206+
thumbCenter: thumbCenter,
207+
isDiscrete: isDiscrete,
208+
isEnabled: isEnabled,
209+
additionalActiveTrackHeight: additionalActiveTrackHeight,
210+
);
179211
}
180212
}

widgetbook/lib/src/components/slider.widgetbook.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Widget sliderUseCase(BuildContext context) {
2020
value: value,
2121
divisions: context.knobs.intOrNull.slider(label: 'Divisions', min: 1, initialValue: 10),
2222
onChange: context.knobs.boolean(label: 'Disabled') ? null : (newValue) => setState(() => value = newValue),
23+
rounded: context.knobs.boolean(label: 'Rounded'),
2324
);
2425
},
2526
);

0 commit comments

Comments
 (0)