CI / build (push) Canceled after 0s
- Add 12 × 8 and 24 × 16 wireframe presets plus custom columns, rows, gutter, opacity, and colour - Place the raster on the current slide, its layout, or the slide master so background rasters sit behind content - Keep one raster per presentation: add clears every scope and remove cleans the whole presentation - Share the colour swatch control across grids, guidelines, and rasters, including grey - Add raster geometry tests and document scope, background, and export caveats
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
/**
|
|
* @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<SwatchColor, string> = {
|
|
blue: "#4472C4",
|
|
red: "#C00000",
|
|
yellow: "#FFC000",
|
|
green: "#70AD47",
|
|
gray: "#D9D9D9",
|
|
};
|
|
|
|
const SWATCH_LABELS: Record<SwatchColor, string> = {
|
|
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<ColorSwatchesProps> = ({ label, value, onChange }) => {
|
|
const styles = useStyles();
|
|
const labelId = React.useId();
|
|
|
|
return (
|
|
<div className={styles.row}>
|
|
<Text id={labelId} size={200} className={styles.label}>
|
|
{label}
|
|
</Text>
|
|
<div className={styles.group} role="group" aria-labelledby={labelId}>
|
|
{SWATCH_ORDER.map((color) => {
|
|
const selected = color === value;
|
|
return (
|
|
<Button
|
|
key={color}
|
|
appearance="subtle"
|
|
className={`${styles.button} ${selected ? styles.selected : ""}`}
|
|
style={{
|
|
backgroundColor: SWATCH_VALUES[color],
|
|
color: getSwatchForeground(color),
|
|
width: "32px",
|
|
minWidth: "32px",
|
|
height: "32px",
|
|
padding: 0,
|
|
}}
|
|
onClick={() => onChange(color)}
|
|
title={`${SWATCH_LABELS[color]} color`}
|
|
aria-label={`${SWATCH_LABELS[color]} color`}
|
|
aria-pressed={selected}
|
|
icon={selected ? <CheckmarkRegular /> : undefined}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ColorSwatches;
|