[ui] DaySentence: Her folded petal, the words and their source; the library bundled after validation
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import type { PetalNow } from '@rosea/engine';
|
||||
import type { HopeSentence } from '@rosea/schema';
|
||||
import { tick } from 'svelte';
|
||||
import { en } from '../copy/en.js';
|
||||
// The art board's stand-in until real art is accepted (docs/ART.md).
|
||||
import folded from '../../../../art/placeholders/petal-folded.svg?url';
|
||||
|
||||
/**
|
||||
* The rose's folded petal (day-sentence.md). The engine decides which sentence and
|
||||
* whether it is open; this shows it and hands the player's tap back.
|
||||
*/
|
||||
let { petal, sentences, onopen }: { petal: PetalNow; sentences: readonly HopeSentence[]; onopen: () => void } = $props();
|
||||
|
||||
const uid = $props.id();
|
||||
/** Today's open petal is shown; the player can fold it away and back for the rest of the day. */
|
||||
let showing = $state(true);
|
||||
let words = $state<HTMLElement>();
|
||||
|
||||
const find = (id: string | null): HopeSentence | undefined => (id === null ? undefined : sentences.find((s) => s.id === id));
|
||||
const today = $derived(petal.kind === 'open' ? find(petal.id) : undefined);
|
||||
const remembered = $derived(petal.kind === 'open' ? find(petal.remembered) : undefined);
|
||||
const source = (s: HopeSentence): string => en.rose.petal.source(s.source.work, s.source.author, s.source.translation);
|
||||
|
||||
async function open(): Promise<void> {
|
||||
onopen();
|
||||
showing = true;
|
||||
// The player acted, so focus follows them to the words.
|
||||
await tick();
|
||||
words?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if petal.kind === 'folded'}
|
||||
<div class="petal">
|
||||
<img src={folded} alt={en.rose.petal.folded} width="56" height="56" />
|
||||
<button type="button" onclick={open}>{en.rose.petal.open}</button>
|
||||
</div>
|
||||
{:else if petal.kind === 'open' && today}
|
||||
<div class="petal">
|
||||
<button type="button" class="quiet" aria-expanded={showing} aria-controls="{uid}-words" onclick={() => (showing = !showing)}>{en.rose.petal.today}</button>
|
||||
{#if showing}
|
||||
<div id="{uid}-words" class="words" tabindex="-1" bind:this={words}>
|
||||
<figure>
|
||||
<blockquote>{today.text.en}</blockquote>
|
||||
<figcaption>{source(today)}</figcaption>
|
||||
</figure>
|
||||
{#if remembered}
|
||||
<p class="remember">{en.rose.petal.remember}</p>
|
||||
<figure>
|
||||
<blockquote>{remembered.text.en}</blockquote>
|
||||
<figcaption>{source(remembered)}</figcaption>
|
||||
</figure>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.petal {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
img {
|
||||
width: 3.5rem;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.words {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
max-width: 24rem;
|
||||
padding: var(--space-3);
|
||||
border-radius: 1.25rem;
|
||||
background: color-mix(in srgb, var(--rose) 10%, var(--paper));
|
||||
}
|
||||
|
||||
.words:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
figure {
|
||||
margin: 0;
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 1.15rem;
|
||||
line-height: 1.45;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
figcaption,
|
||||
.remember {
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--rose);
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.quiet {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: var(--space-1) 0;
|
||||
color: var(--rose);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
button:focus-visible {
|
||||
outline: 2px solid var(--rose);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user