import clsx from "clsx"; import { useAtom } from "../../editor-jotai"; import { useEffect, useRef } from "react"; import { activeColorPickerSectionAtom, getColorNameAndShadeFromColor, } from "./colorPickerUtils"; import HotkeyLabel from "./HotkeyLabel"; import { t } from "../../i18n"; import type { ColorPaletteCustom } from "../../colors"; interface ShadeListProps { hex: string; onChange: (color: string) => void; palette: ColorPaletteCustom; } export const ShadeList = ({ hex, onChange, palette }: ShadeListProps) => { const colorObj = getColorNameAndShadeFromColor({ color: hex || "transparent", palette, }); const [activeColorPickerSection, setActiveColorPickerSection] = useAtom( activeColorPickerSectionAtom, ); const btnRef = useRef(null); useEffect(() => { if (btnRef.current && activeColorPickerSection === "shades") { btnRef.current.focus(); } }, [colorObj, activeColorPickerSection]); if (colorObj) { const { colorName, shade } = colorObj; const shades = palette[colorName]; if (Array.isArray(shades)) { return (
{shades.map((color, i) => ( ))}
); } } return (
); };