mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
feat(ThemeCreator): add accordian menu's to toggle large settings
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
|
||||||
import type { CustomTheme } from '@/types/CustomThemes'
|
import { type LoadedCustomTheme } from '@/types/CustomThemes'
|
||||||
|
|
||||||
import { settingsState } from '@/seqta/utils/listeners/SettingsState'
|
import { settingsState } from '@/seqta/utils/listeners/SettingsState'
|
||||||
import { getTheme } from '@/seqta/ui/themes/getTheme'
|
import { getTheme } from '@/seqta/ui/themes/getTheme'
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
} from '../utils/themeImageHandlers';
|
} from '../utils/themeImageHandlers';
|
||||||
|
|
||||||
const { themeID } = $props<{ themeID: string }>()
|
const { themeID } = $props<{ themeID: string }>()
|
||||||
let theme = $state<CustomTheme>({
|
let theme = $state<LoadedCustomTheme>({
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
@@ -36,11 +37,32 @@
|
|||||||
hideThemeName: false,
|
hideThemeName: false,
|
||||||
forceDark: false
|
forceDark: false
|
||||||
})
|
})
|
||||||
|
let closedAccordions = $state<string[]>([])
|
||||||
|
|
||||||
|
function toggleAccordion(title: string) {
|
||||||
|
if (closedAccordions.includes(title)) {
|
||||||
|
closedAccordions = closedAccordions.filter(t => t !== title);
|
||||||
|
} else {
|
||||||
|
closedAccordions = [...closedAccordions, title];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (themeID) {
|
if (themeID) {
|
||||||
const tempTheme = await getTheme(themeID)
|
const tempTheme = await getTheme(themeID)
|
||||||
if (tempTheme) theme = tempTheme
|
|
||||||
|
if (!tempTheme) return
|
||||||
|
|
||||||
|
// convert temptheme to LoadedCustomTheme
|
||||||
|
const loadedTheme = {
|
||||||
|
...tempTheme,
|
||||||
|
CustomImages: tempTheme.CustomImages.map(image => ({
|
||||||
|
...image,
|
||||||
|
url: image.blob ? URL.createObjectURL(image.blob) : null
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempTheme) theme = loadedTheme
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,7 +84,7 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
|
|
||||||
})
|
});
|
||||||
|
|
||||||
type SettingType = 'switch' | 'button' | 'slider' | 'colourPicker' | 'select' | 'codeEditor' | 'imageUpload';
|
type SettingType = 'switch' | 'button' | 'slider' | 'colourPicker' | 'select' | 'codeEditor' | 'imageUpload';
|
||||||
|
|
||||||
@@ -85,11 +107,26 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet settingItem(item: SettingItem)}
|
{#snippet settingItem(item: SettingItem)}
|
||||||
<div class="flex justify-between {item.direction === 'vertical' ? 'flex-col items-start gap-2' : 'items-center'} py-3">
|
<div class="flex justify-between {item.direction === 'vertical' ? 'flex-col items-start' : 'items-center'} py-3">
|
||||||
<div class="pr-4">
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
|
<div
|
||||||
|
onclick={() => { item.direction === 'vertical' && toggleAccordion(item.title) }}
|
||||||
|
onkeydown={(e) => { e.key === 'Enter' && item.direction === 'vertical' && toggleAccordion(item.title) }}
|
||||||
|
class="flex justify-between pr-4 {item.direction === 'vertical' ? 'cursor-pointer w-full select-none' : ''}">
|
||||||
|
<div>
|
||||||
<h2 class="text-sm font-bold">{item.title}</h2>
|
<h2 class="text-sm font-bold">{item.title}</h2>
|
||||||
<p class="text-xs">{item.description}</p>
|
<p class="text-xs">{item.description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if item.direction === 'vertical'}
|
||||||
|
<div class="flex items-center justify-center h-full text-xl font-light text-zinc-500 dark:text-zinc-300">
|
||||||
|
<span class='font-IconFamily transition-transform duration-300 {closedAccordions.includes(item.title) ? 'rotate-180' : ''}'>{'\ue9e6'}</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if !closedAccordions.includes(item.title)}
|
||||||
|
<div class="{item.direction === 'vertical' ? 'w-full mt-2' : ''}" transition:slide={{ duration: 300 }}>
|
||||||
{#if item.type === 'switch'}
|
{#if item.type === 'switch'}
|
||||||
<Switch {...(item.props as SwitchProps)} />
|
<Switch {...(item.props as SwitchProps)} />
|
||||||
{:else if item.type === 'button'}
|
{:else if item.type === 'button'}
|
||||||
@@ -102,9 +139,9 @@
|
|||||||
<CodeEditor {...(item.props as CodeEditorProps)} />
|
<CodeEditor {...(item.props as CodeEditorProps)} />
|
||||||
{:else if item.type === 'imageUpload'}
|
{:else if item.type === 'imageUpload'}
|
||||||
{#each theme.CustomImages as image (image.id)}
|
{#each theme.CustomImages as image (image.id)}
|
||||||
<div class="flex items-center h-16 py-2 mb-4 bg-white rounded-lg shadow-lg dark:bg-zinc-900">
|
<div class="flex items-center h-16 py-2 mb-4 bg-white rounded-lg shadow-lg dark:bg-zinc-700">
|
||||||
<div class="flex-1 h-full ">
|
<div class="flex-1 h-full ">
|
||||||
<img src={URL.createObjectURL(image.blob)} alt={image.variableName} class="object-contain h-full rounded" />
|
<img src={image.url} alt={image.variableName} class="object-contain h-full rounded" />
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -119,13 +156,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<div class="relative flex justify-center w-full h-8 gap-1 overflow-hidden transition rounded-lg place-items-center bg-zinc-100 dark:bg-zinc-900">
|
<div class="relative flex justify-center w-full h-8 gap-1 overflow-hidden transition rounded-lg place-items-center bg-zinc-100 dark:bg-zinc-700">
|
||||||
<span class='font-IconFamily'>{'\uec60'}</span>
|
<span class='font-IconFamily'>{'\uec60'}</span>
|
||||||
<span class='dark:text-white'>Add image</span>
|
<span class='dark:text-white'>Add image</span>
|
||||||
<input type="file" accept='image/*' onchange={onImageUpload} class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" />
|
<input type="file" accept='image/*' onchange={onImageUpload} class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
<div class='h-screen overflow-y-scroll {$settingsState.DarkMode && "dark"} '>
|
<div class='h-screen overflow-y-scroll {$settingsState.DarkMode && "dark"} '>
|
||||||
@@ -147,7 +186,7 @@
|
|||||||
type='text'
|
type='text'
|
||||||
placeholder='What is your theme called?'
|
placeholder='What is your theme called?'
|
||||||
bind:value={theme.name}
|
bind:value={theme.name}
|
||||||
class='w-full p-2 mb-4 transition-all duration-300 rounded-lg focus:outline-none ring-0 focus:ring-1 ring-zinc-100 dark:ring-zinc-700 dark:bg-zinc-900 dark:text-white' />
|
class='w-full p-2 mb-4 transition border-0 rounded-lg placeholder-zinc-300 bg-zinc-100 dark:bg-zinc-700 focus:bg-zinc-200/50 dark:focus:bg-zinc-600' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -156,12 +195,12 @@
|
|||||||
id='themeDescription'
|
id='themeDescription'
|
||||||
placeholder="Don't worry, this one's optional!"
|
placeholder="Don't worry, this one's optional!"
|
||||||
bind:value={theme.description}
|
bind:value={theme.description}
|
||||||
class='w-full p-2 rounded-lg focus:outline-none ring-0 focus:ring-1 ring-zinc-100 dark:ring-zinc-700 dark:bg-zinc-900 dark:text-white'></textarea>
|
class='w-full p-2 transition border-0 rounded-lg placeholder-zinc-300 bg-zinc-100 dark:bg-zinc-700 focus:outline-none focus:ring-1 focus:ring-zinc-100 dark:focus:ring-zinc-700 focus:bg-zinc-200/50 dark:focus:bg-zinc-600'></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<div class="relative flex justify-center w-full gap-1 overflow-hidden transition rounded-lg aspect-theme group place-items-center bg-zinc-100 dark:bg-zinc-900">
|
<div class="relative flex justify-center w-full gap-1 overflow-hidden transition rounded-lg aspect-theme group place-items-center bg-zinc-100 dark:bg-zinc-700">
|
||||||
<div class={`transition pointer-events-none z-30 font-IconFamily ${ theme.coverImage ? 'opacity-0 group-hover:opacity-100' : ''}`}>
|
<div class={`transition pointer-events-none z-30 font-IconFamily ${ theme.coverImage ? 'opacity-0 group-hover:opacity-100' : ''}`}>
|
||||||
{'\uec60'}
|
{'\uec60'}
|
||||||
</div>
|
</div>
|
||||||
@@ -172,7 +211,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if theme.coverImage}
|
{#if theme.coverImage}
|
||||||
<div class="absolute z-20 w-full h-full transition-opacity opacity-0 pointer-events-none group-hover:opacity-100 bg-black/20"></div>
|
<div class="absolute z-20 w-full h-full transition-opacity opacity-0 pointer-events-none group-hover:opacity-100 bg-black/20"></div>
|
||||||
<img src={URL.createObjectURL(theme.coverImage)} alt='Cover' class="absolute z-0 object-cover w-full h-full rounded" />
|
<img src={theme.coverImageUrl} alt='Cover' class="absolute z-0 object-cover w-full h-full rounded" />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { CustomTheme } from '@/types/CustomThemes';
|
import type { LoadedCustomTheme } from '@/types/CustomThemes';
|
||||||
|
|
||||||
export function generateImageId(): string {
|
export function generateImageId(): string {
|
||||||
return Math.random().toString(36).substr(2, 9);
|
return Math.random().toString(36).substr(2, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleImageUpload(event: Event, theme: CustomTheme): Promise<CustomTheme> | CustomTheme {
|
export function handleImageUpload(event: Event, theme: LoadedCustomTheme): Promise<LoadedCustomTheme> | LoadedCustomTheme {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
const file = input.files?.[0];
|
const file = input.files?.[0];
|
||||||
input.value = '';
|
input.value = '';
|
||||||
@@ -17,7 +17,7 @@ export function handleImageUpload(event: Event, theme: CustomTheme): Promise<Cus
|
|||||||
const variableName = `custom-image-${theme.CustomImages.length}`;
|
const variableName = `custom-image-${theme.CustomImages.length}`;
|
||||||
resolve({
|
resolve({
|
||||||
...theme,
|
...theme,
|
||||||
CustomImages: [...theme.CustomImages, { id: imageId, blob: imageBlob, variableName }],
|
CustomImages: [...theme.CustomImages, { id: imageId, blob: imageBlob, variableName, url: URL.createObjectURL(imageBlob) }],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
@@ -26,23 +26,23 @@ export function handleImageUpload(event: Event, theme: CustomTheme): Promise<Cus
|
|||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleRemoveImage(imageId: string, theme: CustomTheme): CustomTheme {
|
export function handleRemoveImage(imageId: string, theme: LoadedCustomTheme): LoadedCustomTheme {
|
||||||
return {
|
return {
|
||||||
...theme,
|
...theme,
|
||||||
CustomImages: theme.CustomImages.filter((image) => image.id !== imageId),
|
CustomImages: theme.CustomImages.filter((image) => image.id !== imageId),
|
||||||
};
|
} as LoadedCustomTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleImageVariableChange(imageId: string, variableName: string, theme: CustomTheme): CustomTheme {
|
export function handleImageVariableChange(imageId: string, variableName: string, theme: LoadedCustomTheme): LoadedCustomTheme {
|
||||||
return {
|
return {
|
||||||
...theme,
|
...theme,
|
||||||
CustomImages: theme.CustomImages.map((image) =>
|
CustomImages: theme.CustomImages.map((image) =>
|
||||||
image.id === imageId ? { ...image, variableName } : image
|
image.id === imageId ? { ...image, variableName } : image
|
||||||
),
|
),
|
||||||
};
|
} as LoadedCustomTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleCoverImageUpload(event: Event, theme: CustomTheme): Promise<CustomTheme> {
|
export function handleCoverImageUpload(event: Event, theme: LoadedCustomTheme): Promise<LoadedCustomTheme> {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
const file = input.files?.[0];
|
const file = input.files?.[0];
|
||||||
input.value = '';
|
input.value = '';
|
||||||
@@ -51,7 +51,7 @@ export function handleCoverImageUpload(event: Event, theme: CustomTheme): Promis
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = async () => {
|
reader.onload = async () => {
|
||||||
const imageBlob = await fetch(reader.result as string).then(res => res.blob());
|
const imageBlob = await fetch(reader.result as string).then(res => res.blob());
|
||||||
resolve({ ...theme, coverImage: imageBlob });
|
resolve({ ...theme, coverImage: imageBlob, coverImageUrl: URL.createObjectURL(imageBlob) });
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ export type CustomTheme = {
|
|||||||
forceDark?: boolean;
|
forceDark?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LoadedCustomTheme = CustomTheme & {
|
||||||
|
CustomImages: Array<{
|
||||||
|
id: string;
|
||||||
|
blob: Blob;
|
||||||
|
variableName: string;
|
||||||
|
url: string | null;
|
||||||
|
}>;
|
||||||
|
coverImageUrl?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type DownloadedTheme = CustomTheme & {
|
export type DownloadedTheme = CustomTheme & {
|
||||||
webURL: string;
|
webURL: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user