@cypress-design/react-checkbox 0.1.0 → 0.2.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
@@ -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,20 +104,61 @@ 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; _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);
112
+ if (attributes.className) {
113
+ compiledClasses.push(attributes.className);
114
+ }
115
+ if (compiledClasses.length) {
116
+ componentProps.className = compiledClasses.join(' ');
117
+ }
118
+ return componentProps;
119
+ };
120
+ var IconCheckmarkSmall = function (props) {
121
+ var _a = iconsRegistry__namespace.getComponentAttributes(__assign(__assign({}, props), { availableSizes: ["16"] })), size = _a.sizeWithDefault, compiledClasses = _a.compiledClasses;
122
+ 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\"/>"
124
+ };
125
+ var body = iconBodies[size];
126
+ if (!body) {
127
+ throw Error("Icon \"checkmark-small\" is not available in size " + size);
128
+ }
129
+ return React__namespace.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
130
+ };
131
+
64
132
  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))));
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"]);
138
+ var _e = React__namespace.useState(checked), localChecked = _e[0], setChecked = _e[1];
139
+ function onChangeInput(event) {
140
+ setChecked(!localChecked);
141
+ onChange(event);
142
+ }
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))));
77
162
  };
78
163
 
79
164
  module.exports = Checkbox;