|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useCallback, useState } from "react"; |
| 4 | +import { |
| 5 | + HvColorPicker, |
| 6 | + HvIconButton, |
| 7 | + HvTypography, |
| 8 | +} from "@hitachivantara/uikit-react-core"; |
| 9 | + |
| 10 | +import { ColorsConfig } from "./Dialogs/ColorsConfig"; |
| 11 | +import { useGeneratorContext } from "./GeneratorContext"; |
| 12 | + |
| 13 | +const colorsToDisplay = [ |
| 14 | + "bgPage", |
| 15 | + "positive", |
| 16 | + "negative", |
| 17 | + "warning", |
| 18 | + "info", |
| 19 | + "accent", |
| 20 | + "primary", |
| 21 | + "secondary", |
| 22 | + "text", |
| 23 | + "border", |
| 24 | +]; |
| 25 | + |
| 26 | +export const Colors = () => { |
| 27 | + const [configOpen, setConfigOpen] = useState(false); |
| 28 | + const { customTheme, updateCustomTheme, colorMode } = useGeneratorContext(); |
| 29 | + |
| 30 | + const updateTheme = useCallback( |
| 31 | + (changes: Record<string, any>) => { |
| 32 | + updateCustomTheme(changes); |
| 33 | + }, |
| 34 | + [updateCustomTheme], |
| 35 | + ); |
| 36 | + |
| 37 | + return ( |
| 38 | + <> |
| 39 | + {configOpen && <ColorsConfig open={configOpen} setOpen={setConfigOpen} />} |
| 40 | + <div className="flex flex-col gap-xs"> |
| 41 | + <div className="flex items-center gap-xs"> |
| 42 | + <div className="i-ph-paint-bucket" /> |
| 43 | + <HvTypography variant="title4">Colors</HvTypography> |
| 44 | + <div className="border-1 border-borderSubtle h-1px flex-1" /> |
| 45 | + <HvIconButton |
| 46 | + aria-label="Settings" |
| 47 | + title="Customize colors" |
| 48 | + onClick={() => setConfigOpen(true)} |
| 49 | + > |
| 50 | + <div className="i-ph-gear" /> |
| 51 | + </HvIconButton> |
| 52 | + </div> |
| 53 | + <div className="grid grid-cols-4 gap-sm"> |
| 54 | + {colorsToDisplay.map((color) => ( |
| 55 | + <div key={color} className="flex flex-col gap-xxs items-center"> |
| 56 | + <HvColorPicker |
| 57 | + iconOnly |
| 58 | + value={customTheme.colors.modes[colorMode][color]} |
| 59 | + onChangeComplete={(c) => { |
| 60 | + return updateTheme({ |
| 61 | + colors: { modes: { [colorMode]: { [color]: c } } }, |
| 62 | + }); |
| 63 | + }} |
| 64 | + /> |
| 65 | + <HvTypography variant="caption2">{color}</HvTypography> |
| 66 | + </div> |
| 67 | + ))} |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </> |
| 71 | + ); |
| 72 | +}; |
0 commit comments