-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial page for creating a new list
- Loading branch information
Showing
11 changed files
with
301 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<script lang="ts"> | ||
import ListCard from "$lib/components/ListCard.svelte"; | ||
import { t } from "svelte-i18n"; | ||
import IconSelector from "$lib/components/IconSelector.svelte"; | ||
import { enhance } from "$app/forms"; | ||
import ClearableInput from "$lib/components/ClearableInput.svelte"; | ||
import { rgbToHex } from "$lib/util"; | ||
import type { List, User } from "@prisma/client"; | ||
interface ListProps extends Partial<Pick<List, "id" | "icon" | "iconColor" | "name">> { | ||
owner: Pick<User, "name" | "username" | "picture">; | ||
} | ||
interface Props { | ||
data: { | ||
list: ListProps; | ||
}; | ||
persistButtonName: string; | ||
} | ||
const { data, persistButtonName }: Props = $props(); | ||
let list = $state(data.list); | ||
let colorElement: Element | undefined = $state(); | ||
let defaultColor: string = $derived.by(() => { | ||
if (colorElement) { | ||
const rgbColor = getComputedStyle(colorElement).backgroundColor; | ||
const rgbValues = rgbColor.match(/\d+/g)?.map(Number.parseFloat); | ||
return rgbValues ? rgbToHex(rgbValues[0], rgbValues[1], rgbValues[2]) : ""; | ||
} | ||
return list.iconColor || ""; | ||
}); | ||
let colorValue: string | null = $state((() => defaultColor)()); | ||
$effect(() => { | ||
if (!colorValue) colorValue = defaultColor; | ||
}); | ||
</script> | ||
|
||
<form | ||
method="POST" | ||
use:enhance={(e) => { | ||
if (e.formData.get("iconColor") === defaultColor) { | ||
e.formData.delete("iconColor"); | ||
} | ||
}} | ||
> | ||
<div class="grid grid-cols-1 gap-4 pb-4 md:grid-cols-2"> | ||
<label class="col-span-1 md:col-span-2" for="name"> | ||
<span>{$t("auth.name")}</span> | ||
<ClearableInput | ||
id="name" | ||
name="name" | ||
class="input" | ||
autocomplete="off" | ||
clearButtonLabel={$t("a11y.clear-name-field")} | ||
onValueClear={() => (list.name = null)} | ||
placeholder={$t("wishes.wishes-for", { values: { listOwner: list.owner.name } })} | ||
showClearButton={() => list.name !== null} | ||
type="text" | ||
bind:value={list.name} | ||
/> | ||
</label> | ||
|
||
<label class="col-span-1 flex flex-col" for="name"> | ||
<span>{$t("general.icon-bg-color")}</span> | ||
<div class="grid grid-cols-[auto_1fr] gap-2"> | ||
<input | ||
id="iconColor" | ||
name="iconColor" | ||
class="input" | ||
onchange={(e) => (list.iconColor = e.currentTarget?.value)} | ||
type="color" | ||
bind:value={colorValue} | ||
/> | ||
<ClearableInput | ||
class="input" | ||
clearButtonLabel={$t("a11y.clear-color-field")} | ||
onValueClear={() => { | ||
colorValue = defaultColor; | ||
list.iconColor = defaultColor; | ||
}} | ||
readonly | ||
showClearButton={() => colorValue !== defaultColor} | ||
tabindex={-1} | ||
type="text" | ||
value={colorValue} | ||
/> | ||
</div> | ||
</label> | ||
<div class="col-span-1"> | ||
<IconSelector id="icon" icon={list.icon} onIconSelected={(icon) => (list.icon = icon)} /> | ||
</div> | ||
|
||
<div class="col-span-1 md:col-span-2"> | ||
<div class="flex flex-col space-y-2"> | ||
<span>{$t("wishes.preview")}</span> | ||
<ListCard hideCount {list} preventNavigate /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="flex flex-row justify-between"> | ||
<button class="variant-ghost-secondary btn w-min" onclick={() => history.back()} type="button"> | ||
{$t("general.cancel")} | ||
</button> | ||
<button class="variant-filled-primary btn w-min" type="submit"> | ||
{persistButtonName} | ||
</button> | ||
</div> | ||
</form> | ||
|
||
<div bind:this={colorElement} class="bg-primary-400-500-token hidden"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.