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"> |
<script> |
||||
<div class="spectrum-Textfield"> |
import Field from "./Field.svelte" |
||||
<svg |
import Search from "./Core/Search.svelte" |
||||
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-icon" |
import { createEventDispatcher } from "svelte" |
||||
focusable="false" |
|
||||
aria-hidden="true"> |
export let value = null |
||||
<use xlink:href="#spectrum-icon-18-Magnify" /> |
export let label = null |
||||
</svg> |
export let labelPosition = "above" |
||||
<input |
export let placeholder = null |
||||
type="search" |
export let disabled = false |
||||
placeholder="Search" |
|
||||
name="search" |
const dispatch = createEventDispatcher() |
||||
value="" |
const onChange = e => { |
||||
class="spectrum-Textfield-input spectrum-Search-input" |
value = e.detail |
||||
autocomplete="off" /> |
dispatch("change", e.detail) |
||||
</div> |
} |
||||
<button type="reset" class="spectrum-ClearButton spectrum-Search-clearButton"> |
</script> |
||||
<svg |
|
||||
class="spectrum-Icon spectrum-UIIcon-Cross75" |
<Field {label} {labelPosition} {disabled}> |
||||
focusable="false" |
<Search |
||||
aria-hidden="true"> |
{disabled} |
||||
<use xlink:href="#spectrum-css-icon-Cross75" /> |
{value} |
||||
</svg> |
{placeholder} |
||||
</button> |
on:change={onChange} |
||||
</form> |
on:click |
||||
|
on:input /> |
||||
|
</Field> |
||||
|
|||||
Loading…
Reference in new issue