@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
83 lines • 4.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var classNames = require("classnames");
var Styled_1 = require("../_Common/Styled");
var typestyle_1 = require("typestyle");
var withTheme_1 = require("../../../Common/theming/withTheme");
var theming_1 = require("../../../Common/theming");
var check_1 = require("./check");
var BaseCheckBox = function (props) {
var checked = props.checked, disabled = props.disabled, className = props.className, text = props.text, name = props.name, value = props.value, onChange = props.onChange, tabIndex = props.tabIndex, readonly = props.readonly;
return (React.createElement("label", { className: classNames('up-control', 'up-checkbox', typestyle_1.style(Styled_1.getCheckableStyles(props)), className) },
React.createElement("input", { onClick: function (e) {
e.stopPropagation();
e.persist();
!readonly && onChange(e, { name: name, checked: !checked });
}, onChange: function (e) { }, checked: checked, disabled: disabled, name: name, type: "checkbox", value: value }),
React.createElement("span", { className: "up-control-indicator" }, checked && React.createElement(check_1.default, null)),
React.createElement("span", { className: "up-control-label" }, text)));
};
var UpCheckbox = (function (_super) {
tslib_1.__extends(UpCheckbox, _super);
function UpCheckbox(props) {
var _this = _super.call(this, props) || this;
_this.stopPropagation = function (event) {
event.stopPropagation();
};
_this.handleChangeEvent = function (event, optionChange) {
var options = tslib_1.__spreadArrays(_this.currentOptions);
for (var propKey in options) {
var option = options[propKey];
if (option.name == optionChange.name &&
option.onOptionChange != undefined) {
option.onOptionChange(event, optionChange.checked);
if (!_this.isControlled) {
option.checked = optionChange.checked;
}
}
}
if (!_this.isControlled) {
_this.setState({ options: options });
}
};
_this.state = {
options: props.options,
};
return _this;
}
Object.defineProperty(UpCheckbox.prototype, "isControlled", {
get: function () {
return this.props.options !== undefined;
},
enumerable: true,
configurable: true
});
Object.defineProperty(UpCheckbox.prototype, "currentOptions", {
get: function () {
return this.isControlled
? this.props.options
: this.state.options;
},
enumerable: true,
configurable: true
});
UpCheckbox.prototype.render = function () {
var _this = this;
var options = this.currentOptions;
return (React.createElement("div", { className: classNames('up-checkbox', this.props.className), onClick: this.stopPropagation, style: this.props.styles },
React.createElement("label", { style: { display: 'none' } },
React.createElement("input", { type: "checkbox" })),
options.map(function (option) {
return (React.createElement(BaseCheckBox, tslib_1.__assign({}, option, { onChange: _this.handleChangeEvent, key: "Key_" + option.name + "_" + (option.value || ''), theme: _this.props.theme, tabIndex: _this.props.tabIndex })));
})));
};
UpCheckbox.defaultProps = {
theme: theming_1.default,
};
return UpCheckbox;
}(React.Component));
exports.UpCheckbox = UpCheckbox;
exports.default = withTheme_1.default(UpCheckbox);
//# sourceMappingURL=UpCheckBox.js.map