Skip to content

Commit 98e95e7

Browse files
committed
✨ Add disabled state to sliders
1 parent 6a386ef commit 98e95e7

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ html body {
132132
--w-scrollbar-bg: var(--w-color-primary-60);
133133
--w-scrollbar-fg: var(--w-color-primary-50);
134134

135+
// Slider component
136+
--w-slider-background: var(--w-color-primary-50);
137+
--w-slider-color: var(--w-color-primary);
138+
--w-slider-thumb: var(--w-color-primary-50);
139+
135140
// Spinner component
136141
--w-spinner-color: var(--w-color-primary);
137142
--w-spinner-width: 2px;

src/components/Slider/Slider.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
max,
1212
value,
1313
step,
14+
disabled,
1415
color,
1516
background,
1617
thumb,
@@ -36,6 +37,7 @@ const styleVariables = classNames([
3637
max={max}
3738
value={value || min}
3839
step={step}
40+
disabled={disabled}
3941
class:list={classes}
4042
id={id}
4143
style={styleVariables}

src/components/Slider/Slider.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export let max: SvelteSliderProps['max'] = 100
99
export let value: SvelteSliderProps['value'] = 0
1010
export let step: SvelteSliderProps['step'] = 1
11+
export let disabled: SvelteSliderProps['disabled'] = false
1112
export let color: SvelteSliderProps['color'] = ''
1213
export let background: SvelteSliderProps['background'] = ''
1314
export let thumb: SvelteSliderProps['thumb'] = ''
@@ -33,8 +34,9 @@
3334
max={max}
3435
value={value || min}
3536
step={step}
37+
disabled={disabled}
3638
class={classes}
37-
id={id}
38-
style={styleVariables}
39+
id={id || null}
40+
style={styleVariables || null}
3941
on:change={onChange}
4042
/>

src/components/Slider/Slider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Slider = ({
99
max,
1010
value,
1111
step,
12+
disabled,
1213
color,
1314
background,
1415
thumb,
@@ -34,6 +35,7 @@ const Slider = ({
3435
max={max}
3536
defaultValue={value || min}
3637
step={step}
38+
disabled={disabled}
3739
className={classes}
3840
id={id}
3941
style={styleVariables}

src/components/Slider/slider.module.scss

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ body {
1616
-webkit-appearance: none;
1717
appearance: none;
1818
cursor: pointer;
19+
20+
&[disabled]::-webkit-slider-runnable-track {
21+
@include background(primary-50);
22+
}
23+
24+
&[disabled]::-moz-range-track {
25+
@include background(primary-50);
26+
}
27+
28+
&[disabled]::-webkit-slider-thumb {
29+
@include background(primary-50);
30+
@include border(primary-30);
31+
box-shadow: -995px 0 0 990px var(--w-color-primary-30);
32+
}
33+
34+
&[disabled]::-moz-range-thumb {
35+
@include background(primary-50);
36+
@include border(primary-30);
37+
box-shadow: -995px 0 0 990px var(--w-color-primary-30);
38+
}
1939
}
2040

2141
.slider::-webkit-slider-runnable-track {
@@ -35,7 +55,7 @@ body {
3555

3656
-webkit-appearance: none;
3757
appearance: none;
38-
box-shadow: -405px 0 0 400px var(--w-slider-color);
58+
box-shadow: -995px 0 0 990px var(--w-slider-color);
3959
}
4060

4161
.slider::-moz-range-thumb {
@@ -44,5 +64,5 @@ body {
4464
@include border-radius(max);
4565
@include border(var(--w-slider-color));
4666

47-
box-shadow: -405px 0 0 400px var(--w-slider-color);
67+
box-shadow: -995px 0 0 990px var(--w-slider-color);
4868
}

src/components/Slider/slider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ export type SliderProps = {
33
max: number
44
value?: number
55
step?: number
6-
id?: string
6+
disabled?: boolean
77
color?: string
88
background?: string
99
thumb?: string
10+
id?: string
1011
className?: string
1112
}
1213

src/pages/slider.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ const sections = getSections({
8686
className="labelled1"
8787
/>
8888
</ComponentWrapper>
89+
90+
<ComponentWrapper title="Disabled">
91+
<section.component
92+
min={0}
93+
max={100}
94+
value={40}
95+
disabled={true}
96+
/>
97+
</ComponentWrapper>
8998
</div>
9099
))}
91100
</Layout>
@@ -101,5 +110,4 @@ const sections = getSections({
101110
slider2?.addEventListener('change', (e: any) => {
102111
e.target.previousElementSibling.innerText = e.target.value
103112
})
104-
105113
</script>

0 commit comments

Comments
 (0)