diff --git a/apps/web/src/routes/+page.svelte b/apps/web/src/routes/+page.svelte index f91daea8b..142e26acf 100644 --- a/apps/web/src/routes/+page.svelte +++ b/apps/web/src/routes/+page.svelte @@ -44,6 +44,24 @@ +
+

ตัวอย่าง Input

+ + + +
+

Testtsetst

= T & { currentTarget: EventTarget & HTMLInputElement } +const inputVariants = tv({ + base: 'flex w-full h-10 rounded-button border-none px-4 text-button2 placeholder:text-on-surface hover:outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 disabled:bg-surface-container-lowest disabled:border-none disabled:ring-0 disabled:placeholder:text-on-surface-disabled', + variants: { + state: { + default: + 'bg-surface-container-lowest hover:ring-primary hover:ring-1 focus-visible:ring-1.5 focus-visible:ring-primary', + error: 'ring-error ring-1.5', + success: 'ring-success ring-1.5', + }, + }, + defaultVariants: { + state: 'default', + }, +}) + export type InputEvents = { blur: FormInputEvent change: FormInputEvent @@ -23,8 +41,12 @@ export type InputEvents = { wheel: FormInputEvent } -export { - // - Root as Input, - Root, +type State = VariantProps['state'] + +type Props = HTMLInputAttributes & { + state?: State } + +type Events = InputEvents + +export { type Events, Root as Input, inputVariants, type Props } diff --git a/packages/ui/src/components/atom/input/input.stories.svelte b/packages/ui/src/components/atom/input/input.stories.svelte new file mode 100644 index 000000000..2fd80ffd1 --- /dev/null +++ b/packages/ui/src/components/atom/input/input.stories.svelte @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/packages/ui/src/components/atom/input/input.svelte b/packages/ui/src/components/atom/input/input.svelte index 0216d9ff4..b7e536994 100644 --- a/packages/ui/src/components/atom/input/input.svelte +++ b/packages/ui/src/components/atom/input/input.svelte @@ -2,20 +2,19 @@ import { createBubbler, passive } from 'svelte/legacy' const bubble = createBubbler() - import type { HTMLInputAttributes } from 'svelte/elements' import { cn } from '@repo/utils' - import type { InputEvents } from './index.js' + import { type Events, inputVariants, type Props } from './index.js' - type $$Props = HTMLInputAttributes - type $$Events = InputEvents + type $$Props = Props + type $$Events = Events // Workaround for https://github.com/sveltejs/svelte/issues/9305 - - interface Props { + interface InputProps { class?: $$Props['class'] value?: $$Props['value'] + state?: $$Props['state'] // Fixed in Svelte 5, but not backported to 4.x. readonly?: $$Props['readonly'] [key: string]: unknown @@ -24,16 +23,14 @@ let { class: className = undefined, value = $bindable(undefined), + state = 'default', readonly = undefined, ...rest - }: Props = $props() + }: InputProps = $props()