feat(themes): various UI/UX tweaks

This commit is contained in:
StroepWafel committed 2026-08-26 18:01:16 +09:30
1 parent 95acfc139d
commit 1ce95f64e9
9 files changed
+163 -41

No files matched your search

@@ -1,5 +1,8 @@
<script lang="ts">
let { width, height} = $props<{width?: string, height?: string}>()
let { width, height } = $props<{ width?: string; height?: string }>();
</script>
<div style="width: {width ? width : '100%'}; height: {height ? height : '100%'}; background: #e0e0e0;" class="animate-pulse"></div>
<div
style="width: {width ? width : '100%'}; height: {height ? height : '100%'};"
class="animate-pulse rounded-xl border border-zinc-200 bg-zinc-200 dark:border-zinc-700/80 dark:bg-zinc-800"
></div>
+1 -1
View File
@@ -71,7 +71,7 @@
role="tab"
aria-selected={activePage === tab.id}
onclick={() => setActivePage(tab.id)}
class="relative z-10 h-10 flex-1 whitespace-nowrap rounded-full px-4 text-base transition-colors duration-200
class="relative z-10 h-10 flex-1 whitespace-nowrap rounded-full px-4 text-lg transition-colors duration-200
{activePage === tab.id
? 'font-semibold text-zinc-900 dark:text-white'
: 'text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white'}"
@@ -9,6 +9,10 @@ flavourCarouselImageUrl,
masterCarouselImageUrl,
masterGridDisplayDownloadCount,
} from '@/interface/utils/themeStoreFlavours'
import {
getThemeApplyButtonStyles,
resolveStoreVariantAccentColor,
} from '@/interface/utils/themeListFilters'
let {
theme,
currentThemes,
@@ -23,6 +27,7 @@ toggleFavorite,
isLoggedIn,
onRequestSignIn,
selectedThemeId = '',
installedThemeColors = {},
} = $props<{
theme: Theme | null
currentThemes: string[]
@@ -38,7 +43,16 @@ toggleFavorite?: (theme: Theme) => void
isLoggedIn?: boolean
onRequestSignIn?: () => void
selectedThemeId?: string
installedThemeColors?: Record<string, string>
}>()
function variantApplyStyles(variantId: string) {
if (!theme) {
return getThemeApplyButtonStyles(undefined)
}
return getThemeApplyButtonStyles(
resolveStoreVariantAccentColor(theme, variantId, installedThemeColors),
)
}
const modalDisplayDownloadCount = $derived.by(() => {
const t = theme
if (!t) return 0
@@ -110,7 +124,7 @@ $effect(() => {
if (displayTheme && modalElement) {
animate(
modalElement,
{ y: [500, 0], opacity: [0, 1] },
{ y: [16, 0], opacity: [0, 1], scale: [0.98, 1] },
{
type: 'spring',
stiffness: 150,
@@ -122,7 +136,7 @@ damping: 20,
const hideModal = (relatedTheme = null) => {
animate(
modalElement,
{ y: [10, 500], opacity: [1, 0] },
{ y: [0, 16], opacity: [1, 0], scale: [1, 0.98] },
{
type: 'spring',
stiffness: 150,
@@ -170,7 +184,7 @@ else await runRemove(theme.id)
}
</script>
<div
class="flex fixed inset-0 z-50 justify-center items-end bg-black/70 backdrop-blur-sm"
class="flex fixed inset-0 z-50 items-center justify-center bg-black/70 backdrop-blur-sm p-4 sm:p-6"
onclick={(e) => {
if (e.target === e.currentTarget) hideModal()
}}
@@ -183,7 +197,7 @@ transition:fade
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
bind:this={modalElement}
class="w-full max-w-[600px] h-[95%] p-4 bg-white rounded-t-2xl dark:bg-zinc-800 overflow-y-auto overflow-x-hidden rounded-xl border border-zinc-200 dark:border-zinc-700 cursor-auto transition-colors duration-200"
class="flex w-full max-w-[600px] h-fit max-h-[calc(100dvh-3rem)] flex-col overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-2xl shadow-black/30 dark:border-zinc-700 dark:bg-zinc-800 cursor-auto transition-colors duration-200"
onclick={(e) => e.stopPropagation()}
onkeydown={(e) => e.stopPropagation()}
role="dialog"
@@ -191,7 +205,7 @@ aria-modal="true"
tabindex="-1"
>
{#if theme}
<div class="relative h-auto">
<div class="relative flex max-h-[calc(100dvh-3rem)] flex-col overflow-y-auto overflow-x-hidden p-5 pb-8">
<div class="absolute top-0 right-0 flex gap-1 items-center">
<button
type="button"
@@ -314,7 +328,8 @@ class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11re
type="button"
onclick={(e) => { e.stopPropagation(); void runApply(theme.id) }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-emerald-500 text-white hover:bg-emerald-600 disabled:opacity-70"
style={variantApplyStyles(theme.id).apply}
class="px-3 py-1.5 text-sm font-semibold rounded-lg hover:brightness-90 disabled:opacity-70"
>
Apply
</button>
@@ -383,7 +398,8 @@ class="relative w-full overflow-hidden rounded-2xl min-h-[9.5rem] sm:min-h-[11re
type="button"
onclick={(e) => { e.stopPropagation(); scrollHeroToFlavourIndex(flavourIdx); void runApply(f.id) }}
disabled={installingId !== null}
class="px-3 py-1.5 text-sm font-semibold rounded-lg bg-emerald-500 text-white hover:bg-emerald-600 disabled:opacity-70"
style={variantApplyStyles(f.id).apply}
class="px-3 py-1.5 text-sm font-semibold rounded-lg hover:brightness-90 disabled:opacity-70"
>
Apply
</button>
@@ -450,7 +466,8 @@ aria-label={theme.is_favorited ? 'Unfavorite' : 'Favorite'}
<button
type="button"
disabled
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-emerald-700 rounded-lg dark:text-emerald-300 bg-emerald-100 dark:bg-emerald-950/50 opacity-90"
style={variantApplyStyles(theme.id).applied}
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] rounded-lg opacity-90"
>
Applied
</button>
@@ -459,7 +476,8 @@ Applied
type="button"
onclick={() => runApply(theme.id)}
disabled={installingId !== null}
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-white rounded-lg bg-emerald-600 hover:bg-emerald-700 transition-all duration-200 hover:scale-105 active:scale-95 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 disabled:opacity-70"
style={variantApplyStyles(theme.id).apply}
class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] rounded-lg transition-all duration-200 hover:brightness-90 active:scale-95 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-70"
>
{#if installingId === theme.id}
<svg class="absolute w-4 h-4 animate-spin" width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
@@ -500,11 +518,11 @@ class="relative flex justify-center items-center px-4 py-2 min-w-[8rem] text-bla
{/if}
</div>
{#if relatedThemes.length > 0}
<div class="my-8 border-b border-zinc-200 dark:border-zinc-700"></div>
<div class="pt-6 mt-6 border-t border-zinc-200 dark:border-zinc-700"></div>
<h3 class="mb-4 text-lg font-bold text-zinc-900 dark:text-white">
Related themes
</h3>
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div class="grid grid-cols-1 gap-4 pb-2 sm:grid-cols-2">
{#each relatedThemes as relatedTheme (relatedTheme.id)}
<button
type="button"
@@ -526,7 +544,7 @@ class="relative z-0 hover:z-20 w-full cursor-pointer rounded-xl overflow-hidden
{/if}
</div>
{:else}
<div class="flex justify-center items-center h-full text-zinc-600 dark:text-zinc-300">
<div class="flex justify-center items-center p-8 text-zinc-600 dark:text-zinc-300">
<button
type="button"
class="px-4 py-2 rounded-lg bg-zinc-200 dark:bg-zinc-700 transition-all duration-200 hover:scale-105 active:scale-95 dark:text-white focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 dark:focus:ring-offset-zinc-800"
@@ -171,10 +171,12 @@
const visibleThemes = $derived(
themes ? filterThemesByMode(themes.themes, listMode) : [],
);
const useTwoColumnLayout = $derived(listMode === 'downloaded' || listMode === 'custom');
</script>
<div
class="pt-5 mb-1 w-full max-w-lg mx-auto"
class="mb-1 w-full {useTwoColumnLayout ? '' : 'max-w-lg mx-auto'}"
role="list"
tabindex="-1"
ondragover={handleDragOver}
@@ -196,7 +198,7 @@
</div>
</div>
</div>
<div class="flex flex-col gap-2 px-2">
<div class="{useTwoColumnLayout ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-2 px-2'}">
{#if themes}
{#each visibleThemes as theme (theme.id)}
<button
@@ -268,7 +270,7 @@
{/if}
{#if tempTheme}
<div class="flex justify-center place-items-center w-full bg-gray-200 rounded-xl animate-pulse dark:bg-zinc-700/50 aspect-theme">
<div class="flex justify-center place-items-center w-full bg-gray-200 rounded-xl animate-pulse dark:bg-zinc-700/50 aspect-theme {useTwoColumnLayout ? 'col-span-2' : ''}">
<svg class="w-5 h-5 text-white animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
@@ -277,7 +279,7 @@
{/if}
{#if themes && visibleThemes.length === 0 && !tempTheme}
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center">
<div class="flex min-h-56 flex-col items-center justify-center px-4 py-10 text-center {useTwoColumnLayout ? 'col-span-2' : ''}">
{#if listMode === 'custom'}
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
No custom themes yet
@@ -342,30 +344,30 @@
{/if}
{#if themes && ((showNavigation && visibleThemes.length > 0) || (listMode === 'custom' && visibleThemes.length > 0) || (listMode === 'downloaded' && visibleThemes.length > 0))}
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600"></div>
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600 {useTwoColumnLayout ? 'col-span-2' : ''}"></div>
{#if listMode === 'custom'}
<button
onclick={() => void openThemeCreator()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white {useTwoColumnLayout ? 'col-span-2' : ''}"
>
<span class="text-xl font-IconFamily">&#xec60;</span>
<span class="ml-2">Create theme</span>
</button>
<a href="https://docs.betterseqta.org/theme-creation/" class="block w-full cursor-pointer">
<div class="flex flex-col justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white hover:bg-zinc-200 dark:hover:bg-zinc-800">
<div class="text-2xl font-IconFamily">{'\uecb3'}</div>
<div class="text-lg font-bold text-center">
Got a Theme Idea?
<p class="text-base font-light text-zinc-600 dark:text-zinc-400">Transform it into a stunning theme!</p>
</div>
</div>
<a
href="https://docs.betterseqta.org/theme-creation/"
target="_blank"
rel="noopener noreferrer"
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white hover:bg-zinc-200 dark:hover:bg-zinc-800 {useTwoColumnLayout ? 'col-span-2' : ''}"
>
<span class="text-xl font-IconFamily">{'\uecb3'}</span>
<span class="ml-2">View theme creation docs</span>
</a>
{:else if listMode === 'downloaded'}
<button
onclick={() => void openStorePage()}
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white"
class="flex justify-center items-center w-full rounded-xl transition aspect-theme bg-zinc-100 dark:bg-zinc-900 dark:text-white {useTwoColumnLayout ? 'col-span-2' : ''}"
>
<span class="text-xl font-IconFamily">&#xecc5;</span>
<span class="ml-2">Theme Store</span>
+11 -7
View File
@@ -31,13 +31,17 @@
: clearTheme ? 'Clear Background' : 'No Background Selected'}
</button>
{/if}
<div class="relative w-full">
<button
onclick={() => editMode = !editMode}
class="absolute top-0 right-0 z-10 px-2 h-8 text-lg rounded-xl bg-zinc-100 dark:bg-zinc-700">
<span class="mr-2">{editMode ? 'Done' : 'Edit'}</span>
<span class="font-IconFamily">{editMode ? '\ue9e4' : '\uec38'}</span>
</button>
<div class="w-full">
{#if showThemes || showBackgrounds}
<div class="mb-3 flex justify-end">
<button
onclick={() => editMode = !editMode}
class="inline-flex h-8 items-center rounded-xl bg-zinc-100 px-3 text-lg dark:bg-zinc-700">
<span class="mr-2">{editMode ? 'Done' : 'Remove'}</span>
<span class="font-IconFamily">{editMode ? '\ue9e4' : '\uec38'}</span>
</button>
</div>
{/if}
{#if showBackgrounds}
<BackgroundSelector isEditMode={editMode} bind:selectedBackground={selectedBackground} bind:selectNoBackground={selectNoBackground} />
+5
View File
@@ -54,6 +54,7 @@
let displayTheme = $state<Theme | null>(null);
let currentThemes = $state<string[]>([]);
let selectedThemeId = $state('');
let installedThemeColors = $state<Record<string, string>>({});
let error = $state<string | null>(null);
let fetchAttempt = $state(0);
@@ -76,6 +77,9 @@
const themes = await themeManager.getAvailableThemes();
currentThemes = themes.filter(theme => theme !== null).map(theme => theme.id);
selectedThemeId = themeManager.getSelectedThemeId() || '';
installedThemeColors = Object.fromEntries(
themes.filter((theme) => theme != null).map((theme) => [theme.id, theme.defaultColour]),
);
};
const setDisplayTheme = (theme: Theme | null) => {
@@ -313,6 +317,7 @@
isLoggedIn={cloudLoggedIn}
onRequestSignIn={() => (showSignInOverlay = true)}
{selectedThemeId}
{installedThemeColors}
onInstall={async (themeId: string) => {
if (displayTheme) await installThemeFromStore(themeId, displayTheme);
}}
+39 -1
View File
@@ -1,6 +1,11 @@
import type { CustomTheme } from '@/types/CustomThemes';
import type { Theme } from '@/interface/types/Theme';
import { filterThemesByMode, isStoreThemeInstalled } from './themeListFilters';
import {
filterThemesByMode,
getThemeApplyButtonStyles,
isStoreThemeInstalled,
resolveStoreVariantAccentColor,
} from './themeListFilters';
function makeCustomTheme(overrides: Partial<CustomTheme> & Pick<CustomTheme, 'id' | 'name'>): CustomTheme {
return {
@@ -66,3 +71,36 @@ describe('isStoreThemeInstalled', () => {
expect(isStoreThemeInstalled(theme, ['other-theme'])).toBe(false);
});
});
describe('resolveStoreVariantAccentColor', () => {
it('prefers installed theme colour for the variant id', () => {
const theme = makeStoreTheme({
id: 'master-1',
name: 'Master',
flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#111111', cover_image: '' }],
});
expect(resolveStoreVariantAccentColor(theme, 'flavour-1', { 'flavour-1': '#ff0000' })).toBe('#ff0000');
});
it('falls back to flavour accent when not installed locally', () => {
const theme = makeStoreTheme({
id: 'master-1',
name: 'Master',
flavours: [{ id: 'flavour-1', name: 'Dark', accent_color: '#112233', cover_image: '' }],
});
expect(resolveStoreVariantAccentColor(theme, 'flavour-1')).toBe('#112233');
});
});
describe('getThemeApplyButtonStyles', () => {
it('uses the theme accent as the apply button background', () => {
const styles = getThemeApplyButtonStyles('#ff0000');
expect(styles.apply).toContain('background-color: #FF0000');
});
it('uses a muted version of the accent for the applied state', () => {
const styles = getThemeApplyButtonStyles('#ff0000');
expect(styles.applied).toContain('background-color:');
expect(styles.applied).toContain('color: #FF0000');
});
});
+37
View File
@@ -1,8 +1,11 @@
import type { CustomTheme } from '@/types/CustomThemes';
import type { Theme } from '@/interface/types/Theme';
import { parseCssColor } from '@/seqta/ui/colors/parseCssColor';
export type ThemeListMode = 'downloaded' | 'custom' | 'all';
const DEFAULT_THEME_ACCENT = 'rgba(0, 123, 255, 1)';
export function filterThemesByMode(themes: CustomTheme[], mode: ThemeListMode): CustomTheme[] {
if (mode === 'all') return themes;
if (mode === 'custom') return themes.filter((theme) => theme.isEditable === true);
@@ -14,3 +17,37 @@ export function isStoreThemeInstalled(theme: Theme, installedIds: string[]): boo
if (installed.has(theme.id)) return true;
return (theme.flavours ?? []).some((flavour) => installed.has(flavour.id));
}
export function resolveStoreVariantAccentColor(
theme: Theme,
variantId: string,
installedThemeColors: Record<string, string> = {},
): string {
const installed = installedThemeColors[variantId]?.trim();
if (installed) return installed;
const flavour = theme.flavours?.find((entry) => entry.id === variantId);
if (flavour?.accent_color?.trim()) return flavour.accent_color.trim();
if (variantId === theme.id) {
const firstFlavourAccent = theme.flavours?.find((entry) => entry.accent_color?.trim())?.accent_color?.trim();
if (firstFlavourAccent) return firstFlavourAccent;
}
return DEFAULT_THEME_ACCENT;
}
export type ThemeApplyButtonStyles = {
apply: string;
applied: string;
};
export function getThemeApplyButtonStyles(accentColor: string | undefined): ThemeApplyButtonStyles {
const parsed = parseCssColor(accentColor?.trim() || DEFAULT_THEME_ACCENT, DEFAULT_THEME_ACCENT);
const onAccent = parsed.lightness() >= 60 ? '#18181b' : '#ffffff';
return {
apply: `background-color: ${parsed.hex()}; color: ${onAccent};`,
applied: `background-color: ${parsed.alpha(0.18).string()}; color: ${parsed.hex()};`,
};
}
+18 -3
View File
@@ -18,13 +18,28 @@ function toHexByte(value: number): string {
}
function createColor(channels: ColorChannels) {
const hex = () =>
`#${toHexByte(channels.r)}${toHexByte(channels.g)}${toHexByte(channels.b)}`.toUpperCase();
const color = {
red: () => clampByte(channels.r),
green: () => clampByte(channels.g),
blue: () => clampByte(channels.b),
alpha: () => clampAlpha(channels.a),
hex: () =>
`#${toHexByte(channels.r)}${toHexByte(channels.g)}${toHexByte(channels.b)}`,
hex,
lightness: () => {
const r = channels.r / 255;
const g = channels.g / 255;
const b = channels.b / 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
return ((max + min) / 2) * 100;
},
string: () => {
if (channels.a < 1) {
return `rgba(${clampByte(channels.r)}, ${clampByte(channels.g)}, ${clampByte(channels.b)}, ${clampAlpha(channels.a)})`;
}
return hex();
},
};
return {