-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathNcAppNavigationCaption.vue
More file actions
294 lines (267 loc) · 6.43 KB
/
NcAppNavigationCaption.vue
File metadata and controls
294 lines (267 loc) · 6.43 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<docs>
### Basic usage
```vue
<template>
<div class="styleguide-nc-content">
<NcAppNavigation>
<template #list>
<NcAppNavigationCaption
name="Your caption goes here">
<template #actions>
<NcActionButton>
<template #icon>
<IconPlus :size="20" />
</template>
This is an action
</NcActionButton>
</template>
</NcAppNavigationCaption>
</template>
</NcAppNavigation>
</div>
</template>
<script>
import IconPlus from 'vue-material-design-icons/Plus.vue'
export default {
components: {
IconPlus,
},
}
</script>
<style scoped>
/* Mock NcContent */
.styleguide-nc-content {
background-color: var(--color-background-plain);
overflow: hidden;
}
</style>
```
### Element with a slot for custom actions icon
```vue
<template>
<div class="styleguide-nc-content">
<NcAppNavigation>
<template #list>
<NcAppNavigationCaption
name="Your caption goes here">
<template #actionsTriggerIcon>
<IconPlus slot="icon" :size="20" />
</template>
<template #actions>
<NcActionButton>
<template #icon>
<IconPencil :size="20" />
</template>
Rename
</NcActionButton>
<NcActionButton>
<template #icon>
<IconDelete :size="20" />
</template>
Delete
</NcActionButton>
<NcActionButton>
<template #icon>
<IconArrowRight :size="20" />
</template>
Validate
</NcActionButton>
<NcActionButton>
<template #icon>
<IconDownload :size="20" />
</template>
Download
</NcActionButton>
</template>
</NcAppNavigationCaption>
</template>
</NcAppNavigation>
</div>
</template>
<script>
import IconArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import IconDelete from 'vue-material-design-icons/Delete.vue'
import IconDownload from 'vue-material-design-icons/Download.vue'
import IconPencil from 'vue-material-design-icons/Pencil.vue'
import IconPlus from 'vue-material-design-icons/Plus.vue'
export default {
components: {
IconArrowRight,
IconDelete,
IconDownload,
IconPencil,
IconPlus,
}
}
</script>
<style scoped>
/* Mock NcContent */
.styleguide-nc-content {
background-color: var(--color-background-plain);
overflow: hidden;
}
</style>
```
### Element used as a heading
```vue
<template>
<div class="styleguide-nc-content">
<NcAppNavigation>
<!-- if you need multiple lists you can use it in the default slot like this: -->
<NcAppNavigationCaption heading-id="people-heading"
is-heading
name="People" />
<NcAppNavigationList aria-labelledby="people-heading">
<NcAppNavigationItem name="Emma" />
<NcAppNavigationItem name="Jane" />
<NcAppNavigationItem name="Jake" />
</NcAppNavigationList>
<NcAppNavigationCaption heading-id="places-heading"
is-heading
name="Places" />
<NcAppNavigationList aria-labelledby="places-heading">
<NcAppNavigationItem name="America" />
<NcAppNavigationItem name="Australia" />
<NcAppNavigationItem name="Europe" />
</NcAppNavigationList>
</NcAppNavigation>
</div>
</template>
<style scoped>
/* Mock NcContent */
.styleguide-nc-content {
background-color: var(--color-background-plain);
overflow: hidden;
}
</style>
```
</docs>
<template>
<component
:is="wrapperTag"
class="app-navigation-caption"
:class="{ 'app-navigation-caption--heading': isHeading }">
<!-- Name of the caption -->
<component
:is="captionTag"
:id="headingId"
class="app-navigation-caption__name">
{{ name }}
</component>
<!-- Actions -->
<div
v-if="hasActions"
class="app-navigation-caption__actions">
<NcActions
v-bind="$attrs"
v-on="$listeners">
<!-- @slot Slot for the actions menu -->
<slot name="actions" />
<template #icon>
<slot name="actionsTriggerIcon" />
</template>
</NcActions>
</div>
</component>
</template>
<script>
import NcActions from '../NcActions/index.js'
export default {
name: 'NcAppNavigationCaption',
components: {
NcActions,
},
inheritAttrs: false,
props: {
/**
* The text of the caption
*/
name: {
type: String,
required: true,
},
/**
* `id` to set on the inner caption
* Can be used for connecting the `NcActionCaption` with `NcActionList` using `aria-labelledby`.
*/
headingId: {
type: String,
default: null,
},
/**
* Enable when used as a heading
* e.g. Before NcAppNavigationList
*/
isHeading: {
type: Boolean,
default: false,
},
/**
* If `isHeading` is set, this defines the heading level that should be used
*/
headingLevel: {
type: Number,
default: 2,
},
/**
* Any [NcActions](#/Components/NcActions?id=ncactions-1) prop
*/
// Not an actual prop but needed to show in vue-styleguidist docs
// eslint-disable-next-line
' ': {},
},
computed: {
wrapperTag() {
return this.isHeading ? 'div' : 'li'
},
captionTag() {
// Limit to at least h2 as h1 is considered invalid and reserved
const headingLevel = Math.max(2, this.headingLevel)
return this.isHeading ? `h${headingLevel}` : 'span'
},
// Check if the actions slot is populated
hasActions() {
return !!this.$slots.actions
},
},
}
</script>
<style lang="scss" scoped>
.app-navigation-caption {
display: flex;
justify-content: space-between;
&--heading {
padding: var(--app-navigation-padding);
&:not(:first-child):not(:last-child) {
padding: 0 var(--app-navigation-padding);
}
}
&__name {
font-weight: var(--font-weight-heading, bold);
color: var(--color-main-text);
font-size: var(--default-font-size);
line-height: var(--default-clickable-area);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
box-shadow: none !important;
flex-shrink: 1;
// padding to align the name with the icon of app navigation items
padding-block: 0;
padding-inline: calc(var(--default-grid-baseline, 4px) * 2) 0;
margin-top: 0px;
margin-bottom: var(--default-grid-baseline);
}
&__actions {
flex: 0 0 var(--default-clickable-area);
}
}
// extra top space if it's not the first item on the list
.app-navigation-caption:not(:first-child) {
margin-top: calc(var(--default-clickable-area) / 2);
}
</style>