|
@@ -4,10 +4,11 @@ import _ from 'lodash';
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
label: string;
|
|
label: string;
|
|
|
checked: boolean;
|
|
checked: boolean;
|
|
|
|
|
+ className?: string;
|
|
|
labelClass?: string;
|
|
labelClass?: string;
|
|
|
switchClass?: string;
|
|
switchClass?: string;
|
|
|
transparent?: boolean;
|
|
transparent?: boolean;
|
|
|
- onChange: (event) => any;
|
|
|
|
|
|
|
+ onChange: (event?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface State {
|
|
export interface State {
|
|
@@ -19,20 +20,21 @@ export class Switch extends PureComponent<Props, State> {
|
|
|
id: _.uniqueId(),
|
|
id: _.uniqueId(),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- internalOnChange = event => {
|
|
|
|
|
|
|
+ internalOnChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
|
- this.props.onChange(event);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.props.onChange();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { labelClass = '', switchClass = '', label, checked, transparent } = this.props;
|
|
|
|
|
|
|
+ const { labelClass = '', switchClass = '', label, checked, transparent, className } = this.props;
|
|
|
|
|
|
|
|
const labelId = `check-${this.state.id}`;
|
|
const labelId = `check-${this.state.id}`;
|
|
|
const labelClassName = `gf-form-label ${labelClass} ${transparent ? 'gf-form-label--transparent' : ''} pointer`;
|
|
const labelClassName = `gf-form-label ${labelClass} ${transparent ? 'gf-form-label--transparent' : ''} pointer`;
|
|
|
const switchClassName = `gf-form-switch ${switchClass} ${transparent ? 'gf-form-switch--transparent' : ''}`;
|
|
const switchClassName = `gf-form-switch ${switchClass} ${transparent ? 'gf-form-switch--transparent' : ''}`;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <label htmlFor={labelId} className="gf-form gf-form-switch-container">
|
|
|
|
|
|
|
+ <label htmlFor={labelId} className={`gf-form gf-form-switch-container ${className}`}>
|
|
|
{label && <div className={labelClassName}>{label}</div>}
|
|
{label && <div className={labelClassName}>{label}</div>}
|
|
|
<div className={switchClassName}>
|
|
<div className={switchClassName}>
|
|
|
<input id={labelId} type="checkbox" checked={checked} onChange={this.internalOnChange} />
|
|
<input id={labelId} type="checkbox" checked={checked} onChange={this.internalOnChange} />
|