@appscode/design-system 2.6.22-alpha-0.0.9 → 2.6.22-alpha-0.0.11
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,42 +1,99 @@
|
|
|
1
|
-
<script setup>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { nextTick, watch, ref, computed } from "vue";
|
|
3
|
+
import { useRoute } from "vue-router";
|
|
2
4
|
import CogIcon from "../../icons/CogIcon.vue";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
interface SidebarEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
icon?: any;
|
|
10
|
+
url: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SidebarSection {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
icon?: any;
|
|
17
|
+
entries: SidebarEntry[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
items: SidebarSection[];
|
|
22
|
+
isActive: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Props
|
|
26
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
27
|
+
items: () => [],
|
|
28
|
+
isActive: false
|
|
14
29
|
});
|
|
30
|
+
|
|
31
|
+
const sidebarItem = ref<HTMLElement | null>(null);
|
|
32
|
+
|
|
33
|
+
const route = useRoute();
|
|
34
|
+
|
|
35
|
+
const updatedItems = computed(() => {
|
|
36
|
+
return props.items.map((section) => {
|
|
37
|
+
const updatedEntries = section.entries.map((entry) => ({
|
|
38
|
+
...entry,
|
|
39
|
+
isActive: route.path === entry.url,
|
|
40
|
+
}));
|
|
41
|
+
return { ...section, entries: updatedEntries };
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Scroll active item into view
|
|
46
|
+
watch(
|
|
47
|
+
() => props.isActive,
|
|
48
|
+
(n) => {
|
|
49
|
+
if (n) {
|
|
50
|
+
nextTick(() => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
const top = (sidebarItem.value && sidebarItem.value.getBoundingClientRect().top) || 0;
|
|
53
|
+
if (top > window.innerHeight - 200) {
|
|
54
|
+
sidebarItem.value?.scrollIntoView({
|
|
55
|
+
behavior: "smooth",
|
|
56
|
+
block: "center",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}, 300);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{ immediate: true },
|
|
64
|
+
);
|
|
15
65
|
</script>
|
|
16
66
|
|
|
17
67
|
<template>
|
|
18
68
|
<div class="sidebar-style-2">
|
|
19
69
|
<div class="left-sidebar">
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<label class="label">{{ data.label }}</label>
|
|
70
|
+
<div class="sidebar-items" v-for="(section, sIdx) in updatedItems" :key="section.id">
|
|
71
|
+
<label class="label">{{ section.name }}</label>
|
|
23
72
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
73
|
+
<slot
|
|
74
|
+
name="sidebar-item"
|
|
75
|
+
v-for="(entry, iIdx) in section.entries"
|
|
76
|
+
:key="entry.id"
|
|
77
|
+
:item="entry"
|
|
78
|
+
>
|
|
79
|
+
<router-link
|
|
80
|
+
:to="entry.url"
|
|
81
|
+
class="sidebar-item"
|
|
82
|
+
:class="{ 'is-active': entry.isActive }"
|
|
83
|
+
:ref="entry.isActive ? sidebarItem : null"
|
|
84
|
+
>
|
|
27
85
|
<span class="icon">
|
|
28
|
-
<
|
|
86
|
+
<img :src="entry.icon || CogIcon" alt="icon" />
|
|
29
87
|
</span>
|
|
30
|
-
<span>{{
|
|
31
|
-
</
|
|
88
|
+
<span>{{ entry.name }}</span>
|
|
89
|
+
</router-link>
|
|
32
90
|
</slot>
|
|
33
91
|
</div>
|
|
34
92
|
</div>
|
|
35
93
|
</div>
|
|
36
94
|
</template>
|
|
37
95
|
|
|
38
|
-
<style lang="scss">
|
|
39
|
-
// sidebar items
|
|
96
|
+
<style lang="scss" scoped>
|
|
40
97
|
.sidebar-style-2 {
|
|
41
98
|
border: 1px solid $color-border;
|
|
42
99
|
border-radius: 4px;
|