ช่องเลือกสี
ColourInput
A colour picker with the chosen colour's hex code beside it, such as for a chart series or a label.
ใช้ให้ผู้ใช้เลือกสีของสิ่งที่ตั้งค่าเองได้ เช่น สีของป้ายกำกับ ค่าเป็นรหัส hex และแสดงรหัสข้างช่อง สีของหน้าจอใช้ token ของแนวทางการออกแบบเสมอ ไม่ใช้ช่องนี้
import { ColourInput } from "@bsru/ui";ตัวอย่าง
เลือกสี
value เป็นรหัส hex ตัวพิมพ์เล็ก รหัสข้างช่องแสดงเป็นตัวพิมพ์ใหญ่
#1F7533const [value, setValue] = useState("#1f7533");
<ColourInput
label="สีของป้ายกำกับ"
value={value}
onValueChange={setValue}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label | "สีของป้ายกำกับ" | string | The visible label, already in the screen language. Every field needs one, unless the screen labels it another way. |
| value | value | string | The colour as a hex code, such as #1f7533, when the screen keeps it. |
| onValueChange | setValue | (next: string) => void | Hears the hex code on each change. |
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. |
| value | string | — | The colour as a hex code, such as #1f7533, when the screen keeps it. |
| defaultValue | string | "#1f7533" | The starting colour, when the input keeps it. |
| onValueChange | (next: string) => void | — | Hears the hex code on each change. |
| disabled | boolean | — | — |
ข้อควรปฏิบัติ
- อย่าใช้สีเป็นข้อมูลเพียงอย่างเดียว ป้ายกำกับต้องมีชื่อเสมอ
ซอร์สโค้ด: ui/src/choice-inputs.tsx