|
| 1 | +# Slider |
| 2 | + |
| 3 | +### Intro |
| 4 | + |
| 5 | +Used to select a value within a given range. |
| 6 | + |
| 7 | +### Install |
| 8 | + |
| 9 | +```tsx |
| 10 | +import { Slider } from "@quarkd/quark-react"; |
| 11 | +``` |
| 12 | + |
| 13 | +### Basic Usage |
| 14 | + |
| 15 | +```html |
| 16 | +<Slider value="50"></Slider> |
| 17 | +``` |
| 18 | + |
| 19 | +### Dual Thumb |
| 20 | + |
| 21 | +Add `range` attribute to enable dual thumb mode. Make sure `value` is an array. |
| 22 | + |
| 23 | +```html |
| 24 | +<Slider value="[20, 60]" range></Slider> |
| 25 | +``` |
| 26 | + |
| 27 | +### Range |
| 28 | + |
| 29 | +```html |
| 30 | +<Slider value="0" min="-50" max="50" /> |
| 31 | +``` |
| 32 | + |
| 33 | +### Disabled |
| 34 | + |
| 35 | +```html |
| 36 | +<Slider value="50" disabled /> |
| 37 | +``` |
| 38 | + |
| 39 | +### Readonly |
| 40 | + |
| 41 | +```html |
| 42 | +<Slider value="50" readonly /> |
| 43 | +``` |
| 44 | + |
| 45 | +### Step Size |
| 46 | + |
| 47 | +```html |
| 48 | +<Slider value="50" step="10" /> |
| 49 | +``` |
| 50 | + |
| 51 | +### Custom Style |
| 52 | + |
| 53 | +```html |
| 54 | +<Slider value="50" barheight="4" activecolor="#ee0a24" /> |
| 55 | +``` |
| 56 | + |
| 57 | +### Custom Button |
| 58 | + |
| 59 | +```html |
| 60 | +<Slider value="50"> |
| 61 | + <div slot="button" className="custom-button">50</div> |
| 62 | +</Slider> |
| 63 | +``` |
| 64 | + |
| 65 | +```css |
| 66 | +.custom-button { |
| 67 | + width: 26px; |
| 68 | + color: #fff; |
| 69 | + font-size: 10px; |
| 70 | + line-height: 18px; |
| 71 | + text-align: center; |
| 72 | + background-color: #1989fa; |
| 73 | + border-radius: 100px; |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +### Vertical |
| 78 | + |
| 79 | +Set `vertical` attribute to display slider vertically. The height will be 100% of parent element. |
| 80 | + |
| 81 | +```html |
| 82 | +<div style={{ height: '150px', display: 'flex' }}> |
| 83 | + <Slider value="50" vertical /> |
| 84 | + <Slider value="[20, 60]" range vertical style={{ marginLeft: '100px' }} /> |
| 85 | +</div> |
| 86 | +``` |
| 87 | + |
| 88 | +### Change Event |
| 89 | + |
| 90 | +```tsx |
| 91 | +export default () => { |
| 92 | + const [value, setValue] = useState(50); |
| 93 | + const handleChange = ({ detail }) => { |
| 94 | + setValue(detail.value); |
| 95 | + }; |
| 96 | + return <Slider onChange={handleChange} value={value} />; |
| 97 | +}; |
| 98 | +``` |
| 99 | + |
| 100 | +## API |
| 101 | + |
| 102 | +### Props |
| 103 | + |
| 104 | +| Attribute | Description | Type | Default | |
| 105 | +| :-----------: | :--------------------------------------------: | :-----------------------------------------------------------------------------------------------: | :-------- | |
| 106 | +| value | Current value, array format in dual thumb mode | `number \| [number, number]` | `0` | |
| 107 | +| min | Minimum | `number` | `0` | |
| 108 | +| max | Maximum | `number` | `100` | |
| 109 | +| step | Step size | `number` | `1` | |
| 110 | +| barheight | Height of bar, unit is px | `number` | `2` | |
| 111 | +| buttonsize | Button size, unit is px | `number` | `24` | |
| 112 | +| activecolor | Active color of bar | `string` | `#1989fa` | |
| 113 | +| inactivecolor | Inactive color of bar | `string` | `#e5e5e5` | |
| 114 | +| range | Whether to enable dual thumb mode | `boolean` | `false` | |
| 115 | +| reverse | Whether to reverse slider | `boolean` | `false` | |
| 116 | +| disabled | Whether to disable slider | `boolean` | `false` | |
| 117 | +| readonly | Whether to be readonly | `boolean` | `false` | |
| 118 | +| vertical | Whether to display slider vertically | `boolean` | `false` | |
| 119 | +| onChange | Emitted when value changed | `(e: { detail: { value: number \| [number, number] } }) => void` | | |
| 120 | +| onDragStart | Emitted when start dragging | `(e: { detail: { event: TouchEvent \| MouseEvent } }) => void` | | |
| 121 | +| onDragEnd | Emitted when end dragging | `(e: { detail: { value: number \| [number, number], event: TouchEvent \| MouseEvent } }) => void` | | |
| 122 | + |
| 123 | +### Slots |
| 124 | + |
| 125 | +| Name | Description | |
| 126 | +| :----------: | :-------------------------------: | |
| 127 | +| button | Custom button | |
| 128 | +| left-button | Custom left button in range mode | |
| 129 | +| right-button | Custom right button in range mode | |
| 130 | + |
| 131 | +## CSS Variables |
| 132 | + |
| 133 | +The component provides the following [CSS variables](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Using_CSS_custom_properties), which can be used to customize styles. Please refer to [ConfigProvider component](#/zh-CN/guide/theme). |
| 134 | + |
| 135 | +| Name | Description | Default | |
| 136 | +| ------------------------------------ | -------------------- | --------------------------- | |
| 137 | +| `--quark-slider-active-background` | Active background | `#1989fa` | |
| 138 | +| `--quark-slider-inactive-background` | Inactive background | `#e5e5e5` | |
| 139 | +| `--quark-slider-disabled-opacity` | Disabled opacity | `0.5` | |
| 140 | +| `--quark-slider-bar-height` | Bar height | `2px` | |
| 141 | +| `--quark-slider-button-width` | Button width | `24px` | |
| 142 | +| `--quark-slider-button-height` | Button height | `24px` | |
| 143 | +| `--quark-slider-button-radius` | Button border radius | `50%` | |
| 144 | +| `--quark-slider-button-background` | Button background | `#fff` | |
| 145 | +| `--quark-slider-button-shadow` | Button shadow | `0 1px 2px rgba(0,0,0,0.5)` | |
0 commit comments