Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | 1x 1x 1x 1x 4x | import React, { Fragment, useState } from "react"; import { Slider } from "@tencent/tea-component/lib/slider"; import { InputNumber } from "@tencent/tea-component/lib/inputnumber"; import { InputAdornment } from "@tencent/tea-component/lib/inputadornment"; const marks = [{ value: 0 }, { value: 20 }, { value: 50 }, { value: 100 }]; export default function SliderExample() { const [value1, setValue1] = useState(20); const [value2, setValue2] = useState(50); return ( <Fragment> <h3>基本用法</h3> <section> <Slider min={20} max={100} marks={marks} onChange={value => console.log("onChange", value)} onUpdate={value => console.log("onUpdate", value)} /> </section> <h3>受控组件</h3> <section> <Slider min={0} max={100} marks={marks} value={value1} onChange={value => { // onChange 的时候不更新值,则会一直使用传入的 value // setValue1(value); console.log("onChange", value); }} onUpdate={value => console.log("onUpdate", value)} after={ <InputNumber min={0} max={100} value={value1} onChange={value => setValue1(value)} /> } /> </section> <h3>格式化提示</h3> <section> <Slider min={0} max={100} tipFormatter={value => `${value} 台`} marks={marks.map(({ value }) => ({ value, label: `${value} 台` }))} value={value2} onChange={value => { setValue2(value); console.log(value); }} after={ <InputAdornment after="台" appearance="pure"> <InputNumber min={0} max={100} step={5} value={value2} onChange={value => setValue2(value)} /> </InputAdornment> } /> </section> <h3>滑轨提示</h3> <section> <Slider min={0} max={100} marks={marks} defaultValue={0} enableTrackTip /> </section> <h3>可拖动范围</h3> <section> <Slider min={0} max={100} range={[20, 90]} marks={marks} onChange={value => console.log("onChange", value)} onUpdate={value => console.log("onUpdate", value)} /> </section> <h3>步长调整</h3> <section> <Slider min={0} max={100} step={5} marks={marks} defaultValue={20} onChange={value => console.log(value)} /> </section> <h3>只能移动至刻度</h3> <section> <Slider min={0} max={100} step={5} marks={marks} markValueOnly defaultValue={50} onChange={value => console.log(value)} /> </section> <h3>禁用</h3> <section> <Slider disabled min={0} max={100} marks={marks} defaultValue={50} /> </section> </Fragment> ); } |