@cypress-design/react-checkbox 0.5.0 → 1.0.0
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 +6 -0
- package/CHANGELOG.md +76 -0
- package/Checkbox.rootstory.tsx +17 -0
- package/Checkbox.tsx +11 -17
- package/CheckboxReact.cy.tsx +14 -7
- package/ReadMe.md +19 -0
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.mjs +84 -32
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +90 -42
- package/dist/index.umd.js.map +1 -1
- package/package.json +11 -6
- package/rollup.config.mjs +3 -0
- package/tsconfig.build.json +1 -0
- package/Checkbox.stories.mdx +0 -67
- package/rollup.config.js +0 -3
- package/tsconfig.json +0 -4
package/dist/index.umd.js
CHANGED
|
@@ -4,10 +4,7 @@ var clsx = require('clsx');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var iconsRegistry = require('@cypress-design/icon-registry');
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
function _interopNamespace(e) {
|
|
10
|
-
if (e && e.__esModule) return e;
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
11
8
|
var n = Object.create(null);
|
|
12
9
|
if (e) {
|
|
13
10
|
Object.keys(e).forEach(function (k) {
|
|
@@ -20,13 +17,12 @@ function _interopNamespace(e) {
|
|
|
20
17
|
}
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
|
-
n
|
|
20
|
+
n.default = e;
|
|
24
21
|
return Object.freeze(n);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var iconsRegistry__namespace = /*#__PURE__*/_interopNamespace(iconsRegistry);
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
|
+
var iconsRegistry__namespace = /*#__PURE__*/_interopNamespaceDefault(iconsRegistry);
|
|
30
26
|
|
|
31
27
|
/******************************************************************************
|
|
32
28
|
Copyright (c) Microsoft Corporation.
|
|
@@ -42,6 +38,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
42
38
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
43
39
|
PERFORMANCE OF THIS SOFTWARE.
|
|
44
40
|
***************************************************************************** */
|
|
41
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
42
|
+
|
|
45
43
|
|
|
46
44
|
var __assign$1 = function() {
|
|
47
45
|
__assign$1 = Object.assign || function __assign(t) {
|
|
@@ -64,7 +62,12 @@ function __rest$1(s, e) {
|
|
|
64
62
|
t[p[i]] = s[p[i]];
|
|
65
63
|
}
|
|
66
64
|
return t;
|
|
67
|
-
}
|
|
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
|
+
};
|
|
68
71
|
|
|
69
72
|
/******************************************************************************
|
|
70
73
|
Copyright (c) Microsoft Corporation.
|
|
@@ -80,6 +83,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
80
83
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
81
84
|
PERFORMANCE OF THIS SOFTWARE.
|
|
82
85
|
***************************************************************************** */
|
|
86
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
87
|
+
|
|
83
88
|
|
|
84
89
|
var __assign = function() {
|
|
85
90
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -102,20 +107,47 @@ function __rest(s, e) {
|
|
|
102
107
|
t[p[i]] = s[p[i]];
|
|
103
108
|
}
|
|
104
109
|
return t;
|
|
105
|
-
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
113
|
+
var e = new Error(message);
|
|
114
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
115
|
+
};
|
|
106
116
|
|
|
107
117
|
var compileReactIconProperties = function (_a) {
|
|
108
|
-
var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
|
|
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"]);
|
|
109
119
|
var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
|
|
110
|
-
if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(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
|
|
111
124
|
newAttributes[attrName] =
|
|
112
125
|
attributes[attrName];
|
|
113
126
|
}
|
|
114
127
|
return newAttributes;
|
|
115
128
|
}, {});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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);
|
|
119
151
|
if (attributes.className) {
|
|
120
152
|
compiledClasses.push(attributes.className);
|
|
121
153
|
}
|
|
@@ -124,19 +156,39 @@ var compileReactIconProperties = function (_a) {
|
|
|
124
156
|
}
|
|
125
157
|
return componentProps;
|
|
126
158
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
var body = iconBodies[size];
|
|
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;
|
|
133
164
|
if (!body) {
|
|
134
|
-
throw Error("Icon \"
|
|
165
|
+
throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
|
|
135
166
|
}
|
|
136
|
-
return
|
|
137
|
-
}
|
|
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
|
+
|
|
138
175
|
|
|
139
|
-
/* <
|
|
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
|
+
};
|
|
140
192
|
|
|
141
193
|
var uid = function () {
|
|
142
194
|
return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
|
|
@@ -148,31 +200,27 @@ var Checkbox = function (_a) {
|
|
|
148
200
|
setChecked(!localChecked);
|
|
149
201
|
onChange(event);
|
|
150
202
|
}
|
|
151
|
-
return (React__namespace.createElement("span", __assign$1({ className:
|
|
152
|
-
React__namespace.createElement("input", { id: id, className:
|
|
153
|
-
React__namespace.createElement("label", { className:
|
|
203
|
+
return (React__namespace.createElement("span", __assign$1({ className: clsx(className, Classes.wrapper) }, rest),
|
|
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 },
|
|
154
206
|
localChecked && (
|
|
155
|
-
// <
|
|
207
|
+
// <tw-keep strokeColor="white"/>
|
|
156
208
|
React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
157
|
-
React__namespace.createElement("span", { className:
|
|
158
|
-
|
|
209
|
+
React__namespace.createElement("span", { className: clsx([
|
|
210
|
+
Classes.visibleCheckbox,
|
|
159
211
|
disabled
|
|
160
|
-
?
|
|
212
|
+
? CheckboxColors.disabled
|
|
161
213
|
: localChecked
|
|
162
|
-
?
|
|
163
|
-
|
|
164
|
-
'border-jade-500 bg-jade-400': color === 'jade',
|
|
165
|
-
'border-red-500 bg-red-400': color === 'red'
|
|
166
|
-
}
|
|
167
|
-
: 'border-gray-200 bg-white',
|
|
214
|
+
? CheckboxColors[color]
|
|
215
|
+
: CheckboxColors.empty,
|
|
168
216
|
]) }),
|
|
169
|
-
label && (React__namespace.createElement("span", { className:
|
|
217
|
+
label && (React__namespace.createElement("span", { className: clsx([
|
|
170
218
|
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
171
|
-
|
|
219
|
+
Classes.trueLabel,
|
|
172
220
|
]) }, label)))));
|
|
173
221
|
};
|
|
174
222
|
|
|
175
223
|
module.exports = Checkbox;
|
|
176
|
-
|
|
177
|
-
/* <windicss-keep class="block relative flex items-center absolute inset-0 w-0 h-0 opacity-0 border border-solid rounded h-[16px] w-[16px] flex-shrink-0 text-white border-gray-200 bg-gray-100 border-indigo-500 bg-indigo-400 border-jade-500 bg-jade-400 border-red-500 bg-red-400 bg-white text-gray-500 text-gray-800 ml-[8px] text-[16px] leading-[24px] font-light select-none icon-dark-white"> */
|
|
178
224
|
//# sourceMappingURL=index.umd.js.map
|
|
225
|
+
|
|
226
|
+
/* <wind-keep class="absolute text-gray-500 text-gray-800 icon-dark-white relative flex items-center inset-0 w-0 h-0 opacity-0 border border-solid rounded h-[16px] w-[16px] flex-shrink-0 text-white block ml-[8px] text-[16px] leading-[24px] font-light select-none border-indigo-500 bg-indigo-400 border-jade-500 bg-jade-400 border-red-500 bg-red-400 border-gray-200 bg-gray-100 bg-white"> */
|