ds-selection-group-item.tsx 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react'
  2. type DSSelectionGroupItemProps<ValueType> = {
  3. checked?: boolean
  4. disabled?: boolean
  5. onChange?: (value: ValueType) => void
  6. required?: boolean
  7. children: React.ReactNode
  8. } & (
  9. | {
  10. type: 'radio'
  11. name: string
  12. value: ValueType
  13. }
  14. | {
  15. type: 'checkbox'
  16. name?: string
  17. value?: ValueType
  18. }
  19. )
  20. export default function DSSelectionGroupItem(
  21. props: DSSelectionGroupItemProps<any>
  22. ) {
  23. const handleChange = () => {
  24. props.onChange?.(props.value)
  25. }
  26. return (
  27. <li className="selection-group-ds-item">
  28. <label>
  29. <input
  30. type={props.type}
  31. className="check-input-ds"
  32. name={props.name}
  33. value={props.value}
  34. checked={props.checked}
  35. disabled={props.disabled}
  36. required={props.required}
  37. onChange={handleChange}
  38. />
  39. {props.children}
  40. </label>
  41. </li>
  42. )
  43. }