chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.4.0 Latest 5 packages
0
0
<script lang="ts">
import Handle from '../atoms/Handle.svelte';
import Icon from '../atoms/Icon.svelte';
import ThemeSwatch from '../atoms/ThemeSwatch.svelte';
import type { IconName } from '../icons';
import { themeId, type Theme } from '../theme';
/**
* The theme menu: the system's light or dark, HUD's own light and dark,
* HUD's palettes, then the themes this person made (each deleted here),
* and the one chosen if it is someone else's. Then making one, and
* browsing everyone's. The one chosen is checked; choosing draws the
* page in it at once, and every page and app the person is signed in
* to. On a phone it is a sheet.
*/
let {
open = $bindable(false),
themes,
mine,
chosen,
onopen,
onchoose,
onnew,
onbrowse,
ondelete
}: {
open?: boolean;
/** HUD's themes. */
themes: Theme[];
/** This person's, once read. */
mine: Theme[] | null;
/** The theme chosen; none, the system's. */
chosen: Theme | null;
/** The menu opened: this person's themes are read again. */
onopen: () => void;
onchoose: (theme: Theme | null) => void;
onnew: () => void;
onbrowse: () => void;
ondelete: (theme: Theme) => void;
} = $props();
const plain = $derived(themes.filter((theme) => !theme.palette));
const painted = $derived(themes.filter((theme) => theme.palette));
const chosenId = $derived(chosen ? themeId(chosen) : null);
/** The theme chosen, if it is a person's not among this person's own. */
const theirs = $derived(chosen?.uri && !(mine ?? []).some((theme) => theme.uri === chosen.uri) ? chosen : null);
const iconOf = (theme: Theme): IconName => (theme.colorScheme === 'dark' ? 'dark' : 'light');
const schemeWord = (theme: Theme) => (theme.colorScheme === 'dark' ? 'Dark' : 'Light');
$effect(() => {
if (open) onopen();
});
function choose(theme: Theme | null) {
open = false;
if ((theme ? themeId(theme) : null) !== chosenId) onchoose(theme);
}
function act(run: () => void) {
open = false;
run();
}
</script>
{#snippet row(theme: Theme | null, sub: string | null)}
{@const id = theme ? themeId(theme) : null}
<button type="button" class="menu-item" role="menuitemradio" aria-checked={id === chosenId} onclick={() => choose(theme)}>
{#if theme?.palette}
<ThemeSwatch palette={theme.palette} />
{:else}
<span class="mark"><Icon name={theme ? iconOf(theme) : 'system'} /></span>
{/if}
<span class="grow name">{theme?.name ?? 'System'}</span>
{#if sub}<span class="mute">{sub}</span>{/if}
<span class="chosen">{#if id === chosenId}<Icon name="check" />{/if}</span>
</button>
{/snippet}
<details class="popover sheet end" bind:open>
<summary class="icon-button" title="Theme" aria-label="Theme"><Icon name="theme" /></summary>
<div class="menu" role="menu">
<p class="menu-head">Theme</p>
{@render row(null, 'As your device is')}
{#each plain as theme (themeId(theme))}
{@render row(theme, null)}
{/each}
{#each painted as theme (themeId(theme))}
{@render row(theme, schemeWord(theme))}
{/each}
<hr />
<p class="menu-head">Yours</p>
{#if mine === null}
<p class="empty-state">Loading your themes…</p>
{:else}
{#each mine as theme (themeId(theme))}
<div class="line">
{@render row(theme, schemeWord(theme))}
<button type="button" class="icon-button" title="Delete" aria-label="Delete {theme.name}" onclick={() => act(() => ondelete(theme))}><Icon name="close" /></button>
</div>
{:else}
<p class="empty-state">No themes of yours yet</p>
{/each}
{/if}
{#if theirs}
<p class="menu-head">In use</p>
<div class="line">
{@render row(theirs, null)}
</div>
{#if theirs.creator}<p class="by mute">By <Handle did={theirs.creator.did} handle={theirs.creator.handle} /></p>{/if}
{/if}
<hr />
<button type="button" class="menu-item" role="menuitem" onclick={() => act(onnew)}>
<span class="mark"><Icon name="add" /></span>
<span class="grow">New theme</span>
</button>
<button type="button" class="menu-item" role="menuitem" onclick={() => act(onbrowse)}>
<span class="mark"><Icon name="search" /></span>
<span class="grow">Browse everyone’s themes</span>
</button>
</div>
</details>
<style>
.mark {
display: inline-grid;
flex: none;
place-items: center;
width: var(--swatch);
}
.grow {
flex: 1;
min-width: 0;
}
.name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* The check's column, kept on every row so the words beside it line up. */
.chosen {
display: inline-grid;
flex: none;
place-items: center;
width: var(--icon);
}
.line {
display: flex;
align-items: center;
padding-right: var(--space-2);
}
.line:hover {
background: var(--hover);
}
.line .menu-item {
min-width: 0;
}
.line .menu-item:hover {
background: none;
}
.by {
padding: 0 var(--space-3) var(--space-2);
font-size: var(--text-xs);
}
</style>