แถบเลื่อนค่า
RangeInput
A slider for a number in a range, with the value shown beside it, such as a percentage. Use it when the exact number matters less than where it sits. For an exact number, use NumberStepper or MoneyInput.
ใช้เลือกตัวเลขในช่วงที่กำหนดด้วยการเลื่อน เมื่อค่าโดยประมาณสำคัญกว่าตัวเลขที่แน่นอน เช่น เกณฑ์แจ้งเตือนเป็นเปอร์เซ็นต์ ค่าแสดงข้างแถบเสมอ ถ้าต้องกรอกตัวเลขที่แน่นอน ใช้ NumberStepper หรือ MoneyInput
import { RangeInput } from "@bsru/ui";ตัวอย่าง
เกณฑ์เป็นเปอร์เซ็นต์
unit แสดงต่อท้ายตัวเลข ค่าเริ่มต้นของช่วงคือ 0 ถึง 100
ส่งอีเมลถึงหัวหน้าหน่วยงานเมื่อถึงเกณฑ์
const [value, setValue] = useState(80);
<RangeInput
label="แจ้งเตือนเมื่อใช้งบถึง"
unit="%"
value={value}
onValueChange={setValue}
hint="ส่งอีเมลถึงหัวหน้าหน่วยงานเมื่อถึงเกณฑ์"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "แจ้งเตือนเมื่อใช้งบถึง" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| unit | "%" | string | Shown after the number, such as % or บาท. |
| value | value | number | The number, when the screen keeps it. |
| onValueChange | setValue | (next: number) => void | Hears the number on each move. |
| hint | "ส่งอีเมลถึงหัวหน้าหน่วยงานเมื่อถึงเกณฑ์" | string | Help under the field, such as the format or a limit. |
ช่วงที่กำหนดเอง
min max และ step กำหนดช่วงและระยะของแต่ละขั้น
<RangeInput
label="จำนวนวันก่อนครบกำหนด"
min={1}
max={30}
defaultValue={7}
unit=" วัน"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "จำนวนวันก่อนครบกำหนด" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| min | 1 | number | — |
| max | 30 | number | — |
| defaultValue | 7 | number | The starting number, when the slider keeps it. Defaults to min. |
| unit | " วัน" | string | Shown after the number, such as % or บาท. |
| onValueChange | ไม่ได้ส่งในตัวอย่างนี้ | (next: number) => void | Hears the number on each move. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label | string | — | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| hint | string | — | Help under the field, such as the format or a limit. |
| error | string | — | What's wrong and how to fix it, shown under the field. It marks the field invalid. |
| required | boolean | — | Marks the label with a red star, and the control as required. |
| id | string | — | The input's id. One is made when it's left out. |
| min | number | 0 | — |
| max | number | 100 | — |
| step | number | 1 | The amount each move changes it by. |
| unit | string | "" | Shown after the number, such as % or บาท. |
| value | number | — | The number, when the screen keeps it. |
| defaultValue | number | — | The starting number, when the slider keeps it. Defaults to min. |
| onValueChange | (next: number) => void | — | Hears the number on each move. |
| disabled | boolean | — | — |
ข้อควรปฏิบัติ
- ลูกศรซ้ายขวาเลื่อนทีละ step โปรแกรมอ่านหน้าจออ่านค่าพร้อมหน่วย
ซอร์สโค้ด: ui/src/choice-inputs.tsx