@cypress-design/react-checkbox 0.3.0 → 0.3.2

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.
@@ -105,10 +101,17 @@ function __rest(s, e) {
105
101
  }
106
102
 
107
103
  var compileReactIconProperties = function (_a) {
108
- var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size; _a.strokeColor; _a.fillColor; _a.secondaryStrokeColor; _a.secondaryFillColor; var attributes = __rest(_a, ["body", "compiledClasses", "size", "strokeColor", "fillColor", "secondaryStrokeColor", "secondaryFillColor"]);
109
- var componentProps = __assign({ width: size, height: size, fill: 'none', dangerouslySetInnerHTML: {
110
- __html: body
111
- } }, attributes);
104
+ var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
105
+ var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
106
+ if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) && attrName !== 'name') {
107
+ newAttributes[attrName] =
108
+ attributes[attrName];
109
+ }
110
+ return newAttributes;
111
+ }, {});
112
+ var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
113
+ __html: body,
114
+ } }, filteredAttributes);
112
115
  if (attributes.className) {
113
116
  compiledClasses.push(attributes.className);
114
117
  }
@@ -120,46 +123,64 @@ var compileReactIconProperties = function (_a) {
120
123
  var IconCheckmarkSmall = function (props) {
121
124
  var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
122
125
  var iconBodies = {
123
- "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\"/>"
126
+ "16": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M5 8.5 7.5 11 11 5\" class=\"icon-dark\"/>"
124
127
  };
125
128
  var body = iconBodies[size];
126
129
  if (!body) {
127
- throw Error("Icon \"checkmark-small\" is not available in size " + size);
130
+ throw Error("Icon \"checkmark-small\" is not available in size ".concat(size));
128
131
  }
129
132
  return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
130
133
  };
131
134
 
135
+
136
+ /* <wind-keep class=""> */
137
+
138
+ const Classes = {
139
+ wrapper: 'relative flex items-center',
140
+ hiddenInput: 'absolute inset-0 w-0 h-0 opacity-0',
141
+ labelTag: 'flex items-center',
142
+ visibleCheckbox: 'border border-solid rounded h-[16px] w-[16px] flex flex-shrink-0 items-center text-white',
143
+ trueLabel: 'block ml-[8px] text-[16px] leading-[24px] font-light select-none',
144
+ };
145
+ const CheckboxColors = {
146
+ indigo: 'border-indigo-500 bg-indigo-400',
147
+ jade: 'border-jade-500 bg-jade-400',
148
+ red: 'border-red-500 bg-red-400',
149
+ disabled: 'border-gray-200 bg-gray-100',
150
+ empty: 'border-gray-200 bg-white',
151
+ };
152
+
153
+ var uid = function () {
154
+ return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
155
+ };
132
156
  var Checkbox = function (_a) {
133
- var
134
- // @ts-ignore
135
- _b = _a.id,
136
- // @ts-ignore
137
- id = _b === void 0 ? crypto.randomUUID() : _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, rest = __rest$1(_a, ["id", "checked", "onChange", "color", "label", "disabled"]);
157
+ 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$1(_a, ["id", "checked", "onChange", "color", "label", "disabled", "className", "name"]);
138
158
  var _e = React__namespace.useState(checked), localChecked = _e[0], setChecked = _e[1];
139
159
  function onChangeInput(event) {
140
160
  setChecked(!localChecked);
141
161
  onChange(event);
142
162
  }
143
- return (React__namespace.createElement("label", __assign$1({}, rest, { className: clsx__default["default"](rest.className, 'relative flex items-center') }),
144
- React__namespace.createElement("input", { id: id, className: "absolute inset-0 w-0 h-0 opacity-0", "aria-describedby": id + "-description", name: id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
145
- localChecked && (React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
146
- React__namespace.createElement("span", { className: clsx__default["default"]([
147
- "block border-1 rounded h-16px w-16px flex items-center text-white",
148
- disabled
149
- ? 'border-gray-200 bg-gray-100'
150
- : localChecked
151
- ? {
152
- 'border-indigo-500 bg-indigo-400': color === 'indigo',
153
- 'border-jade-500 bg-jade-400': color === 'jade',
154
- 'border-red-500 bg-red-400': color === 'red'
155
- }
156
- : 'border-gray-200 bg-white',
157
- ]) }),
158
- label && (React__namespace.createElement("span", { className: clsx__default["default"]([
159
- disabled ? 'text-gray-500' : 'text-gray-800',
160
- 'block ml-2 text-16px leading-normal font-light select-none',
161
- ]) }, label))));
163
+ return (React__namespace.createElement("span", __assign$1({ className: clsx(className, Classes.wrapper) }, rest),
164
+ 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 }),
165
+ React__namespace.createElement("label", { className: Classes.labelTag, htmlFor: id },
166
+ localChecked && (
167
+ // <tw-keep strokeColor="white"/>
168
+ React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
169
+ React__namespace.createElement("span", { className: clsx([
170
+ Classes.visibleCheckbox,
171
+ disabled
172
+ ? CheckboxColors.disabled
173
+ : localChecked
174
+ ? CheckboxColors[color]
175
+ : CheckboxColors.empty,
176
+ ]) }),
177
+ label && (React__namespace.createElement("span", { className: clsx([
178
+ disabled ? 'text-gray-500' : 'text-gray-800 dark:text-gray-200',
179
+ Classes.trueLabel,
180
+ ]) }, label)))));
162
181
  };
163
182
 
164
183
  module.exports = Checkbox;
165
184
  //# sourceMappingURL=index.umd.js.map
185
+
186
+ /* <wind-keep class="absolute text-gray-500 text-gray-800 dark:text-gray-200 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"> */