Skip to content

Commit c33c781

Browse files
committed
feat(ui): add chip to announcement bar
1 parent 28eb2cf commit c33c781

7 files changed

Lines changed: 43 additions & 3 deletions

File tree

playground/app.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default defineAppConfig({
88
// Announcement
99
announcement: {
1010
show: true,
11+
chipText: 'News',
1112
message: 'This is a site wide announcement!',
1213
buttonText: 'Click me',
1314
buttonUrl: 'https://nuxtify.dev/',

src/module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ export default defineNuxtModule<ModuleOptions>().with({
8787
announcement: {
8888
show: false,
8989
message: '',
90+
chipText: '',
91+
chipColor: '',
9092
buttonText: '',
9193
buttonUrl: '',
92-
exclude: [],
94+
exclude: [] as string[],
9395
},
9496

9597
// Navigation

src/runtime/components/app/AppAnnouncement.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ const isExternalLink = computed(() =>
1111
isExternalUrl(nuxtifyConfig.announcement?.buttonUrl ?? '', nuxtifyConfig.brand?.domain ?? ''),
1212
)
1313
14+
const chipText = computed(() => nuxtifyConfig.announcement?.chipText?.toUpperCase() ?? '')
15+
1416
const shouldShow = computed(() => {
1517
if (!nuxtifyConfig.announcement?.show) return false
1618
17-
const hasContent = nuxtifyConfig.announcement?.message || (nuxtifyConfig.announcement?.buttonText && nuxtifyConfig.announcement?.buttonUrl)
19+
const hasContent
20+
= nuxtifyConfig.announcement?.message
21+
|| nuxtifyConfig.announcement?.chipText
22+
|| (nuxtifyConfig.announcement?.buttonText && nuxtifyConfig.announcement?.buttonUrl)
1823
if (!hasContent) return false
1924
2025
// Exclude routes
@@ -30,6 +35,14 @@ const shouldShow = computed(() => {
3035
:order="-100"
3136
class="app-announcement justify-center text-start d-print-none"
3237
>
38+
<v-chip
39+
v-if="chipText"
40+
:color="nuxtifyConfig.announcement?.chipColor || 'secondary'"
41+
size="small"
42+
class="mr-2 font-weight-bold"
43+
>
44+
{{ chipText }}
45+
</v-chip>
3346
<div
3447
v-if="nuxtifyConfig.announcement?.message"
3548
:class="`${xs ? 'text-subtitle-2' : 'text-subtitle-1'} mr-4`"

src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export interface ModuleOptions {
106106
announcement?: {
107107
show?: boolean
108108
message?: string
109+
/**
110+
* Text for the announcement chip.
111+
*/
112+
chipText?: string
113+
/**
114+
* Color for the announcement chip.
115+
*
116+
* @default "secondary"
117+
*/
118+
chipColor?: string
109119
buttonText?: string
110120
buttonUrl?: string
111121
exclude?: string[]

test/basic.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ describe('ssr', async () => {
1111
// Get response to a server-rendered page with `$fetch`.
1212
const html = await $fetch('/')
1313
expect(html).toContain('<div>basic</div>')
14+
expect(html).toContain('NEWS')
15+
expect(html).toContain('This is a test announcement!')
1416
})
1517
})

test/fixtures/basic/app.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<template>
2-
<div>basic</div>
2+
<v-app>
3+
<AppAnnouncement />
4+
<v-main>
5+
<div>basic</div>
6+
</v-main>
7+
</v-app>
38
</template>
49

510
<script setup>

test/fixtures/basic/nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ export default defineNuxtConfig({
44
modules: [
55
nuxtifyCore,
66
],
7+
nuxtifyCore: {
8+
announcement: {
9+
show: true,
10+
chipText: 'News',
11+
message: 'This is a test announcement!',
12+
},
13+
},
714
})

0 commit comments

Comments
 (0)