UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

44 lines (43 loc) 2.42 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; define(["require", "exports", 'react', '../../utilities/css', '../../utilities/object', './Checkbox.scss'], function (require, exports, React, css_1, object_1) { "use strict"; var Checkbox = (function (_super) { __extends(Checkbox, _super); function Checkbox(props) { _super.call(this, props); this._id = object_1.getId('checkbox-'); this._onChange = this._onChange.bind(this); } Checkbox.prototype.render = function () { var _this = this; var _a = this.props, checked = _a.checked, className = _a.className, defaultChecked = _a.defaultChecked, disabled = _a.disabled, inputProps = _a.inputProps, label = _a.label; return (React.createElement("div", {className: css_1.css('ms-ChoiceField', className)}, React.createElement("input", React.__spread({}, inputProps, (checked !== undefined && { checked: checked }), (defaultChecked !== undefined && { defaultChecked: defaultChecked }), {disabled: disabled, ref: function (el) { return _this._checkBox = el; }, id: this._id, name: this._id, className: 'ms-ChoiceField-input', type: 'checkbox', role: 'checkbox', onChange: this._onChange, "aria-checked": checked})), React.createElement("label", {htmlFor: this._id, className: 'ms-ChoiceField-field'}, label && React.createElement("span", {className: 'ms-Label'}, label)))); }; Object.defineProperty(Checkbox.prototype, "checked", { get: function () { return this._checkBox ? this._checkBox.checked : false; }, enumerable: true, configurable: true }); Checkbox.prototype.focus = function () { if (this._checkBox) { this._checkBox.focus(); } }; Checkbox.prototype._onChange = function (ev) { var onChange = this.props.onChange; var isChecked = ev.target.checked; if (onChange) { onChange(ev, isChecked); } }; Checkbox.defaultProps = {}; return Checkbox; }(React.Component)); exports.Checkbox = Checkbox; });