ข้ามไปยังเนื้อหา

แถบเลื่อนค่า

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

80%

ส่งอีเมลถึงหัวหน้าหน่วยงานเมื่อถึงเกณฑ์

const [value, setValue] = useState(80);

<RangeInput
  label="แจ้งเตือนเมื่อใช้งบถึง"
  unit="%"
  value={value}
  onValueChange={setValue}
  hint="ส่งอีเมลถึงหัวหน้าหน่วยงานเมื่อถึงเกณฑ์"
/>

ช่วงที่กำหนดเอง

min max และ step กำหนดช่วงและระยะของแต่ละขั้น

7 วัน
<RangeInput
  label="จำนวนวันก่อนครบกำหนด"
  min={1}
  max={30}
  defaultValue={7}
  unit=" วัน"
/>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

RangeInput props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
labelstring—The visible label, already in the screen language. Every field needs one, unless the screen labels it another way.
hintstring—Help under the field, such as the format or a limit.
errorstring—What's wrong and how to fix it, shown under the field. It marks the field invalid.
requiredboolean—Marks the label with a red star, and the control as required.
idstring—The input's id. One is made when it's left out.
minnumber0—
maxnumber100—
stepnumber1The amount each move changes it by.
unitstring""Shown after the number, such as % or บาท.
valuenumber—The number, when the screen keeps it.
defaultValuenumber—The starting number, when the slider keeps it. Defaults to min.
onValueChange(next: number) => void—Hears the number on each move.
disabledboolean——

ข้อควรปฏิบัติ

  • ลูกศรซ้ายขวาเลื่อนทีละ step โปรแกรมอ่านหน้าจออ่านค่าพร้อมหน่วย

ซอร์สโค้ด: ui/src/choice-inputs.tsx