@cypress-design/react-checkbox 0.3.0 → 0.4.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/CHANGELOG.md +30 -0
- package/Checkbox.tsx +29 -19
- package/dist/Checkbox.d.ts +5 -1
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/{index.es.js → index.es.mjs} +23 -12
- package/dist/index.es.mjs.map +1 -0
- package/dist/index.umd.js +21 -11
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/dist/index.es.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @cypress-design/react-checkbox
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#68](https://github.com/cypress-io/cypress-design/pull/68) [`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13) Thanks [@elevatebart](https://github.com/elevatebart)! - feat: publish `.mjs` files for esm intead of `.js`
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`8c577fb`](https://github.com/cypress-io/cypress-design/commit/8c577fb0c6a0411cf8218dfe78281834df3d6f13)]:
|
|
10
|
+
- @cypress-design/react-icon@0.4.2
|
|
11
|
+
|
|
12
|
+
## 0.4.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`2afa4d5`](https://github.com/cypress-io/cypress-design/commit/2afa4d54a2373692f82bee35ae40446bc9bb3f91) Thanks [@elevatebart](https://github.com/elevatebart)! - avoid duplicate ids in checkboxes
|
|
17
|
+
|
|
18
|
+
## 0.4.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- [#51](https://github.com/cypress-io/cypress-design/pull/51) [`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e) Thanks [@elevatebart](https://github.com/elevatebart)! - in the build asset, add a comment containing all used windicss classes in the component
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [#57](https://github.com/cypress-io/cypress-design/pull/57) [`6fa7d52`](https://github.com/cypress-io/cypress-design/commit/6fa7d52e409762bd1b32a8b04edaf78765830754) Thanks [@elevatebart](https://github.com/elevatebart)! - fix: move the input for checkboxes outside of label for accessibility
|
|
27
|
+
|
|
28
|
+
Source: https://www.a11ymatters.com/pattern/checkbox/
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`ccd8f9a`](https://github.com/cypress-io/cypress-design/commit/ccd8f9a8feb624c0a52deaa9754c76969f43fc1e), [`0866c65`](https://github.com/cypress-io/cypress-design/commit/0866c654f24c36951c98468d789462748606b428), [`43b53eb`](https://github.com/cypress-io/cypress-design/commit/43b53eb6bd10111629239a87374cfcc894eda0e3)]:
|
|
31
|
+
- @cypress-design/react-icon@0.4.0
|
|
32
|
+
|
|
3
33
|
## 0.3.0
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
package/Checkbox.tsx
CHANGED
|
@@ -4,12 +4,16 @@ import type { FunctionComponent, HTMLProps, ReactNode } from 'react'
|
|
|
4
4
|
import { IconCheckmarkSmall } from '@cypress-design/react-icon'
|
|
5
5
|
|
|
6
6
|
export interface CheckboxProps
|
|
7
|
-
extends Omit<HTMLProps<
|
|
7
|
+
extends Omit<HTMLProps<HTMLDivElement>, 'label' | 'onChange' | 'name'> {
|
|
8
8
|
/**
|
|
9
9
|
* A unique identifier for the checkbox on the whole page.
|
|
10
10
|
* It will be used to give match label with input for a11y.
|
|
11
11
|
*/
|
|
12
12
|
id?: string
|
|
13
|
+
/**
|
|
14
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
15
|
+
*/
|
|
16
|
+
name?: string
|
|
13
17
|
/**
|
|
14
18
|
* Is the checkbox checked when it is first rendered.
|
|
15
19
|
*/
|
|
@@ -31,14 +35,21 @@ export interface CheckboxProps
|
|
|
31
35
|
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
|
|
32
36
|
}
|
|
33
37
|
|
|
38
|
+
const uid = () =>
|
|
39
|
+
String(Date.now().toString(32) + Math.random().toString(16)).replace(
|
|
40
|
+
/\./g,
|
|
41
|
+
''
|
|
42
|
+
)
|
|
43
|
+
|
|
34
44
|
export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
35
|
-
|
|
36
|
-
id = crypto.randomUUID(),
|
|
45
|
+
id = uid(),
|
|
37
46
|
checked = false,
|
|
38
47
|
onChange,
|
|
39
48
|
color = 'indigo',
|
|
40
49
|
label,
|
|
41
50
|
disabled,
|
|
51
|
+
className,
|
|
52
|
+
name,
|
|
42
53
|
...rest
|
|
43
54
|
}) => {
|
|
44
55
|
const [localChecked, setChecked] = React.useState(checked)
|
|
@@ -49,15 +60,12 @@ export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
return (
|
|
52
|
-
<
|
|
53
|
-
{...rest}
|
|
54
|
-
className={clsx(rest.className, 'relative flex items-center')}
|
|
55
|
-
>
|
|
63
|
+
<div className={clsx(className, 'relative flex items-center')} {...rest}>
|
|
56
64
|
<input
|
|
57
65
|
id={id}
|
|
58
66
|
className="absolute inset-0 w-0 h-0 opacity-0"
|
|
59
67
|
aria-describedby={`${id}-description`}
|
|
60
|
-
name={id}
|
|
68
|
+
name={name || id}
|
|
61
69
|
type="checkbox"
|
|
62
70
|
onChange={onChangeInput}
|
|
63
71
|
disabled={disabled}
|
|
@@ -80,17 +88,19 @@ export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
|
80
88
|
: 'border-gray-200 bg-white',
|
|
81
89
|
])}
|
|
82
90
|
/>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
<label htmlFor={id}>
|
|
92
|
+
{label && (
|
|
93
|
+
<span
|
|
94
|
+
className={clsx([
|
|
95
|
+
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
96
|
+
'block ml-2 text-16px leading-normal font-light select-none',
|
|
97
|
+
])}
|
|
98
|
+
>
|
|
99
|
+
{label}
|
|
100
|
+
</span>
|
|
101
|
+
)}
|
|
102
|
+
</label>
|
|
103
|
+
</div>
|
|
94
104
|
)
|
|
95
105
|
}
|
|
96
106
|
|
package/dist/Checkbox.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { FunctionComponent, HTMLProps, ReactNode } from 'react';
|
|
3
|
-
export interface CheckboxProps extends Omit<HTMLProps<
|
|
3
|
+
export interface CheckboxProps extends Omit<HTMLProps<HTMLDivElement>, 'label' | 'onChange' | 'name'> {
|
|
4
4
|
/**
|
|
5
5
|
* A unique identifier for the checkbox on the whole page.
|
|
6
6
|
* It will be used to give match label with input for a11y.
|
|
7
7
|
*/
|
|
8
8
|
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
11
|
+
*/
|
|
12
|
+
name?: string;
|
|
9
13
|
/**
|
|
10
14
|
* Is the checkbox checked when it is first rendered.
|
|
11
15
|
*/
|
package/dist/Checkbox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGpE,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../Checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGpE,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IACtE;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;IACjC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAA;CAC/D;AAQD,eAAO,MAAM,QAAQ,EAAE,iBAAiB,CAAC,aAAa,CA6DrD,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import * as iconsRegistry from '@cypress-design/icon-registry';
|
|
4
|
+
import { ICON_COLOR_PROP_NAMES } from '@cypress-design/icon-registry';
|
|
4
5
|
|
|
5
6
|
/******************************************************************************
|
|
6
7
|
Copyright (c) Microsoft Corporation.
|
|
@@ -79,10 +80,17 @@ function __rest(s, e) {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
var compileReactIconProperties = function (_a) {
|
|
82
|
-
var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size
|
|
83
|
+
var body = _a.body, compiledClasses = _a.compiledClasses, size = _a.size, attributes = __rest(_a, ["body", "compiledClasses", "size"]);
|
|
84
|
+
var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
|
|
85
|
+
if (!ICON_COLOR_PROP_NAMES.includes(attrName)) {
|
|
86
|
+
newAttributes[attrName] =
|
|
87
|
+
attributes[attrName];
|
|
88
|
+
}
|
|
89
|
+
return newAttributes;
|
|
90
|
+
}, {});
|
|
83
91
|
var componentProps = __assign({ width: size, height: size, fill: 'none', dangerouslySetInnerHTML: {
|
|
84
92
|
__html: body
|
|
85
|
-
} },
|
|
93
|
+
} }, filteredAttributes);
|
|
86
94
|
if (attributes.className) {
|
|
87
95
|
compiledClasses.push(attributes.className);
|
|
88
96
|
}
|
|
@@ -103,19 +111,20 @@ var IconCheckmarkSmall = function (props) {
|
|
|
103
111
|
return React.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
|
|
104
112
|
};
|
|
105
113
|
|
|
114
|
+
/* <windicss-keep class=""> */
|
|
115
|
+
|
|
116
|
+
var uid = function () {
|
|
117
|
+
return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
|
|
118
|
+
};
|
|
106
119
|
var Checkbox = function (_a) {
|
|
107
|
-
var
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
_b = _a.id,
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
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"]);
|
|
120
|
+
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"]);
|
|
112
121
|
var _e = React.useState(checked), localChecked = _e[0], setChecked = _e[1];
|
|
113
122
|
function onChangeInput(event) {
|
|
114
123
|
setChecked(!localChecked);
|
|
115
124
|
onChange(event);
|
|
116
125
|
}
|
|
117
|
-
return (React.createElement("
|
|
118
|
-
React.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 }),
|
|
126
|
+
return (React.createElement("div", __assign$1({ className: clsx(className, 'relative flex items-center') }, rest),
|
|
127
|
+
React.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 }),
|
|
119
128
|
localChecked && (React.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
120
129
|
React.createElement("span", { className: clsx([
|
|
121
130
|
"block border-1 rounded h-16px w-16px flex items-center text-white",
|
|
@@ -129,11 +138,13 @@ var Checkbox = function (_a) {
|
|
|
129
138
|
}
|
|
130
139
|
: 'border-gray-200 bg-white',
|
|
131
140
|
]) }),
|
|
132
|
-
label && (React.createElement("span", { className: clsx([
|
|
141
|
+
React.createElement("label", { htmlFor: id }, label && (React.createElement("span", { className: clsx([
|
|
133
142
|
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
134
143
|
'block ml-2 text-16px leading-normal font-light select-none',
|
|
135
|
-
]) }, label))));
|
|
144
|
+
]) }, label)))));
|
|
136
145
|
};
|
|
137
146
|
|
|
138
147
|
export { Checkbox as default };
|
|
139
|
-
|
|
148
|
+
|
|
149
|
+
/* <windicss-keep class="relative flex items-center absolute inset-0 w-0 h-0 opacity-0 block border-1 rounded h-16px w-16px 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-2 text-16px leading-normal font-light select-none"> */
|
|
150
|
+
//# sourceMappingURL=index.es.mjs.map
|