Skip to content

Commit 7903035

Browse files
authored
Merge pull request #40 from connorabbas/develop
Theme preset selector
2 parents f053780 + 16ae9cf commit 7903035

File tree

6 files changed

+90
-9
lines changed

6 files changed

+90
-9
lines changed

src/app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import './assets/css/app.css';
22
import './assets/css/tailwind.css';
33
import 'nprogress/nprogress.css';
44

5-
import { useColorMode } from '@vueuse/core';
6-
import customThemePreset from './theme/noir-preset';
7-
85
import { createApp } from 'vue';
96
import { createPinia } from 'pinia';
107

@@ -17,16 +14,25 @@ import ToastService from 'primevue/toastservice';
1714
import Container from '@/components/Container.vue';
1815
import PageTitleSection from '@/components/PageTitleSection.vue';
1916

17+
import { useColorMode } from '@vueuse/core';
18+
import { useThemePreset } from '@/composables/useThemePreset';
19+
20+
// Site light/dark mode
21+
const colorMode = useColorMode({ emitAuto: true });
22+
23+
// Site theme preset
24+
const { getCurrentPreset } = useThemePreset();
25+
const themePreset = getCurrentPreset();
26+
2027
const app = createApp(App);
2128
const pinia = createPinia();
22-
const colorMode = useColorMode({ emitAuto: true });
2329

2430
app.provide('colorMode', colorMode)
2531
.use(pinia)
2632
.use(router)
2733
.use(PrimeVue, {
2834
theme: {
29-
preset: customThemePreset,
35+
preset: themePreset,
3036
options: {
3137
darkModeSelector: '.dark',
3238
cssLayer: {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup>
2+
import { useThemePreset } from '@/composables/useThemePreset';
3+
4+
const { presets, selectedPreset, setPreset } = useThemePreset();
5+
</script>
6+
7+
<template>
8+
<Select
9+
v-model="selectedPreset"
10+
:options="presets"
11+
optionLabel="label"
12+
optionValue="value"
13+
@change="setPreset(selectedPreset)"
14+
/>
15+
</template>

src/composables/useThemePreset.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { ref, Ref } from 'vue';
2+
import { usePreset } from '@primeuix/themes';
3+
import { Preset } from '@primeuix/themes/types';
4+
import { useStorage } from '@vueuse/core';
5+
import bootstrap from '@/theme/bootstrap-preset';
6+
import breeze from '@/theme/breeze-preset';
7+
import enterprise from '@/theme/enterprise-preset';
8+
import noir from '@/theme/noir-preset';
9+
import warm from '@/theme/warm-preset';
10+
11+
interface ThemePreset {
12+
label: string,
13+
value: string,
14+
preset: Preset,
15+
}
16+
17+
const presets = ref<ThemePreset[]>([
18+
{ label: 'Bootstrap', value: 'bootstrap', preset: bootstrap },
19+
{ label: 'Breeze', value: 'breeze', preset: breeze },
20+
{ label: 'Enterprise', value: 'enterprise', preset: enterprise },
21+
{ label: 'Noir', value: 'noir', preset: noir },
22+
{ label: 'Warm', value: 'warm', preset: warm },
23+
]);
24+
25+
const selectedPreset: Ref<string> = useStorage('theme-preset', 'noir');
26+
27+
function getCurrentPreset(): Preset {
28+
return (
29+
presets.value.find((p) => p.value === selectedPreset.value)?.preset ||
30+
presets.value[3].preset
31+
);
32+
}
33+
34+
function setPreset(presetValue: string): void {
35+
const themePreset = presets.value.find((p) => p.value === presetValue);
36+
if (themePreset) {
37+
usePreset(themePreset.preset);
38+
}
39+
}
40+
41+
setPreset(selectedPreset.value);
42+
43+
export function useThemePreset() {
44+
return {
45+
presets,
46+
selectedPreset,
47+
getCurrentPreset,
48+
setPreset,
49+
};
50+
}

src/layouts/app/HeaderLayout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const toggleMobileUserMenu = (event) => {
4646
<div>
4747
<PanelMenu
4848
:model="menuItems"
49-
class="w-full"
49+
class="mt-1 w-full"
5050
/>
5151
</div>
5252
<template #footer>

src/layouts/app/SidebarLayout.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const toggleMobileUserMenu = (event) => {
4444
<div>
4545
<PanelMenu
4646
:model="menuItems"
47-
class="w-full"
47+
class="mt-1 w-full"
4848
/>
4949
</div>
5050
<template #footer>
@@ -117,7 +117,7 @@ const toggleMobileUserMenu = (event) => {
117117
<div>
118118
<PanelMenu
119119
:model="menuItems"
120-
class="w-full"
120+
class="mt-1 w-full"
121121
/>
122122
</div>
123123
</div>

src/views/settings/Appearance.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import AppLayout from '@/layouts/AppLayout.vue';
33
import SettingsLayout from '@/layouts/UserSettingsLayout.vue';
44
import SelectColorModeButton from '@/components/SelectColorModeButton.vue';
5+
import ThemePresetSelector from '@/components/ThemePresetSelector.vue';
56
</script>
67

78
<template>
@@ -18,7 +19,16 @@ import SelectColorModeButton from '@/components/SelectColorModeButton.vue';
1819
Update your account's appearance settings
1920
</template>
2021
<template #content>
21-
<SelectColorModeButton />
22+
<div class="space-y-6">
23+
<div class="flex flex-col gap-2">
24+
<label for="color-mode-selector">Color Mode</label>
25+
<SelectColorModeButton id="color-mode-selector" />
26+
</div>
27+
<div class="flex flex-col gap-2">
28+
<label for="theme-preset-selector">Theme</label>
29+
<ThemePresetSelector id="theme-preset-selector" />
30+
</div>
31+
</div>
2232
</template>
2333
</Card>
2434
</SettingsLayout>

0 commit comments

Comments
 (0)