ColorPicker
نمای کلیimport { ColorDot, ColorPicker, ColorSlider, ColorSpectrum } from '@nili/ui';این همان صفحهی نمای کلیِ خود کتابخانه است که زنده رندر میشود. زبان یا تم را از هدر عوض کنید، همراهش میآید.
نقطهٔ رنگ
یک دکمهٔ نمونهرنگ. ده رنگ پالت، یا هر رنگ CSS از طریق value. aria-label الزامی است — یک دایرهٔ رنگی نام دسترسپذیری از خودش ندارد.
import { ColorDot } from "@nili/ui"
export function Example() {
const [selected, setSelected] = useState("blue")
return (
<>
{palette.map((color) => (
<ColorDot
key={color}
color={color}
aria-label={color}
selected={selected === color}
onClick={() => setSelected(color)}
/>
))}
{/* an arbitrary colour */}
<ColorDot value="#0E121B" aria-label="Ink" />
</>
)
}انتخابگر رنگ
طیف، ریل فام و یک فیلد هگز. با defaultValue بدون کنترل، یا با value بههمراه onChange کنترلشده — که با یک رشتهٔ هگز صدا زده میشود، و وقتی کدری روشن است جفت آلفا را هم دارد.
#335CFFimport { ColorPicker } from "@nili/ui"
export function Example() {
const [color, setColor] = useState("#335CFF")
return <ColorPicker value={color} onChange={setColor} />
}کدری و نمونهرنگها
withOpacity ریل آلفا را اضافه میکند و فیلد هگز را به هشت رقم میبرد. swatches همان ردیف رنگهای اخیر یا برند زیر کنترلهاست.
import { ColorPicker } from "@nili/ui"
export function Example() {
return (
<ColorPicker
withOpacity
defaultValue="#7D52F4CC"
swatches={["#335CFF", "#1FC16B", "#FB3748", "#F6B51E", "#7D52F4"]}
/>
)
}پابرگ و برچسبها
footer زیر فیلد هگز مینشیند — معمولاً یک دکمهٔ تأیید، وقتی انتخابگر داخل پاپاور است. هر رشتهٔ دیدهشدنی یک پراپ است، پس کامپوننت پشتهٔ ترجمهٔ خودش را همراه نمیبرد.
import { ColorPicker, Button } from "@nili/ui"
export function Example() {
return (
<ColorPicker
withOpacity
defaultValue="#FB3748"
swatches={swatches}
labels={{
spectrum: "Saturation and brightness",
hue: "Hue",
opacity: "Opacity",
hex: "Hex value",
swatches: "Saved colours",
eyedropper: "Pick a colour from the screen",
}}
footer={<Button size="xs" fullWidth>Apply</Button>}
/>
)
}ColorDot
extends Omit< ComponentPropsWithoutRef<'button'>, 'color' >
محورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| color | gray | blue | orange | red | green | yellow | purple | sky | pink | teal | — | One of the ten palette colours, or a raw CSS colour via `value`. |
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| disabled | boolean | — | |
| required | boolean | — | |
| readOnly | boolean | — | |
| value | string | — | Arbitrary colour. Wins over `color`. |
| defaultValue | string | — | |
| name | string | — | |
| aria-label* | string | — | Accessible name — a coloured circle has none. |
| selected | boolean | false |
ColorDotSwatch
داخلیColorPicker
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' | 'defaultValue' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| value | string | — | Controlled hex, e.g. `'#335CFF'` or `'#335CFF80'`. |
| defaultValue | string | #335CFF | |
| onChange | (hex: string) => void | — | |
| withOpacity | boolean | true | Show the alpha track. |
| swatches | string[] | — | Swatch row under the controls. |
| footer | ReactNode | — | Rendered under the hex field — a confirm button, for instance. |
| labels | { format?: string; eyedropper?: string; spectrum?: string; hue?: string; opacity?: string; hex?: string; swatches?: string; } | — |
ColorSlider
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' >
محورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| type | hue | opacity | hue |
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| value* | number | — | |
| onChange* | (value: number) => void | — | |
| baseColor | string | #000 | For the opacity track, the colour the gradient fades to. |
| thumbColor | string | — | Fill of the thumb. Figma paints it with the picked colour. |
| label | string | — |
ColorSpectrum
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| hue* | number | — | |
| saturation* | number | — | |
| brightness* | number | — | |
| onChange* | (next: { saturation: number; brightness: number }) => void | — | |
| label | string | Saturation and brightness |