@cypress-design/react-checkbox 0.2.2 → 0.4.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/CHANGELOG.md +27 -0
- package/Checkbox.tsx +51 -23
- package/dist/Checkbox.d.ts +27 -5
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/index.es.js +21 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +20 -11
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @cypress-design/react-checkbox
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2afa4d5`](https://github.com/cypress-io/cypress-design/commit/2afa4d54a2373692f82bee35ae40446bc9bb3f91) Thanks [@elevatebart](https://github.com/elevatebart)! - avoid duplicate ids in checkboxes
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#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
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#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
|
|
18
|
+
|
|
19
|
+
Source: https://www.a11ymatters.com/pattern/checkbox/
|
|
20
|
+
|
|
21
|
+
- 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)]:
|
|
22
|
+
- @cypress-design/react-icon@0.4.0
|
|
23
|
+
|
|
24
|
+
## 0.3.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- [#44](https://github.com/cypress-io/cypress-design/pull/44) [`2fdaf6b`](https://github.com/cypress-io/cypress-design/commit/2fdaf6be6f81a2a851761258347ed213577c5b26) Thanks [@elevatebart](https://github.com/elevatebart)! - Add missing descriptions of props in button, tooltip, checkbox
|
|
29
|
+
|
|
3
30
|
## 0.2.2
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/Checkbox.tsx
CHANGED
|
@@ -4,23 +4,52 @@ 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
|
+
/**
|
|
9
|
+
* A unique identifier for the checkbox on the whole page.
|
|
10
|
+
* It will be used to give match label with input for a11y.
|
|
11
|
+
*/
|
|
8
12
|
id?: string
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
15
|
+
*/
|
|
16
|
+
name?: string
|
|
17
|
+
/**
|
|
18
|
+
* Is the checkbox checked when it is first rendered.
|
|
19
|
+
*/
|
|
20
|
+
checked?: boolean
|
|
21
|
+
/**
|
|
22
|
+
* The color of the background in the checkbox.
|
|
23
|
+
* The checkmark will always be white.
|
|
24
|
+
*/
|
|
25
|
+
color?: 'red' | 'indigo' | 'jade'
|
|
26
|
+
/**
|
|
27
|
+
* If the checkbox is disabled, it will not be clickable.
|
|
28
|
+
*/
|
|
13
29
|
disabled?: boolean
|
|
30
|
+
/**
|
|
31
|
+
* Label for the checkbox.
|
|
32
|
+
* It is very important to set this to make the checkbox accessible.
|
|
33
|
+
*/
|
|
34
|
+
label?: ReactNode
|
|
35
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
|
|
14
36
|
}
|
|
15
37
|
|
|
38
|
+
const uid = () =>
|
|
39
|
+
String(Date.now().toString(32) + Math.random().toString(16)).replace(
|
|
40
|
+
/\./g,
|
|
41
|
+
''
|
|
42
|
+
)
|
|
43
|
+
|
|
16
44
|
export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
17
|
-
|
|
18
|
-
id = crypto.randomUUID(),
|
|
45
|
+
id = uid(),
|
|
19
46
|
checked = false,
|
|
20
47
|
onChange,
|
|
21
48
|
color = 'indigo',
|
|
22
49
|
label,
|
|
23
50
|
disabled,
|
|
51
|
+
className,
|
|
52
|
+
name,
|
|
24
53
|
...rest
|
|
25
54
|
}) => {
|
|
26
55
|
const [localChecked, setChecked] = React.useState(checked)
|
|
@@ -31,15 +60,12 @@ export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
|
31
60
|
}
|
|
32
61
|
|
|
33
62
|
return (
|
|
34
|
-
<
|
|
35
|
-
{...rest}
|
|
36
|
-
className={clsx(rest.className, 'relative flex items-center')}
|
|
37
|
-
>
|
|
63
|
+
<div className={clsx(className, 'relative flex items-center')} {...rest}>
|
|
38
64
|
<input
|
|
39
65
|
id={id}
|
|
40
66
|
className="absolute inset-0 w-0 h-0 opacity-0"
|
|
41
67
|
aria-describedby={`${id}-description`}
|
|
42
|
-
name={id}
|
|
68
|
+
name={name || id}
|
|
43
69
|
type="checkbox"
|
|
44
70
|
onChange={onChangeInput}
|
|
45
71
|
disabled={disabled}
|
|
@@ -62,17 +88,19 @@ export const Checkbox: FunctionComponent<CheckboxProps> = ({
|
|
|
62
88
|
: 'border-gray-200 bg-white',
|
|
63
89
|
])}
|
|
64
90
|
/>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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>
|
|
76
104
|
)
|
|
77
105
|
}
|
|
78
106
|
|
package/dist/Checkbox.d.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* A unique identifier for the checkbox on the whole page.
|
|
6
|
+
* It will be used to give match label with input for a11y.
|
|
7
|
+
*/
|
|
4
8
|
id?: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
11
|
+
*/
|
|
12
|
+
name?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Is the checkbox checked when it is first rendered.
|
|
15
|
+
*/
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The color of the background in the checkbox.
|
|
19
|
+
* The checkmark will always be white.
|
|
20
|
+
*/
|
|
21
|
+
color?: 'red' | 'indigo' | 'jade';
|
|
22
|
+
/**
|
|
23
|
+
* If the checkbox is disabled, it will not be clickable.
|
|
24
|
+
*/
|
|
9
25
|
disabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Label for the checkbox.
|
|
28
|
+
* It is very important to set this to make the checkbox accessible.
|
|
29
|
+
*/
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
10
32
|
}
|
|
11
33
|
export declare const Checkbox: FunctionComponent<CheckboxProps>;
|
|
12
34
|
export default Checkbox;
|
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"}
|
package/dist/index.es.js
CHANGED
|
@@ -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
|
}
|
|
@@ -102,20 +110,20 @@ var IconCheckmarkSmall = function (props) {
|
|
|
102
110
|
}
|
|
103
111
|
return React.createElement('svg', compileReactIconProperties(__assign(__assign({}, props), { size: size, body: body, compiledClasses: compiledClasses })));
|
|
104
112
|
};
|
|
113
|
+
/* <windicss-keep class=""> */
|
|
105
114
|
|
|
115
|
+
var uid = function () {
|
|
116
|
+
return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, '');
|
|
117
|
+
};
|
|
106
118
|
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"]);
|
|
119
|
+
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
120
|
var _e = React.useState(checked), localChecked = _e[0], setChecked = _e[1];
|
|
113
121
|
function onChangeInput(event) {
|
|
114
122
|
setChecked(!localChecked);
|
|
115
123
|
onChange(event);
|
|
116
124
|
}
|
|
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 }),
|
|
125
|
+
return (React.createElement("div", __assign$1({ className: clsx(className, 'relative flex items-center') }, rest),
|
|
126
|
+
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
127
|
localChecked && (React.createElement(IconCheckmarkSmall, { strokeColor: "white", className: "absolute" })),
|
|
120
128
|
React.createElement("span", { className: clsx([
|
|
121
129
|
"block border-1 rounded h-16px w-16px flex items-center text-white",
|
|
@@ -129,11 +137,13 @@ var Checkbox = function (_a) {
|
|
|
129
137
|
}
|
|
130
138
|
: 'border-gray-200 bg-white',
|
|
131
139
|
]) }),
|
|
132
|
-
label && (React.createElement("span", { className: clsx([
|
|
140
|
+
React.createElement("label", { htmlFor: id }, label && (React.createElement("span", { className: clsx([
|
|
133
141
|
disabled ? 'text-gray-500' : 'text-gray-800',
|
|
134
142
|
'block ml-2 text-16px leading-normal font-light select-none',
|
|
135
|
-
]) }, label))));
|
|
143
|
+
]) }, label)))));
|
|
136
144
|
};
|
|
137
145
|
|
|
138
146
|
export { Checkbox as default };
|
|
147
|
+
/* <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"> */
|
|
148
|
+
|
|
139
149
|
//# sourceMappingURL=index.es.js.map
|