-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributeValue.svelte
More file actions
83 lines (71 loc) · 1.86 KB
/
AttributeValue.svelte
File metadata and controls
83 lines (71 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<script lang="ts">
import { tick, onMount } from 'svelte'
import { getContext } from 'svelte'
import './../../app.css'
let element: HTMLElement
export let focused: boolean = false
export let value: string
export let typ: AttributeType
const onfocus = () => (focused = true)
const onblur = () => (focused = false)
let inputProps = {}
$: if (typ) inputProps = {}
$: if (typ?.pattern) inputProps.pattern = typ.pattern
$: if (typ?.placeholder) inputProps.placeholder = typ.placeholder
$: if (typ?.ident.endsWith('mobilenumber')) inputProps.type = 'tel'
$: inputSize = value?.length
? value.length * 0.8 + 1
: typ?.placeholder
? typ.placeholder.length * 0.8 + 1
: 10
const { policy, signing } = getContext('store')
onMount(() => element.focus())
</script>
{#if signing}
<input
bind:this={element}
on:blur={onblur}
bind:value
readonly
size=1
class="signing"
{...inputProps}
/>
{:else if typ?.options}
<select bind:this={element} on:blur={onblur} bind:value required>
{#each typ.options as option}
<option>{option}</option>
{/each}
</select>
{:else if typ?.type === 'string'}
<input
bind:this={element}
on:blur={onblur}
bind:value
required
size={inputSize}
{...inputProps}
/>
{:else if typ?.type === 'boolean'}
<select bind:this={element} on:blur={onblur} bind:value required>
<option>Yes</option>
<option>No</option>
</select>
{/if}
<style lang="scss">
input,
select {
border: 0px solid black;
background-color: var(--pg-white);
&:focus {
outline: none;
}
}
input {
height: 100%;
padding: 0px 2px;
}
input.signing {
cursor: default !important;
}
</style>