Skip to content

Commit 31df0eb

Browse files
[docs][Slider] Add range slider example (#1600)
Signed-off-by: Zeeshan Tamboli <[email protected]> Co-authored-by: Albert Yu <[email protected]>
1 parent 5c11ddf commit 31df0eb

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.Control {
2+
box-sizing: border-box;
3+
display: flex;
4+
align-items: center;
5+
width: 14rem;
6+
padding-block: 0.75rem;
7+
touch-action: none;
8+
user-select: none;
9+
}
10+
11+
.Track {
12+
width: 100%;
13+
height: 0.25rem;
14+
background-color: var(--color-gray-200);
15+
box-shadow: inset 0 0 0 1px var(--color-gray-200);
16+
border-radius: 0.25rem;
17+
user-select: none;
18+
}
19+
20+
.Indicator {
21+
border-radius: 0.25rem;
22+
background-color: var(--color-gray-700);
23+
user-select: none;
24+
}
25+
26+
.Thumb {
27+
width: 1rem;
28+
height: 1rem;
29+
border-radius: 100%;
30+
background-color: white;
31+
outline: 1px solid var(--color-gray-300);
32+
user-select: none;
33+
34+
&:focus-visible {
35+
outline: 2px solid var(--color-blue);
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import { Slider } from '@base-ui-components/react/slider';
3+
import styles from './index.module.css';
4+
5+
export default function ExampleSlider() {
6+
return (
7+
<Slider.Root defaultValue={[25, 45]}>
8+
<Slider.Control className={styles.Control}>
9+
<Slider.Track className={styles.Track}>
10+
<Slider.Indicator className={styles.Indicator} />
11+
<Slider.Thumb className={styles.Thumb} />
12+
<Slider.Thumb className={styles.Thumb} />
13+
</Slider.Track>
14+
</Slider.Control>
15+
</Slider.Root>
16+
);
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use client';
2+
export { default as CssModules } from './css-modules';
3+
export { default as Tailwind } from './tailwind';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { Slider } from '@base-ui-components/react/slider';
3+
4+
export default function ExampleSlider() {
5+
return (
6+
<Slider.Root defaultValue={[25, 45]}>
7+
<Slider.Control className="flex w-56 touch-none items-center py-3 select-none">
8+
<Slider.Track className="h-1 w-full rounded bg-gray-200 shadow-[inset_0_0_0_1px] shadow-gray-200 select-none">
9+
<Slider.Indicator className="rounded bg-gray-700 select-none" />
10+
<Slider.Thumb className="size-4 rounded-full bg-white outline outline-1 outline-gray-300 select-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-blue-800" />
11+
<Slider.Thumb className="size-4 rounded-full bg-white outline outline-1 outline-gray-300 select-none focus-visible:outline focus-visible:outline-2 focus-visible:outline-blue-800" />
12+
</Slider.Track>
13+
</Slider.Control>
14+
</Slider.Root>
15+
);
16+
}

docs/src/app/(public)/(content)/react/components/slider/page.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ import { Slider } from '@base-ui-components/react/slider';
2727
```
2828

2929
<Reference component="Slider" parts="Root, Value, Control, Track, Indicator, Thumb" />
30+
31+
## Examples
32+
33+
### Range slider
34+
35+
To create a range slider, provide an array of values with corresponding thumbs:
36+
37+
<Demo compact path="./demos/range-slider" />

0 commit comments

Comments
 (0)