-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathinputCheckbox.svelte
More file actions
67 lines (62 loc) · 1.78 KB
/
inputCheckbox.svelte
File metadata and controls
67 lines (62 loc) · 1.78 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
<script lang="ts">
import { Selector } from '@appwrite.io/pink-svelte';
import { Helper } from '.';
interface $$Props extends Partial<HTMLLabelElement> {
id: string;
label?: string;
checked?: boolean;
required?: boolean;
disabled?: boolean;
element?: HTMLInputElement | undefined;
indeterminate?: boolean;
size?: 's' | 'm';
description?: string;
truncate?: boolean;
}
export let id: string = '';
export let label: string | undefined = undefined;
export let checked = false;
export let required = false;
export let disabled = false;
export let element: HTMLInputElement | undefined = undefined;
export let size: $$Props['size'] = 's';
export let description = '';
export let truncate: boolean = false;
let error: string;
const handleInvalid = (event: Event) => {
event.preventDefault();
if (element.validity.valueMissing) {
error = 'This field is required';
return;
}
error = element.validationMessage;
};
$: if (checked) {
error = null;
}
</script>
<div>
<div class="choice-item">
<div class="input-text-wrapper">
<Selector.Checkbox
bind:checked
{...$$restProps}
{id}
{disabled}
{size}
{label}
{required}
{description}
{truncate}
on:invalid={handleInvalid}
on:click
on:change />
</div>
<div class="choice-item-content">
<slot name="description" />
</div>
</div>
{#if error}
<Helper type="warning">{error}</Helper>
{/if}
</div>