office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
52 lines (51 loc) • 3.08 kB
JavaScript
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 __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", 'react', '../../utilities/autobind', '../../utilities/css', '../../utilities/object', './Checkbox.scss'], function (require, exports, React, autobind_1, 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-');
}
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 = {};
__decorate([
autobind_1.autobind
], Checkbox.prototype, "_onChange", null);
return Checkbox;
}(React.Component));
exports.Checkbox = Checkbox;
});