151 lines
5.0 KiB
Plaintext
151 lines
5.0 KiB
Plaintext
component SearchBox {
|
|
outputs {
|
|
search(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
|
|
clear(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
|
|
}
|
|
|
|
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='wrn-search-box {class}'
|
|
@submit='event.preventDefault(); output.search({ value: query, name: name })'
|
|
>
|
|
<label
|
|
class="wrn-search-box__label"
|
|
data-hidden='{label === "" ? "true" : "false"}'
|
|
>
|
|
{label}
|
|
</label>
|
|
|
|
<div class="wrn-search-box__control">
|
|
<span
|
|
class="icon-[lucide--search] wrn-search-box__search-icon"
|
|
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="wrn-search-box__input"
|
|
data-size='{size}'
|
|
@input='query = event.target.value'
|
|
@change='query = event.target.value'
|
|
/>
|
|
|
|
<button
|
|
type="button"
|
|
aria-label="Clear search"
|
|
data-show='query.length > 0 && !disabled'
|
|
class="wrn-search-box__button wrn-search-box__clear"
|
|
@click='query = ""; event.currentTarget.parentElement.querySelector("input")?.focus(); output.clear({ value: "", name: name })'
|
|
>
|
|
<span class="icon-[lucide--x] wrn-search-box__button-icon" aria-hidden="true"></span>
|
|
</button>
|
|
|
|
<button
|
|
type="submit"
|
|
aria-label='{label || "Search"}'
|
|
disabled='{disabled}'
|
|
class="wrn-search-box__button wrn-search-box__submit"
|
|
>
|
|
<span class="icon-[lucide--arrow-right] wrn-search-box__button-icon" aria-hidden="true"></span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
}
|
|
|
|
style {
|
|
.wrn-search-box { width: 100%; }
|
|
.wrn-search-box__label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: var(--wrn-color-text);
|
|
font-size: 0.875rem;
|
|
font-weight: 600;
|
|
}
|
|
.wrn-search-box__label[data-hidden="true"] {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
padding: 0;
|
|
margin: -1px;
|
|
overflow: hidden;
|
|
clip: rect(0, 0, 0, 0);
|
|
white-space: nowrap;
|
|
border: 0;
|
|
}
|
|
.wrn-search-box__control { position: relative; display: flex; align-items: center; }
|
|
.wrn-search-box__search-icon {
|
|
position: absolute;
|
|
left: 1rem;
|
|
width: 1.25rem;
|
|
height: 1.25rem;
|
|
color: var(--wrn-color-input-placeholder);
|
|
pointer-events: none;
|
|
}
|
|
.wrn-search-box__input {
|
|
width: 100%;
|
|
height: 3rem;
|
|
padding: 0 6rem 0 3rem;
|
|
border: 1px solid var(--wrn-color-input-border);
|
|
border-radius: var(--wrn-radius);
|
|
outline: none;
|
|
color: var(--wrn-color-input-text);
|
|
background: var(--wrn-color-input-background);
|
|
transition: border-color var(--wrn-motion-base) var(--wrn-ease-standard), box-shadow var(--wrn-motion-base) var(--wrn-ease-standard);
|
|
}
|
|
.wrn-search-box__input[data-size="sm"] { height: 2.5rem; }
|
|
.wrn-search-box__input[data-size="lg"] { height: 3.5rem; }
|
|
.wrn-search-box__input::placeholder { color: var(--wrn-color-input-placeholder); }
|
|
.wrn-search-box__input:hover { border-color: var(--wrn-color-input-border-hover); }
|
|
.wrn-search-box__input:focus {
|
|
border-color: var(--wrn-color-input-border-focus);
|
|
box-shadow: 0 0 0 2px var(--wrn-color-focus);
|
|
}
|
|
.wrn-search-box__input:disabled, .wrn-search-box__button:disabled { cursor: not-allowed; opacity: 0.6; }
|
|
.wrn-search-box__button {
|
|
position: absolute;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 0;
|
|
border: 0;
|
|
border-radius: var(--wrn-radius-sm);
|
|
transition: color var(--wrn-motion-base), background var(--wrn-motion-base);
|
|
}
|
|
.wrn-search-box__clear { right: 3rem; width: 2rem; height: 2rem; color: var(--wrn-color-text-muted); background: transparent; }
|
|
.wrn-search-box__clear:hover { color: var(--wrn-color-text); background: var(--wrn-color-surface-soft); }
|
|
.wrn-search-box__submit { right: 0.5rem; width: 2.25rem; height: 2.25rem; color: var(--wrn-color-on-primary); background: var(--wrn-color-primary); }
|
|
.wrn-search-box__submit:hover { background: var(--wrn-color-primary-hover); }
|
|
.wrn-search-box__button:focus-visible { outline: 2px solid var(--wrn-color-focus); outline-offset: 2px; }
|
|
.wrn-search-box__button-icon { width: 1rem; height: 1rem; }
|
|
}
|
|
}
|