This component no longer exists. It was in diceui/base’s manifest when we first indexed it and is not there now — the registry served its inventory on 2026-08-13 and this item was not on it. The install command below will fail. It is kept here because a tutorial somewhere still tells people to run it.
color-swatch
diceui-base/color-swatchRemovedComponent
diceui/base publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/color-swatch.jsonSource
1"use client";23import { mergeProps } from "@base-ui/react/merge-props";4import { useRender } from "@base-ui/react/use-render";5import { cva, type VariantProps } from "class-variance-authority";6import * as React from "react";7import { cn } from "@/lib/utils";89const colorSwatchVariants = cva(10 "box-border rounded-sm border bg-clip-padding shadow-sm data-disabled:pointer-events-none data-disabled:opacity-50",11 {12 variants: {13 size: {14 default: "size-8",15 sm: "size-6",16 lg: "size-12",17 },18 },19 defaultVariants: {20 size: "default",21 },22 },23);2425function getIsCssColor(v: string): boolean {26 try {27 return typeof CSS !== "undefined" && typeof CSS.supports === "function"28 ? CSS.supports("color", v)29 : true;30 } catch {31 return false;32 }33}3435function getHasAlpha(v: string): boolean {36 const s = v.trim().toLowerCase();3738 if (s === "transparent") return true;3940 if (/^#(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.test(s)) return true;4142 if (/\b(?:rgba|hsla)\s*\(/i.test(s)) return true;4344 if (45 /\b(?:rgb|hsl|lab|lch|oklab|oklch|color)\s*\([^)]*\/\s*[\d.]+%?\s*\)/i.test(46 s,47 )48 ) {49 return true;50 }5152 return false;53}5455interface ColorSwatchProps56 extends Omit<React.ComponentProps<"div">, "children">,57 VariantProps<typeof colorSwatchVariants>,58 useRender.ComponentProps<"div"> {59 color?: string;60 disabled?: boolean;61 withoutTransparency?: boolean;62}6364function ColorSwatch({65 color,66 size = "default",67 disabled = false,68 withoutTransparency = false,69 className,70 style,71 render,72 ...props73}: ColorSwatchProps) {74 const colorValue = color?.trim();7576 const backgroundStyle = React.useMemo<React.CSSProperties>(() => {77 if (!colorValue) {78 return {79 background:80 "linear-gradient(to bottom right, transparent calc(50% - 1px), hsl(var(--destructive)) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) no-repeat",81 };82 }8384 if (!getIsCssColor(colorValue)) {85 return { backgroundColor: "transparent" };86 }8788 if (!withoutTransparency && getHasAlpha(colorValue)) {89 return {90 background: `linear-gradient(${colorValue}, ${colorValue}), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0% 50% / 10px 10px`,91 };92 }9394 return { backgroundColor: colorValue };95 }, [colorValue, withoutTransparency]);9697 const ariaLabel = !colorValue98 ? "No color selected"99 : `Color swatch: ${colorValue}`;100101 return useRender({102// … truncated
What it pulls in
npm packages
