Color Function
ridiculous/color-functionFreeComponent
Ridiculously typed editor for the modern CSS color functions — color-mix(), light-dark(), and relative color — each with its own compile-time grammar and per-space channel strictness. Reuses color-picker and ships a result-swatch preview.
Install it
npx shadcn@latest add http://ridiculous.turtlesocks.dev/r/color-function.jsonSource
1"use client"23import { useEffect, useRef, useState } from "react"4import { Button } from "@/components/ui/button"5import {6 Popover,7 PopoverContent,8 PopoverTrigger,9} from "@/components/ui/popover"10import { cn } from "@/lib/utils"11import {12 defaultState,13 formatColorFunction,14 parseColorFunction,15} from "./color-function.helpers"16import type {17 ColorFunctionMode,18 ColorFunctionState,19 ColorFunctionStringMap,20} from "./color-function.types"21import { ColorFunctionPreview } from "./color-function-preview"22import { ColorMixEditor } from "./color-mix-editor"23import { FamilySelect } from "./family-select"24import { LightDarkEditor } from "./light-dark-editor"25import { LiveString } from "./live-string"26import { RelativeColorEditor } from "./relative-color-editor"2728export type { ColorFunctionPreviewProps } from "./color-function-preview"29// Re-export the public sub-components so consumers (and tests) can import them30// either from this entry or from the package index — the split is invisible.31export { ColorFunctionPreview } from "./color-function-preview"32export type { ColorMixEditorProps } from "./color-mix-editor"33export { ColorMixEditor } from "./color-mix-editor"34export type { LightDarkEditorProps } from "./light-dark-editor"35export { LightDarkEditor } from "./light-dark-editor"36export type { RelativeColorEditorProps } from "./relative-color-editor"37export { RelativeColorEditor } from "./relative-color-editor"3839// ---------------------------------------------------------------------------40// Props41// ---------------------------------------------------------------------------4243export interface ColorFunctionPanelProps<44 TMode extends ColorFunctionMode = "color-mix",45> {46 /**47 * Which family to edit. When omitted, the panel shows a family selector48 * and edits any of the three at runtime; the `onChange` string type then49 * defaults to the `color-mix` suggestion shape for typing purposes.50 */51 mode?: TMode52 value: ColorFunctionStringMap[TMode] | (string & {})53 onChange: (value: ColorFunctionStringMap[TMode]) => void54 className?: string55 "aria-label"?: string56}5758export interface ColorFunctionProps<59 TMode extends ColorFunctionMode = "color-mix",60> extends ColorFunctionPanelProps<TMode> {}6162// ---------------------------------------------------------------------------63// ColorFunction — popover-wrapped64// ---------------------------------------------------------------------------6566// … truncated
What it pulls in
Other registry items
Files it writes
More from ridiculous
All 22 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| All ridiculous componentsall | ridiculous | Components | Free | no deps | |
| Anchor Position Editoranchor-position-editor | ridiculous | Components | Free | no deps · 9 files | |
| Background Editorbackground-editor | ridiculous | Components | Free | no deps · 9 files | |
| Box Shadow Editorbox-shadow-editor | ridiculous | Components | Free | no deps · 7 files | |
| Calc Editorcalc-editor | ridiculous | Components | Free | no deps · 4 files | |
| Clip Path Editorclip-path-editor | ridiculous | Components | Free | no deps · 20 files | |
| Color Pickercolor-picker | ridiculous | Components | Free | no deps · 11 files | |
| Easing Pickereasing-picker | ridiculous | Components | Free | no deps · 17 files |
