forked from tsai/budibase
6 changed files with 121 additions and 35 deletions
@ -0,0 +1,82 @@ |
|||
<script> |
|||
import "@spectrum-css/search/dist/index-vars.css" |
|||
import { createEventDispatcher } from "svelte" |
|||
|
|||
export let value = "" |
|||
export let placeholder = null |
|||
export let disabled = false |
|||
export let id = null |
|||
|
|||
const dispatch = createEventDispatcher() |
|||
let focus = false |
|||
|
|||
const updateValue = value => { |
|||
dispatch("change", value) |
|||
} |
|||
|
|||
const onFocus = () => { |
|||
focus = true |
|||
} |
|||
|
|||
const onBlur = event => { |
|||
focus = false |
|||
updateValue(event.target.value) |
|||
} |
|||
|
|||
const updateValueOnEnter = event => { |
|||
if (event.key === "Enter") { |
|||
updateValue(event.target.value) |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<div class="spectrum-Search" class:is-disabled={disabled}> |
|||
<div |
|||
class="spectrum-Textfield" |
|||
class:is-focused={focus} |
|||
class:is-disabled={disabled}> |
|||
<svg |
|||
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-icon" |
|||
focusable="false" |
|||
aria-hidden="true"> |
|||
<use xlink:href="#spectrum-icon-18-Magnify" /> |
|||
</svg> |
|||
<input |
|||
on:click |
|||
on:keyup={updateValueOnEnter} |
|||
{disabled} |
|||
{id} |
|||
value={value || ''} |
|||
placeholder={placeholder || ''} |
|||
on:blur={onBlur} |
|||
on:focus={onFocus} |
|||
on:input |
|||
type="search" |
|||
class="spectrum-Textfield-input spectrum-Search-input" |
|||
autocomplete="off" /> |
|||
</div> |
|||
<button |
|||
on:click={() => updateValue('')} |
|||
type="reset" |
|||
class="spectrum-ClearButton spectrum-Search-clearButton"> |
|||
<svg |
|||
class="spectrum-Icon spectrum-UIIcon-Cross75" |
|||
focusable="false" |
|||
aria-hidden="true"> |
|||
<use xlink:href="#spectrum-css-icon-Cross75" /> |
|||
</svg> |
|||
</button> |
|||
</div> |
|||
|
|||
<style> |
|||
.spectrum-Search, |
|||
.spectrum-Textfield { |
|||
width: 100%; |
|||
} |
|||
.spectrum-Search-input { |
|||
padding-right: 24px; |
|||
} |
|||
.is-disabled { |
|||
pointer-events: none; |
|||
} |
|||
</style> |
|||
@ -1,25 +1,27 @@ |
|||
<form class="spectrum-Search"> |
|||
<div class="spectrum-Textfield"> |
|||
<svg |
|||
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-icon" |
|||
focusable="false" |
|||
aria-hidden="true"> |
|||
<use xlink:href="#spectrum-icon-18-Magnify" /> |
|||
</svg> |
|||
<input |
|||
type="search" |
|||
placeholder="Search" |
|||
name="search" |
|||
value="" |
|||
class="spectrum-Textfield-input spectrum-Search-input" |
|||
autocomplete="off" /> |
|||
</div> |
|||
<button type="reset" class="spectrum-ClearButton spectrum-Search-clearButton"> |
|||
<svg |
|||
class="spectrum-Icon spectrum-UIIcon-Cross75" |
|||
focusable="false" |
|||
aria-hidden="true"> |
|||
<use xlink:href="#spectrum-css-icon-Cross75" /> |
|||
</svg> |
|||
</button> |
|||
</form> |
|||
<script> |
|||
import Field from "./Field.svelte" |
|||
import Search from "./Core/Search.svelte" |
|||
import { createEventDispatcher } from "svelte" |
|||
|
|||
export let value = null |
|||
export let label = null |
|||
export let labelPosition = "above" |
|||
export let placeholder = null |
|||
export let disabled = false |
|||
|
|||
const dispatch = createEventDispatcher() |
|||
const onChange = e => { |
|||
value = e.detail |
|||
dispatch("change", e.detail) |
|||
} |
|||
</script> |
|||
|
|||
<Field {label} {labelPosition} {disabled}> |
|||
<Search |
|||
{disabled} |
|||
{value} |
|||
{placeholder} |
|||
on:change={onChange} |
|||
on:click |
|||
on:input /> |
|||
</Field> |
|||
|
|||
Loading…
Reference in new issue