@fiscozen/checkbox 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/checkbox",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Design System Checkbox and Checkbox Group component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "peerDependencies": {
14
14
  "tailwindcss": "^3.4.1",
15
15
  "vue": "^3.4.13",
16
- "@fiscozen/icons": "^0.1.3"
16
+ "@fiscozen/icons": "^0.1.4"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@rushstack/eslint-patch": "^1.3.3",
@@ -35,9 +35,9 @@
35
35
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
36
36
  "@fortawesome/vue-fontawesome": "^3.0.6",
37
37
  "@fiscozen/eslint-config": "^0.1.0",
38
+ "@fiscozen/icons": "^0.1.4",
38
39
  "@fiscozen/prettier-config": "^0.1.0",
39
- "@fiscozen/tsconfig": "^0.1.0",
40
- "@fiscozen/icons": "^0.1.3"
40
+ "@fiscozen/tsconfig": "^0.1.0"
41
41
  },
42
42
  "license": "MIT",
43
43
  "scripts": {
@@ -2,7 +2,7 @@
2
2
  <div class="flex justify-center flex-col w-fit">
3
3
  <input
4
4
  type="checkbox"
5
- :id="value.replace(/ /g, '-').toLowerCase()"
5
+ :id="id"
6
6
  :disabled="disabled"
7
7
  :checked="checked"
8
8
  :class="staticInputClass"
@@ -14,7 +14,7 @@
14
14
  ref="refCheckbox"
15
15
  />
16
16
  <label
17
- :for="value.replace(/ /g, '-').toLowerCase()"
17
+ :for="id"
18
18
  :class="[staticLabelClass, computedLabelClass]"
19
19
  >
20
20
  <FzIcon
@@ -44,9 +44,13 @@ const props = withDefaults(defineProps<FzCheckboxProps>(), {
44
44
  indeterminate: false,
45
45
  });
46
46
 
47
- const value = props.value || props.label;
47
+ const currentValue = computed(() => props.value ?? props.label);
48
48
 
49
- const model = defineModel<boolean | string[]>({
49
+ const id = computed(() => {
50
+ return currentValue.value.toString().replace(/ /g, "-").toLowerCase();
51
+ })
52
+
53
+ const model = defineModel<boolean | (string | number | boolean)[]>({
50
54
  required: true,
51
55
  });
52
56
 
@@ -96,7 +100,7 @@ const checkValueIsInModel = () => {
96
100
  if (typeof model.value === "boolean") {
97
101
  return model.value;
98
102
  } else {
99
- return model.value.includes(value);
103
+ return model.value.includes(currentValue.value);
100
104
  }
101
105
  };
102
106
 
@@ -130,9 +134,9 @@ onMounted(() => {
130
134
  if (model.value) refCheckbox.value?.dispatchEvent(new Event("change"));
131
135
  else if (props.checked !== undefined) model.value = props.checked;
132
136
  } else {
133
- if (model.value.includes(value))
137
+ if (model.value.includes(currentValue.value))
134
138
  refCheckbox.value?.dispatchEvent(new Event("change"));
135
- else if (props.checked) model.value.push(value);
139
+ else if (props.checked) model.value.push(currentValue.value);
136
140
  }
137
141
  });
138
142
  </script>
@@ -9,10 +9,10 @@
9
9
  <div :class="[staticSlotContainerClass, computedSlotContainerClass]">
10
10
  <FzCheckboxGroupOption
11
11
  v-for="option in options"
12
- :key="option.value"
12
+ :key="option.value ? option.value.toString() : option.label"
13
13
  v-model="model"
14
- v-bind="option"
15
14
  :disabled="disabled"
15
+ v-bind="option"
16
16
  :emphasis="emphasis"
17
17
  :error="error"
18
18
  :size="size"
@@ -26,11 +26,15 @@
26
26
 
27
27
  <script setup lang="ts">
28
28
  import { computed } from "vue";
29
- import { FzCheckboxGroupProps, ParentCheckbox } from "./types";
29
+ import { FzCheckboxGroupProps } from "./types";
30
30
  import FzCheckboxErrorText from "./components/FzCheckboxErrorText.vue";
31
31
  import { mapSizeToClasses } from "./common";
32
32
  import FzCheckboxGroupOption from "./components/FzCheckboxGroupOption.vue";
33
33
 
34
+ FzCheckboxGroupOption.compatConfig = {
35
+ MODE:3
36
+ }
37
+
34
38
  const props = defineProps<FzCheckboxGroupProps>();
35
39
  const id = `fz-checkbox-group-${generateRandomId()}`;
36
40
 
@@ -14,10 +14,10 @@
14
14
  <div :class="[staticChildContainerClass, computedChildContainerClasses]">
15
15
  <FzCheckbox
16
16
  v-for="child in children"
17
- :key="child.value"
17
+ :key="child.value ? child.value.toString() : child.label"
18
18
  v-model="model"
19
- v-bind="child"
20
19
  :disabled="disabled"
20
+ v-bind="child"
21
21
  :emphasis="emphasis"
22
22
  :error="error"
23
23
  :size="size"
@@ -32,9 +32,13 @@ import { computed } from "vue";
32
32
  import FzCheckbox from "../FzCheckbox.vue";
33
33
  import { ParentCheckbox } from "../types";
34
34
 
35
- const props = defineProps<ParentCheckbox & { size: "sm" | "md" }>();
35
+ FzCheckbox.compatConfig = {
36
+ MODE: 3,
37
+ };
36
38
 
37
- const model = defineModel<string[]>({
39
+ const props = defineProps<ParentCheckbox & { size: "sm" | "md" }>();
40
+ const currentValue = computed(() => props.value ?? props.label);
41
+ const model = defineModel<(string | number | boolean)[]>({
38
42
  required: true,
39
43
  default: [],
40
44
  });
@@ -50,7 +54,7 @@ const isIndeterminate = computed(() => {
50
54
  if (!props.children) return false;
51
55
 
52
56
  const numChecked = props.children.filter((child) =>
53
- model.value.includes(child.value || child.label),
57
+ model.value.includes(child.value ?? child.label),
54
58
  ).length;
55
59
  return numChecked > 0 && numChecked < props.children.length;
56
60
  });
@@ -58,28 +62,28 @@ const isIndeterminate = computed(() => {
58
62
  function handleCheckboxParentChange() {
59
63
  if (!props.children) return;
60
64
  const numChecked = props.children.filter((child) =>
61
- model.value.includes(child.value || child.label),
65
+ model.value.includes(child.value ?? child.label),
62
66
  ).length;
63
67
 
64
68
  if (numChecked === props.children.length) {
65
69
  // push parent value to model (using concat to force reactivity, push seems to not work)
66
- model.value = model.value.concat(props.value || props.label);
70
+ model.value = model.value.concat(currentValue.value);
67
71
  } else {
68
72
  // remove parent value from model if it exists
69
- if (model.value.includes(props.value || props.label))
73
+ if (model.value.includes(currentValue.value))
70
74
  model.value = model.value.filter(
71
- (value) => value !== (props.value || props.label),
75
+ (value) => value !== currentValue.value,
72
76
  );
73
77
  }
74
78
  }
75
79
 
76
80
  function onCheckboxParentChange() {
77
81
  if (!props.children) return;
78
- if (model.value.includes(props.value || props.label)) {
82
+ if (model.value.includes(currentValue.value)) {
79
83
  // push all children values to model that are not already in model
80
84
  model.value = model.value.concat(
81
85
  props.children
82
- ?.map((child) => child.value || child.label)
86
+ ?.map((child) => child.value ?? child.label)
83
87
  .filter((value) => !model.value.includes(value)),
84
88
  );
85
89
  } else {
@@ -87,7 +91,7 @@ function onCheckboxParentChange() {
87
91
  model.value = model.value.filter(
88
92
  (value) =>
89
93
  !props.children
90
- ?.map((child) => child.value || child.label)
94
+ ?.map((child) => child.value ?? child.label)
91
95
  .includes(value),
92
96
  );
93
97
  }
package/src/types.ts CHANGED
@@ -6,7 +6,7 @@ export type FzCheckboxProps = {
6
6
  /**
7
7
  * The value of the checkbox. If not provided, the value will be the label
8
8
  */
9
- value?: string;
9
+ value?: string | number | boolean;
10
10
  /**
11
11
  * The size of the checkbox
12
12
  */