primevue-mirror/apps/showcase/components/layout/AppDesigner.vue

201 lines
7.7 KiB
Vue
Raw Normal View History

2024-11-10 19:16:58 +00:00
<template>
2024-11-12 09:18:07 +00:00
<Drawer v-model:visible="$appState.designerActive" header="Theme Designer" position="right" class="designer !w-screen md:!w-[48rem]" :modal="false">
2024-11-10 19:16:58 +00:00
<Tabs value="0">
<TabList>
2024-11-12 12:38:29 +00:00
<Tab value="0">Base</Tab>
<Tab value="1">Primitive</Tab>
<Tab value="2">Semantic</Tab>
<Tab value="3">Component</Tab>
2024-11-10 19:16:58 +00:00
</TabList>
<TabPanels class="!px-0">
<TabPanel value="0">
2024-11-12 12:38:29 +00:00
<div class="text-lg font-semibold mb-4">Choose a Theme to Get Started</div>
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-4 border border-surface-200 dark:border-surface-700 rounded-md p-4">
<span class="font-semibold">Built-in Themes</span>
<SelectButton v-model="$appState.preset" @update:modelValue="onPresetChange" :options="presetOptions" optionLabel="label" optionValue="value" :allowEmpty="false" />
</div>
<Divider>OR</Divider>
<div class="flex flex-col gap-4 border border-surface-200 dark:border-surface-700 rounded-md p-4">
<span class="font-semibold">Import Figma Tokens</span>
<input type="file" />
</div>
<Divider>OR</Divider>
<div class="flex flex-col gap-4 border border-surface-200 dark:border-surface-700 rounded-md p-4 items-start">
<span class="font-semibold">Saved Theme</span>
<Button icon="pi pi-upload" label="Load" class="!px-3 !py-2" severity="secondary" />
</div>
</div>
</TabPanel>
<TabPanel value="1">
2024-11-10 19:16:58 +00:00
<div class="flex flex-col gap-3">
<DesignBorderRadius />
<DesignColors />
</div>
</TabPanel>
2024-11-12 12:38:29 +00:00
<TabPanel value="2">
2024-11-10 19:16:58 +00:00
<Accordion :value="['0', '1']" multiple>
<AccordionPanel value="0">
<AccordionHeader>Common</AccordionHeader>
<AccordionContent>
<div class="flex flex-col gap-3">
<DesignGeneral />
<DesignFormField />
<DesignList />
<DesignNavigation />
<DesignOverlay />
</div>
</AccordionContent>
</AccordionPanel>
<AccordionPanel value="1">
<AccordionHeader>Color Scheme</AccordionHeader>
<AccordionContent>
<Tabs value="cs-0">
<TabList>
<Tab value="cs-0">Light</Tab>
<Tab value="cs-1">Dark</Tab>
</TabList>
<TabPanels class="!px-0">
<TabPanel value="cs-0">
<DesignCS :value="preset.semantic.colorScheme.light" />
</TabPanel>
<TabPanel value="cs-1">
<DesignCS :value="preset.semantic.colorScheme.dark" />
</TabPanel>
</TabPanels>
</Tabs>
</AccordionContent>
</AccordionPanel>
</Accordion>
</TabPanel>
2024-11-12 12:38:29 +00:00
<TabPanel value="3"> <div class="p-4">Component tokens are not supported by the Visual Editor at the moment.</div></TabPanel>
2024-11-10 19:16:58 +00:00
</TabPanels>
</Tabs>
<template #footer>
2024-11-12 09:56:37 +00:00
<div class="flex justify-between gap-2">
2024-11-12 12:38:29 +00:00
<Button type="button" @click="download" label="Download" variant="outlined" icon="pi pi-download" class="!px-3 !py-2" />
<Button type="button" @click="apply" label="Apply" class="!px-3 !py-2" />
2024-11-10 19:16:58 +00:00
</div>
</template>
</Drawer>
</template>
<script>
2024-11-12 12:38:29 +00:00
import { updatePreset, usePreset } from '@primevue/themes';
import Aura from '@primevue/themes/aura';
import Lara from '@primevue/themes/lara';
import Material from '@primevue/themes/material';
import Nora from '@primevue/themes/nora';
import { computed } from 'vue';
const presets = {
Aura,
Material,
Lara,
Nora
};
2024-11-10 19:16:58 +00:00
export default {
provide() {
return {
2024-11-12 12:38:29 +00:00
$preset: computed(() => this.preset)
2024-11-10 19:16:58 +00:00
};
},
data() {
return {
2024-11-12 12:38:29 +00:00
preset: {
primitive: Aura.primitive,
semantic: Aura.semantic
},
presetOptions: [
{ label: 'Aura', value: 'Aura' },
{ label: 'Material', value: 'Material' },
{ label: 'Lara', value: 'Lara' },
{ label: 'Nora', value: 'Nora' }
],
customThemes: {},
newThemeName: null
2024-11-10 19:16:58 +00:00
};
},
mounted() {
2024-11-12 12:38:29 +00:00
const savedTheme = localStorage.getItem(this.$appState.designerKey);
if (savedTheme) {
this.preset = JSON.parse(savedTheme).defaultTheme;
setTimeout(() => {
usePreset(this.preset);
}, 2000);
} else {
this.preset.semantic.primary = this.preset.primitive.emerald;
this.preset.semantic.colorScheme.light.surface = { ...{ 0: '#ffffff' }, ...this.preset.primitive.slate };
this.preset.semantic.colorScheme.dark.surface = { ...{ 0: '#ffffff' }, ...this.preset.primitive.zinc };
}
},
2024-11-10 19:16:58 +00:00
methods: {
apply() {
2024-11-12 12:38:29 +00:00
this.saveTheme();
2024-11-10 19:16:58 +00:00
updatePreset(this.preset);
2024-11-12 09:56:37 +00:00
},
download() {
const theme = JSON.stringify(this.preset, null, 4).replace(/"([^"]+)":/g, '$1:');
const textContent = `import { createApp } from "vue";
import PrimeVue from "primevue/config";
import Aura from "@primevue/themes/aura";
import { definePreset } from "@primevue/themes";
const app = createApp(App);
const MyPreset = definePreset(Aura, ${theme});
app.use(PrimeVue, {
theme: {
preset: MyPreset
},
});
app.mount("#app");
`;
const blob = new Blob([textContent], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'mytheme.js';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
2024-11-12 12:38:29 +00:00
},
onPresetChange(value) {
this.$appState.preset = value;
const newPreset = presets[value];
if (value === 'Material') {
document.body.classList.add('material');
this.$primevue.config.ripple = true;
} else {
document.body.classList.remove('material');
}
usePreset(newPreset);
this.preset = {
primitive: newPreset.primitive,
semantic: newPreset.semantic
};
},
saveTheme() {
const themeRecord = {
defaultTheme: this.preset
};
localStorage.setItem(this.$appState.designerKey, JSON.stringify(themeRecord));
2024-11-10 19:16:58 +00:00
}
}
};
</script>