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