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 |