81 lines
3.3 KiB
Plaintext
81 lines
3.3 KiB
Plaintext
component SearchBox {
|
|
props {
|
|
size: string = "default"
|
|
color: string = "primary"
|
|
label: string = "Search Box"
|
|
name: string = ""
|
|
value: string = ""
|
|
placeholder: string = ""
|
|
type: string = "search"
|
|
min: string = ""
|
|
max: string = ""
|
|
step: string = ""
|
|
disabled: boolean = false
|
|
required: boolean = false
|
|
class: string = ""
|
|
}
|
|
|
|
state query = value
|
|
|
|
view {
|
|
<form
|
|
data-ui-component="SearchBox"
|
|
role="search"
|
|
class='w-full {class}'
|
|
@submit='event.preventDefault(); event.currentTarget.dispatchEvent(new CustomEvent("search", { bubbles: true, detail: { value: query, name: name } }))'
|
|
>
|
|
<label
|
|
class="mb-2 block text-sm font-semibold text-[var(--wire-color-text)]"
|
|
class:sr-only='label === ""'
|
|
>
|
|
{label}
|
|
</label>
|
|
|
|
<div class="relative flex items-center">
|
|
<span
|
|
class="icon-[lucide--search] pointer-events-none absolute left-4 size-5 text-[var(--wire-color-input-placeholder)]"
|
|
aria-hidden="true"
|
|
></span>
|
|
|
|
<input
|
|
name='{name}'
|
|
type='{type}'
|
|
value='{query}'
|
|
placeholder='{placeholder}'
|
|
min='{min}'
|
|
max='{max}'
|
|
step='{step}'
|
|
disabled='{disabled}'
|
|
required='{required}'
|
|
autocomplete="off"
|
|
class="w-full rounded-xl border border-[var(--wire-color-input-border)] bg-[var(--wire-color-input-background)] pl-12 pr-24 text-[var(--wire-color-input-text)] outline-none transition placeholder:text-[var(--wire-color-input-placeholder)] hover:border-[var(--wire-color-input-border-hover)] focus:border-[var(--wire-color-input-border-focus)] focus:ring-2 focus:ring-[var(--wire-color-focus)] disabled:cursor-not-allowed disabled:opacity-60"
|
|
class:h-10='size === "sm"'
|
|
class:h-12='size === "default" || size === "md"'
|
|
class:h-14='size === "lg"'
|
|
@input='query = event.target.value'
|
|
@change='query = event.target.value'
|
|
/>
|
|
|
|
<button
|
|
type="button"
|
|
aria-label="Clear search"
|
|
data-show='query.length > 0 && !disabled'
|
|
class="absolute right-12 inline-flex size-8 items-center justify-center rounded-lg text-[var(--wire-color-text-muted)] transition hover:bg-[var(--wire-color-surface-soft)] hover:text-[var(--wire-color-text)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--wire-color-focus)]"
|
|
@click='query = ""; event.currentTarget.parentElement.querySelector("input")?.focus(); event.currentTarget.dispatchEvent(new CustomEvent("clear", { bubbles: true, detail: { value: "", name: name } }))'
|
|
>
|
|
<span class="icon-[lucide--x] size-4" aria-hidden="true"></span>
|
|
</button>
|
|
|
|
<button
|
|
type="submit"
|
|
aria-label='{label || "Search"}'
|
|
disabled='{disabled}'
|
|
class="absolute right-2 inline-flex size-9 items-center justify-center rounded-lg bg-[var(--wire-color-primary)] text-[var(--wire-color-on-primary)] transition hover:bg-[var(--wire-color-primary-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--wire-color-focus)] disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
<span class="icon-[lucide--arrow-right] size-4" aria-hidden="true"></span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
}
|
|
}
|