93 lines
3.9 KiB
Plaintext
93 lines
3.9 KiB
Plaintext
component Input {
|
|
props {
|
|
@event input = function
|
|
@event change = function
|
|
@event focus = function
|
|
@event blur = function
|
|
@event invalid = function
|
|
@event keydown = function
|
|
@event keyup = function
|
|
size = "default"
|
|
color = "primary"
|
|
id = ""
|
|
name = ""
|
|
label = "Input"
|
|
hiddenLabel = false
|
|
placeholder = ""
|
|
value = ""
|
|
type = "text"
|
|
variant = "normal"
|
|
icon = ""
|
|
iconPosition = "start"
|
|
helperText = ""
|
|
cornerHint = ""
|
|
error = ""
|
|
inline = false
|
|
readonly = false
|
|
disabled = false
|
|
required = false
|
|
autocomplete = ""
|
|
inputmode = ""
|
|
minlength = ""
|
|
maxlength = ""
|
|
pattern = ""
|
|
min = ""
|
|
max = ""
|
|
step = ""
|
|
class = ""
|
|
}
|
|
functions {
|
|
function detail(sourceEvent) {
|
|
return { value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }
|
|
}
|
|
function handleInput(sourceEvent) { sourceEvent.stopPropagation(); $emit("input", detail(sourceEvent)) }
|
|
function handleChange(sourceEvent) { sourceEvent.stopPropagation(); $emit("change", detail(sourceEvent)) }
|
|
function handleFocus(sourceEvent) { sourceEvent.stopPropagation(); $emit("focus", detail(sourceEvent)) }
|
|
function handleBlur(sourceEvent) { sourceEvent.stopPropagation(); $emit("blur", detail(sourceEvent)) }
|
|
function handleInvalid(sourceEvent) { sourceEvent.stopPropagation(); $emit("invalid", { value: sourceEvent.currentTarget.value, name: name, message: sourceEvent.currentTarget.validationMessage, sourceEvent: sourceEvent }) }
|
|
function handleKeydown(sourceEvent) { sourceEvent.stopPropagation(); $emit("keydown", { key: sourceEvent.key, value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }) }
|
|
function handleKeyup(sourceEvent) { sourceEvent.stopPropagation(); $emit("keyup", { key: sourceEvent.key, value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }) }
|
|
}
|
|
view {
|
|
<div {...attrs} class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--field wire-next--input {class}" data-variant="{variant}" data-inline="{inline}" data-floating="{variant === 'floating'}" data-invalid="{error ? 'true' : 'false'}">
|
|
<div class="wire-next__field-heading">
|
|
<label class="{hiddenLabel ? 'wire-next__sr-only' : ''}" for="{id || name}">{label}</label>
|
|
{#if cornerHint}<span class="wire-next__field-hint">{cornerHint}</span>{/if}
|
|
</div>
|
|
<div class="wire-next__field-control" data-icon-position="{iconPosition}">
|
|
{#if icon}<span class="{icon} wire-next__field-icon" aria-hidden="true"></span>{/if}
|
|
<input
|
|
id="{id || name}"
|
|
type="{type}"
|
|
name="{name}"
|
|
value="{value}"
|
|
placeholder="{variant === 'floating' ? ' ' : placeholder}"
|
|
readonly="{readonly}"
|
|
disabled="{disabled}"
|
|
required="{required}"
|
|
autocomplete="{autocomplete}"
|
|
inputmode="{inputmode}"
|
|
minlength="{minlength}"
|
|
maxlength="{maxlength}"
|
|
pattern="{pattern}"
|
|
min="{min}"
|
|
max="{max}"
|
|
step="{step}"
|
|
aria-invalid="{error ? 'true' : 'false'}"
|
|
aria-describedby="{error ? (id || name) + '-error' : (helperText ? (id || name) + '-help' : '')}"
|
|
@input="handleInput(event)"
|
|
@change="handleChange(event)"
|
|
@focus="handleFocus(event)"
|
|
@blur="handleBlur(event)"
|
|
@invalid="handleInvalid(event)"
|
|
@keydown="handleKeydown(event)"
|
|
@keyup="handleKeyup(event)"
|
|
/>
|
|
{#if variant === "floating"}<span class="wire-next__field-floating-label">{label}</span>{/if}
|
|
</div>
|
|
{#if helperText}<small id="{(id || name) + '-help'}" class="wire-next__field-help">{helperText}</small>{/if}
|
|
<small id="{(id || name) + '-error'}" class="wire-next__field-error" data-error="{name}">{error}</small>
|
|
</div>
|
|
}
|
|
}
|