excalidraw/packages/excalidraw/components/ButtonIconCycle.tsx
Marcel Mraz 21ffaf4d76
All checks were successful
Tests / test (push) Successful in 4m38s
refactor: auto ordered imports (#9163)
2025-03-12 15:23:31 +01:00

30 lines
701 B
TypeScript

import clsx from "clsx";
import type { JSX } from "react";
export const ButtonIconCycle = <T extends any>({
options,
value,
onChange,
group,
}: {
options: { value: T; text: string; icon: JSX.Element }[];
value: T | null;
onChange: (value: T) => void;
group: string;
}) => {
const current = options.find((op) => op.value === value);
const cycle = () => {
const index = options.indexOf(current!);
const next = (index + 1) % options.length;
onChange(options[next].value);
};
return (
<label key={group} className={clsx({ active: current!.value !== null })}>
<input type="button" name={group} onClick={cycle} />
{current!.icon}
</label>
);
};