1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 |
|
10 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
11 |
|
12 | var _core = require("@emotion/core");
|
13 |
|
14 | var _react = require("react");
|
15 |
|
16 | var _Box = _interopRequireDefault(require("../Box"));
|
17 |
|
18 | var _ColorModeProvider = require("../ColorModeProvider");
|
19 |
|
20 | var _ControlBox = _interopRequireDefault(require("../ControlBox"));
|
21 |
|
22 | var _Icon = _interopRequireDefault(require("../Icon"));
|
23 |
|
24 | var _VisuallyHidden = _interopRequireDefault(require("../VisuallyHidden"));
|
25 |
|
26 | var _styles = _interopRequireDefault(require("./styles"));
|
27 |
|
28 | var _utils = require("../utils");
|
29 |
|
30 |
|
31 | var Checkbox = (0, _react.forwardRef)(function (_ref2, ref) {
|
32 | var id = _ref2.id,
|
33 | name = _ref2.name,
|
34 | value = _ref2.value,
|
35 | ariaLabel = _ref2["aria-label"],
|
36 | ariaLabelledBy = _ref2["aria-labelledby"],
|
37 | _ref2$variantColor = _ref2.variantColor,
|
38 | variantColor = _ref2$variantColor === void 0 ? "blue" : _ref2$variantColor,
|
39 | defaultIsChecked = _ref2.defaultIsChecked,
|
40 | isChecked = _ref2.isChecked,
|
41 | isFullWidth = _ref2.isFullWidth,
|
42 | _ref2$size = _ref2.size,
|
43 | size = _ref2$size === void 0 ? "md" : _ref2$size,
|
44 | isDisabled = _ref2.isDisabled,
|
45 | isInvalid = _ref2.isInvalid,
|
46 | isReadOnly = _ref2.isReadOnly,
|
47 | onChange = _ref2.onChange,
|
48 | onBlur = _ref2.onBlur,
|
49 | onFocus = _ref2.onFocus,
|
50 | isIndeterminate = _ref2.isIndeterminate,
|
51 | children = _ref2.children,
|
52 | iconColor = _ref2.iconColor,
|
53 | _ref2$iconSize = _ref2.iconSize,
|
54 | iconSize = _ref2$iconSize === void 0 ? "10px" : _ref2$iconSize,
|
55 | rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, ["id", "name", "value", "aria-label", "aria-labelledby", "variantColor", "defaultIsChecked", "isChecked", "isFullWidth", "size", "isDisabled", "isInvalid", "isReadOnly", "onChange", "onBlur", "onFocus", "isIndeterminate", "children", "iconColor", "iconSize"]);
|
56 |
|
57 |
|
58 | (0, _utils.useVariantColorWarning)("Checkbox", variantColor);
|
59 |
|
60 | var _useColorMode = (0, _ColorModeProvider.useColorMode)(),
|
61 | colorMode = _useColorMode.colorMode;
|
62 |
|
63 | var styleProps = (0, _styles["default"])({
|
64 | color: variantColor,
|
65 | size: size,
|
66 | colorMode: colorMode
|
67 | });
|
68 | var ownRef = (0, _react.useRef)();
|
69 |
|
70 | var _ref = (0, _utils.useForkRef)(ownRef, ref);
|
71 |
|
72 | (0, _react.useEffect)(function () {
|
73 | if (_ref.current) {
|
74 | _ref.current.indeterminate = Boolean(isIndeterminate);
|
75 | }
|
76 | }, [isIndeterminate, _ref]);
|
77 | return (0, _core.jsx)(_Box["default"], (0, _extends2["default"])({
|
78 | as: "label",
|
79 | display: "inline-flex",
|
80 | verticalAlign: "top",
|
81 | alignItems: "center",
|
82 | width: isFullWidth ? "full" : undefined,
|
83 | cursor: isDisabled ? "not-allowed" : "pointer"
|
84 | }, rest), (0, _core.jsx)(_VisuallyHidden["default"], {
|
85 | as: "input",
|
86 | type: "checkbox",
|
87 | "aria-label": ariaLabel,
|
88 | "aria-labelledby": ariaLabelledBy,
|
89 | id: id,
|
90 | ref: _ref,
|
91 | name: name,
|
92 | value: value,
|
93 | onChange: isReadOnly ? undefined : onChange,
|
94 | onBlur: onBlur,
|
95 | onFocus: onFocus,
|
96 | defaultChecked: isReadOnly ? undefined : defaultIsChecked,
|
97 | checked: isReadOnly ? Boolean(isChecked) : defaultIsChecked ? undefined : isChecked,
|
98 | disabled: isDisabled,
|
99 | readOnly: isReadOnly,
|
100 | "aria-readonly": isReadOnly,
|
101 | "aria-invalid": isInvalid,
|
102 | "aria-checked": isIndeterminate ? "mixed" : isChecked
|
103 | }), (0, _core.jsx)(_ControlBox["default"], (0, _extends2["default"])({
|
104 | opacity: isReadOnly ? 0.8 : 1
|
105 | }, styleProps), (0, _core.jsx)(_Icon["default"], {
|
106 | name: isIndeterminate ? "minus" : "check",
|
107 | size: iconSize,
|
108 | color: iconColor,
|
109 | transition: "transform 240ms, opacity 240ms"
|
110 | })), children && (0, _core.jsx)(_Box["default"], {
|
111 | ml: 2,
|
112 | fontSize: size,
|
113 | userSelect: "none",
|
114 | opacity: isDisabled ? 0.4 : 1
|
115 | }, children));
|
116 | });
|
117 | Checkbox.displayName = "Checkbox";
|
118 | var _default = Checkbox;
|
119 | exports["default"] = _default; |
\ | No newline at end of file |