@code-coaching/vuetiful 0.12.1 → 0.13.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.
Files changed (30) hide show
  1. package/dist/types/components/atoms/VRadio/VRadioDescription.test.d.ts +1 -0
  2. package/dist/types/components/atoms/VRadio/VRadioDescription.vue.d.ts +14 -0
  3. package/dist/types/components/atoms/VRadio/VRadioGroup.test.d.ts +1 -0
  4. package/dist/types/components/atoms/VRadio/VRadioGroup.vue.d.ts +70 -0
  5. package/dist/types/components/atoms/VRadio/VRadioItem.test.d.ts +1 -0
  6. package/dist/types/components/atoms/{VRadioItem.vue.d.ts → VRadio/VRadioItem.vue.d.ts} +2 -2
  7. package/dist/types/components/atoms/VRadio/VRadioLabel.test.d.ts +1 -0
  8. package/dist/types/components/atoms/VRadio/VRadioLabel.vue.d.ts +14 -0
  9. package/dist/types/components/atoms/index.d.ts +5 -3
  10. package/dist/types/components/index.d.ts +2 -3
  11. package/dist/types/components/molecules/VDrawer.vue.d.ts +1 -1
  12. package/dist/types/utils/code-block/VCodeBlock.vue.d.ts +1 -1
  13. package/package.json +2 -1
  14. package/src/components/atoms/VRadio/VRadioDescription.test.ts +55 -0
  15. package/src/components/atoms/VRadio/VRadioDescription.vue +14 -0
  16. package/src/components/atoms/VRadio/VRadioGroup.test.ts +81 -0
  17. package/src/components/atoms/VRadio/VRadioGroup.vue +71 -0
  18. package/src/components/atoms/VRadio/VRadioItem.test.ts +183 -0
  19. package/src/components/atoms/VRadio/VRadioItem.vue +26 -0
  20. package/src/components/atoms/VRadio/VRadioLabel.test.ts +55 -0
  21. package/src/components/atoms/VRadio/VRadioLabel.vue +14 -0
  22. package/src/components/atoms/index.ts +6 -3
  23. package/src/components/index.ts +2 -4
  24. package/dist/style.css +0 -10
  25. package/dist/styles/all.css +0 -6753
  26. package/dist/types/components/atoms/VRadioGroup.vue.d.ts +0 -32
  27. package/dist/vuetiful.es.mjs +0 -47478
  28. package/dist/vuetiful.umd.js +0 -18
  29. package/src/components/atoms/VRadioGroup.vue +0 -42
  30. package/src/components/atoms/VRadioItem.vue +0 -154
@@ -1,42 +0,0 @@
1
- <script setup lang="ts">
2
- import { defineEmits, provide, ref, watch } from "vue";
3
-
4
- const emits = defineEmits(["update:modelValue"]);
5
-
6
- const props = defineProps({
7
- name: {
8
- type: String,
9
- required: true,
10
- },
11
- modelValue: {
12
- type: [String, Number],
13
- required: true,
14
- },
15
-
16
- labelledby: {
17
- type: String,
18
- default: "",
19
- },
20
- });
21
-
22
- const radioGroupRef = ref<HTMLElement>();
23
- const selectedOption = ref(props.modelValue);
24
- provide("selectedOption", selectedOption);
25
- provide("name", props.name);
26
- provide("radioGroup", radioGroupRef);
27
-
28
- watch(selectedOption, (newVal) => {
29
- emits("update:modelValue", newVal);
30
- });
31
- </script>
32
-
33
- <template>
34
- <div
35
- ref="radioGroupRef"
36
- role="radiogroup"
37
- class="radio-group inline-flex space-x-1 p-1 bg-surface-200-700-token border-token border-surface-400-500-token rounded-token"
38
- tabindex="-1"
39
- >
40
- <slot></slot>
41
- </div>
42
- </template>
@@ -1,154 +0,0 @@
1
- <template>
2
- <!-- A11y attributes are not allowed on <label> -->
3
- <label :for="id">
4
- <div
5
- :class="`radio-item cursor-pointer px-4 py-1 text-center text-base rounded-token ${
6
- checked ? 'variant-filled' : 'hover:variant-soft'
7
- } `"
8
- role="radio"
9
- :aria-checked="checked"
10
- :tabindex="tabbable"
11
- :name="name"
12
- @keydown="handleKeydown"
13
- >
14
- <!-- NOTE: Don't use `hidden` as it prevents `required` from operating -->
15
- <div class="h-0 w-0 overflow-hidden">
16
- <input
17
- tabindex="-1"
18
- type="radio"
19
- :id="id"
20
- :name="name"
21
- :value="value"
22
- v-model="selectedOption"
23
- />
24
- </div>
25
- <slot />
26
- </div>
27
- </label>
28
- </template>
29
-
30
- <script setup lang="ts">
31
- import { ComputedRef, computed, defineProps, inject } from "vue";
32
-
33
- const props = defineProps({
34
- value: {
35
- type: [String, Number],
36
- required: true,
37
- },
38
- });
39
-
40
- const radioGroup = inject("radioGroup") as ComputedRef<HTMLElement>;
41
- const selectedOption = inject("selectedOption") as ComputedRef<string>;
42
- const name = inject("name") as string;
43
-
44
- const id = `radio-${Math.random().toString(36).substring(2, 9)}`;
45
- const isFirst = computed(() => {
46
- const idOfFirstChild = radioGroup.value?.children[0].querySelector("input")?.id;
47
- return idOfFirstChild === id;
48
- });
49
-
50
- const checked = computed(() => {
51
- return selectedOption.value === props.value;
52
- });
53
- const tabbable = computed(() => {
54
- if (!selectedOption.value) return isFirst.value ? 0 : -1;
55
- return selectedOption.value === props.value ? 0 : -1;
56
- });
57
-
58
- const setChecked = (target: HTMLElement) => {
59
- const input = target.querySelector("input");
60
- input?.click();
61
- input?.focus();
62
- };
63
-
64
- const setCheckedToNextItem = (target: HTMLElement) => {
65
- const activeId = target.querySelector("input")?.id;
66
- const children = radioGroup.value?.children;
67
- const activeChild = Array.from(children).find((child) => {
68
- const input = child.querySelector("input");
69
- return input?.id === activeId;
70
- });
71
-
72
- const firstchild = children[0];
73
- const isLast = activeChild === children[children.length - 1];
74
- if (isLast) {
75
- const input = firstchild.querySelector("input");
76
- if (input) {
77
- input.click();
78
- input.focus();
79
- }
80
- return;
81
- }
82
-
83
- const nextChild = activeChild?.nextElementSibling;
84
- const input = nextChild?.querySelector("input");
85
- if (input) {
86
- input.click();
87
- input.focus();
88
- }
89
- };
90
-
91
- const setCheckedToPreviousItem = (target: HTMLElement) => {
92
- const activeId = target.querySelector("input")?.id;
93
- const children = radioGroup.value?.children;
94
- const activeChild = Array.from(children).find((child) => {
95
- const input = child.querySelector("input");
96
- return input?.id === activeId;
97
- });
98
-
99
- const lastchild = children[children.length - 1];
100
- const isFirst = activeChild === children[0];
101
- if (isFirst) {
102
- const input = lastchild.querySelector("input");
103
- if (input) {
104
- input.click();
105
- input.focus();
106
- }
107
- return;
108
- }
109
-
110
- const previousChild = activeChild?.previousElementSibling;
111
- const input = previousChild?.querySelector("input");
112
- if (input) {
113
- input.click();
114
- input.focus();
115
- }
116
- };
117
-
118
- const handleKeydown = (event: KeyboardEvent) => {
119
- const target = event.currentTarget as HTMLElement;
120
- let flag = false;
121
-
122
- switch (event.key) {
123
- case " ":
124
- case "Enter":
125
- setChecked(target);
126
- flag = true;
127
- break;
128
-
129
- case "Up":
130
- case "ArrowUp":
131
- case "Left":
132
- case "ArrowLeft":
133
- setCheckedToPreviousItem(target);
134
- flag = true;
135
- break;
136
-
137
- case "Down":
138
- case "ArrowDown":
139
- case "Right":
140
- case "ArrowRight":
141
- setCheckedToNextItem(target);
142
- flag = true;
143
- break;
144
-
145
- default:
146
- break;
147
- }
148
-
149
- if (flag) {
150
- event.stopPropagation();
151
- event.preventDefault();
152
- }
153
- };
154
- </script>