-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Storybook.vue
123 lines (110 loc) · 2.36 KB
/
Storybook.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<template>
<div>
<div class="sidebar">
<div class="sections">
<div
class="section"
v-for="(section, sectionIndex) in sections"
:key="sectionIndex"
>
<div class="section-title">{{ section.title }}</div>
<div class="stories">
<router-link
:to="{ query: { section: section.title, story: story.title } }"
:class="[
`story-title`,
$route.query.story === story.title &&
$route.query.section === section.title &&
`is-active`
]"
v-for="(story, storyIndex) in section.stories"
:key="storyIndex"
>{{ story.title }}</router-link
>
</div>
</div>
</div>
</div>
<div class="main">
<component :is="currentComponent" />
</div>
</div>
</template>
<script>
export default {
props: ['sections', 'site'],
computed: {
current() {
const { query } = this.$route
for (const section of this.sections) {
if (section.title === query.section) {
for (const story of section.stories) {
if (story.title === query.story) {
return {
section,
story
}
}
}
}
}
},
currentComponent() {
return this.current?.story.component;
},
currentTitle() {
if (this.current) {
const { story, section } = this.current
return `${story.title} ${section.title} - - ${this.site.title}`
}
return this.site.title
}
},
watch: {
currentTitle: {
handler(title) {
document.title = title
},
immediate: true
}
}
}
</script>
<style>
:root {
--sidebar-width: 240px;
}
</style>
<style scoped>
.sidebar {
border-right: 1px solid #e2e2e2;
width: var(--sidebar-width);
position: fixed;
top: 0;
bottom: 0;
left: 0;
}
.section:not(:last-child) {
border-bottom: 1px solid #e2e2e2;
}
.section-title {
padding: 10px;
border-bottom: 1px solid #e2e2e2;
}
.story-title {
display: block;
padding: 10px;
color: blue;
text-decoration: none;
}
.story-title:hover {
background: #f9f9f9;
}
.story-title.is-active {
background: #f0f0f0;
}
.main {
padding: 20px;
margin-left: var(--sidebar-width);
}
</style>