123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import InputField from 'sentry/components/deprecatedforms/inputField';
- import Tooltip from 'sentry/components/tooltip';
- import {IconQuestion} from 'sentry/icons';
- import {defined} from 'sentry/utils';
- type Props = InputField['props'];
- type State = InputField['state'] & {
- value: boolean;
- };
- // XXX: This is ONLY used in GenericField. If we can delete that this can go.
- /**
- * @deprecated Do not use this
- */
- export default class BooleanField extends InputField<Props, State> {
- coerceValue(initialValue: string | number) {
- const value = super.coerceValue(initialValue);
- return value ? true : false;
- }
- onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
- const value = e.target.checked;
- this.setValue(value);
- };
- getField() {
- return (
- <input
- id={this.getId()}
- type={this.getType()}
- checked={this.state.value}
- onChange={this.onChange.bind(this)}
- disabled={this.props.disabled}
- />
- );
- }
- render() {
- const {error} = this.state;
- let className = this.getClassName();
- if (error) {
- className += ' has-error';
- }
- return (
- <div className={className}>
- <div className="controls">
- <label className="control-label">
- {this.getField()}
- {this.props.label}
- {this.props.disabled && this.props.disabledReason && (
- <Tooltip title={this.props.disabledReason}>
- <IconQuestion size="xs" />
- </Tooltip>
- )}
- </label>
- {defined(this.props.help) && <p className="help-block">{this.props.help}</p>}
- {error && <p className="error">{error}</p>}
- </div>
- </div>
- );
- }
- getClassName() {
- return 'control-group checkbox';
- }
- getType() {
- return 'checkbox';
- }
- }
|