ButtonIconSelect.tsx 830 B

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