dm-web-react
Version:
The DM web client with React.
76 lines • 3.51 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import * as React from "react";
import { withTheme } from "styled-components";
import { CheckboxButton, CheckboxButtonActive, CheckboxNormal, CheckboxNormalActive, IconWrapper, IconChecked, IconUnchecked } from "./styled";
var Checkbox = /** @class */ (function (_super) {
__extends(Checkbox, _super);
function Checkbox(props) {
var _this = _super.call(this, props) || this;
_this.handleChange = function () {
var props = _this.props;
if (props.disabled) {
return;
}
var checked = !_this.state.checked;
_this.setState({ checked: checked });
if (props.onChange) {
props.onChange(checked);
}
};
_this.state = {
checked: props.checked || false,
};
return _this;
}
Checkbox.prototype.componentWillReceiveProps = function (nextProps) {
var thisProps = this.props;
if (typeof nextProps.checked !== "undefined" && nextProps.checked !== thisProps.checked) {
this.setState({ checked: nextProps.checked });
}
};
Checkbox.prototype.render = function () {
var _this = this;
var _a = this.props, type = _a.type, children = _a.children, style = _a.style, activeStyle = _a.activeStyle, checked = _a.checked;
var CheckboxElement;
var checkboxStyle = checked ? __assign({}, style, activeStyle) : style;
if (type === "button") {
CheckboxElement = checked ? CheckboxButtonActive : CheckboxButton;
}
else {
CheckboxElement = checked ? CheckboxNormalActive : CheckboxNormal;
}
if (type === "button") {
return (React.createElement(CheckboxElement, { style: checkboxStyle, onMouseDown: function () { return _this.handleChange(); } }, children !== undefined ? React.createElement("span", null, children) : null));
}
return (React.createElement(CheckboxElement, { style: checkboxStyle, onMouseDown: function () { return _this.handleChange(); } },
React.createElement(IconWrapper, null, checked ? React.createElement(IconChecked, null) : React.createElement(IconUnchecked, null)),
"\u00A0",
children !== undefined ? React.createElement("span", null, children) : null));
};
return Checkbox;
}(React.PureComponent));
export default withTheme(Checkbox);
//# sourceMappingURL=Checkbox.js.map