Files
gpx.studio/website/src/lib/components/ui/input/input.svelte

53 lines
1.9 KiB
Svelte
Raw Normal View History

2024-06-12 18:48:03 +02:00
<script lang="ts">
2025-06-08 16:32:41 +02:00
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from "svelte/elements";
2025-06-21 21:07:36 +02:00
import { cn, type WithElementRef } from "$lib/utils.js";
2024-06-12 18:48:03 +02:00
2025-06-08 16:32:41 +02:00
type InputType = Exclude<HTMLInputTypeAttribute, "file">;
2024-06-12 18:48:03 +02:00
2025-06-08 16:32:41 +02:00
type Props = WithElementRef<
Omit<HTMLInputAttributes, "type"> &
({ type: "file"; files?: FileList } | { type?: InputType; files?: undefined })
>;
2024-06-12 18:48:03 +02:00
2025-06-08 16:32:41 +02:00
let {
ref = $bindable(null),
value = $bindable(),
type,
files = $bindable(),
class: className,
2025-10-18 18:51:11 +02:00
"data-slot": dataSlot = "input",
2025-06-08 16:32:41 +02:00
...restProps
}: Props = $props();
2024-06-12 18:48:03 +02:00
</script>
2025-06-08 16:32:41 +02:00
{#if type === "file"}
<input
bind:this={ref}
2025-10-18 18:51:11 +02:00
data-slot={dataSlot}
2025-06-08 16:32:41 +02:00
class={cn(
2025-10-18 18:51:11 +02:00
"selection:bg-primary dark:bg-input/30 selection:text-primary-foreground border-input ring-offset-background placeholder:text-muted-foreground shadow-xs flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 pt-1.5 text-sm font-medium outline-none transition-[color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50",
2025-06-21 21:07:36 +02:00
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
2025-06-08 16:32:41 +02:00
className
)}
type="file"
bind:files
bind:value
{...restProps}
/>
{:else}
<input
bind:this={ref}
2025-10-18 18:51:11 +02:00
data-slot={dataSlot}
2025-06-08 16:32:41 +02:00
class={cn(
2025-06-21 21:07:36 +02:00
"border-input bg-background selection:bg-primary dark:bg-input/30 selection:text-primary-foreground ring-offset-background placeholder:text-muted-foreground shadow-xs flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base outline-none transition-[color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
2025-06-08 16:32:41 +02:00
className
)}
{type}
bind:value
{...restProps}
/>
{/if}