radioField.tsx 1.1 KB

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