TypeScriptify TextArea.
This commit is contained in:
parent
ebbdc578f9
commit
21a3e259d6
|
@ -1,25 +1,22 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/textfield/dist/index-vars.css"
|
import "@spectrum-css/textfield/dist/index-vars.css"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
import { FocusEventHandler } from "svelte/elements"
|
||||||
|
|
||||||
export let value = ""
|
export let value: string | null = null
|
||||||
export let placeholder = null
|
export let placeholder: string | null = null
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
export let readonly = false
|
export let readonly = false
|
||||||
export let id = null
|
export let id: string | null = null
|
||||||
export let height = null
|
export let height: number | null = null
|
||||||
export let minHeight = null
|
export let minHeight: number | null = null
|
||||||
export const getCaretPosition = () => ({
|
|
||||||
start: textarea.selectionStart,
|
|
||||||
end: textarea.selectionEnd,
|
|
||||||
})
|
|
||||||
export let align = null
|
export let align = null
|
||||||
|
|
||||||
let isFocused = false
|
let isFocused = false
|
||||||
let textarea
|
let textarea: HTMLTextAreaElement
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher<{ change: string }>()
|
||||||
const onChange = event => {
|
const onChange: FocusEventHandler<HTMLTextAreaElement> = event => {
|
||||||
dispatch("change", event.target.value)
|
dispatch("change", event.currentTarget.value)
|
||||||
isFocused = false
|
isFocused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +28,7 @@
|
||||||
return textarea.value
|
return textarea.value
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStyleString = (attribute, value) => {
|
const getStyleString = (attribute: string, value: number | null) => {
|
||||||
if (!attribute || value == null) {
|
if (!attribute || value == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
import TextArea from "./Core/TextArea.svelte"
|
import TextArea from "./Core/TextArea.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
export let value = null
|
export let value: string | undefined = undefined
|
||||||
export let label = null
|
export let label: string | undefined = undefined
|
||||||
export let labelPosition = "above"
|
export let labelPosition = "above"
|
||||||
export let placeholder = null
|
export let placeholder: string | undefined = undefined
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
export let error = null
|
export let error: string | undefined = undefined
|
||||||
export let getCaretPosition = null
|
export let height: number | undefined = undefined
|
||||||
export let height = null
|
export let minHeight: number | undefined = undefined
|
||||||
export let minHeight = null
|
export let helpText: string | undefined = undefined
|
||||||
export let helpText = null
|
|
||||||
|
|
||||||
let textarea
|
let textarea: TextArea
|
||||||
export function focus() {
|
export function focus() {
|
||||||
textarea.focus()
|
textarea.focus()
|
||||||
}
|
}
|
||||||
|
@ -24,7 +23,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = (e: CustomEvent<string>) => {
|
||||||
value = e.detail
|
value = e.detail
|
||||||
dispatch("change", e.detail)
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
|
@ -33,8 +32,6 @@
|
||||||
<Field {helpText} {label} {labelPosition} {error}>
|
<Field {helpText} {label} {labelPosition} {error}>
|
||||||
<TextArea
|
<TextArea
|
||||||
bind:this={textarea}
|
bind:this={textarea}
|
||||||
bind:getCaretPosition
|
|
||||||
{error}
|
|
||||||
{disabled}
|
{disabled}
|
||||||
{value}
|
{value}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
|
|
|
@ -485,7 +485,12 @@
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Popover bind:this={popover} minWidth={popoverWidth} anchor={popoverAnchor}>
|
<Popover
|
||||||
|
bind:this={popover}
|
||||||
|
minWidth={popoverWidth}
|
||||||
|
anchor={popoverAnchor}
|
||||||
|
align="left-outside"
|
||||||
|
>
|
||||||
{#if promptLoading}
|
{#if promptLoading}
|
||||||
<div class="prompt-spinner">
|
<div class="prompt-spinner">
|
||||||
<Spinner size="20" color="white" />
|
<Spinner size="20" color="white" />
|
||||||
|
|
Loading…
Reference in New Issue