radio.tsx 917 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import { Radio } from 'antd';
  3. import { FormItemHeight } from '../constants';
  4. interface IProps {
  5. label?: string;
  6. value?: string | number;
  7. options?: {
  8. label: string | number;
  9. value: string | number;
  10. }[];
  11. width?: number | string;
  12. onChange?: (value: string | number) => void;
  13. }
  14. const SelectField: React.FC<IProps> = props => {
  15. const { label = '', value, onChange, options = [], width } = props;
  16. return (
  17. <div className="group">
  18. <label>{label}</label>
  19. <Radio.Group
  20. value={value}
  21. style={{
  22. width,
  23. height: FormItemHeight,
  24. }}
  25. onChange={e => {
  26. onChange?.(e.target.value);
  27. }}
  28. >
  29. {options.map(item => (
  30. <Radio key={`${item.value}-${item.label}`} value={item.value}>{item.label}</Radio>
  31. ))}
  32. </Radio.Group>
  33. </div>
  34. );
  35. };
  36. export default SelectField;