@cypress-design/vue-checkbox 0.2.1 → 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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # @cypress-design/vue-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/vue-icon@0.5.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.1
4
31
 
5
32
  ### Patch 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,26 +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
- // @ts-ignore
19
- id: crypto.randomUUID(),
46
+ id: () => uid(),
20
47
  color: 'indigo',
21
48
  }
22
49
  )
23
50
 
51
+
52
+
24
53
  const localChecked = ref(props.modelValue || props.checked)
25
54
 
26
55
  const emit = defineEmits<{
@@ -48,16 +77,18 @@ const checkboxClasses = computed(() => [
48
77
  </script>
49
78
 
50
79
  <template>
51
- <label class="relative flex items-center">
52
- <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"
53
82
  :disabled="props.disabled" :checked="localChecked" />
54
83
  <IconCheckmarkSmall v-if="localChecked" strokeColor="white" class="absolute" />
55
84
  <span :class="checkboxClasses" />
56
- <slot name="label">
57
- <span v-if="label"
58
- :class="['block ml-2 text-16px leading-normal font-light select-none', disabled ? 'text-gray-500' : 'text-gray-800']">
59
- {{ label }}
60
- </span>
61
- </slot>
62
- </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>
63
94
  </template>
@@ -1,30 +1,74 @@
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
- id: any;
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
- id: any;
65
+ id: () => string;
22
66
  color: string;
23
67
  }>>> & {
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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oJK;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,102 +1,100 @@
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
- const compileVueIconProperties = ({
4
- body,
5
- compiledClasses,
6
- size,
7
- class: className,
8
- interactiveColorsOnGroup,
9
- ...attributes
1
+ import { defineComponent as k, h as p, ref as y, computed as C, openBlock as i, createElementBlock as b, createElementVNode as d, createBlock as v, unref as m, createCommentVNode as h, normalizeClass as g, renderSlot as x, toDisplayString as w } from "vue";
2
+ import * as S from "@cypress-design/icon-registry";
3
+ import { compileIcon as j, ICON_COLOR_PROP_NAMES as z } from "@cypress-design/icon-registry";
4
+ const f = ({
5
+ body: e,
6
+ compiledClasses: t,
7
+ size: o,
8
+ class: l,
9
+ interactiveColorsOnGroup: c,
10
+ ...a
10
11
  }) => {
11
- Object.keys(attributes).forEach((key) => {
12
- if (key.toLowerCase().endsWith("color")) {
13
- delete attributes[key];
14
- }
15
- });
16
- const componentProps = {
17
- width: size,
18
- height: size,
12
+ const n = Object.keys(a).reduce((u, s) => (z.includes(s) || (u[s] = a[s]), u), {}), r = {
13
+ width: o,
14
+ height: o,
19
15
  fill: "none",
20
- innerHTML: body,
21
- ...attributes
16
+ innerHTML: e,
17
+ ...n
22
18
  };
23
- if (compiledClasses.length) {
24
- componentProps.class = compiledClasses.join(" ");
25
- }
26
- return componentProps;
19
+ return t.length && (r.class = t.join(" ")), r;
27
20
  };
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"/>'
32
- };
33
- const body = iconBodies[size];
34
- if (!body) {
35
- throw Error(`Icon "checkmark-small" is not available in size ${size}`);
36
- }
37
- return h("svg", compileVueIconProperties({
38
- ...props,
39
- size,
40
- body,
41
- compiledClasses
21
+ k((e) => p("svg", f(j(e))));
22
+ const B = (e) => {
23
+ const { sizeWithDefault: t, compiledClasses: o } = S.getComponentAttributes({ ...e, availableSizes: ["16"] }), l = {
24
+ 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"/>'
25
+ }[t];
26
+ if (!l)
27
+ throw Error(`Icon "checkmark-small" is not available in size ${t}`);
28
+ return p("svg", f({
29
+ ...e,
30
+ size: t,
31
+ body: l,
32
+ compiledClasses: o
42
33
  }));
43
- };
44
- const _hoisted_1 = { class: "relative flex items-center" };
45
- const _hoisted_2 = ["id", "name", "disabled", "checked"];
46
- const _sfc_main = /* @__PURE__ */ defineComponent({
34
+ }, O = { class: "relative flex items-center" }, V = ["id", "name", "disabled", "checked"], E = ["for"];
35
+ function M() {
36
+ return String(Date.now().toString(32) + Math.random().toString(16)).replace(/\./g, "");
37
+ }
38
+ const I = /* @__PURE__ */ k({
47
39
  __name: "Checkbox",
48
40
  props: {
49
- id: { default: crypto.randomUUID() },
50
- modelValue: { type: Boolean },
41
+ id: { default: () => M() },
42
+ name: null,
43
+ checked: { type: Boolean },
51
44
  color: { default: "indigo" },
52
- label: null,
53
45
  disabled: { type: Boolean },
54
- checked: { type: Boolean }
46
+ modelValue: { type: Boolean },
47
+ label: null
55
48
  },
56
49
  emits: ["update:modelValue"],
57
- setup(__props, { emit }) {
58
- const props = __props;
59
- const localChecked = ref(props.modelValue || props.checked);
60
- function updated() {
61
- localChecked.value = !localChecked.value;
62
- emit("update:modelValue", localChecked.value);
50
+ setup(e, { emit: t }) {
51
+ const o = e, l = y(o.modelValue || o.checked);
52
+ function c() {
53
+ l.value = !l.value, t("update:modelValue", l.value);
63
54
  }
64
- const checkboxClasses = computed(() => [
55
+ const a = C(() => [
65
56
  "block border-1 rounded h-16px w-16px",
66
- props.disabled ? "border-gray-200 bg-gray-100" : localChecked.value ? {
67
- "border-indigo-500 bg-indigo-400": props.color === "indigo",
68
- "border-jade-500 bg-jade-400": props.color === "jade",
69
- "border-red-500 bg-red-400": props.color === "red"
57
+ o.disabled ? "border-gray-200 bg-gray-100" : l.value ? {
58
+ "border-indigo-500 bg-indigo-400": o.color === "indigo",
59
+ "border-jade-500 bg-jade-400": o.color === "jade",
60
+ "border-red-500 bg-red-400": o.color === "red"
70
61
  } : "border-gray-200 bg-white"
71
62
  ]);
72
- return (_ctx, _cache) => {
73
- return openBlock(), createElementBlock("label", _hoisted_1, [
74
- createElementVNode("input", {
75
- id: __props.id,
76
- class: "absolute inset-0 w-0 h-0 opacity-0",
77
- name: __props.id,
78
- type: "checkbox",
79
- onChange: updated,
80
- disabled: props.disabled,
81
- checked: localChecked.value
82
- }, null, 40, _hoisted_2),
83
- localChecked.value ? (openBlock(), createBlock(unref(IconCheckmarkSmall), {
84
- key: 0,
85
- strokeColor: "white",
86
- class: "absolute"
87
- })) : createCommentVNode("", true),
88
- createElementVNode("span", {
89
- class: normalizeClass(unref(checkboxClasses))
90
- }, null, 2),
91
- renderSlot(_ctx.$slots, "label", {}, () => [
92
- __props.label ? (openBlock(), createElementBlock("span", {
63
+ return (n, r) => (i(), b("div", O, [
64
+ d("input", {
65
+ id: e.id,
66
+ class: "absolute inset-0 w-0 h-0 opacity-0",
67
+ name: e.name || e.id,
68
+ type: "checkbox",
69
+ onChange: c,
70
+ disabled: o.disabled,
71
+ checked: l.value
72
+ }, null, 40, V),
73
+ l.value ? (i(), v(m(B), {
74
+ key: 0,
75
+ strokeColor: "white",
76
+ class: "absolute"
77
+ })) : h("", !0),
78
+ d("span", {
79
+ class: g(m(a))
80
+ }, null, 2),
81
+ d("label", {
82
+ class: "block",
83
+ for: e.id
84
+ }, [
85
+ x(n.$slots, "label", {}, () => [
86
+ e.label ? (i(), b("span", {
93
87
  key: 0,
94
- class: normalizeClass(["block ml-2 text-16px leading-normal font-light select-none", __props.disabled ? "text-gray-500" : "text-gray-800"])
95
- }, toDisplayString(__props.label), 3)) : createCommentVNode("", true)
88
+ class: g(["ml-2 text-16px leading-normal font-light select-none", e.disabled ? "text-gray-500" : "text-gray-800"])
89
+ }, w(e.label), 3)) : h("", !0)
96
90
  ])
97
- ]);
98
- };
91
+ ], 8, E)
92
+ ]));
99
93
  }
100
94
  });
101
- export { _sfc_main as default };
95
+ export {
96
+ I as default
97
+ };
98
+ /* <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"> */
99
+
102
100
  //# sourceMappingURL=index.es.js.map