Skip to content

Commit 487b4ba

Browse files
committed
feat: add more functionality to theme generator
1 parent a54da14 commit 487b4ba

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

src/components/themes/ThemeGenerator.vue

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,36 @@ import JSZip from "jszip";
1313
import { VueCodeHighlighterMulti } from "vue-code-highlighter";
1414
import "vue-code-highlighter/dist/style.css";
1515
16+
const cssEnabled = ref<boolean>(false);
1617
const selected = ref<typeof CustomizationTabs[number]["Key"]>("colors");
1718
const colors = ref<typeof DefaultColors>({ ...DefaultColors });
1819
const codeView = ref<boolean>(false);
1920
2021
const currentCode = computed(() => {
21-
return [
22-
{
23-
"lang" : "json",
24-
"title": "theme.json",
25-
"code" : JSON.stringify({
26-
"colors": {
27-
...colors.value,
28-
"fadeAmount": 0.5,
29-
"fadeColor" : "#000000",
30-
},
31-
"name" : `A Custom Theme <${Math.floor(Math.random() * 10_000)}>`,
32-
"widgets": "Fusion",
33-
}, null, 2),
34-
},
35-
{
36-
"lang" : "css",
37-
"title": "themeStyle.css",
38-
"code" : "/* WIP */",
39-
},
40-
];
22+
return {
23+
// needed to re-render the code view component
24+
"key" : Math.random().toString(),
25+
"data": [
26+
{
27+
"lang" : "json",
28+
"title": "theme.json",
29+
"code" : JSON.stringify({
30+
"colors": {
31+
...colors.value,
32+
"fadeAmount": 0.5,
33+
"fadeColor" : "#000000",
34+
},
35+
"name" : `A Custom Theme <${Math.floor(Math.random() * 10_000)}>`,
36+
"widgets": "Fusion",
37+
}, null, 2),
38+
},
39+
{
40+
"lang" : "css",
41+
"title": "themeStyle.css",
42+
"code" : "/* WIP */",
43+
},
44+
],
45+
};
4146
});
4247
4348
function selectColor({
@@ -53,6 +58,10 @@ function resetColors() {
5358
colors.value = { ...DefaultColors };
5459
}
5560
61+
function toggleCSS() {
62+
cssEnabled.value = !cssEnabled.value;
63+
selected.value = "colors";
64+
}
5665
function downloadTheme() {
5766
const zip = new JSZip;
5867
const randomKey = Math.floor(Math.random() * 10_000);
@@ -63,7 +72,7 @@ function downloadTheme() {
6372
}
6473
6574
folder.file("themeStyle.css", "/* WIP */");
66-
folder.file("theme.json", currentCode.value[0].code);
75+
folder.file("theme.json", currentCode.value.data[0].code);
6776
6877
zip.generateAsync({ "type": "blob" }).then(content => {
6978
saveAs(content, `customTheme${randomKey}.zip`);
@@ -91,12 +100,13 @@ function importTheme() {}
91100
:key="tab.Key"
92101
:aria-label="tab.Name"
93102
:title="tab.Name"
94-
class="group px-4 py-2 first:pt-4"
103+
:disabled="tab.Key !== 'colors' && !cssEnabled"
104+
class="group px-4 py-2 first:pt-4 disabled:opacity-60"
95105
>
96106
<span
97107
:class="[
98108
'grid size-10 place-items-center rounded-md transition-[background-color]',
99-
'group-hover:bg-catppuccin-800',
109+
'group-hover:bg-catppuccin-800 group-disabled:group-hover:bg-transparent',
100110
selected === tab.Key
101111
? 'bg-catppuccin-800'
102112
: 'bg-catppuccin-900',
@@ -107,16 +117,21 @@ function importTheme() {}
107117
</button>
108118
</div>
109119
<div class="w-full flex flex-col gap-4 py-4 pl-4 pr-4 sm:pl-0">
110-
<div class="flex flex-wrap gap-4 sm:flex-nowrap">
120+
<div class="flex flex-wrap gap-4">
111121
<button
112122
v-for="item in [
113-
{ 'name': 'Export', 'icon': 'i-lucide-share-2', 'action': downloadTheme },
114-
{ 'name': 'Show JSON & CSS', 'icon': 'i-lucide-braces', 'action': toggleCodeView },
115-
{ 'name': 'Import Colors', 'icon': 'i-lucide-import', 'action': importTheme },
123+
{ 'name': 'Toggle CSS', 'icon': 'i-lucide-brush', 'action': toggleCSS, 'active': cssEnabled },
124+
{ 'name': 'Export', 'icon': 'i-lucide-share-2', 'action': downloadTheme, 'active': false },
125+
{ 'name': 'Show JSON & CSS', 'icon': 'i-lucide-braces',
126+
'action': toggleCodeView, 'active': codeView },
127+
{ 'name': 'Import Colors', 'icon': 'i-lucide-import', 'action': importTheme, 'active': false, },
116128
]"
117129
:key="item.name"
118130
@click="item.action"
119-
class="w-fit flex flex-nowrap items-center gap-4 rounded-md p-2 transition-[background-color] hover:bg-catppuccin-800"
131+
:class="[
132+
'w-fit flex flex-nowrap items-center gap-4 rounded-md p-2 transition-[background-color]',
133+
item.active && 'bg-catppuccin-800',
134+
]"
120135
>
121136
<span :class="[item.icon, 'block size-6']" />
122137
<span class="block text-white font-medium">
@@ -127,7 +142,8 @@ function importTheme() {}
127142
<div class="select-text">
128143
<VueCodeHighlighterMulti
129144
v-if="codeView"
130-
:code="currentCode"
145+
:key="currentCode.key"
146+
:code="currentCode.data"
131147
/>
132148
</div>
133149
<ColorGenerator

0 commit comments

Comments
 (0)