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

ช่องเลือกสี

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 ตัวพิมพ์เล็ก รหัสข้างช่องแสดงเป็นตัวพิมพ์ใหญ่

#1F7533
const [value, setValue] = useState("#1f7533");

<ColourInput
  label="สีของป้ายกำกับ"
  value={value}
  onValueChange={setValue}
/>

props ทั้งหมด

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

ColourInput 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.
valuestring—The colour as a hex code, such as #1f7533, when the screen keeps it.
defaultValuestring"#1f7533"The starting colour, when the input keeps it.
onValueChange(next: string) => void—Hears the hex code on each change.
disabledboolean——

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

  • อย่าใช้สีเป็นข้อมูลเพียงอย่างเดียว ป้ายกำกับต้องมีชื่อเสมอ

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