This repository has been archived by the owner on Mar 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.svelte
102 lines (91 loc) · 1.67 KB
/
Input.svelte
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script>
export let type = 'text'
export let id
export let label
export let value = undefined
export let checked = false
export let rows = undefined
export let monospace = false
export let required = false
export let autofocus = false
function handleAutofocus (node) {
if (autofocus) {
node.focus()
}
}
</script>
<style>
.vr-input {
margin-bottom: 1em;
}
.vr-input__label {
display: inline-block;
margin-bottom: 0.25em;
cursor: pointer;
}
.vr-input__input {
box-sizing: border-box;
display: block;
width: 100%;
padding: 0.5em;
font-size: inherit;
font-family: inherit;
line-height: inherit;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 3px;
}
.vr-input__input.is-monospace {
font-family: 'Courier New', Courier, monospace;
}
.vr-input__checkbox {
cursor: pointer;
}
</style>
<div class="vr-input">
<label
class="vr-input__label"
for={id}
>
{#if type === 'checkbox'}
<input
class="vr-input__checkbox"
type="checkbox"
bind:checked
use:handleAutofocus
on:change
{id}
{required}
>
{/if}
{label}
</label>
{#if type === 'text'}
<input
class="vr-input__input"
type="text"
bind:value
use:handleAutofocus
{id}
{required}
/>
{:else if type === 'password'}
<input
class="vr-input__input"
type="password"
bind:value
use:handleAutofocus
{id}
{required}
/>
{:else if type === 'textarea'}
<textarea
class="vr-input__input"
class:is-monospace={monospace}
bind:value
use:handleAutofocus
{id}
{rows}
{required}
/>
{/if}
</div>