@cypress-design/vue-checkbox 0.2.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 CHANGED
@@ -1,5 +1,35 @@
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
+
18
+ ## 0.3.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [#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
23
+
24
+ ## 0.2.1
25
+
26
+ ### Patch Changes
27
+
28
+ - [`e3eb9c7`](https://github.com/cypress-io/cypress-design/commit/e3eb9c7fee2d7a6e0a773e85ed4b73be04d83587) Thanks [@elevatebart](https://github.com/elevatebart)! - downgrade typescript to 4.4 for compat with app
29
+
30
+ - Updated dependencies [[`e3eb9c7`](https://github.com/cypress-io/cypress-design/commit/e3eb9c7fee2d7a6e0a773e85ed4b73be04d83587)]:
31
+ - @cypress-design/vue-icon@0.4.2
32
+
3
33
  ## 0.2.0
4
34
 
5
35
  ### Minor Changes
@@ -30,7 +30,7 @@ import Checkbox from './Checkbox.vue'
30
30
  <br />
31
31
  <Checkbox label="Unchecked" :color="color"/>
32
32
  <br />
33
- <Checkbox chedked disabled label="Disabled & checked" :color="color"/>
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,25 +1,55 @@
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'
4
13
 
5
-
6
- type CheckboxColor = 'red' | 'indigo' | 'jade'
7
-
8
14
  const props = withDefaults(
9
15
  defineProps<{
16
+ /**
17
+ * A unique identifier for the checkbox on the whole page.
18
+ * It will be used to give match label with input for a11y.
19
+ */
10
20
  id?: string
21
+ /**
22
+ * Name attribute of the <input type="checkbox"/>.
23
+ */
24
+ name?: string
25
+ /**
26
+ * Is the checkbox checked when it is first rendered.
27
+ */
28
+ checked?: boolean
29
+ /**
30
+ * The color of the background in the checkbox.
31
+ * The checkmark will always be white.
32
+ */
33
+ color?: 'red' | 'indigo' | 'jade'
34
+ /**
35
+ * If the checkbox is disabled, it will not be clickable.
36
+ */
37
+ disabled?: boolean
11
38
  modelValue?: boolean
12
- color?: CheckboxColor
39
+ /**
40
+ * Label for the checkbox.
41
+ * It is very important to set this to make the checkbox accessible.
42
+ */
13
43
  label?: string
14
- disabled?: boolean
15
- checked?: boolean
16
44
  }>(),
17
45
  {
18
- id: crypto.randomUUID(),
46
+ id: uid(),
19
47
  color: 'indigo',
20
48
  }
21
49
  )
22
50
 
51
+
52
+
23
53
  const localChecked = ref(props.modelValue || props.checked)
24
54
 
25
55
  const emit = defineEmits<{
@@ -47,16 +77,18 @@ const checkboxClasses = computed(() => [
47
77
  </script>
48
78
 
49
79
  <template>
50
- <label class="relative flex items-center">
51
- <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"
52
82
  :disabled="props.disabled" :checked="localChecked" />
53
83
  <IconCheckmarkSmall v-if="localChecked" strokeColor="white" class="absolute" />
54
84
  <span :class="checkboxClasses" />
55
- <slot name="label">
56
- <span v-if="label"
57
- :class="['block ml-2 text-16px leading-normal font-light select-none', disabled ? 'text-gray-500' : 'text-gray-800']">
58
- {{ label }}
59
- </span>
60
- </slot>
61
- </label>
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>
62
94
  </template>
@@ -1,22 +1,66 @@
1
1
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
2
+ /**
3
+ * A unique identifier for the checkbox on the whole page.
4
+ * It will be used to give match label with input for a11y.
5
+ */
2
6
  id?: string | undefined;
7
+ /**
8
+ * Name attribute of the <input type="checkbox"/>.
9
+ */
10
+ name?: string | undefined;
11
+ /**
12
+ * Is the checkbox checked when it is first rendered.
13
+ */
14
+ checked?: boolean | undefined;
15
+ /**
16
+ * The color of the background in the checkbox.
17
+ * The checkmark will always be white.
18
+ */
19
+ color?: "indigo" | "red" | "jade" | undefined;
20
+ /**
21
+ * If the checkbox is disabled, it will not be clickable.
22
+ */
23
+ disabled?: boolean | undefined;
3
24
  modelValue?: boolean | undefined;
4
- color?: ("indigo" | "red" | "jade") | undefined;
25
+ /**
26
+ * Label for the checkbox.
27
+ * It is very important to set this to make the checkbox accessible.
28
+ */
5
29
  label?: string | undefined;
6
- disabled?: boolean | undefined;
7
- checked?: boolean | undefined;
8
30
  }>, {
9
31
  id: string;
10
32
  color: string;
11
33
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
34
  "update:modelValue": (value: boolean) => void;
13
35
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
36
+ /**
37
+ * A unique identifier for the checkbox on the whole page.
38
+ * It will be used to give match label with input for a11y.
39
+ */
14
40
  id?: string | undefined;
41
+ /**
42
+ * Name attribute of the <input type="checkbox"/>.
43
+ */
44
+ name?: string | undefined;
45
+ /**
46
+ * Is the checkbox checked when it is first rendered.
47
+ */
48
+ checked?: boolean | undefined;
49
+ /**
50
+ * The color of the background in the checkbox.
51
+ * The checkmark will always be white.
52
+ */
53
+ color?: "indigo" | "red" | "jade" | undefined;
54
+ /**
55
+ * If the checkbox is disabled, it will not be clickable.
56
+ */
57
+ disabled?: boolean | undefined;
15
58
  modelValue?: boolean | undefined;
16
- color?: ("indigo" | "red" | "jade") | undefined;
59
+ /**
60
+ * Label for the checkbox.
61
+ * It is very important to set this to make the checkbox accessible.
62
+ */
17
63
  label?: string | undefined;
18
- disabled?: boolean | undefined;
19
- checked?: boolean | undefined;
20
64
  }>, {
21
65
  id: string;
22
66
  color: string;
@@ -24,7 +68,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
24
68
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
25
69
  }, {
26
70
  id: string;
27
- color: "indigo" | "red" | "jade";
71
+ color: 'red' | 'indigo' | 'jade';
28
72
  }>;
29
73
  export default _default;
30
74
  declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.vue.d.ts","sourceRoot":"","sources":["../Checkbox.vue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBAoGK;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"}
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,137 +1,98 @@
1
- import { h, defineComponent, ref, computed, openBlock, createElementBlock, createElementVNode, createBlock, unref, createCommentVNode, normalizeClass, renderSlot, toDisplayString } from "vue";
2
- import * as iconsRegistry from "@cypress-design/icon-registry";
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
- var __objRest = (source, exclude) => {
23
- var target = {};
24
- for (var prop in source)
25
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
- target[prop] = source[prop];
27
- if (source != null && __getOwnPropSymbols)
28
- for (var prop of __getOwnPropSymbols(source)) {
29
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
- target[prop] = source[prop];
31
- }
32
- return target;
33
- };
34
- const compileVueIconProperties = (_a) => {
35
- var _b = _a, {
36
- body,
37
- compiledClasses,
38
- size,
39
- strokeColor,
40
- fillColor,
41
- secondaryStrokeColor,
42
- secondaryFillColor,
43
- class: className
44
- } = _b, attributes = __objRest(_b, [
45
- "body",
46
- "compiledClasses",
47
- "size",
48
- "strokeColor",
49
- "fillColor",
50
- "secondaryStrokeColor",
51
- "secondaryFillColor",
52
- "class"
53
- ]);
54
- const componentProps = __spreadValues({
55
- width: size,
56
- height: size,
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
11
+ }) => {
12
+ const n = Object.keys(a).reduce((u, d) => (S.includes(d) || (u[d] = a[d]), u), {}), r = {
13
+ width: o,
14
+ height: o,
57
15
  fill: "none",
58
- innerHTML: body
59
- }, attributes);
60
- if (compiledClasses.length) {
61
- componentProps.class = compiledClasses.join(" ");
62
- }
63
- return componentProps;
64
- };
65
- const IconCheckmarkSmall = (props) => {
66
- const { sizeWithDefault: size, compiledClasses } = iconsRegistry.getComponentAttributes(__spreadProps(__spreadValues({}, props), { availableSizes: ["16"] }));
67
- const iconBodies = {
68
- "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
69
18
  };
70
- const body = iconBodies[size];
71
- if (!body) {
72
- throw Error(`Icon "checkmark-small" is not available in size ${size}`);
73
- }
74
- return h("svg", compileVueIconProperties(__spreadProps(__spreadValues({}, props), {
75
- size,
76
- body,
77
- compiledClasses
78
- })));
79
- };
80
- const _hoisted_1 = { class: "relative flex items-center" };
81
- const _hoisted_2 = ["id", "name", "disabled", "checked"];
82
- const _sfc_main = /* @__PURE__ */ defineComponent({
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
31
+ }));
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({
37
+ __name: "Checkbox",
83
38
  props: {
84
- id: { default: crypto.randomUUID() },
85
- modelValue: { type: Boolean },
39
+ id: { default: E() },
40
+ name: null,
41
+ checked: { type: Boolean },
86
42
  color: { default: "indigo" },
87
- label: null,
88
43
  disabled: { type: Boolean },
89
- checked: { type: Boolean }
44
+ modelValue: { type: Boolean },
45
+ label: null
90
46
  },
91
47
  emits: ["update:modelValue"],
92
- setup(__props, { emit }) {
93
- const props = __props;
94
- const localChecked = ref(props.modelValue || props.checked);
95
- function updated() {
96
- localChecked.value = !localChecked.value;
97
- 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);
98
52
  }
99
- const checkboxClasses = computed(() => [
53
+ const a = y(() => [
100
54
  "block border-1 rounded h-16px w-16px",
101
- props.disabled ? "border-gray-200 bg-gray-100" : localChecked.value ? {
102
- "border-indigo-500 bg-indigo-400": props.color === "indigo",
103
- "border-jade-500 bg-jade-400": props.color === "jade",
104
- "border-red-500 bg-red-400": props.color === "red"
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"
105
59
  } : "border-gray-200 bg-white"
106
60
  ]);
107
- return (_ctx, _cache) => {
108
- return openBlock(), createElementBlock("label", _hoisted_1, [
109
- createElementVNode("input", {
110
- id: __props.id,
111
- class: "absolute inset-0 w-0 h-0 opacity-0",
112
- name: __props.id,
113
- type: "checkbox",
114
- onChange: updated,
115
- disabled: props.disabled,
116
- checked: localChecked.value
117
- }, null, 40, _hoisted_2),
118
- localChecked.value ? (openBlock(), createBlock(unref(IconCheckmarkSmall), {
119
- key: 0,
120
- strokeColor: "white",
121
- class: "absolute"
122
- })) : createCommentVNode("", true),
123
- createElementVNode("span", {
124
- class: normalizeClass(unref(checkboxClasses))
125
- }, null, 2),
126
- renderSlot(_ctx.$slots, "label", {}, () => [
127
- __props.label ? (openBlock(), createElementBlock("span", {
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", {
128
85
  key: 0,
129
- class: normalizeClass(["block ml-2 text-16px leading-normal font-light select-none", __props.disabled ? "text-gray-500" : "text-gray-800"])
130
- }, toDisplayString(__props.label), 3)) : createCommentVNode("", true)
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)
131
88
  ])
132
- ]);
133
- };
89
+ ], 8, V)
90
+ ]));
134
91
  }
135
92
  });
136
- export { _sfc_main as default };
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
+
137
98
  //# sourceMappingURL=index.es.js.map