ButtonIconSelect.tsx 843 B

123456789101112131415161718192021222324252627282930313233
  1. import clsx from "clsx";
  2. // TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect />
  3. export const ButtonIconSelect = <T extends Object>({
  4. options,
  5. value,
  6. onChange,
  7. group,
  8. }: {
  9. options: { value: T; text: string; icon: JSX.Element; testId?: string }[];
  10. value: T | null;
  11. onChange: (value: T) => void;
  12. group: string;
  13. }) => (
  14. <div className="buttonList buttonListIcon">
  15. {options.map((option) => (
  16. <label
  17. key={option.text}
  18. className={clsx({ active: value === option.value })}
  19. title={option.text}
  20. >
  21. <input
  22. type="radio"
  23. name={group}
  24. onChange={() => onChange(option.value)}
  25. checked={value === option.value}
  26. data-testid={option.testId}
  27. />
  28. {option.icon}
  29. </label>
  30. ))}
  31. </div>
  32. );