Spaces:
Running
Running
<script lang="ts"> | |
import Icon from '@iconify/svelte'; | |
export let tooltip: string | undefined = undefined; | |
export let label: string; | |
export let subLabel: string | undefined = undefined; | |
export let type: "text" | "number" = "text" | |
export let value: string | number; | |
export let min: number | undefined = undefined; | |
export let max: number | undefined = undefined; | |
let clazz: string | undefined = undefined; | |
export { clazz as class }; | |
export let placeholder: string | undefined = undefined; | |
export let sanitize: undefined | ((value: string | number) => string | number) = undefined; | |
export let onChange: (value: string | number) => void; | |
const handleInputChange = (event: any) => { | |
const newValue = event.target.value; | |
if (type === "number" && /^[0-9]*$/.test(newValue)) { | |
return onChange(newValue) | |
} | |
return onChange(newValue) | |
}; | |
const handleBlur = (event: any) => { | |
const newValue = event.target.value; | |
if (sanitize) return onChange(sanitize(newValue)) | |
} | |
</script> | |
<div class={`w-full relative ${clazz}`}> | |
<div class="flex items-center justify-start gap-2 relative mb-2.5"> | |
{#if tooltip} | |
<div class="group cursor-pointer"> | |
<Icon icon="lucide:info" class="text-slate-500 group-hover:text-slate-300 text-xl" /> | |
<div class="bg-slate-950/90 z-10 rounded-xl p-3 text-white absolute text-xs left-0 bottom-0 translate-y-[calc(100%+8px)] opacity-0 transition-all duration-200 group-hover:opacity-100 pointer-events-none group-hover:pointer-events-auto"> | |
{tooltip} | |
</div> | |
</div> | |
{/if} | |
<p class="font-sans text-slate-400 font-regular text-sm"> | |
{label}: | |
</p> | |
</div> | |
{#if subLabel} <p class="text-slate-500 text-xs mb-2.5">{subLabel}</p>{/if} | |
<input | |
type={type} | |
value={value} | |
min={min} | |
max={max} | |
placeholder={placeholder} | |
class="shadow-inner font-code border border-slate-800 bg-slate-900/60 focus:bg-slate-900/90 focus:border-slate-700/80 text-white rounded-lg text-sm px-4 py-3.5 w-full transition-all duration-200 leading-relaxed outline-none" | |
on:input={handleInputChange} | |
on:blur={handleBlur} | |
/> | |
</div> |