Skip to content

Commit 0a89c2e

Browse files
committed
feat: add logo component
1 parent 27cceb4 commit 0a89c2e

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

playground/app.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<script setup lang="ts">
2-
const nuxtifyConfig = useAppConfig().nuxtify
2+
const nuxtifyConfig = useNuxtifyConfig()
33
</script>
44

55
<template>
6-
<div>
6+
<h1>
77
nuxtify-pages module playground!
8-
<v-btn>
9-
Test
10-
</v-btn>
8+
</h1>
9+
10+
<v-btn>
11+
Test Button
12+
</v-btn>
13+
14+
<div>
15+
<AppLogo />
1116
</div>
1217

1318
<h2>nuxtifyConfig</h2>

src/module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
22
defineNuxtModule,
3+
addComponentsDir,
4+
addImportsDir,
35
addPlugin,
46
createResolver,
57
installModule,
@@ -44,6 +46,12 @@ export default defineNuxtModule<ModuleOptions>({
4446
..._options,
4547
})
4648

49+
// Add auto-imports
50+
addComponentsDir({
51+
path: resolver.resolve('runtime/components'),
52+
})
53+
addImportsDir(resolver.resolve('runtime/composables'))
54+
4755
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
4856
addPlugin(resolver.resolve('./runtime/plugin'))
4957
},
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<script setup lang="ts">
2+
import { useAppConfig } from '#app'
3+
import { useDisplay, computed } from '#imports'
4+
5+
// Props
6+
const props = defineProps({
7+
dark: {
8+
type: Boolean,
9+
default: false,
10+
},
11+
width: {
12+
type: Number,
13+
default: undefined,
14+
},
15+
})
16+
17+
// App state
18+
const nuxtifyConfig = useAppConfig().nuxtify
19+
const { smAndDown } = useDisplay()
20+
21+
// Image URL logic
22+
// Set default to the light image url
23+
let imageUrl = nuxtifyConfig.brand.logo.lightUrl
24+
25+
// If it's dark theme logo and there's a dark image url, use that
26+
if (props.dark && nuxtifyConfig.brand.logo.darkUrl) {
27+
imageUrl = nuxtifyConfig.brand.logo.darkUrl
28+
}
29+
30+
// Image width logic
31+
const width = computed(() => {
32+
if (props.width) {
33+
return props.width
34+
}
35+
else {
36+
return smAndDown.value
37+
? nuxtifyConfig.brand.logo.mobileWidth
38+
: nuxtifyConfig.brand.logo.width
39+
}
40+
})
41+
</script>
42+
43+
<template>
44+
<v-img
45+
v-if="imageUrl"
46+
:width
47+
:src="imageUrl"
48+
:alt="`${nuxtifyConfig.brand.name} logo`"
49+
/>
50+
<span
51+
v-else
52+
:class="`text-subtitle-1 text-sm-h6 ${dark ? '' : 'text-primary'}`"
53+
>
54+
{{ nuxtifyConfig.brand.name }}
55+
</span>
56+
</template>

src/runtime/composables/nuxtify.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { useAppConfig } from '#app'
2+
3+
export const useNuxtifyConfig = () => useAppConfig().nuxtify

0 commit comments

Comments
 (0)