update InputField
This commit is contained in:
parent
680244b1b5
commit
926cd4d6e4
2 changed files with 76 additions and 79 deletions
|
|
@ -4,9 +4,12 @@
|
||||||
import InputField from './InputField.svelte';
|
import InputField from './InputField.svelte';
|
||||||
|
|
||||||
const { Story } = defineMeta({
|
const { Story } = defineMeta({
|
||||||
title: 'Data Input/Text Input',
|
title: 'Data Input/Input Field',
|
||||||
component: InputField,
|
component: InputField,
|
||||||
argTypes: {
|
argTypes: {
|
||||||
|
block: {
|
||||||
|
control: 'boolean',
|
||||||
|
},
|
||||||
color: {
|
color: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
options: ['primary', 'secondary', 'accent', 'info', 'success', 'warning', 'error'],
|
options: ['primary', 'secondary', 'accent', 'info', 'success', 'warning', 'error'],
|
||||||
|
|
@ -14,13 +17,8 @@
|
||||||
disabled: {
|
disabled: {
|
||||||
control: 'boolean',
|
control: 'boolean',
|
||||||
},
|
},
|
||||||
error: {
|
|
||||||
control: 'text',
|
|
||||||
},
|
|
||||||
fade: { control: 'boolean' },
|
|
||||||
start: { control: 'text' },
|
start: { control: 'text' },
|
||||||
end: { control: 'text' },
|
end: { control: 'text' },
|
||||||
label: { control: 'text' },
|
|
||||||
placeholder: { control: 'text' },
|
placeholder: { control: 'text' },
|
||||||
size: {
|
size: {
|
||||||
control: 'select',
|
control: 'select',
|
||||||
|
|
@ -38,20 +36,45 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Story name="Default" args={{ color: 'primary', name: 'text', start: 'Text' }} />
|
<Story name="Default" args={{ name: 'text' }} />
|
||||||
|
|
||||||
<Story name="Icon Start">
|
<Story name="Labels">
|
||||||
<InputField name="text" color="secondary">
|
<div class="flex flex-col gap-2">
|
||||||
|
<InputField name="text" start="Label" />
|
||||||
|
<InputField name="text">
|
||||||
{#snippet start()}
|
{#snippet start()}
|
||||||
<User />
|
<User />
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</InputField>
|
</InputField>
|
||||||
</Story>
|
<InputField name="text">
|
||||||
|
|
||||||
<Story name="Icon End">
|
|
||||||
<InputField name="text" color="secondary">
|
|
||||||
{#snippet end()}
|
{#snippet end()}
|
||||||
<User />
|
<User />
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</InputField>
|
</InputField>
|
||||||
|
</div>
|
||||||
</Story>
|
</Story>
|
||||||
|
|
||||||
|
<Story name="Colors">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<InputField name="text" color="primary" placeholder="Primary" />
|
||||||
|
<InputField name="text" color="secondary" placeholder="Secondary" />
|
||||||
|
<InputField name="text" color="accent" placeholder="Accent" />
|
||||||
|
<InputField name="text" color="neutral" placeholder="Neutral" />
|
||||||
|
<InputField name="text" color="info" placeholder="Info" />
|
||||||
|
<InputField name="text" color="success" placeholder="Success" />
|
||||||
|
<InputField name="text" color="warning" placeholder="Warning" />
|
||||||
|
<InputField name="text" color="error" placeholder="Error" />
|
||||||
|
</div>
|
||||||
|
</Story>
|
||||||
|
|
||||||
|
<Story name="Sizes">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<InputField name="text" size="xs" placeholder="XS" />
|
||||||
|
<InputField name="text" size="sm" placeholder="SM" />
|
||||||
|
<InputField name="text" size="md" placeholder="MD" />
|
||||||
|
<InputField name="text" size="lg" placeholder="LG" />
|
||||||
|
<InputField name="text" size="xl" placeholder="XL" />
|
||||||
|
</div>
|
||||||
|
</Story>
|
||||||
|
|
||||||
|
<Story name="Disabled" args={{ name: 'text', placeholder: 'Disabled', disabled: true }} />
|
||||||
|
|
@ -7,11 +7,11 @@
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
import type { HTMLInputTypeAttribute, SvelteHTMLElements } from 'svelte/elements';
|
import type { HTMLInputTypeAttribute, SvelteHTMLElements } from 'svelte/elements';
|
||||||
import { fade as fadeTransition } from 'svelte/transition';
|
|
||||||
import { twMerge } from 'tailwind-merge';
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
color?: Exclude<DaisyColor, 'neutral'>;
|
block?: boolean;
|
||||||
|
color?: DaisyColor;
|
||||||
error?: string | Snippet;
|
error?: string | Snippet;
|
||||||
fade?: boolean;
|
fade?: boolean;
|
||||||
start?: string | Snippet;
|
start?: string | Snippet;
|
||||||
|
|
@ -26,60 +26,35 @@
|
||||||
} & Omit<SvelteHTMLElements['input'], 'type' | 'size'>;
|
} & Omit<SvelteHTMLElements['input'], 'type' | 'size'>;
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
block,
|
||||||
class: className,
|
class: className,
|
||||||
color,
|
color,
|
||||||
error,
|
|
||||||
fade,
|
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
label,
|
|
||||||
size = 'md',
|
size = 'md',
|
||||||
style,
|
style,
|
||||||
...props
|
...props
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label class="form-control w-full" transition:fadeTransition={{ duration: fade ? 200 : 0 }}>
|
<div
|
||||||
<div class="label">
|
class="input flex items-center gap-2 transition-[width] delay-150 duration-300 ease-in-out"
|
||||||
<span
|
class:w-full={block}
|
||||||
class="label-text flex items-center gap-2"
|
|
||||||
class:text-primary={color === 'primary'}
|
|
||||||
class:text-secondary={color === 'secondary'}
|
|
||||||
class:text-accent={color === 'accent'}
|
|
||||||
class:text-info={color === 'info'}
|
|
||||||
class:text-success={color === 'success'}
|
|
||||||
class:text-warning={color === 'warning'}
|
|
||||||
class:text-error={color === 'error' || error}
|
|
||||||
>
|
|
||||||
{#if typeof label === 'string'}
|
|
||||||
{label}
|
|
||||||
{:else if label}
|
|
||||||
{@render label()}
|
|
||||||
{/if}
|
|
||||||
</span>
|
|
||||||
<span class="label-text-alt text-error font-semibold">
|
|
||||||
{#if typeof error === 'string'}
|
|
||||||
{error}
|
|
||||||
{:else if error}
|
|
||||||
{@render error()}
|
|
||||||
{/if}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="input flex w-full items-center gap-2"
|
|
||||||
class:input-primary={color === 'primary'}
|
class:input-primary={color === 'primary'}
|
||||||
class:input-secondary={color === 'secondary'}
|
class:input-secondary={color === 'secondary'}
|
||||||
class:input-accent={color === 'accent'}
|
class:input-accent={color === 'accent'}
|
||||||
|
class:input-neutral={color === 'neutral'}
|
||||||
class:input-info={color === 'info'}
|
class:input-info={color === 'info'}
|
||||||
class:input-success={color === 'success'}
|
class:input-success={color === 'success'}
|
||||||
class:input-warning={color === 'warning'}
|
class:input-warning={color === 'warning'}
|
||||||
class:input-error={color === 'error' || error}
|
class:input-error={color === 'error'}
|
||||||
class:input-ghost={style === 'ghost'}
|
class:input-ghost={style === 'ghost'}
|
||||||
class:input-xs={size === 'xs'}
|
class:input-xs={size === 'xs'}
|
||||||
class:input-sm={size === 'sm'}
|
class:input-sm={size === 'sm'}
|
||||||
|
class:input-md={size === 'md'}
|
||||||
class:input-lg={size === 'lg'}
|
class:input-lg={size === 'lg'}
|
||||||
class:input-xl={size === 'xl'}
|
class:input-xl={size === 'xl'}
|
||||||
>
|
>
|
||||||
{#if typeof start === 'string'}
|
{#if typeof start === 'string'}
|
||||||
{start}
|
{start}
|
||||||
{:else}
|
{:else}
|
||||||
|
|
@ -91,5 +66,4 @@
|
||||||
{:else}
|
{:else}
|
||||||
{@render end?.()}
|
{@render end?.()}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
|
||||||
Loading…
Add table
Reference in a new issue