radio-button-setting.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react'
  2. import OLFormCheckbox from '@/shared/components/ol/ol-form-checkbox'
  3. export type RadioOption<T extends string = string> = {
  4. value: T
  5. label: string
  6. description?: string
  7. }
  8. type RadioButtonSettingProps<T extends string = string> = {
  9. id: string
  10. options: Array<RadioOption<T>>
  11. value: T | undefined
  12. onChange: (value: T) => void
  13. }
  14. export default function RadioButtonSetting<T extends string = string>({
  15. id,
  16. options,
  17. value,
  18. onChange,
  19. }: RadioButtonSettingProps<T>) {
  20. const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
  21. onChange(event.target.value as T)
  22. }
  23. return (
  24. <div className="ide-radio-setting-options">
  25. {options.map(option => (
  26. <OLFormCheckbox
  27. key={`${id}-${option.value}`}
  28. type="radio"
  29. id={`${id}-${option.value}`}
  30. name={id}
  31. value={option.value}
  32. checked={value === option.value}
  33. onChange={handleChange}
  34. label={option.label}
  35. description={option.description}
  36. />
  37. ))}
  38. </div>
  39. )
  40. }