Color Picker
fluid-functionalism/color-pickerPaidComponent
Color picker with HEX, RGB, HSL, and OKLCH formats, alpha channel, optional swatches, and a popover trigger. Built on Base UI's Popover, Menu, and NumberField primitives with native EyeDropper support.
Install it
npx shadcn@latest add https://fluidfunctionalism.com/r/color-picker.jsonSource
1"use client";23import {4 createContext,5 forwardRef,6 useContext,7 useRef,8 useState,9 useEffect,10 useCallback,11 useMemo,12 type CSSProperties,13 type HTMLAttributes,14 type ReactNode,15} from "react";16import { motion, AnimatePresence } from "framer-motion";17import { Popover } from "@base-ui/react/popover";18import { Menu } from "@base-ui/react/menu";19import { NumberField } from "@base-ui/react/number-field";20import { cn } from "@/lib/utils";21import { spring } from "@/lib/springs";22import { fontWeights } from "@/lib/font-weight";23import { useShape, shapeMap } from "@/lib/shape-context";24import { useSurface, SurfaceProvider } from "@/lib/surface-context";25import { surfaceClasses } from "@/lib/surface-classes";26import { useIcon } from "@/lib/icon-context";27import { useProximityHover } from "@/hooks/use-proximity-hover";28import { Elevated } from "@/lib/elevated";29import { Slider } from "@/registry/radix/slider";30import { Tooltip } from "@/registry/radix/tooltip";3132// ---------------------------------------------------------------------------33// Types34// ---------------------------------------------------------------------------3536type ColorFormat = "hex" | "rgb" | "hsl" | "oklch";3738// Allows consumers (e.g. the /demo carousel) to portal popups inside a39// CSS-scaled ancestor so menu/popover layers visually scale with the picker.40const ColorPickerPortalContainerContext = createContext<HTMLElement | null>(null);4142function ColorPickerPortalContainer({43 value,44 children,45}: {46 value: HTMLElement | null;47 children: ReactNode;48}) {49 return (50 <ColorPickerPortalContainerContext.Provider value={value}>51 {children}52 </ColorPickerPortalContainerContext.Provider>53 );54}5556interface ParsedColor {57 // HSV (canonical, 0..360 / 0..1 / 0..1)58 h: number;59 s: number;60 v: number;61 a: number;62 // sRGB 0..25563 r: number;64 g: number;65 b: number;66 // Formatted strings67 hex: string;68 rgb: string;69 hsl: string;70 oklch: string;71}7273interface ColorPickerProps74 extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> {75 value?: string;76 defaultValue?: string;77 onValueChange?: (value: string, parsed: ParsedColor) => void;78 format?: ColorFormat;79 defaultFormat?: ColorFormat;80 onFormatChange?: (format: ColorFormat) => void;81 swatches?: string[];82 hideEyedropper?: boolean;83 /** Controls the format dropdown's open state. When provided, the dropdown84 * is fully controlled and ignores user toggles. */85 formatOpen?: boolean;86// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fluid-functionalism
All 53 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | fluid-functionalism | Components | Free | 3 deps | |
| Accordion (Base UI)accordion-base | fluid-functionalism | Components | Free | 3 deps | |
| Ask User Questionsask-user-questions | fluid-functionalism | Components | Free | 2 deps | |
| Badgebadge | fluid-functionalism | Components | Free | 1 dep | |
| Buttonbutton | fluid-functionalism | Components | Free | 4 deps | |
| Button (Base UI)button-base | fluid-functionalism | Components | Free | 4 deps | |
| Cardcard | fluid-functionalism | Components | Free | 1 dep | |
| Chat Messagechat-message | fluid-functionalism | Components | Free | 1 dep |
