Skip to content

Commit 164ef34

Browse files
committed
Create InputTime for only times
1 parent 6878449 commit 164ef34

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/lib/elements/forms/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ export { default as InputSecret } from './inputSecret.svelte';
2727
export { default as Helper } from './helper.svelte';
2828
export { default as Label } from './label.svelte';
2929
export { default as InputDate } from './inputDate.svelte';
30+
export { default as InputTime } from './inputTime.svelte';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script lang="ts">
2+
import { onMount } from 'svelte';
3+
import { FormItem, Helper, Label } from '.';
4+
5+
export let label: string;
6+
export let showLabel = true;
7+
export let optionalText: string | undefined = undefined;
8+
export let id: string;
9+
export let value = '';
10+
export let required = false;
11+
export let min: string | number | undefined = undefined;
12+
export let max: string | number | undefined = undefined;
13+
export let disabled = false;
14+
export let readonly = false;
15+
export let autofocus = false;
16+
export let autocomplete = false;
17+
18+
let element: HTMLInputElement;
19+
let error: string;
20+
21+
onMount(() => {
22+
if (element && autofocus) {
23+
element.focus();
24+
}
25+
});
26+
27+
function handleInvalid(event: Event) {
28+
event.preventDefault();
29+
30+
if (element.validity.valueMissing) {
31+
error = 'This field is required';
32+
return;
33+
}
34+
35+
error = element.validationMessage;
36+
}
37+
38+
$: if (value) {
39+
error = null;
40+
}
41+
</script>
42+
43+
<FormItem>
44+
<Label {required} {optionalText} hide={!showLabel} for={id}>
45+
{label}
46+
</Label>
47+
48+
<div class="input-text-wrapper" style="--amount-of-buttons:1; --button-size: 1rem">
49+
<input
50+
{id}
51+
{disabled}
52+
{readonly}
53+
{required}
54+
{min}
55+
{max}
56+
step="60"
57+
autocomplete={autocomplete ? 'on' : 'off'}
58+
type="time"
59+
class="input-text"
60+
bind:value
61+
bind:this={element}
62+
on:invalid={handleInvalid} />
63+
</div>
64+
{#if error}
65+
<Helper type="warning">{error}</Helper>
66+
{/if}
67+
</FormItem>

0 commit comments

Comments
 (0)