allow snippets on labels

This commit is contained in:
Benjamin Palko 2024-12-30 18:25:29 -05:00
parent 12e9233ace
commit 01704b5a88

View file

@ -1,12 +1,13 @@
<script lang="ts"> <script lang="ts">
import type { DaisyColor, DaisySize } from '$lib/types'; import type { DaisyColor, DaisySize } from '$lib/types';
import type { Snippet } from 'svelte';
type Props = { type Props = {
bordered?: boolean; bordered?: boolean;
color?: Omit<DaisyColor, 'neutral'>; color?: Omit<DaisyColor, 'neutral'>;
disabled?: boolean; disabled?: boolean;
error?: string; error?: string | Snippet;
label?: string; label?: string | Snippet;
size?: DaisySize; size?: DaisySize;
}; };
let { bordered, color, disabled, error, label, size }: Props = $props(); let { bordered, color, disabled, error, label, size }: Props = $props();
@ -14,7 +15,6 @@
<label class="form-control w-full max-w-lg"> <label class="form-control w-full max-w-lg">
<div class="label"> <div class="label">
{#if label}
<span <span
class="label-text" class="label-text"
class:text-primary={color === 'primary'} class:text-primary={color === 'primary'}
@ -23,12 +23,21 @@
class:text-info={color === 'info'} class:text-info={color === 'info'}
class:text-success={color === 'success'} class:text-success={color === 'success'}
class:text-warning={color === 'warning'} class:text-warning={color === 'warning'}
class:text-error={color === 'error' || error}>{label}</span class:text-error={color === 'error' || error}
> >
{#if typeof label === 'string'}
{label}
{:else if label}
{@render label()}
{/if} {/if}
{#if error} </span>
<span class="label-text-alt font-semibold text-error">{error}</span> <span class="label-text-alt font-semibold text-error">
{#if typeof error === 'string'}
{error}
{:else if error}
{@render error()}
{/if} {/if}
</span>
</div> </div>
<textarea <textarea
class="textarea" class="textarea"