radioField.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import * as React from 'react';
  2. import RadioGroup from 'app/views/settings/components/forms/controls/radioGroup';
  3. import InputField, {onEvent} from 'app/views/settings/components/forms/inputField';
  4. type RadioGroupProps = React.ComponentProps<typeof RadioGroup>;
  5. type Props = Omit<InputField['props'], 'type'> &
  6. Pick<RadioGroupProps, 'choices' | 'orientInline'>;
  7. class RadioField extends React.Component<Props> {
  8. onChange = (
  9. id: string,
  10. onChange: onEvent,
  11. onBlur: onEvent,
  12. e: React.FormEvent<HTMLInputElement>
  13. ) => {
  14. onChange(id, e);
  15. onBlur(id, e);
  16. };
  17. render() {
  18. return (
  19. <InputField
  20. {...this.props}
  21. field={({onChange, onBlur, value, disabled, orientInline, ...props}) => (
  22. <RadioGroup
  23. choices={props.choices}
  24. disabled={disabled}
  25. orientInline={orientInline}
  26. value={value === '' ? null : value}
  27. label={props.label}
  28. onChange={(id, e) => this.onChange(id, onChange, onBlur, e)}
  29. />
  30. )}
  31. />
  32. );
  33. }
  34. }
  35. export default RadioField;