@cypress-design/react-checkbox 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +3 -1
- package/CHANGELOG.md +9 -0
- package/dist/index.es.mjs +5 -126
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +13 -134
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/rollup.config.mjs +5 -1
package/dist/index.umd.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var clsx = require('clsx');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var
|
|
5
|
+
var reactIcon = require('@cypress-design/react-icon');
|
|
6
|
+
var constantsCheckbox = require('@cypress-design/constants-checkbox');
|
|
6
7
|
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
var n = Object.create(null);
|
|
@@ -22,52 +23,6 @@ function _interopNamespaceDefault(e) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
|
-
var iconsRegistry__namespace = /*#__PURE__*/_interopNamespaceDefault(iconsRegistry);
|
|
26
|
-
|
|
27
|
-
/******************************************************************************
|
|
28
|
-
Copyright (c) Microsoft Corporation.
|
|
29
|
-
|
|
30
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
31
|
-
purpose with or without fee is hereby granted.
|
|
32
|
-
|
|
33
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
34
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
35
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
36
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
37
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
38
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
39
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
40
|
-
***************************************************************************** */
|
|
41
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var __assign$1 = function() {
|
|
45
|
-
__assign$1 = Object.assign || function __assign(t) {
|
|
46
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
47
|
-
s = arguments[i];
|
|
48
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
49
|
-
}
|
|
50
|
-
return t;
|
|
51
|
-
};
|
|
52
|
-
return __assign$1.apply(this, arguments);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function __rest$1(s, e) {
|
|
56
|
-
var t = {};
|
|
57
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
58
|
-
t[p] = s[p];
|
|
59
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
60
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
61
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
62
|
-
t[p[i]] = s[p[i]];
|
|
63
|
-
}
|
|
64
|
-
return t;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
68
|
-
var e = new Error(message);
|
|
69
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
70
|
-
};
|
|
71
26
|
|
|
72
27
|
/******************************************************************************
|
|
73
28
|
Copyright (c) Microsoft Corporation.
|
|
@@ -114,113 +69,37 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
114
69
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
115
70
|
};
|
|
116
71
|
|
|
117
|
-
var compileReactIconProperties = function (_a) {
|
|
118
|
-
var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, alt = _a.alt, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name", "alt"]);
|
|
119
|
-
var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
|
|
120
|
-
if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) &&
|
|
121
|
-
attrName !== 'name') {
|
|
122
|
-
// @ts-expect-error the ky of React's SVGProps is too broad and
|
|
123
|
-
// breaks here. Since we do not need to check for it. We keep the expect error
|
|
124
|
-
newAttributes[attrName] =
|
|
125
|
-
attributes[attrName];
|
|
126
|
-
}
|
|
127
|
-
return newAttributes;
|
|
128
|
-
}, {});
|
|
129
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
130
|
-
React__namespace.useEffect(function () {
|
|
131
|
-
var iconFileId = "".concat(name, "_").concat(size);
|
|
132
|
-
if (defs) {
|
|
133
|
-
if (document.querySelector("[data-cy-svg-defs=\"".concat(iconFileId, "\"]"))) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
var svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
137
|
-
svgElement.setAttribute('data-cy-svg-defs', iconFileId);
|
|
138
|
-
svgElement.setAttribute('width', '0');
|
|
139
|
-
svgElement.setAttribute('height', '0');
|
|
140
|
-
svgElement.innerHTML = defs;
|
|
141
|
-
document.body.appendChild(svgElement);
|
|
142
|
-
}
|
|
143
|
-
}, [defs, name, size]);
|
|
144
|
-
var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
|
|
145
|
-
__html: alt
|
|
146
|
-
? "<title>".concat(alt.replace(/[><]/g, function (s) {
|
|
147
|
-
return s === '>' ? '>' : '<';
|
|
148
|
-
}), "</title>").concat(body)
|
|
149
|
-
: body,
|
|
150
|
-
}, className: undefined }, filteredAttributes);
|
|
151
|
-
if (attributes.className) {
|
|
152
|
-
compiledClasses.push(attributes.className);
|
|
153
|
-
}
|
|
154
|
-
if (compiledClasses.length) {
|
|
155
|
-
componentProps.className = compiledClasses.join(' ');
|
|
156
|
-
}
|
|
157
|
-
return componentProps;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
function useIconProps(props, iconBodiesAndDefs, availableSizes, name) {
|
|
161
|
-
var interactiveColorsOnGroup = props.interactiveColorsOnGroup, cleanProps = __rest(props, ["interactiveColorsOnGroup"]);
|
|
162
|
-
var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, cleanProps), { availableSizes: availableSizes, interactiveColorsOnGroup: interactiveColorsOnGroup })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
|
|
163
|
-
var _b = iconBodiesAndDefs[size] || {}, body = _b.body, defs = _b.defs;
|
|
164
|
-
if (!body) {
|
|
165
|
-
throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
|
|
166
|
-
}
|
|
167
|
-
return compileReactIconProperties(__assign(__assign({}, cleanProps), { name: name, size: size, body: body, defs: defs, compiledClasses: compiledClasses }));
|
|
168
|
-
}
|
|
169
|
-
var IconCheckmarkSmall = function (props) { return React__namespace.createElement('svg', useIconProps(props, {
|
|
170
|
-
"16": {
|
|
171
|
-
"body": "<path d=\"M5 8.5 7.5 11 11 5\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
|
|
172
|
-
}
|
|
173
|
-
}, ["16"], "checkmark-small")); };
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
/* <wind-keep class="filter icon-light-secondary icon-dark-secondary"> */
|
|
177
|
-
|
|
178
|
-
const Classes = {
|
|
179
|
-
wrapper: 'relative flex items-center',
|
|
180
|
-
hiddenInput: 'absolute inset-0 w-0 h-0 opacity-0',
|
|
181
|
-
labelTag: 'flex items-center',
|
|
182
|
-
visibleCheckbox: 'border border-solid rounded h-[16px] w-[16px] flex flex-shrink-0 items-center text-white',
|
|
183
|
-
trueLabel: 'block ml-[8px] text-[16px] leading-[24px] font-light select-none',
|
|
184
|
-
};
|
|
185
|
-
const CheckboxColors = {
|
|
186
|
-
indigo: 'border-indigo-500 bg-indigo-400',
|
|
187
|
-
jade: 'border-jade-500 bg-jade-400',
|
|
188
|
-
red: 'border-red-500 bg-red-400',
|
|
189
|
-
disabled: 'border-gray-200 bg-gray-100',
|
|
190
|
-
empty: 'border-gray-200 bg-white',
|
|
191
|
-
};
|
|
192
|
-
|
|
193
72
|
var uid = function () {
|
|
194
73
|
return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
|
|
195
74
|
};
|
|
196
75
|
var Checkbox = function (_a) {
|
|
197
|
-
var _b = _a.id, id = _b === void 0 ? uid() : _b, _c = _a.checked, checked = _c === void 0 ? false : _c, onChange = _a.onChange, _d = _a.color, color = _d === void 0 ? 'indigo' : _d, label = _a.label, disabled = _a.disabled, className = _a.className, name = _a.name, rest = __rest
|
|
76
|
+
var _b = _a.id, id = _b === void 0 ? uid() : _b, _c = _a.checked, checked = _c === void 0 ? false : _c, onChange = _a.onChange, _d = _a.color, color = _d === void 0 ? 'indigo' : _d, label = _a.label, disabled = _a.disabled, className = _a.className, name = _a.name, rest = __rest(_a, ["id", "checked", "onChange", "color", "label", "disabled", "className", "name"]);
|
|
198
77
|
var _e = React__namespace.useState(checked), localChecked = _e[0], setChecked = _e[1];
|
|
199
78
|
function onChangeInput(event) {
|
|
200
79
|
setChecked(!localChecked);
|
|
201
80
|
onChange(event);
|
|
202
81
|
}
|
|
203
|
-
return (React__namespace.createElement("span", __assign
|
|
204
|
-
React__namespace.createElement("input", { id: id, className: Classes.hiddenInput, "aria-describedby": "".concat(id, "-description"), name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
|
|
205
|
-
React__namespace.createElement("label", { className: Classes.labelTag, htmlFor: id },
|
|
82
|
+
return (React__namespace.createElement("span", __assign({ className: clsx(className, constantsCheckbox.Classes.wrapper) }, rest),
|
|
83
|
+
React__namespace.createElement("input", { id: id, className: constantsCheckbox.Classes.hiddenInput, "aria-describedby": "".concat(id, "-description"), name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
|
|
84
|
+
React__namespace.createElement("label", { className: constantsCheckbox.Classes.labelTag, htmlFor: id },
|
|
206
85
|
localChecked && (
|
|
207
86
|
// <tw-keep strokeColor="white"/>
|
|
208
|
-
React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
87
|
+
React__namespace.createElement(reactIcon.IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
209
88
|
React__namespace.createElement("span", { className: clsx([
|
|
210
|
-
Classes.visibleCheckbox,
|
|
89
|
+
constantsCheckbox.Classes.visibleCheckbox,
|
|
211
90
|
disabled
|
|
212
|
-
? CheckboxColors.disabled
|
|
91
|
+
? constantsCheckbox.CheckboxColors.disabled
|
|
213
92
|
: localChecked
|
|
214
|
-
? CheckboxColors[color]
|
|
215
|
-
: CheckboxColors.empty,
|
|
93
|
+
? constantsCheckbox.CheckboxColors[color]
|
|
94
|
+
: constantsCheckbox.CheckboxColors.empty,
|
|
216
95
|
]) }),
|
|
217
96
|
label && (React__namespace.createElement("span", { className: clsx([
|
|
218
97
|
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
219
|
-
Classes.trueLabel,
|
|
98
|
+
constantsCheckbox.Classes.trueLabel,
|
|
220
99
|
]) }, label)))));
|
|
221
100
|
};
|
|
222
101
|
|
|
223
102
|
module.exports = Checkbox;
|
|
224
103
|
//# sourceMappingURL=index.umd.js.map
|
|
225
104
|
|
|
226
|
-
/* <wind-keep class="absolute text-gray-500 text-gray-800 icon-dark-white
|
|
105
|
+
/* <wind-keep class="absolute text-gray-500 text-gray-800 icon-dark-white"> */
|