@code-coaching/vuetiful 0.12.0 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-coaching/vuetiful",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "onchange 'src/**/*.vue' 'src/**/*.ts' 'src/**/*.css' -- npm run build",
@@ -18,6 +18,7 @@
18
18
  "vue": "^3.2.25"
19
19
  },
20
20
  "dependencies": {
21
+ "@headlessui/vue": "^1.7.13",
21
22
  "highlight.js": "^11.7.0"
22
23
  },
23
24
  "devDependencies": {
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ import { RadioGroupDescription } from '@headlessui/vue';
3
+
4
+ defineProps({
5
+ as: RadioGroupDescription.props['as'],
6
+ });
7
+ </script>
8
+
9
+ <template>
10
+ <RadioGroupDescription :as="as"><slot /></RadioGroupDescription>
11
+ </template>
@@ -0,0 +1,60 @@
1
+ <script setup lang="ts">
2
+ import { RadioGroup } from '@headlessui/vue';
3
+ import { provide, ref, watch } from 'vue';
4
+
5
+ const emit = defineEmits(['update:modelValue']);
6
+ const props = defineProps({
7
+ as: RadioGroup.props['as'],
8
+ disabled: RadioGroup.props['disabled'],
9
+ by: RadioGroup.props['by'],
10
+ modelValue: RadioGroup.props['modelValue'],
11
+
12
+ active: {
13
+ type: String,
14
+ default: 'variant-filled',
15
+ },
16
+ hover: {
17
+ type: String,
18
+ default: 'hover:variant-ghost',
19
+ },
20
+
21
+ background: {
22
+ type: String,
23
+ default: 'bg-surface-200-700-token',
24
+ },
25
+ text: {
26
+ type: String,
27
+ default: 'text-surface-900 dark:text-surface-50',
28
+ },
29
+ });
30
+
31
+ const parentModelValue = ref(props.modelValue);
32
+ watch(
33
+ () => props.modelValue,
34
+ (newValue) => {
35
+ parentModelValue.value = newValue;
36
+ }
37
+ );
38
+ watch(
39
+ () => parentModelValue.value,
40
+ (newValue) => {
41
+ console.log('test: ', newValue)
42
+ emit('update:modelValue', newValue);
43
+ }
44
+ );
45
+
46
+ provide('active', props.active);
47
+ provide('hover', props.hover);
48
+ </script>
49
+
50
+ <template>
51
+ <radio-group
52
+ v-model="parentModelValue"
53
+ :as="as"
54
+ :disabled="disabled"
55
+ :by="by"
56
+ :class="`radio-group inline-flex gap-1 p-1 ${background} ${text} border-token border-surface-400-500-token rounded-container-token`"
57
+ >
58
+ <slot></slot>
59
+ </radio-group>
60
+ </template>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { RadioGroupOption } from '@headlessui/vue';
3
+ import { inject } from 'vue';
4
+
5
+ defineProps({
6
+ value: {
7
+ type: [String, Number],
8
+ required: true,
9
+ },
10
+ });
11
+
12
+ const active = (inject('active') as string) || 'variant-filled';
13
+ const hover = (inject('hover') as string) || 'hover:variant-ghost';
14
+ </script>
15
+
16
+ <template>
17
+ <RadioGroupOption v-slot="{ checked, disabled }" :value="value">
18
+ <span
19
+ :class="`radio-item px-4 py-1 text-center text-base rounded-token ${checked ? active : hover} ${
20
+ disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer'
21
+ }`"
22
+ >
23
+ <slot />
24
+ </span>
25
+ </RadioGroupOption>
26
+ </template>
@@ -0,0 +1,16 @@
1
+ <script setup lang="ts">
2
+ import { RadioGroupLabel } from '@headlessui/vue';
3
+
4
+ defineProps({
5
+ as: {
6
+ type: RadioGroupLabel.props['as'].type,
7
+ default: 'p'
8
+ }
9
+ });
10
+
11
+
12
+ </script>
13
+
14
+ <template>
15
+ <RadioGroupLabel :as="as"><slot /></RadioGroupLabel>
16
+ </template>
@@ -1,7 +1,10 @@
1
1
  import VBadge from "./VBadge.vue";
2
2
  import VButton from "./VButton.vue";
3
3
  import VChip from "./VChip.vue";
4
- import VRadioGroup from "./VRadioGroup.vue";
5
- import VRadioItem from "./VRadioItem.vue";
6
4
 
7
- export { VButton, VBadge, VChip, VRadioGroup, VRadioItem };
5
+ import VRadioDescription from "./VRadio/VRadioDescription.vue";
6
+ import VRadioGroup from "./VRadio/VRadioGroup.vue";
7
+ import VRadioItem from "./VRadio/VRadioItem.vue";
8
+ import VRadioLabel from "./VRadio/VRadioLabel.vue";
9
+
10
+ export { VButton, VBadge, VChip, VRadioGroup, VRadioItem, VRadioLabel, VRadioDescription };
@@ -1,4 +1,2 @@
1
- import { VBadge, VButton, VChip, VRadioGroup, VRadioItem } from "./atoms";
2
- import { VDrawer, VRail, VRailTile, VShell } from "./molecules";
3
-
4
- export { VButton, VRail, VRailTile, VShell, VDrawer, VBadge, VChip, VRadioGroup, VRadioItem };
1
+ export * from './atoms';
2
+ export * from './molecules';
@@ -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>