import {Fragment} from 'react'; import InputField from 'sentry/components/forms/inputField'; import {defined} from 'sentry/utils'; type Props = { yesLabel: string; noLabel: string; yesFirst?: boolean; } & InputField['props']; export default class RadioBooleanField extends InputField { static defaultProps = { ...InputField.defaultProps, yesLabel: 'Yes', noLabel: 'No', yesFirst: true, }; coerceValue(props) { const value = super.coerceValue(props); return value ? true : false; } onChange = e => { const value = e.target.value === 'true'; this.setValue(value); }; getType() { return 'radio'; } getField() { const yesOption = (
); const noOption = (
); return (
{this.props.yesFirst ? ( {yesOption} {noOption} ) : ( {noOption} {yesOption} )}
); } render() { const {label, hideErrorMessage, help, style} = this.props; const {error} = this.state; const cx = this.getFinalClassNames(); const shouldShowErrorMessage = error && !hideErrorMessage; return (
{label && ( )} {defined(help) &&

{help}

} {this.getField()} {this.renderDisabledReason()} {shouldShowErrorMessage &&

{error}

}
); } }