@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,6 +1,6 @@
1
1
  {
2
2
  "name": "@appscode/design-system",
3
- "version": "2.6.22-alpha-0.0.9",
3
+ "version": "2.6.22-alpha-0.0.11",
4
4
  "description": "A design system for Appscode websites and dashboards made using Bulma",
5
5
  "main": "main.scss",
6
6
  "scripts": {
@@ -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
- // Define the props to accept the data structure
5
- const props = defineProps({
6
- label: {
7
- type: String,
8
- default: "Default Label", // Optional default value
9
- },
10
- items: {
11
- type: Array,
12
- default: () => [],
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
- <!-- Iterate through each section (based on your sidebar JSON structure) -->
21
- <div class="sidebar-items" v-for="(data, idx) in props.items" :key="idx">
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
- <!-- Iterate through the items inside each section -->
25
- <slot name="sidebar-item" v-for="(item, idx) in data.items" :key="idx" :item="item">
26
- <a :href="item.link || '#'" class="sidebar-item" :class="{ 'is-active': item.isActive }">
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
- <component :is="item.icon || CogIcon" />
86
+ <img :src="entry.icon || CogIcon" alt="icon" />
29
87
  </span>
30
- <span>{{ item.text }}</span>
31
- </a>
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;