From 6ec259a0e71174651bae95d4628138bf6fd68742 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Sun, 15 Mar 2026 16:19:35 -0400 Subject: refactor: packages/ --- .../excalidraw/components/ButtonIconSelect.tsx | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 packages/excalidraw/components/ButtonIconSelect.tsx (limited to 'packages/excalidraw/components/ButtonIconSelect.tsx') diff --git a/packages/excalidraw/components/ButtonIconSelect.tsx b/packages/excalidraw/components/ButtonIconSelect.tsx new file mode 100644 index 0000000..26191b5 --- /dev/null +++ b/packages/excalidraw/components/ButtonIconSelect.tsx @@ -0,0 +1,58 @@ +import type { JSX } from "react"; +import clsx from "clsx"; +import { ButtonIcon } from "./ButtonIcon"; + +// TODO: It might be "clever" to add option.icon to the existing component +export const ButtonIconSelect = ( + props: { + options: { + value: T; + text: string; + icon: JSX.Element; + testId?: string; + /** if not supplied, defaults to value identity check */ + active?: boolean; + }[]; + value: T | null; + type?: "radio" | "button"; + } & ( + | { type?: "radio"; group: string; onChange: (value: T) => void } + | { + type: "button"; + onClick: ( + value: T, + event: React.MouseEvent, + ) => void; + } + ), +) => ( + + {props.options.map((option) => + props.type === "button" ? ( + props.onClick(option.value, event)} + /> + ) : ( + + props.onChange(option.value)} + checked={props.value === option.value} + data-testid={option.testId} + /> + {option.icon} + + ), + )} + +); -- cgit v1.2.3