@cypress-design/react-checkbox 0.1.0 → 0.1.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/dist/index.umd.js CHANGED
@@ -1,6 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var clsx = require('clsx');
3
4
  var React = require('react');
5
+ var iconsRegistry = require('@cypress-design/icon-registry');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
4
8
 
5
9
  function _interopNamespace(e) {
6
10
  if (e && e.__esModule) return e;
@@ -20,7 +24,47 @@ function _interopNamespace(e) {
20
24
  return Object.freeze(n);
21
25
  }
22
26
 
27
+ var clsx__default = /*#__PURE__*/_interopDefaultLegacy(clsx);
23
28
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
+ var iconsRegistry__namespace = /*#__PURE__*/_interopNamespace(iconsRegistry);
30
+
31
+ /******************************************************************************
32
+ Copyright (c) Microsoft Corporation.
33
+
34
+ Permission to use, copy, modify, and/or distribute this software for any
35
+ purpose with or without fee is hereby granted.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
38
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
40
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
41
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
42
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
43
+ PERFORMANCE OF THIS SOFTWARE.
44
+ ***************************************************************************** */
45
+
46
+ var __assign$1 = function() {
47
+ __assign$1 = Object.assign || function __assign(t) {
48
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
49
+ s = arguments[i];
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
51
+ }
52
+ return t;
53
+ };
54
+ return __assign$1.apply(this, arguments);
55
+ };
56
+
57
+ function __rest$1(s, e) {
58
+ var t = {};
59
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
60
+ t[p] = s[p];
61
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
62
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
63
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
64
+ t[p[i]] = s[p[i]];
65
+ }
66
+ return t;
67
+ }
24
68
 
25
69
  /******************************************************************************
26
70
  Copyright (c) Microsoft Corporation.
@@ -60,21 +104,86 @@ function __rest(s, e) {
60
104
  return t;
61
105
  }
62
106
 
63
- // TODO: how do you disable it? does it work?
107
+ var compileReactIconProperties = function (_a) {
108
+ var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
109
+ var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
110
+ if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) && attrName !== 'name') {
111
+ newAttributes[attrName] =
112
+ attributes[attrName];
113
+ }
114
+ return newAttributes;
115
+ }, {});
116
+ var componentProps = __assign({ width: size, height: size, viewBox: "0 0 " + size + " " + size, fill: 'none', dangerouslySetInnerHTML: {
117
+ __html: body
118
+ } }, filteredAttributes);
119
+ if (attributes.className) {
120
+ compiledClasses.push(attributes.className);
121
+ }
122
+ if (compiledClasses.length) {
123
+ componentProps.className = compiledClasses.join(' ');
124
+ }
125
+ return componentProps;
126
+ };
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];
133
+ if (!body) {
134
+ throw Error("Icon \"checkmark-small\" is not available in size " + size);
135
+ }
136
+ return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
137
+ };
138
+
139
+ /* <windicss-keep class=""> */
140
+
141
+ var Classes = {
142
+ wrapper: 'relative flex items-center',
143
+ hiddenInput: 'absolute inset-0 w-0 h-0 opacity-0',
144
+ labelTag: 'flex items-center',
145
+ visibleCheckbox: 'border border-solid rounded h-[16px] w-[16px] flex flex-shrink-0 items-center text-white',
146
+ trueLabel: 'block ml-[8px] text-[16px] leading-[24px] font-light select-none'
147
+ };
148
+ var CheckboxColors = {
149
+ indigo: 'border-indigo-500 bg-indigo-400',
150
+ jade: 'border-jade-500 bg-jade-400',
151
+ red: 'border-red-500 bg-red-400',
152
+ disabled: 'border-gray-200 bg-gray-100',
153
+ empty: 'border-gray-200 bg-white'
154
+ };
155
+
156
+ var uid = function () {
157
+ return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
158
+ };
64
159
  var Checkbox = function (_a) {
65
- var _b = _a.id, id = _b === void 0 ? crypto.randomUUID() : _b, modelValue = _a.modelValue, onChange = _a.onChange, _c = _a.state, state = _c === void 0 ? 'default' : _c, label = _a.label, rest = __rest(_a, ["id", "modelValue", "onChange", "state", "label"]);
66
- return (React__namespace.createElement("div", __assign({}, rest, { className: "relative flex items-center" }),
67
- React__namespace.createElement("div", { className: "flex items-center h-5" },
68
- React__namespace.createElement("input", { id: id, defaultChecked: modelValue, "aria-describedby": "".concat(id, "-description"), name: id, type: "checkbox", className: "border-1 rounded border-gray-200 bg-white h-4 w-4 text-indigo-500 disabled:bg-gray-100 checked:bg-indigo-500 ".concat(state === 'default'
69
- ? 'text-indigo-500 checked:border-indigo-300 checked:bg-indigo-600 checked:text-indigo-600'
70
- : '', " ").concat(state === 'success'
71
- ? 'checked:border-jade-300 checked:bg-jade-600 checked:text-jade-600'
72
- : '', " ").concat(state === 'danger'
73
- ? 'checked:border-red-300 checked:bg-red-600 checked:text-red-600'
74
- : ''), onChange: onChange })),
75
- React__namespace.createElement("div", { className: "ml-2 text-16px leading-normal" },
76
- React__namespace.createElement("label", { "v-if": "label", htmlFor: id, className: "disabled:text-gray-500 text-gray-800 font-light select-none" }, label))));
160
+ 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"]);
161
+ var _e = React__namespace.useState(checked), localChecked = _e[0], setChecked = _e[1];
162
+ function onChangeInput(event) {
163
+ setChecked(!localChecked);
164
+ onChange(event);
165
+ }
166
+ return (React__namespace.createElement("span", __assign$1({ className: clsx__default["default"](className, Classes.wrapper) }, rest),
167
+ React__namespace.createElement("input", { id: id, className: Classes.hiddenInput, "aria-describedby": id + "-description", name: name || id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
168
+ React__namespace.createElement("label", { className: Classes.labelTag, htmlFor: id },
169
+ localChecked && (
170
+ // <tw-keep strokeColor="white"/>
171
+ React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
172
+ React__namespace.createElement("span", { className: clsx__default["default"]([
173
+ Classes.visibleCheckbox,
174
+ disabled
175
+ ? CheckboxColors.disabled
176
+ : localChecked
177
+ ? CheckboxColors[color]
178
+ : CheckboxColors.empty,
179
+ ]) }),
180
+ label && (React__namespace.createElement("span", { className: clsx__default["default"]([
181
+ disabled ? 'text-gray-500' : 'text-gray-800',
182
+ Classes.trueLabel,
183
+ ]) }, label)))));
77
184
  };
78
185
 
79
186
  module.exports = Checkbox;
187
+
188
+ /* <windicss-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"> */
80
189
  //# sourceMappingURL=index.umd.js.map