@cypress-design/react-checkbox 0.4.6 → 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/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 _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
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["default"] = e;
20
+ n.default = e;
24
21
  return Object.freeze(n);
25
22
  }
26
23
 
27
- var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
28
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
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
- var componentProps = __assign({ width: size, height: size, viewBox: "0 0 " + size + " " + size, fill: 'none', dangerouslySetInnerHTML: {
117
- __html: body
118
- } }, filteredAttributes);
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 === '>' ? '&gt;' : '&lt;';
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
- var IconCheckmarkSmall = function (props) {
128
- var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
129
- var iconBodies = {
130
- "16": "<path d=\"M5 8.5 7.5 11 11 5\" stroke=\"currentColor\" class=\"icon-dark\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>"
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 \"checkmark-small\" is not available in size " + size);
165
+ throw Error("Icon \"".concat(name, "\" is not available in size ").concat(size));
135
166
  }
136
- return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
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
- /* <windicss-keep class=""> */
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: clsx__default["default"](className, 'block relative flex items-center') }, rest),
152
- React__namespace.createElement("input", { id: id, className: "absolute inset-0 w-0 h-0 opacity-0", "aria-describedby": id + "-description", name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
153
- React__namespace.createElement("label", { className: "flex items-center", htmlFor: id },
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
- // <windi-keep strokeColor="white"/>
207
+ // <tw-keep strokeColor="white"/>
156
208
  React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
157
- React__namespace.createElement("span", { className: clsx__default["default"]([
158
- "block border-1 border-solid rounded h-16px w-16px flex flex-shrink-0 items-center text-white",
209
+ React__namespace.createElement("span", { className: clsx([
210
+ Classes.visibleCheckbox,
159
211
  disabled
160
- ? 'border-gray-200 bg-gray-100'
212
+ ? CheckboxColors.disabled
161
213
  : localChecked
162
- ? {
163
- 'border-indigo-500 bg-indigo-400': color === 'indigo',
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: clsx__default["default"]([
217
+ label && (React__namespace.createElement("span", { className: clsx([
170
218
  disabled ? 'text-gray-500' : 'text-gray-800',
171
- 'block ml-8px text-16px leading-24px font-light select-none',
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-1 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"> */