feat: better components
This commit is contained in:
30
client/src/lib/ui/form/errors.svelte
Normal file
30
client/src/lib/ui/form/errors.svelte
Normal file
@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { cn } from '$lib/utils';
|
||||
import { getFormContext } from './context.svelte';
|
||||
import type { WithElementRef, WithoutChildren } from 'bits-ui';
|
||||
import type { HTMLAttributes } from 'svelte/elements';
|
||||
import type { Violation } from '@bufbuild/protovalidate';
|
||||
import type { ConnectError } from '@connectrpc/connect';
|
||||
|
||||
type Props = WithoutChildren<WithElementRef<HTMLAttributes<HTMLDivElement>>> & {
|
||||
errors?: Violation[] | ConnectError;
|
||||
};
|
||||
let {
|
||||
ref = $bindable(null),
|
||||
class: className,
|
||||
errors = $bindable(),
|
||||
...restProps
|
||||
}: Props = $props();
|
||||
|
||||
const item = getFormContext();
|
||||
</script>
|
||||
|
||||
<div bind:this={ref} class={cn('text-red text-sm', className)} {...restProps}>
|
||||
{#if errors && Array.isArray(errors)}
|
||||
{#each errors as error}
|
||||
<label for={item?.id}>{error.message}</label>
|
||||
{/each}
|
||||
{:else if errors}
|
||||
<span>{errors.message}</span>
|
||||
{/if}
|
||||
</div>
|
Reference in New Issue
Block a user