87 lines
1.6 KiB
Svelte
87 lines
1.6 KiB
Svelte
<script lang="ts">
|
|
import { untrack } from "svelte";
|
|
import { t } from "#lib/i18n/locale.svelte.js";
|
|
import Button from "../ui/Button.svelte";
|
|
|
|
interface Props {
|
|
initial?: string;
|
|
oncancel?: () => void;
|
|
onsubmit: (text: string) => void;
|
|
saving?: boolean;
|
|
submitLabel?: string;
|
|
}
|
|
|
|
const {
|
|
initial = "",
|
|
saving = false,
|
|
submitLabel,
|
|
oncancel,
|
|
onsubmit,
|
|
}: Props = $props();
|
|
|
|
let text = $state(untrack(() => initial));
|
|
|
|
const valid = $derived(text.trim() !== "");
|
|
|
|
function submit() {
|
|
if (!valid) {
|
|
return;
|
|
}
|
|
onsubmit(text.trim());
|
|
if (oncancel === undefined) {
|
|
text = "";
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<form
|
|
class="annotation-editor"
|
|
onsubmit={(e) => {
|
|
e.preventDefault();
|
|
submit();
|
|
}}
|
|
>
|
|
<textarea
|
|
placeholder={t("notes.placeholder")}
|
|
rows={oncancel ? 2 : 3}
|
|
bind:value={text}
|
|
></textarea>
|
|
<div class="actions">
|
|
{#if oncancel}
|
|
<Button onclick={oncancel} variant="translucent">
|
|
{t("common.cancel")}
|
|
</Button>
|
|
{/if}
|
|
<Button disabled={saving || !valid} type="submit">
|
|
{submitLabel ?? t("notes.add")}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
|
|
<style lang="scss">
|
|
.annotation-editor {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
textarea {
|
|
width: 100%;
|
|
padding: 0.5rem;
|
|
border: 1px solid var(--color-borders);
|
|
border-radius: 0.5rem;
|
|
|
|
color: var(--color-text);
|
|
font: inherit;
|
|
|
|
background: var(--color-background);
|
|
resize: vertical;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 0.5rem;
|
|
}
|
|
</style>
|