/** * @file ColorSwatches.tsx * @description Shared colour picker for grids, guidelines, and rasters. */ import * as React from "react"; import { Button, makeStyles, Text, tokens } from "@fluentui/react-components"; import { CheckmarkRegular } from "@fluentui/react-icons"; export type SwatchColor = "blue" | "red" | "yellow" | "green" | "gray"; /** Colours written to the slide. */ export const SWATCH_VALUES: Record = { blue: "#4472C4", red: "#C00000", yellow: "#FFC000", green: "#70AD47", gray: "#D9D9D9", }; const SWATCH_LABELS: Record = { blue: "Blue", red: "Red", yellow: "Yellow", green: "Green", gray: "Gray", }; const SWATCH_ORDER: readonly SwatchColor[] = ["blue", "red", "yellow", "green", "gray"]; /** Choose a check colour that stays readable on every swatch. */ const getSwatchForeground = (color: SwatchColor): string => color === "yellow" || color === "green" || color === "gray" ? "#000000" : "#ffffff"; const useStyles = makeStyles({ row: { display: "flex", alignItems: "center", gap: tokens.spacingHorizontalS, }, label: { minWidth: "48px", color: tokens.colorNeutralForeground2, }, group: { display: "flex", gap: tokens.spacingHorizontalXS, }, button: { width: "32px", height: "32px", minWidth: "32px", padding: 0, border: `1px solid ${tokens.colorNeutralStroke1}`, borderRadius: tokens.borderRadiusMedium, }, selected: { border: `2px solid ${tokens.colorBrandForeground1}`, }, }); export interface ColorSwatchesProps { /** Visible group label, e.g. "Color" */ label: string; value: SwatchColor; onChange: (color: SwatchColor) => void; } /** * A labelled group of colour swatches with a check mark on the selected value. */ export const ColorSwatches: React.FC = ({ label, value, onChange }) => { const styles = useStyles(); const labelId = React.useId(); return (
{label}
{SWATCH_ORDER.map((color) => { const selected = color === value; return (
); }; export default ColorSwatches;