update with label and error
This commit is contained in:
parent
01704b5a88
commit
be3c7874ff
2 changed files with 77 additions and 37 deletions
|
|
@ -6,27 +6,36 @@
|
||||||
title: 'Data Input/Text Input',
|
title: 'Data Input/Text Input',
|
||||||
component: TextInput,
|
component: TextInput,
|
||||||
argTypes: {
|
argTypes: {
|
||||||
|
bordered: {
|
||||||
|
control: 'boolean',
|
||||||
|
},
|
||||||
color: {
|
color: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
options: [
|
options: [
|
||||||
|
'ghost',
|
||||||
'primary',
|
'primary',
|
||||||
'secondary',
|
'secondary',
|
||||||
'accent',
|
'accent',
|
||||||
'ghost',
|
|
||||||
'link',
|
|
||||||
'info',
|
'info',
|
||||||
'success',
|
'success',
|
||||||
'warning',
|
'warning',
|
||||||
'error',
|
'error',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
bordered: {
|
disabled: {
|
||||||
control: 'boolean',
|
control: 'boolean',
|
||||||
},
|
},
|
||||||
|
error: {
|
||||||
|
control: 'text',
|
||||||
|
},
|
||||||
|
fade: { control: 'boolean' },
|
||||||
|
start: { control: 'text' },
|
||||||
|
end: { control: 'text' },
|
||||||
|
label: { control: 'text' },
|
||||||
|
placeholder: { control: 'text' },
|
||||||
size: {
|
size: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
options: ['Default', 'xs', 'sm', 'lg'],
|
options: ['xs', 'sm', '-', 'lg'],
|
||||||
defaultValue: 'Default',
|
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@
|
||||||
bordered?: boolean;
|
bordered?: boolean;
|
||||||
color?: Exclude<DaisyColor, 'neutral'>;
|
color?: Exclude<DaisyColor, 'neutral'>;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
error?: string | Snippet;
|
||||||
fade?: boolean;
|
fade?: boolean;
|
||||||
start?: Snippet | string;
|
start?: string | Snippet;
|
||||||
end?: Snippet | string;
|
end?: string | Snippet;
|
||||||
|
label?: string | Snippet;
|
||||||
name: string;
|
name: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
size?: DaisySize;
|
size?: DaisySize;
|
||||||
|
|
@ -24,9 +26,11 @@
|
||||||
bordered = false,
|
bordered = false,
|
||||||
color,
|
color,
|
||||||
disabled,
|
disabled,
|
||||||
|
error,
|
||||||
fade,
|
fade,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
|
label,
|
||||||
name,
|
name,
|
||||||
placeholder,
|
placeholder,
|
||||||
size,
|
size,
|
||||||
|
|
@ -34,34 +38,61 @@
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label
|
<label class="form-control w-full">
|
||||||
transition:fadeTransition={{ duration: fade ? 200 : 0 }}
|
<div class="label">
|
||||||
class="input flex w-full items-center gap-2"
|
<span
|
||||||
class:input-bordered={bordered}
|
class="label-text"
|
||||||
class:input-xs={size === 'xs'}
|
class:text-primary={color === 'primary'}
|
||||||
class:input-sm={size === 'sm'}
|
class:text-secondary={color === 'secondary'}
|
||||||
class:input-lg={size === 'lg'}
|
class:text-accent={color === 'accent'}
|
||||||
class:input-primary={color === 'primary'}
|
class:text-info={color === 'info'}
|
||||||
class:input-secondary={color === 'secondary'}
|
class:text-success={color === 'success'}
|
||||||
class:input-accent={color === 'accent'}
|
class:text-warning={color === 'warning'}
|
||||||
class:input-ghost={color === 'ghost'}
|
class:text-error={color === 'error' || error}
|
||||||
class:input-link={color === 'link'}
|
>
|
||||||
class:input-info={color === 'info'}
|
{#if typeof label === 'string'}
|
||||||
class:input-success={color === 'success'}
|
{label}
|
||||||
class:input-warning={color === 'warning'}
|
{:else if label}
|
||||||
class:input-error={color === 'error'}
|
{@render label()}
|
||||||
>
|
{/if}
|
||||||
{#if typeof start === 'string'}
|
</span>
|
||||||
{start}
|
<span class="label-text-alt font-semibold text-error">
|
||||||
{:else}
|
{#if typeof error === 'string'}
|
||||||
{@render start?.()}
|
{error}
|
||||||
{/if}
|
{:else if error}
|
||||||
<input {disabled} {name} {placeholder} {type} class="grow" />
|
{@render error()}
|
||||||
{#if typeof end === 'string'}
|
{/if}
|
||||||
{end}
|
</span>
|
||||||
{:else}
|
</div>
|
||||||
{@render end?.()}
|
<div
|
||||||
{/if}
|
transition:fadeTransition={{ duration: fade ? 200 : 0 }}
|
||||||
|
class="input flex w-full items-center gap-2"
|
||||||
|
class:input-bordered={bordered}
|
||||||
|
class:input-xs={size === 'xs'}
|
||||||
|
class:input-sm={size === 'sm'}
|
||||||
|
class:input-lg={size === 'lg'}
|
||||||
|
class:input-primary={color === 'primary'}
|
||||||
|
class:input-secondary={color === 'secondary'}
|
||||||
|
class:input-accent={color === 'accent'}
|
||||||
|
class:input-ghost={color === 'ghost'}
|
||||||
|
class:input-link={color === 'link'}
|
||||||
|
class:input-info={color === 'info'}
|
||||||
|
class:input-success={color === 'success'}
|
||||||
|
class:input-warning={color === 'warning'}
|
||||||
|
class:input-error={color === 'error' || error}
|
||||||
|
>
|
||||||
|
{#if typeof start === 'string'}
|
||||||
|
{start}
|
||||||
|
{:else}
|
||||||
|
{@render start?.()}
|
||||||
|
{/if}
|
||||||
|
<input {disabled} {name} {placeholder} {type} class="grow" />
|
||||||
|
{#if typeof end === 'string'}
|
||||||
|
{end}
|
||||||
|
{:else}
|
||||||
|
{@render end?.()}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue