Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit 5e701ea

Browse files
committed
Made it possible to import 3rd party themes
1 parent 086d32c commit 5e701ea

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

src/lib/ChangeThemeParams.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</div>
2121
</div>
2222
{#if theme === "CUSTOM"}
23-
<LoadTemplate />
23+
<LoadTemplate bind:customThemeJSON={customThemeJSON} />
2424
{/if}
2525
<Accordion.Root class="w-full" disabled={theme !== "CUSTOM"}>
2626
<Accordion.Item value="mainpagestyles">

src/lib/LoadTemplate.svelte

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,61 @@
22
import { Button } from "$lib/components/ui/button/index.js";
33
import * as Popover from "$lib/components/ui/popover/index.js";
44
import * as Select from "$lib/components/ui/select/index.js";
5+
import { Label } from "$lib/components/ui/label/index.js";
6+
import { Input } from "$lib/components/ui/input/index.js";
7+
import { toast } from "svelte-sonner";
8+
import { CANDY_THEME, DARK_THEME, LIGHT_THEME, type CustomTheme } from "./utils";
9+
10+
export let customThemeJSON: CustomTheme;
511
612
const templates = [
713
{ value: "LIGHT", label: "Light Theme" },
814
{ value: "DARK", label: "Dark Theme" },
15+
{ value: "CANDY", label: "Candy Theme" },
916
{ value: "OTHER", label: "3rd party theme" }
1017
];
1118
12-
let selectedTemplate: string;
19+
let selectedTemplate: undefined | string;
20+
let outsideURL = "";
21+
22+
async function loadOutsideTheme() {
23+
if (outsideURL && outsideURL.length > 0) {
24+
try {
25+
const resp = await fetch(outsideURL);
26+
27+
if (resp.ok) {
28+
const respJSON = await resp.json();
29+
customThemeJSON = structuredClone(respJSON);
30+
31+
toast.success("Success", { description: "Fetched the 3rd party theme!" });
32+
} else {
33+
toast.error("Error", { description: "Failed to fetch 3rd party theme."});
34+
}
35+
} catch (err) {
36+
console.log(err);
37+
toast.error("Error", { description: "Failed to fetch 3rd party theme."});
38+
}
39+
} else {
40+
toast.error("Error", { description: "Invalid link."});
41+
}
42+
}
43+
44+
function setTemplate(theme: string) {
45+
if (theme === "LIGHT") {
46+
customThemeJSON = structuredClone(LIGHT_THEME);
47+
} else if (theme === "DARK") {
48+
customThemeJSON = structuredClone(DARK_THEME);
49+
} else if (theme === "CANDY") {
50+
customThemeJSON = structuredClone(CANDY_THEME);
51+
}
52+
}
1353
1454
$: {
15-
console.log(selectedTemplate)
55+
if (selectedTemplate) setTemplate(selectedTemplate);
1656
}
1757
</script>
1858

19-
<Popover.Root>
59+
<Popover.Root onOutsideClick={() => selectedTemplate = undefined}>
2060
<Popover.Trigger asChild let:builder>
2161
<Button builders={[builder]} variant="outline">Load Template</Button>
2262
</Popover.Trigger>
@@ -37,6 +77,11 @@
3777
</Select.Content>
3878
<Select.Input />
3979
</Select.Root>
80+
{#if selectedTemplate === "OTHER"}
81+
<Label>3rd party url</Label>
82+
<Input bind:value={outsideURL} placeholder="e.g. https://website.com/cooltheme.json" />
83+
<Button on:click={loadOutsideTheme}>Load</Button>
84+
{/if}
4085
</section>
4186
</Popover.Content>
4287
</Popover.Root>

src/lib/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,26 @@ export const DARK_THEME: CustomTheme = {
172172
tagFontSize: "0.6rem",
173173
timeTextColor: "#fdfdfd",
174174
timeTextFontSize: "clamp(0.8rem, 0rem + 1.4vw, 1rem)"
175+
}
176+
177+
export const CANDY_THEME: CustomTheme = {
178+
"backgroundColor": "#fff4e9",
179+
"headerColor": "#8d6b94",
180+
"dayTextColor": "#f5f5f5",
181+
"dayOfWeekSize": "2rem",
182+
"selectedDayTextColor": "#fff4e9",
183+
"headerHeight": "80px",
184+
"headerBoxShadow": "0px 8px 18px -18px rgb(0, 0, 0)",
185+
"daySeparatorLineWidth": "1px",
186+
"daySeparatorLineStyle": "solid",
187+
"daySeparatorLineColor": "#b185a7",
188+
"eventTitleColor": "#fff4e9",
189+
"eventTitleFontSize": "clamp(0.9rem, 0.6951rem + 0.6829vw, 1.25rem)",
190+
"tagFontSize": "0.6rem",
191+
"timeTextColor": "#000000",
192+
"timeTextFontSize": "clamp(0.8rem, 0rem + 1.4vw, 1rem)",
193+
"eventBackgroundColor": "#b185a7",
194+
"resourceFontSize": "1rem",
195+
"resourceTextColor": "#dbdbdb",
196+
"eventBorderRadius": "15px"
175197
}

static/weirdTheme.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"backgroundColor": "#fff4e9",
3+
"headerColor": "#ff0000",
4+
"dayTextColor": "#f5f5f5",
5+
"dayOfWeekSize": "2rem",
6+
"selectedDayTextColor": "#fff4e9",
7+
"headerHeight": "80px",
8+
"headerBoxShadow": "0px 8px 18px -18px rgb(0, 0, 0)",
9+
"daySeparatorLineWidth": "1px",
10+
"daySeparatorLineStyle": "solid",
11+
"daySeparatorLineColor": "#b185a7",
12+
"eventTitleColor": "#fff4e9",
13+
"eventTitleFontSize": "clamp(0.9rem, 0.6951rem + 0.6829vw, 1.25rem)",
14+
"tagFontSize": "0.6rem",
15+
"timeTextColor": "#000000",
16+
"timeTextFontSize": "clamp(0.8rem, 0rem + 1.4vw, 1rem)",
17+
"eventBackgroundColor": "#b185a7",
18+
"resourceFontSize": "1rem",
19+
"resourceTextColor": "#dbdbdb",
20+
"eventBorderRadius": "15px"
21+
}

0 commit comments

Comments
 (0)