@cypress-design/vue-checkbox 0.3.0 → 0.4.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 +15 -0
- package/Checkbox.stories.mdx +1 -1
- package/Checkbox.vue +27 -11
- package/dist/Checkbox.vue.d.ts +10 -2
- package/dist/Checkbox.vue.d.ts.map +1 -1
- package/dist/index.es.js +76 -80
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @cypress-design/vue-checkbox
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#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
|
|
12
|
+
|
|
13
|
+
Source: https://www.a11ymatters.com/pattern/checkbox/
|
|
14
|
+
|
|
15
|
+
- 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)]:
|
|
16
|
+
- @cypress-design/vue-icon@0.5.0
|
|
17
|
+
|
|
3
18
|
## 0.3.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/Checkbox.stories.mdx
CHANGED
|
@@ -30,7 +30,7 @@ import Checkbox from './Checkbox.vue'
|
|
|
30
30
|
<br />
|
|
31
31
|
<Checkbox label="Unchecked" :color="color"/>
|
|
32
32
|
<br />
|
|
33
|
-
<Checkbox
|
|
33
|
+
<Checkbox checked disabled label="Disabled & checked" :color="color"/>
|
|
34
34
|
<br />
|
|
35
35
|
<Checkbox disabled label="Disabled & unchecked" :color="color"/>
|
|
36
36
|
`,
|
package/Checkbox.vue
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
function uid() {
|
|
3
|
+
return String(Date.now().toString(32) + Math.random().toString(16)).replace(
|
|
4
|
+
/\./g,
|
|
5
|
+
''
|
|
6
|
+
)
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
1
10
|
<script lang="ts" setup>
|
|
2
11
|
import { ref, computed } from 'vue'
|
|
3
12
|
import { IconCheckmarkSmall } from '@cypress-design/vue-icon'
|
|
@@ -9,6 +18,10 @@ const props = withDefaults(
|
|
|
9
18
|
* It will be used to give match label with input for a11y.
|
|
10
19
|
*/
|
|
11
20
|
id?: string
|
|
21
|
+
/**
|
|
22
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
23
|
+
*/
|
|
24
|
+
name?: string
|
|
12
25
|
/**
|
|
13
26
|
* Is the checkbox checked when it is first rendered.
|
|
14
27
|
*/
|
|
@@ -30,12 +43,13 @@ const props = withDefaults(
|
|
|
30
43
|
label?: string
|
|
31
44
|
}>(),
|
|
32
45
|
{
|
|
33
|
-
|
|
34
|
-
id: crypto.randomUUID(),
|
|
46
|
+
id: uid(),
|
|
35
47
|
color: 'indigo',
|
|
36
48
|
}
|
|
37
49
|
)
|
|
38
50
|
|
|
51
|
+
|
|
52
|
+
|
|
39
53
|
const localChecked = ref(props.modelValue || props.checked)
|
|
40
54
|
|
|
41
55
|
const emit = defineEmits<{
|
|
@@ -63,16 +77,18 @@ const checkboxClasses = computed(() => [
|
|
|
63
77
|
</script>
|
|
64
78
|
|
|
65
79
|
<template>
|
|
66
|
-
<
|
|
67
|
-
<input :id="id" class="absolute inset-0 w-0 h-0 opacity-0" :name="id" type="checkbox" @change="updated"
|
|
80
|
+
<div class="relative flex items-center">
|
|
81
|
+
<input :id="id" class="absolute inset-0 w-0 h-0 opacity-0" :name="name || id" type="checkbox" @change="updated"
|
|
68
82
|
:disabled="props.disabled" :checked="localChecked" />
|
|
69
83
|
<IconCheckmarkSmall v-if="localChecked" strokeColor="white" class="absolute" />
|
|
70
84
|
<span :class="checkboxClasses" />
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
<label class="block" :for="id">
|
|
86
|
+
<slot name="label">
|
|
87
|
+
<span v-if="label"
|
|
88
|
+
:class="['ml-2 text-16px leading-normal font-light select-none', disabled ? 'text-gray-500' : 'text-gray-800']">
|
|
89
|
+
{{ label }}
|
|
90
|
+
</span>
|
|
91
|
+
</slot>
|
|
92
|
+
</label>
|
|
93
|
+
</div>
|
|
78
94
|
</template>
|
package/dist/Checkbox.vue.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
4
4
|
* It will be used to give match label with input for a11y.
|
|
5
5
|
*/
|
|
6
6
|
id?: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
9
|
+
*/
|
|
10
|
+
name?: string | undefined;
|
|
7
11
|
/**
|
|
8
12
|
* Is the checkbox checked when it is first rendered.
|
|
9
13
|
*/
|
|
@@ -24,7 +28,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
24
28
|
*/
|
|
25
29
|
label?: string | undefined;
|
|
26
30
|
}>, {
|
|
27
|
-
id:
|
|
31
|
+
id: string;
|
|
28
32
|
color: string;
|
|
29
33
|
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
30
34
|
"update:modelValue": (value: boolean) => void;
|
|
@@ -34,6 +38,10 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
34
38
|
* It will be used to give match label with input for a11y.
|
|
35
39
|
*/
|
|
36
40
|
id?: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Name attribute of the <input type="checkbox"/>.
|
|
43
|
+
*/
|
|
44
|
+
name?: string | undefined;
|
|
37
45
|
/**
|
|
38
46
|
* Is the checkbox checked when it is first rendered.
|
|
39
47
|
*/
|
|
@@ -54,7 +62,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
|
|
|
54
62
|
*/
|
|
55
63
|
label?: string | undefined;
|
|
56
64
|
}>, {
|
|
57
|
-
id:
|
|
65
|
+
id: string;
|
|
58
66
|
color: string;
|
|
59
67
|
}>>> & {
|
|
60
68
|
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.vue.d.ts","sourceRoot":"","sources":["../Checkbox.vue.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Checkbox.vue.d.ts","sourceRoot":"","sources":["../Checkbox.vue.ts"],"names":[],"mappings":";IAiFI;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;;OAGG;;IAEH;;OAEG;;;IAGH;;;OAGG;;;;;;;;IA1BH;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;;OAGG;;IAEH;;OAEG;;;IAGH;;;OAGG;;;;;;;;QAtBE,MAAM;WAaH,KAAK,GAAG,QAAQ,GAAG,MAAM;;AAvFrC,wBAoJK;AACL,aAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,aAAK,6BAA6B,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CAAE,CAAC;AAC9M,aAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAE5B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;QACzD,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KACb,GAAG,CAAC,CAAC,CAAC,CAAC;CACR,CAAC"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,52 +1,43 @@
|
|
|
1
|
-
import { h, defineComponent, ref, computed, openBlock, createElementBlock, createElementVNode, createBlock, unref, createCommentVNode, normalizeClass, renderSlot, toDisplayString } from "vue";
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { h as k, defineComponent as p, ref as f, computed as y, openBlock as i, createElementBlock as b, createElementVNode as s, createBlock as C, unref as m, createCommentVNode as h, normalizeClass as g, renderSlot as v, toDisplayString as x } from "vue";
|
|
2
|
+
import * as w from "@cypress-design/icon-registry";
|
|
3
|
+
import { ICON_COLOR_PROP_NAMES as S } from "@cypress-design/icon-registry";
|
|
4
|
+
const j = ({
|
|
5
|
+
body: e,
|
|
6
|
+
compiledClasses: t,
|
|
7
|
+
size: o,
|
|
8
|
+
class: l,
|
|
9
|
+
interactiveColorsOnGroup: c,
|
|
10
|
+
...a
|
|
10
11
|
}) => {
|
|
11
|
-
Object.keys(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const componentProps = {
|
|
17
|
-
width: size,
|
|
18
|
-
height: size,
|
|
12
|
+
const n = Object.keys(a).reduce((u, d) => (S.includes(d) || (u[d] = a[d]), u), {}), r = {
|
|
13
|
+
width: o,
|
|
14
|
+
height: o,
|
|
19
15
|
fill: "none",
|
|
20
|
-
innerHTML:
|
|
21
|
-
...
|
|
22
|
-
};
|
|
23
|
-
if (compiledClasses.length) {
|
|
24
|
-
componentProps.class = compiledClasses.join(" ");
|
|
25
|
-
}
|
|
26
|
-
return componentProps;
|
|
27
|
-
};
|
|
28
|
-
const IconCheckmarkSmall = (props) => {
|
|
29
|
-
const { sizeWithDefault: size, compiledClasses } = iconsRegistry.getComponentAttributes({ ...props, availableSizes: ["16"] });
|
|
30
|
-
const iconBodies = {
|
|
31
|
-
"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"/>'
|
|
16
|
+
innerHTML: e,
|
|
17
|
+
...n
|
|
32
18
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
size
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
return t.length && (r.class = t.join(" ")), r;
|
|
20
|
+
}, z = (e) => {
|
|
21
|
+
const { sizeWithDefault: t, compiledClasses: o } = w.getComponentAttributes({ ...e, availableSizes: ["16"] }), l = {
|
|
22
|
+
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"/>'
|
|
23
|
+
}[t];
|
|
24
|
+
if (!l)
|
|
25
|
+
throw Error(`Icon "checkmark-small" is not available in size ${t}`);
|
|
26
|
+
return k("svg", j({
|
|
27
|
+
...e,
|
|
28
|
+
size: t,
|
|
29
|
+
body: l,
|
|
30
|
+
compiledClasses: o
|
|
42
31
|
}));
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
}, B = { class: "relative flex items-center" }, O = ["id", "name", "disabled", "checked"], V = ["for"];
|
|
33
|
+
function E() {
|
|
34
|
+
return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, "");
|
|
35
|
+
}
|
|
36
|
+
const D = /* @__PURE__ */ p({
|
|
47
37
|
__name: "Checkbox",
|
|
48
38
|
props: {
|
|
49
|
-
id: { default:
|
|
39
|
+
id: { default: E() },
|
|
40
|
+
name: null,
|
|
50
41
|
checked: { type: Boolean },
|
|
51
42
|
color: { default: "indigo" },
|
|
52
43
|
disabled: { type: Boolean },
|
|
@@ -54,49 +45,54 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
54
45
|
label: null
|
|
55
46
|
},
|
|
56
47
|
emits: ["update:modelValue"],
|
|
57
|
-
setup(
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
localChecked.value = !localChecked.value;
|
|
62
|
-
emit("update:modelValue", localChecked.value);
|
|
48
|
+
setup(e, { emit: t }) {
|
|
49
|
+
const o = e, l = f(o.modelValue || o.checked);
|
|
50
|
+
function c() {
|
|
51
|
+
l.value = !l.value, t("update:modelValue", l.value);
|
|
63
52
|
}
|
|
64
|
-
const
|
|
53
|
+
const a = y(() => [
|
|
65
54
|
"block border-1 rounded h-16px w-16px",
|
|
66
|
-
|
|
67
|
-
"border-indigo-500 bg-indigo-400":
|
|
68
|
-
"border-jade-500 bg-jade-400":
|
|
69
|
-
"border-red-500 bg-red-400":
|
|
55
|
+
o.disabled ? "border-gray-200 bg-gray-100" : l.value ? {
|
|
56
|
+
"border-indigo-500 bg-indigo-400": o.color === "indigo",
|
|
57
|
+
"border-jade-500 bg-jade-400": o.color === "jade",
|
|
58
|
+
"border-red-500 bg-red-400": o.color === "red"
|
|
70
59
|
} : "border-gray-200 bg-white"
|
|
71
60
|
]);
|
|
72
|
-
return (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
61
|
+
return (n, r) => (i(), b("div", B, [
|
|
62
|
+
s("input", {
|
|
63
|
+
id: e.id,
|
|
64
|
+
class: "absolute inset-0 w-0 h-0 opacity-0",
|
|
65
|
+
name: e.name || e.id,
|
|
66
|
+
type: "checkbox",
|
|
67
|
+
onChange: c,
|
|
68
|
+
disabled: o.disabled,
|
|
69
|
+
checked: l.value
|
|
70
|
+
}, null, 40, O),
|
|
71
|
+
l.value ? (i(), C(m(z), {
|
|
72
|
+
key: 0,
|
|
73
|
+
strokeColor: "white",
|
|
74
|
+
class: "absolute"
|
|
75
|
+
})) : h("", !0),
|
|
76
|
+
s("span", {
|
|
77
|
+
class: g(m(a))
|
|
78
|
+
}, null, 2),
|
|
79
|
+
s("label", {
|
|
80
|
+
class: "block",
|
|
81
|
+
for: e.id
|
|
82
|
+
}, [
|
|
83
|
+
v(n.$slots, "label", {}, () => [
|
|
84
|
+
e.label ? (i(), b("span", {
|
|
93
85
|
key: 0,
|
|
94
|
-
class:
|
|
95
|
-
},
|
|
86
|
+
class: g(["ml-2 text-16px leading-normal font-light select-none", e.disabled ? "text-gray-500" : "text-gray-800"])
|
|
87
|
+
}, x(e.label), 3)) : h("", !0)
|
|
96
88
|
])
|
|
97
|
-
])
|
|
98
|
-
|
|
89
|
+
], 8, V)
|
|
90
|
+
]));
|
|
99
91
|
}
|
|
100
92
|
});
|
|
101
|
-
export {
|
|
93
|
+
export {
|
|
94
|
+
D as default
|
|
95
|
+
};
|
|
96
|
+
/* <windicss-keep class="block border-1 rounded h-16px w-16px 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 relative flex items-center absolute inset-0 w-0 h-0 opacity-0 ml-2 text-16px leading-normal font-light select-none text-gray-500 text-gray-800 icon-dark-white"> */
|
|
97
|
+
|
|
102
98
|
//# sourceMappingURL=index.es.js.map
|