@cypress-design/react-checkbox 0.1.0 → 0.2.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/CHANGELOG.md +11 -0
- package/Checkbox.stories.mdx +54 -10
- package/Checkbox.tsx +64 -46
- package/CheckboxReact.cy.tsx +23 -0
- package/dist/Checkbox.d.ts +6 -4
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +90 -13
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +94 -13
- package/dist/index.umd.js.map +1 -1
- package/index.ts +1 -1
- package/package.json +5 -1
- package/rollup.config.js +2 -2
- package/tsconfig.build.json +1 -1
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,57 @@ function __rest(s, e) {
|
|
|
60
104
|
return t;
|
|
61
105
|
}
|
|
62
106
|
|
|
63
|
-
|
|
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 ".concat(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,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
133
|
+
var _b = _a.id, 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"]);
|
|
134
|
+
var _e = React__namespace.useState(checked), localChecked = _e[0], setChecked = _e[1];
|
|
135
|
+
function onChangeInput(event) {
|
|
136
|
+
setChecked(!localChecked);
|
|
137
|
+
onChange(event);
|
|
138
|
+
}
|
|
139
|
+
return (React__namespace.createElement("label", __assign$1({}, rest, { className: clsx__default["default"](rest.className, 'relative flex items-center') }),
|
|
140
|
+
React__namespace.createElement("input", { id: id, className: "absolute inset-0 w-0 h-0 opacity-0", "aria-describedby": "".concat(id, "-description"), name: id, type: "checkbox", onChange: onChangeInput, disabled: disabled, checked: localChecked }),
|
|
141
|
+
localChecked && (React__namespace.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
142
|
+
React__namespace.createElement("span", { className: clsx__default["default"]([
|
|
143
|
+
"block border-1 rounded h-16px w-16px flex items-center text-white",
|
|
144
|
+
disabled
|
|
145
|
+
? 'border-gray-200 bg-gray-100'
|
|
146
|
+
: localChecked
|
|
147
|
+
? {
|
|
148
|
+
'border-indigo-500 bg-indigo-400': color === 'indigo',
|
|
149
|
+
'border-jade-500 bg-jade-400': color === 'jade',
|
|
150
|
+
'border-red-500 bg-red-400': color === 'red'
|
|
151
|
+
}
|
|
152
|
+
: 'border-gray-200 bg-white',
|
|
153
|
+
]) }),
|
|
154
|
+
label && (React__namespace.createElement("span", { className: clsx__default["default"]([
|
|
155
|
+
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
156
|
+
'block ml-2 text-16px leading-normal font-light select-none',
|
|
157
|
+
]) }, label))));
|
|
77
158
|
};
|
|
78
159
|
|
|
79
160
|
module.exports = Checkbox;
|