move to InputField

This commit is contained in:
Benjamin Palko 2025-03-26 09:38:52 -04:00
parent bbc85afe11
commit 2e8083509b
2 changed files with 30 additions and 32 deletions

View file

@ -1,27 +1,15 @@
<script module lang="ts"> <script module lang="ts">
import { defineMeta } from '@storybook/addon-svelte-csf'; import { defineMeta } from '@storybook/addon-svelte-csf';
import TextInput from './TextInput.svelte';
import { User } from 'lucide-svelte'; import { User } from 'lucide-svelte';
import InputField from './InputField.svelte';
const { Story } = defineMeta({ const { Story } = defineMeta({
title: 'Data Input/Text Input', title: 'Data Input/Text Input',
component: TextInput, component: InputField,
argTypes: { argTypes: {
bordered: {
control: 'boolean',
},
color: { color: {
control: 'select', control: 'select',
options: [ options: ['primary', 'secondary', 'accent', 'info', 'success', 'warning', 'error'],
'ghost',
'primary',
'secondary',
'accent',
'info',
'success',
'warning',
'error',
],
}, },
disabled: { disabled: {
control: 'boolean', control: 'boolean',
@ -36,7 +24,11 @@
placeholder: { control: 'text' }, placeholder: { control: 'text' },
size: { size: {
control: 'select', control: 'select',
options: ['xs', 'sm', '-', 'lg'], options: ['xs', 'sm', 'md', 'lg', 'xl'],
},
style: {
control: 'radio',
options: [undefined, 'ghost'],
}, },
type: { type: {
control: 'select', control: 'select',
@ -46,18 +38,20 @@
}); });
</script> </script>
<Story name="Text Label" args={{ color: 'primary', name: 'text', start: 'Text' }} /> <Story name="Default" args={{ color: 'primary', name: 'text', start: 'Text' }} />
<Story name="Icon Start"> <Story name="Icon Start">
<TextInput name="text" color="secondary"> <InputField name="text" color="secondary">
{#snippet start()} {#snippet start()}
<User /> <User />
{/snippet} {/snippet}
</TextInput> </InputField>
</Story> </Story>
<Story name="Icon End"> <Story name="Icon End">
<TextInput name="text" color="secondary"> <InputField name="text" color="secondary">
{#snippet end()} {#snippet end()}
<User /> <User />
{/snippet} {/snippet}
</TextInput> </InputField>
</Story> </Story>

View file

@ -1,3 +1,7 @@
<script lang="ts" module>
export type InputFieldStyle = 'ghost';
</script>
<script lang="ts"> <script lang="ts">
import type { DaisyColor, DaisySize } from '$lib/types'; import type { DaisyColor, DaisySize } from '$lib/types';
import clsx from 'clsx'; import clsx from 'clsx';
@ -7,7 +11,6 @@
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
type Props = { type Props = {
bordered?: boolean;
color?: Exclude<DaisyColor, 'neutral'>; color?: Exclude<DaisyColor, 'neutral'>;
error?: string | Snippet; error?: string | Snippet;
fade?: boolean; fade?: boolean;
@ -15,14 +18,14 @@
end?: string | Snippet; end?: string | Snippet;
label?: string | Snippet; label?: string | Snippet;
size?: DaisySize; size?: DaisySize;
style?: InputFieldStyle;
type?: Extract< type?: Extract<
HTMLInputTypeAttribute, HTMLInputTypeAttribute,
'email' | 'password' | 'search' | 'tel' | 'text' | 'url' 'email' | 'password' | 'search' | 'tel' | 'text' | 'url'
>; >;
} & Omit<SvelteHTMLElements['input'], 'type'>; } & Omit<SvelteHTMLElements['input'], 'type' | 'size'>;
let { let {
bordered = false,
class: className, class: className,
color, color,
error, error,
@ -30,7 +33,8 @@
start, start,
end, end,
label, label,
size, size = 'md',
style,
...props ...props
}: Props = $props(); }: Props = $props();
</script> </script>
@ -63,18 +67,18 @@
</div> </div>
<div <div
class="input flex w-full items-center gap-2" 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-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-ghost={color === 'ghost'}
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' || error}
class:input-ghost={style === 'ghost'}
class:input-xs={size === 'xs'}
class:input-sm={size === 'sm'}
class:input-lg={size === 'lg'}
class:input-xl={size === 'xl'}
> >
{#if typeof start === 'string'} {#if typeof start === 'string'}
{start} {start}
@ -88,4 +92,4 @@
{@render end?.()} {@render end?.()}
{/if} {/if}
</div> </div>
</label> </label>