Skip to content

Commit

Permalink
feat: theme configuration
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Jun 18, 2024
1 parent 4d96392 commit a84a6c8
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 55 deletions.
9 changes: 5 additions & 4 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ export default defineAppConfig({
description: 'Beautifully designed Nuxt Content template built with shadcn-vue. Customizable. Compatible. Open Source.',
ogImage: '/hero.png',
},
theme: {
customizable: true,
color: 'zinc',
radius: 0.5,
},
header: {
title: 'shadcn-docs',
showTitle: true,
logo: {
light: '/logo.svg',
dark: '/logo-dark.svg',
},
themeCustomize: true,
darkModeToggle: true,
nav: [
{
Expand All @@ -21,12 +25,10 @@ export default defineAppConfig({
title: 'Getting Started',
to: '/getting-started',
description: 'Start building your document with shadcn-docs-nuxt',
target: undefined,
}, {
title: 'API',
to: '/api',
description: 'Discover the configurations and exposed APIs.',
target: undefined,
}],
},
{
Expand Down Expand Up @@ -56,7 +58,6 @@ export default defineAppConfig({
{
title: 'Use This Template',
to: '/getting-started/installation',
target: undefined,
},
],
links: [{
Expand Down
2 changes: 1 addition & 1 deletion app.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<ConfigProvider :use-id="useIdFunction">
<NuxtLoadingIndicator :color="false" class="z-100 bg-primary" />
<NuxtLoadingIndicator :color="false" class="z-100 bg-primary80" />
<NuxtPage />
<Toaster />
</ConfigProvider>
Expand Down
Binary file modified bun.lockb
Binary file not shown.
19 changes: 8 additions & 11 deletions components/ThemeCustomizer.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<template>
<div class="grid gap-6">
<div class="grid space-y-1">
<h1 class="text-md text-foreground font-semibold">
<h1 class="text-lg text-foreground font-semibold">
Customize
</h1><p class="text-xs text-muted-foreground">
Pick a style and color for your components.
</h1>
<p class="text-sm text-muted-foreground">
Pick a style and color for the docs.
</p>
</div>
<div class="space-y-1.5">
Expand All @@ -18,7 +19,7 @@
@click="setTheme(color)"
>
<span class="h-5 w-5 flex items-center justify-center rounded-full" :style="{ backgroundColor: backgroundColor(color) }">
<Icon v-if="theme === color" name="i-radix-icons-check" size="16" class="text-white" />
<Icon v-if="theme === color" name="lucide:check" size="16" class="text-white" />
</span>
<span class="text-xs capitalize">{{ color }}</span>
</UiButton>
Expand Down Expand Up @@ -49,7 +50,7 @@
:class="{ 'border-primary border-2': colorMode.preference === 'light' }"
@click="colorMode.preference = 'light'"
>
<Icon name="i-ph-sun-dim-duotone" size="16" />
<Icon name="lucide:sun" size="16" />
<span class="text-xs capitalize">Light</span>
</UiButton>
<UiButton
Expand All @@ -58,7 +59,7 @@
:class="{ 'border-primary border-2': colorMode.preference === 'dark' }"
@click="colorMode.preference = 'dark'"
>
<Icon name="i-ph-moon-stars-duotone" size="16" />
<Icon name="lucide:moon" size="16" />
<span class="text-xs capitalize">Dark</span>
</UiButton>
<UiButton
Expand All @@ -67,7 +68,7 @@
:class="{ 'border-primary border-2': colorMode.preference === 'system' }"
@click="colorMode.preference = 'system'"
>
<Icon name="i-lucide-monitor" size="16" />
<Icon name="lucide:monitor" size="16" />
<span class="text-xs capitalize">System</span>
</UiButton>
</div>
Expand Down Expand Up @@ -126,7 +127,3 @@ function backgroundColor(color: Color) {
const colorMode = useColorMode();
</script>

<style scoped>
</style>
13 changes: 11 additions & 2 deletions components/ThemePopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
<UiPopover>
<UiPopoverTrigger as-child>
<UiButton variant="ghost" size="icon">
<Icon name="i-lucide-paintbrush" size="16" />
<Icon name="lucide:paintbrush" size="16" />
</UiButton>
</UiPopoverTrigger>
<UiPopoverContent class="w-[23rem]" align="end">
<UiPopoverContent
class="w-[23rem]"
:align="breakpoints.isGreaterOrEqual('md') ? 'end' : 'center'"
>
<ThemeCustomizer />
</UiPopoverContent>
</UiPopover>
</template>

<script setup lang="ts">
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core';
const breakpoints = useBreakpoints(breakpointsTailwind);
</script>
2 changes: 1 addition & 1 deletion components/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="flex flex-1 justify-end gap-2">
<LayoutSearchButton v-if="!config.search.inAside" />
<div class="flex">
<ThemePopover v-if="config.header.themeCustomize" />
<ThemePopover v-if="config.theme.customizable" />
<DarkModeToggle v-if="config.header.darkModeToggle" />
<NuxtLink
v-for="(link, i) in config.header.links"
Expand Down
6 changes: 5 additions & 1 deletion composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ const defaultConfig: DefaultConfig = {
description: 'Beautifully designed Nuxt Content template built with shadcn-vue. Customizable. Compatible. Open Source.',
ogImage: '/hero.png',
},
theme: {
customizable: true,
color: 'zinc',
radius: 0.5,
},
header: {
title: 'shadcn-docs',
showTitle: true,
logo: {
light: '/logo.svg',
dark: '/logo-dark.svg',
},
themeCustomize: true,
darkModeToggle: true,
nav: [],
links: [],
Expand Down
5 changes: 3 additions & 2 deletions composables/useThemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export function useThemes() {
const { value: color } = useColorMode();
const isDark = color === 'dark';

const defaultTheme = useConfig().value.theme;
const config = useCookie<Config>('theme', {
default: () => ({
theme: 'zinc',
radius: 0.5,
theme: defaultTheme.color as Color,
radius: defaultTheme.radius,
}),
});

Expand Down
14 changes: 14 additions & 0 deletions content/2.api/1.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ interface INav {
::
::

### `theme`

::field-group
::field{name="customizable" type="boolean" defaultValue="true"}
Whether the theme can be customized by the user (show the customize button in the header).
::
::field{name="color" type="Color" defaultValue="zinc"}
The default color theme. https://www.shadcn-vue.com/themes.html
::
::field{name="radius" type="string" defaultValue="0.5"}
The default radius.
::
::

### `header`

::field-group
Expand Down
34 changes: 2 additions & 32 deletions content/2.api/2.themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@ icon: 'lucide:palette'
description: Add colors. Make it yours.
---

Pick a theme from the [shadcn-vue website](https://www.shadcn-vue.com/themes.html).

Copy the code and put them into `assets/css/tailwind.css` by replacing the `@layer base` part.

```css[assets/css/tailwind.css]{5-13}
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
<xxx>
}
.dark {
<xxx>
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
```

::alert{type="success" icon="lucide:circle-check"}
That's it, enjoy your theme!
::Alert{to="http://localhost:3000/api/configuration#theme"}
See how to customize the theme in **Configuration**.
::
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ interface DefaultConfig {
description: string;
ogImage: string;
};
theme: {
customizable: boolean;
color: Color;
radius: number;
};
header: {
title: string;
showTitle: boolean;
logo: {
light: string;
dark: string;
};
themeCustomize: boolean;
darkModeToggle: boolean;
nav: ({
title: string;
Expand Down

0 comments on commit a84a6c8

Please sign in to comment.