Update config

pull/5701/head
Mert Sincan 2024-05-06 16:50:15 +01:00
parent 222efa71a1
commit b303a07b5b
3 changed files with 87 additions and 108 deletions

View File

@ -47,7 +47,7 @@
<script> <script>
import EventBus from '@/layouts/AppEventBus'; import EventBus from '@/layouts/AppEventBus';
import { updatePreset, updateSurfacePalette, $dt } from 'primevue/themes'; import { updatePreset, updateSurfacePalette, $t } from 'primevue/themes';
import Lara from 'primevue/themes/lara'; import Lara from 'primevue/themes/lara';
import Aura from 'primevue/themes/aura'; import Aura from 'primevue/themes/aura';
@ -55,11 +55,10 @@ export default {
data() { data() {
return { return {
selectedPreset: 'Lara', selectedPreset: 'Lara',
presets: ['Lara', 'Aura'], presets: ['Aura', 'Lara'],
selectedPrimaryColor: 'default', selectedPrimaryColor: 'noir',
selectedSurfaceColor: null, selectedSurfaceColor: null,
primaryColors: [ primaryColors: [
{ name: 'default', palette: this.getPrimaryPaletteInTheme() },
{ name: 'noir', palette: { 50: '#fafafa', 100: '#f4f4f5', 200: '#e4e4e7', 300: '#d4d4d8', 400: '#a1a1aa', 500: '#71717a', 600: '#52525b', 700: '#3f3f46', 800: '#27272a', 900: '#18181b', 950: '#09090b' } }, { name: 'noir', palette: { 50: '#fafafa', 100: '#f4f4f5', 200: '#e4e4e7', 300: '#d4d4d8', 400: '#a1a1aa', 500: '#71717a', 600: '#52525b', 700: '#3f3f46', 800: '#27272a', 900: '#18181b', 950: '#09090b' } },
{ name: 'emerald', palette: { 50: '#ecfdf5', 100: '#d1fae5', 200: '#a7f3d0', 300: '#6ee7b7', 400: '#34d399', 500: '#10b981', 600: '#059669', 700: '#047857', 800: '#065f46', 900: '#064e3b', 950: '#022c22' } }, { name: 'emerald', palette: { 50: '#ecfdf5', 100: '#d1fae5', 200: '#a7f3d0', 300: '#6ee7b7', 400: '#34d399', 500: '#10b981', 600: '#059669', 700: '#047857', 800: '#065f46', 900: '#064e3b', 950: '#022c22' } },
{ name: 'green', palette: { 50: '#f0fdf4', 100: '#dcfce7', 200: '#bbf7d0', 300: '#86efac', 400: '#4ade80', 500: '#22c55e', 600: '#16a34a', 700: '#15803d', 800: '#166534', 900: '#14532d', 950: '#052e16' } }, { name: 'green', palette: { 50: '#f0fdf4', 100: '#dcfce7', 200: '#bbf7d0', 300: '#86efac', 400: '#4ade80', 500: '#22c55e', 600: '#16a34a', 700: '#15803d', 800: '#166534', 900: '#14532d', 950: '#052e16' } },
@ -115,23 +114,11 @@ export default {
}; };
}, },
methods: { methods: {
getPrimaryPaletteInTheme() { getPresetExt() {
return [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950].reduce((acc, k) => { const color = this.primaryColors.find((c) => c.name === this.selectedPrimaryColor);
acc[k] = $dt(`primary.${k}`).value;
return acc;
}, {});
},
updateColors(type, color) {
if (type === 'primary') this.selectedPrimaryColor = color.name;
else if (type === 'surface') this.selectedSurfaceColor = color.name;
this.applyTheme(type, color);
},
applyTheme(type, color) {
if (type === 'primary') {
if (color.name === 'noir') { if (color.name === 'noir') {
updatePreset({ return {
semantic: { semantic: {
primary: color.palette, primary: color.palette,
colorScheme: { colorScheme: {
@ -165,9 +152,9 @@ export default {
} }
} }
} }
}); };
} else { } else {
updatePreset({ return {
semantic: { semantic: {
primary: color.palette, primary: color.palette,
colorScheme: { colorScheme: {
@ -201,8 +188,18 @@ export default {
} }
} }
} }
}); };
} }
},
updateColors(type, color) {
if (type === 'primary') this.selectedPrimaryColor = color.name;
else if (type === 'surface') this.selectedSurfaceColor = color.name;
this.applyTheme(type, color);
},
applyTheme(type, color) {
if (type === 'primary') {
updatePreset(this.getPresetExt());
} else if (type === 'surface') { } else if (type === 'surface') {
updateSurfacePalette(color.palette); updateSurfacePalette(color.palette);
} }
@ -213,23 +210,10 @@ export default {
this.$appState.ripple = value; this.$appState.ripple = value;
}, },
onPresetChange(value) { onPresetChange(value) {
switch (value) { const preset = value === 'Lara' ? Lara : Aura;
case 'Lara': const surfacePalette = this.surfaces.find((s) => s.name === this.selectedSurfaceColor)?.palette;
updatePreset(Lara);
break;
case 'Aura': $t().preset(preset).preset(this.getPresetExt()).surfacePalette(surfacePalette).update();
updatePreset(Aura);
break;
default:
break;
}
// @todo
this.primaryColors.find((c) => c.name === 'default').palette = this.getPrimaryPaletteInTheme();
this.selectedPrimaryColor = 'default';
this.selectedSurfaceColor = null;
} }
}, },
computed: { computed: {

View File

@ -1,6 +1,5 @@
//import Noir from '@/themes/app-theme'; import Noir from '@/themes/app-theme';
import PrimeVue from 'primevue/config'; import PrimeVue from 'primevue/config';
import Lara from 'primevue/themes/lara';
import { reactive } from 'vue'; import { reactive } from 'vue';
const $appState = { const $appState = {
@ -21,11 +20,6 @@ const $appState = {
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use($appState); nuxtApp.vueApp.use($appState);
nuxtApp.vueApp.use(PrimeVue, { nuxtApp.vueApp.use(PrimeVue, {
theme: { theme: Noir
preset: Lara,
options: {
darkModeSelector: '.p-dark'
}
}
}); });
}); });

View File

@ -1,7 +1,8 @@
import { definePreset } from 'primevue/themes'; import { definePreset } from 'primevue/themes';
import Aura from 'primevue/themes/aura'; import Lara from 'primevue/themes/lara';
//import Aura from 'primevue/themes/aura';
const Noir = definePreset(Aura, { const Noir = definePreset(Lara, {
semantic: { semantic: {
primary: { primary: {
50: '{zinc.50}', 50: '{zinc.50}',