@code-coaching/vuetiful 0.11.2 → 0.12.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/style.css +1 -1
- package/dist/styles/all.css +9 -0
- package/dist/types/utils/code-block/VCodeBlock.vue.d.ts +15 -0
- package/dist/vuetiful.es.mjs +10 -3
- package/dist/vuetiful.umd.js +2 -2
- package/package.json +1 -1
- package/src/components/atoms/VRadioGroup.vue +42 -0
- package/src/components/atoms/VRadioItem.vue +154 -0
- package/src/components/atoms/index.ts +3 -1
- package/src/components/index.ts +2 -2
- package/src/components/molecules/VShell.vue +4 -1
- package/src/utils/code-block/VCodeBlock.vue +10 -1
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
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>
|
|
@@ -0,0 +1,154 @@
|
|
|
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>
|
|
@@ -1,5 +1,7 @@
|
|
|
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";
|
|
4
6
|
|
|
5
|
-
export { VButton, VBadge, VChip };
|
|
7
|
+
export { VButton, VBadge, VChip, VRadioGroup, VRadioItem };
|
package/src/components/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VBadge, VButton, VChip } from "./atoms";
|
|
1
|
+
import { VBadge, VButton, VChip, VRadioGroup, VRadioItem } from "./atoms";
|
|
2
2
|
import { VDrawer, VRail, VRailTile, VShell } from "./molecules";
|
|
3
3
|
|
|
4
|
-
export { VButton, VRail, VRailTile, VShell, VDrawer, VBadge, VChip };
|
|
4
|
+
export { VButton, VRail, VRailTile, VShell, VDrawer, VBadge, VChip, VRadioGroup, VRadioItem };
|
|
@@ -34,7 +34,10 @@ defineProps({
|
|
|
34
34
|
<slot name="sidebarLeft" />
|
|
35
35
|
</aside>
|
|
36
36
|
|
|
37
|
-
<div
|
|
37
|
+
<div
|
|
38
|
+
tabindex="-1"
|
|
39
|
+
:class="`vuetiful-page flex flex-1 flex-col overflow-x-hidden ${regionPage ?? ''}`"
|
|
40
|
+
>
|
|
38
41
|
<header
|
|
39
42
|
v-if="$slots.pageHeader"
|
|
40
43
|
:class="`vuetiful-page-header flex-none ${slotPageHeader}`"
|
|
@@ -16,11 +16,18 @@ const props = defineProps({
|
|
|
16
16
|
default: "",
|
|
17
17
|
},
|
|
18
18
|
|
|
19
|
+
preventOverflow: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
default: false,
|
|
22
|
+
},
|
|
23
|
+
|
|
19
24
|
headerClass: {
|
|
20
25
|
type: String as () => CssClasses,
|
|
26
|
+
default: "",
|
|
21
27
|
},
|
|
22
28
|
preClass: {
|
|
23
29
|
type: String as () => CssClasses,
|
|
30
|
+
default: "",
|
|
24
31
|
},
|
|
25
32
|
|
|
26
33
|
buttonClass: {
|
|
@@ -75,7 +82,9 @@ function onCopyClick() {
|
|
|
75
82
|
</button>
|
|
76
83
|
</header>
|
|
77
84
|
<pre
|
|
78
|
-
:class="`code-block-pre
|
|
85
|
+
:class="`code-block-pre ${
|
|
86
|
+
preventOverflow ? 'whitespace-pre-wrap break-all' : 'overflow-auto'
|
|
87
|
+
} p-4 pt-1 ${preClass}`"
|
|
79
88
|
><code :class="`code-block-code language-${language}`" v-html="highlight(props.code, props.language)"></code></pre>
|
|
80
89
|
</div>
|
|
81
90
|
</template>
|