-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathinputLine.svelte
More file actions
68 lines (63 loc) · 2.06 KB
/
inputLine.svelte
File metadata and controls
68 lines (63 loc) · 2.06 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
<script lang="ts">
import { Icon, Layout } from '@appwrite.io/pink-svelte';
import InputPoint from './inputPoint.svelte';
import Button from './button.svelte';
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
import type { Snippet } from 'svelte';
type Props = {
values: number[][];
nullable?: boolean;
minDeletableIndex?: number;
allowLineDelete?: boolean;
onAddPoint: (index: number) => void;
onDeletePoint: (index: number) => void;
onChangePoint: (pointIndex: number, coordIndex: number, newValue: number) => void;
addLineButton?: Snippet;
disabled?: boolean;
};
let {
values,
nullable = false,
minDeletableIndex = 2,
allowLineDelete,
onAddPoint,
onDeletePoint,
onChangePoint,
addLineButton,
disabled
}: Props = $props();
function isDeleteDisabled(index: number) {
let disable = index < minDeletableIndex;
if (allowLineDelete !== undefined) {
disable = disable && allowLineDelete;
}
return disable;
}
</script>
<Layout.Stack alignItems="flex-start" gap="xs">
<Layout.Stack>
{#each values as value, index}
<InputPoint
{disabled}
{nullable}
values={value}
deletePoints
disableDelete={isDeleteDisabled(index)}
onDeletePoint={() => onDeletePoint(index)}
onChangePoint={(coordIndex, newValue) =>
onChangePoint?.(index, coordIndex, newValue)} />
{/each}
</Layout.Stack>
{#if values}
<Layout.Stack direction="row" gap="s" alignItems="center">
<Button
size="xs"
compact
on:click={() => onAddPoint(-1)}
disabled={nullable || disabled}>
<Icon icon={IconPlus} size="s" /> Add coordinate
</Button>
{@render addLineButton?.()}
</Layout.Stack>
{/if}
</Layout.Stack>