1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __decorate, __extends, __rest } from "tslib";
|
17 |
|
18 |
|
19 |
|
20 | import classNames from "classnames";
|
21 | import * as React from "react";
|
22 | import { polyfill } from "react-lifecycles-compat";
|
23 | import { AbstractPureComponent2, Classes, refHandler, setRef } from "../../common";
|
24 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var Control = function (_a) {
|
30 | var _b;
|
31 | var alignIndicator = _a.alignIndicator, children = _a.children, className = _a.className, indicatorChildren = _a.indicatorChildren, inline = _a.inline, inputRef = _a.inputRef, label = _a.label, labelElement = _a.labelElement, large = _a.large, style = _a.style, type = _a.type, typeClassName = _a.typeClassName, _c = _a.tagName, tagName = _c === void 0 ? "label" : _c, htmlProps = __rest(_a, ["alignIndicator", "children", "className", "indicatorChildren", "inline", "inputRef", "label", "labelElement", "large", "style", "type", "typeClassName", "tagName"]);
|
32 | var classes = classNames(Classes.CONTROL, typeClassName, (_b = {},
|
33 | _b[Classes.DISABLED] = htmlProps.disabled,
|
34 | _b[Classes.INLINE] = inline,
|
35 | _b[Classes.LARGE] = large,
|
36 | _b), Classes.alignmentClass(alignIndicator), className);
|
37 | return React.createElement(tagName, { className: classes, style: style }, React.createElement("input", __assign({}, htmlProps, { ref: inputRef, type: type })), React.createElement("span", { className: Classes.CONTROL_INDICATOR }, indicatorChildren), label, labelElement, children);
|
38 | };
|
39 | var Switch = (function (_super) {
|
40 | __extends(Switch, _super);
|
41 | function Switch() {
|
42 | return _super !== null && _super.apply(this, arguments) || this;
|
43 | }
|
44 | Switch.prototype.render = function () {
|
45 | var _a = this.props, innerLabelChecked = _a.innerLabelChecked, innerLabel = _a.innerLabel, controlProps = __rest(_a, ["innerLabelChecked", "innerLabel"]);
|
46 | var switchLabels = innerLabel || innerLabelChecked
|
47 | ? [
|
48 | React.createElement("div", { key: "checked", className: Classes.CONTROL_INDICATOR_CHILD },
|
49 | React.createElement("div", { className: Classes.SWITCH_INNER_TEXT }, innerLabelChecked ? innerLabelChecked : innerLabel)),
|
50 | React.createElement("div", { key: "unchecked", className: Classes.CONTROL_INDICATOR_CHILD },
|
51 | React.createElement("div", { className: Classes.SWITCH_INNER_TEXT }, innerLabel)),
|
52 | ]
|
53 | : null;
|
54 | return (React.createElement(Control, __assign({}, controlProps, { type: "checkbox", typeClassName: Classes.SWITCH, indicatorChildren: switchLabels })));
|
55 | };
|
56 | Switch.displayName = DISPLAYNAME_PREFIX + ".Switch";
|
57 | Switch = __decorate([
|
58 | polyfill
|
59 | ], Switch);
|
60 | return Switch;
|
61 | }(AbstractPureComponent2));
|
62 | export { Switch };
|
63 | var Radio = (function (_super) {
|
64 | __extends(Radio, _super);
|
65 | function Radio() {
|
66 | return _super !== null && _super.apply(this, arguments) || this;
|
67 | }
|
68 | Radio.prototype.render = function () {
|
69 | return React.createElement(Control, __assign({}, this.props, { type: "radio", typeClassName: Classes.RADIO }));
|
70 | };
|
71 | Radio.displayName = DISPLAYNAME_PREFIX + ".Radio";
|
72 | Radio = __decorate([
|
73 | polyfill
|
74 | ], Radio);
|
75 | return Radio;
|
76 | }(AbstractPureComponent2));
|
77 | export { Radio };
|
78 | var Checkbox = (function (_super) {
|
79 | __extends(Checkbox, _super);
|
80 | function Checkbox() {
|
81 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
82 | _this.state = {
|
83 | indeterminate: _this.props.indeterminate || _this.props.defaultIndeterminate || false,
|
84 | };
|
85 |
|
86 | _this.input = null;
|
87 | _this.handleInputRef = refHandler(_this, "input", _this.props.inputRef);
|
88 | _this.handleChange = function (evt) {
|
89 | var _a, _b;
|
90 | var indeterminate = evt.target.indeterminate;
|
91 |
|
92 | if (_this.props.indeterminate == null) {
|
93 | _this.setState({ indeterminate: indeterminate });
|
94 | }
|
95 |
|
96 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, evt);
|
97 | };
|
98 | return _this;
|
99 | }
|
100 | Checkbox.getDerivedStateFromProps = function (_a) {
|
101 | var indeterminate = _a.indeterminate;
|
102 |
|
103 | if (indeterminate != null) {
|
104 | return { indeterminate: indeterminate };
|
105 | }
|
106 | return null;
|
107 | };
|
108 | Checkbox.prototype.render = function () {
|
109 | var _a = this.props, defaultIndeterminate = _a.defaultIndeterminate, indeterminate = _a.indeterminate, controlProps = __rest(_a, ["defaultIndeterminate", "indeterminate"]);
|
110 | return (React.createElement(Control, __assign({}, controlProps, { inputRef: this.handleInputRef, onChange: this.handleChange, type: "checkbox", typeClassName: Classes.CHECKBOX })));
|
111 | };
|
112 | Checkbox.prototype.componentDidMount = function () {
|
113 | this.updateIndeterminate();
|
114 | };
|
115 | Checkbox.prototype.componentDidUpdate = function (prevProps) {
|
116 | this.updateIndeterminate();
|
117 | if (prevProps.inputRef !== this.props.inputRef) {
|
118 | setRef(prevProps.inputRef, null);
|
119 | this.handleInputRef = refHandler(this, "input", this.props.inputRef);
|
120 | setRef(this.props.inputRef, this.input);
|
121 | }
|
122 | };
|
123 | Checkbox.prototype.updateIndeterminate = function () {
|
124 | if (this.input != null) {
|
125 | this.input.indeterminate = this.state.indeterminate;
|
126 | }
|
127 | };
|
128 | Checkbox.displayName = DISPLAYNAME_PREFIX + ".Checkbox";
|
129 | Checkbox = __decorate([
|
130 | polyfill
|
131 | ], Checkbox);
|
132 | return Checkbox;
|
133 | }(AbstractPureComponent2));
|
134 | export { Checkbox };
|
135 |
|
\ | No newline at end of file |