UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Office 365.

46 lines 1.74 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { BaseState } from '../../utilities/BaseState'; var ToggleState = /** @class */ (function (_super) { tslib_1.__extends(ToggleState, _super); function ToggleState(props) { var _this = _super.call(this, props, { controlledProps: ['checked', 'text'], transformViewProps: function (newProps) { newProps.text = newProps.checked ? props.onText : props.offText; return newProps; } }) || this; _this._toggleButtonRef = React.createRef(); _this.focus = function () { if (_this._toggleButtonRef.current) { _this._toggleButtonRef.current.focus(); } }; _this._onClick = function (ev) { var _a = _this.props, disabled = _a.disabled, onChange = _a.onChange; var checked = _this.state.checked; if (!disabled) { // Only update the state if the user hasn't provided it. _this.setState({ checked: !checked }); if (onChange) { onChange(ev, !checked); } } }; _this.state = { checked: !!props.defaultChecked, text: !!props.defaultChecked ? props.onText : props.offText, onChange: _this._noop, onClick: _this._onClick, toggleButtonRef: _this._toggleButtonRef }; return _this; } ToggleState.prototype._noop = function () { /* no-op */ }; return ToggleState; }(BaseState)); export { ToggleState }; //# sourceMappingURL=Toggle.state.js.map