diff options
Diffstat (limited to 'web/src/lib/ui/menus/FigureNoteMenu.svelte')
| -rw-r--r-- | web/src/lib/ui/menus/FigureNoteMenu.svelte | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/web/src/lib/ui/menus/FigureNoteMenu.svelte b/web/src/lib/ui/menus/FigureNoteMenu.svelte new file mode 100644 index 0000000..0f79578 --- /dev/null +++ b/web/src/lib/ui/menus/FigureNoteMenu.svelte @@ -0,0 +1,83 @@ +<!-- + A figure's quick note (the reference `SetFigureNoteMenu`): the free-form + note shown inline on a figure's row (character or monster). The note is + committed (via `setFigureNote`) when the field loses focus or the dialog + is dismissed, and only when the text actually changed, so an unedited + open/close doesn't pollute the undo history. +--> +<script lang="ts"> + import type { GameSession } from '$lib/state/session'; + import Menu from '../Menu.svelte'; + + let { + session, + figureId, + initial, + open = $bindable(true) + }: { + session: GameSession; + figureId: string; + initial: string; + open?: boolean; + } = $props(); + + const player = session.player; + + let text = $state(initial); + let lastCommitted = $state(initial); + + function commit() { + const trimmed = text.trim(); + if (trimmed !== lastCommitted) { + lastCommitted = trimmed; + if ($player) + session.command('setFigureNote', { note: trimmed, figureId }); + } + } + + function close() { + commit(); + open = false; + } +</script> + +<Menu {open}> + <textarea + class="search search--area" + rows={3} + maxlength={140} + placeholder="…" + bind:value={text} + readonly={!$player} + onblur={commit} + ></textarea> + {#if $player} + <div class="actions"> + <button class="pill" onclick={close}>Save</button> + </div> + {/if} +</Menu> + +<style> + textarea.search--area { + resize: vertical; + min-height: 64px; + } + .actions { + display: flex; + justify-content: flex-end; + margin-top: 10px; + } + .pill { + padding: 6px 14px; + font-size: 13px; + border: none; + border-radius: 4px; + background: rgba(255, 255, 255, 0.12); + color: inherit; + cursor: pointer; + } + .pill:hover { + background: rgba(255, 255, 255, 0.25); + } +</style> |
