flotilla/src/app/components/RoleForm.svelte

83 lines
2.3 KiB
Svelte
Raw Normal View History

2026-06-22 20:36:57 +00:00
<script module lang="ts">
2026-07-08 17:56:22 +00:00
import type {SpaceRole} from "@app/members"
2026-06-22 20:36:57 +00:00
export type Values = Pick<SpaceRole, "label" | "description" | "color">
</script>
<script lang="ts">
import Spinner from "@lib/components/Spinner.svelte"
import Button from "@lib/components/Button.svelte"
import Field from "@lib/components/Field.svelte"
import Icon from "@lib/components/Icon.svelte"
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {roleColor} from "@app/members"
type Props = {
initialValues?: Partial<Values>
loading?: boolean
onSubmit: (values: Values) => void
}
const {initialValues = {}, loading = false, onSubmit}: Props = $props()
2026-07-01 17:23:23 +00:00
const values = $state({
label: initialValues.label ?? "",
description: initialValues.description ?? "",
})
2026-07-08 17:56:22 +00:00
let hue = $state(initialValues.color ?? Math.floor(Math.random() * 360))
2026-06-22 20:36:57 +00:00
const back = () => history.back()
2026-07-08 17:56:22 +00:00
const submit = () => onSubmit({...values, color: hue})
2026-06-22 20:36:57 +00:00
</script>
<div class="flex flex-col gap-4">
<Field>
{#snippet label()}
<p>Name</p>
{/snippet}
{#snippet input()}
<input bind:value={values.label} class="input w-full" placeholder="Moderator" />
2026-06-22 20:36:57 +00:00
{/snippet}
</Field>
<Field>
{#snippet label()}
<p>Description</p>
{/snippet}
{#snippet input()}
<textarea bind:value={values.description} class="textarea input w-full" rows="2"></textarea>
2026-06-22 20:36:57 +00:00
{/snippet}
</Field>
<Field>
{#snippet label()}
<p>Color</p>
{/snippet}
{#snippet input()}
<div class="flex items-center gap-3">
<div
class="h-8 w-8 shrink-0 rounded-full border-2"
2026-07-08 17:56:22 +00:00
style="background-color: {roleColor(hue)}; border-color: var(--line)">
2026-06-22 20:36:57 +00:00
</div>
2026-07-08 17:56:22 +00:00
<input
type="range"
min="0"
max="360"
bind:value={hue}
class="range grow"
style="color: {roleColor(hue)}; --range-shdw: {roleColor(hue)}" />
2026-06-22 20:36:57 +00:00
</div>
{/snippet}
</Field>
</div>
<ModalFooter>
<Button class="button button-link" onclick={back}>
2026-06-22 20:36:57 +00:00
<Icon icon={AltArrowLeft} />
Go back
</Button>
<Button class="button button-primary" onclick={submit} disabled={loading || !values.label}>
2026-06-22 20:36:57 +00:00
<Spinner {loading}>Save changes</Spinner>
</Button>
</ModalFooter>