2023-01-23 16:38:43 +01:00
|
|
|
<script>
|
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
import FancyField from "./FancyField.svelte"
|
|
|
|
import FancyFieldLabel from "./FancyFieldLabel.svelte"
|
2023-01-25 16:55:57 +01:00
|
|
|
import { fade } from "svelte/transition"
|
2023-01-23 16:38:43 +01:00
|
|
|
|
|
|
|
export let label
|
|
|
|
export let value
|
|
|
|
export let type = "text"
|
|
|
|
export let disabled = false
|
|
|
|
export let error = null
|
|
|
|
export let validate = null
|
2023-01-25 16:55:57 +01:00
|
|
|
export let suffix = null
|
2023-01-23 16:38:43 +01:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
|
|
|
let focused = false
|
|
|
|
$: placeholder = !focused && !value
|
|
|
|
|
|
|
|
const onChange = e => {
|
|
|
|
const newValue = e.target.value
|
|
|
|
dispatch("change", newValue)
|
|
|
|
value = newValue
|
|
|
|
if (validate) {
|
|
|
|
error = validate(newValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<FancyField {error} {value} {validate} {disabled} {focused}>
|
|
|
|
{#if label}
|
|
|
|
<FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
|
|
|
|
{/if}
|
|
|
|
<input
|
|
|
|
{disabled}
|
|
|
|
value={value || ""}
|
|
|
|
type={type || "text"}
|
|
|
|
on:input={onChange}
|
|
|
|
on:focus={() => (focused = true)}
|
|
|
|
on:blur={() => (focused = false)}
|
|
|
|
class:placeholder
|
|
|
|
/>
|
2023-01-25 16:55:57 +01:00
|
|
|
{#if suffix && !placeholder}
|
|
|
|
<div in:fade|local={{ duration: 130 }} class="suffix">{suffix}</div>
|
|
|
|
{/if}
|
2023-01-23 16:38:43 +01:00
|
|
|
</FancyField>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
input {
|
|
|
|
width: 100%;
|
|
|
|
transition: transform 130ms ease-out;
|
|
|
|
transform: translateY(9px);
|
|
|
|
background: transparent;
|
|
|
|
font-size: 15px;
|
|
|
|
line-height: 17px;
|
|
|
|
font-family: var(--font-sans);
|
|
|
|
color: var(--spectrum-global-color-gray-900);
|
|
|
|
outline: none;
|
|
|
|
border: none;
|
2023-01-25 16:57:47 +01:00
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
2023-01-23 16:38:43 +01:00
|
|
|
}
|
|
|
|
input.placeholder {
|
|
|
|
transform: translateY(0);
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
height: 100%;
|
|
|
|
}
|
2023-01-25 16:55:57 +01:00
|
|
|
.suffix {
|
|
|
|
color: var(--spectrum-global-color-gray-600);
|
|
|
|
transform: translateY(9px);
|
|
|
|
font-size: 15px;
|
|
|
|
line-height: 17px;
|
|
|
|
font-family: var(--font-sans);
|
|
|
|
}
|
2023-01-23 16:38:43 +01:00
|
|
|
</style>
|