Skip to content

Commit b3cfb36

Browse files
committed
Use Input component
1 parent 6c0cf19 commit b3cfb36

File tree

10 files changed

+68
-38
lines changed

10 files changed

+68
-38
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/Input.svelte

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
2-
let { label, name, type, value } = $props()
2+
let { autofocus = false, required = false, label, name, type, value = $bindable() } = $props()
33
let focused = $state(value.length > 0)
4+
let input: HTMLElement
45
56
const focus = () => {
67
focused = true
@@ -12,34 +13,65 @@
1213
}
1314
}
1415
16+
const select = () => {
17+
focused = true
18+
if (input) {
19+
input.focus()
20+
}
21+
}
22+
1523
$effect(() => {
1624
focused = value.length > 0
1725
})
1826
</script>
1927

20-
<div class="form-group" class:focused>
21-
<label class="form-label" for="input">{label}</label>
22-
<input class="input" {name} {type} onfocus={focus} onblur={blur} bind:value />
28+
<div class="root" class:focused>
29+
<!-- svelte-ignore a11y_no_noninteractive_element_to_interactive_role -->
30+
<label
31+
class="label"
32+
for={name}
33+
onclick={select}
34+
onkeyup={select}
35+
onkeydown={select}
36+
role="button"
37+
tabindex={0}
38+
>
39+
{label}
40+
</label>
41+
<!-- svelte-ignore a11y_autofocus -->
42+
<input
43+
class="input"
44+
{autofocus}
45+
{required}
46+
{name}
47+
{type}
48+
onfocus={focus}
49+
onblur={blur}
50+
bind:value
51+
bind:this={input}
52+
/>
2353
</div>
2454

2555
<style>
26-
.form-group {
56+
.root {
2757
position: relative;
58+
margin-top: 10px;
2859
}
2960
30-
.form-label {
61+
.label {
3162
position: absolute;
3263
left: 0;
33-
top: 10px;
64+
top: 12px;
3465
color: #999;
3566
background-color: #fff0;
3667
z-index: 10;
68+
cursor: auto;
3769
transition:
3870
transform 150ms ease-out,
3971
font-size 150ms ease-out;
4072
}
4173
42-
.focused .form-label {
74+
.focused .label {
4375
transform: translateY(-125%);
4476
font-size: 0.75em;
4577
}
@@ -50,6 +82,7 @@
5082
width: 100%;
5183
outline: 0;
5284
border: 0;
85+
border-radius: 0px;
5386
box-shadow: 0 1px 0 0 #e5e5e5;
5487
transition: box-shadow 150ms ease-out;
5588

src/lib/Login.svelte

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation'
33
import { error } from '$lib/notification'
4+
import Input from './Input.svelte'
45
56
let email = $state('')
67
let password = $state('')
@@ -19,14 +20,11 @@
1920

2021
<div class="root">
2122
<form onsubmit={submit} class="form">
22-
<label for="email">Email</label>
23-
<!-- svelte-ignore a11y_autofocus -->
24-
<input autofocus required type="email" name="email" bind:value={email} />
25-
26-
<label for="password">Password</label>
27-
<input required type="password" name="password" bind:value={password} />
23+
<h2>Login</h2>
24+
<Input autofocus required type="email" name="email" label="Email" bind:value={email} />
25+
<Input required type="password" name="password" label="Password" bind:value={password} />
2826
<div class="actions">
29-
<button class="button">Login</button>
27+
<button class="button primary">Login</button>
3028
</div>
3129
</form>
3230
</div>
@@ -55,4 +53,3 @@
5553
margin-top: 10px;
5654
}
5755
</style>
58-

src/lib/Register.svelte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation'
33
import { error } from '$lib/notification'
4+
import Input from './Input.svelte'
45
56
let email = $state('')
67
let password = $state('')
@@ -20,18 +21,18 @@
2021

2122
<div class="root">
2223
<form onsubmit={submit} class="form">
23-
<label for="email">Email</label>
24-
<!-- svelte-ignore a11y_autofocus -->
25-
<input autofocus required type="email" name="email" bind:value={email} />
26-
27-
<label for="password">Password</label>
28-
<input required type="password" name="password" bind:value={password} />
29-
30-
<label for="password">Repeat Password</label>
31-
<input required type="password" name="repeatpassword" bind:value={repeatpassword} />
32-
24+
<h2>Register</h2>
25+
<Input autofocus required type="email" name="email" label="Email" bind:value={email} />
26+
<Input required type="password" name="password" label="Password" bind:value={password} />
27+
<Input
28+
required
29+
type="password"
30+
name="repeatpassword"
31+
label="Repeat Password"
32+
bind:value={repeatpassword}
33+
/>
3334
<div class="actions">
34-
<button class="button">Register</button>
35+
<button class="button primary">Register</button>
3536
</div>
3637
</form>
3738
</div>
@@ -60,4 +61,3 @@
6061
margin-top: 10px;
6162
}
6263
</style>
63-

src/lib/Roles.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onMount } from 'svelte'
33
import Modal from '$lib/Modal.svelte'
44
import { error } from '$lib/notification'
5+
import Input from './Input.svelte'
56
import Spinner from './Spinner.svelte'
67
78
let loading = $state(true)
@@ -82,8 +83,7 @@
8283
<Modal open={showCreate}>
8384
<h2>Create</h2>
8485
<form onsubmit={create}>
85-
<!-- svelte-ignore a11y_autofocus -->
86-
<input bind:value={name} autofocus />
86+
<Input bind:value={name} autofocus type="text" name="name" label="Name" />
8787
<div class="actions">
8888
<button class="button primary" type="submit">Create</button>
8989
<button class="button error" onclick={toggleShowCreate}>Close</button>

src/lib/Themes.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { onMount } from 'svelte'
33
import Modal from '$lib/Modal.svelte'
4+
import Input from './Input.svelte'
45
import Spinner from './Spinner.svelte'
56
import { error } from '$lib/notification'
67
@@ -81,8 +82,7 @@
8182
<Modal open={showCreate}>
8283
<h2>Create</h2>
8384
<form onsubmit={create}>
84-
<!-- svelte-ignore a11y_autofocus -->
85-
<input bind:value={name} autofocus />
85+
<Input bind:value={name} autofocus type="text" name="name" label="Name" />
8686
<div class="actions">
8787
<button class="button primary" type="submit">Create</button>
8888
<button class="button error" onclick={toggleShowCreate}>Close</button>

src/routes/roles/[pk]/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const load = ({ params }) => {
22
return {
3-
pk: params.pk
3+
pk: params.pk,
44
}
55
}

src/routes/themes/[name]/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const load = ({ params }) => {
22
return {
3-
name: params.name
3+
name: params.name,
44
}
55
}

src/routes/users/[pk]/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const load = ({ params }) => {
22
return {
3-
pk: params.pk
3+
pk: params.pk,
44
}
55
}

src/routes/verify/[token]/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const load = ({ params }) => {
22
return {
3-
token: params.token
3+
token: params.token,
44
}
55
}

0 commit comments

Comments
 (0)