@joyautomation/salt 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,35 +3,39 @@
|
|
|
3
3
|
import Input from './Input.svelte'
|
|
4
4
|
import Select from './Select.svelte'
|
|
5
5
|
import Switch from './Switch.svelte'
|
|
6
|
-
import type { FormInputs } from './types.js'
|
|
6
|
+
import type { FormGroup, FormInputs } from './types.js'
|
|
7
7
|
import { slide } from 'svelte/transition'
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
inputs: propInputs,
|
|
11
|
+
groups: propGroups,
|
|
11
12
|
action,
|
|
12
13
|
buttonText = 'Submit',
|
|
13
14
|
onsubmitstart,
|
|
14
15
|
onsubmitend
|
|
15
16
|
}: {
|
|
16
|
-
inputs
|
|
17
|
+
inputs?: FormInputs
|
|
18
|
+
groups?: FormGroup[]
|
|
17
19
|
action: string
|
|
18
20
|
buttonText?: string
|
|
19
21
|
onsubmitstart?: () => void
|
|
20
22
|
onsubmitend?: () => void
|
|
21
23
|
} = $props()
|
|
22
24
|
|
|
23
|
-
let
|
|
25
|
+
let groups = $state(propGroups ?? [{ rows: propInputs ?? [] }])
|
|
24
26
|
let submitting = $state(false)
|
|
25
27
|
|
|
26
28
|
$effect(() => {
|
|
27
|
-
|
|
29
|
+
groups = propGroups ?? [{ rows: propInputs ?? [] }]
|
|
28
30
|
})
|
|
29
31
|
|
|
32
|
+
const allInputs = $derived(groups.flatMap((g) => g.rows))
|
|
33
|
+
|
|
30
34
|
const valid = $derived(
|
|
31
|
-
|
|
35
|
+
allInputs.every((row) =>
|
|
32
36
|
row.every((input) => {
|
|
33
37
|
return input.validations.every(([validation]) => {
|
|
34
|
-
return !validation(input.value,
|
|
38
|
+
return !validation(input.value, allInputs)
|
|
35
39
|
})
|
|
36
40
|
})
|
|
37
41
|
)
|
|
@@ -52,20 +56,32 @@
|
|
|
52
56
|
}
|
|
53
57
|
}}
|
|
54
58
|
>
|
|
55
|
-
{#each
|
|
56
|
-
<
|
|
57
|
-
{#
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
{#each groups as group}
|
|
60
|
+
<fieldset class="form__group">
|
|
61
|
+
{#if group.heading}
|
|
62
|
+
<legend class="form__group-heading">{group.heading}</legend>
|
|
63
|
+
{/if}
|
|
64
|
+
{#each group.rows as row}
|
|
65
|
+
<div class="form__row">
|
|
66
|
+
{#each row as input}
|
|
67
|
+
<div>
|
|
68
|
+
{#if input.type === 'select'}
|
|
69
|
+
<Select
|
|
70
|
+
{...input}
|
|
71
|
+
bind:value={input.value}
|
|
72
|
+
inputs={allInputs}
|
|
73
|
+
options={input.options || []}
|
|
74
|
+
/>
|
|
75
|
+
{:else if input.type === 'checkbox'}
|
|
76
|
+
<Switch {...input} bind:value={input.value} inputs={allInputs} />
|
|
77
|
+
{:else}
|
|
78
|
+
<Input {...input} bind:value={input.value} inputs={allInputs} />
|
|
79
|
+
{/if}
|
|
80
|
+
</div>
|
|
81
|
+
{/each}
|
|
66
82
|
</div>
|
|
67
83
|
{/each}
|
|
68
|
-
</
|
|
84
|
+
</fieldset>
|
|
69
85
|
{/each}
|
|
70
86
|
<button class="button--primary" disabled={!valid || submitting}>
|
|
71
87
|
{#if submitting}
|
|
@@ -83,11 +99,29 @@
|
|
|
83
99
|
<style>.form {
|
|
84
100
|
display: flex;
|
|
85
101
|
flex-direction: column;
|
|
102
|
+
gap: calc(var(--spacing-unit) * 4);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.form__group {
|
|
106
|
+
border: none;
|
|
107
|
+
padding: 0;
|
|
108
|
+
margin: 0;
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-direction: column;
|
|
111
|
+
gap: calc(var(--spacing-unit) * 1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.form__group-heading {
|
|
115
|
+
font-size: var(--text-base);
|
|
116
|
+
font-weight: 600;
|
|
117
|
+
color: var(--theme-text);
|
|
118
|
+
padding: 0;
|
|
86
119
|
}
|
|
87
|
-
|
|
120
|
+
|
|
121
|
+
.form__row {
|
|
88
122
|
display: flex;
|
|
89
123
|
}
|
|
90
|
-
.
|
|
124
|
+
.form__row > * {
|
|
91
125
|
flex-grow: 1;
|
|
92
126
|
}
|
|
93
127
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { FormInputs } from './types.js';
|
|
1
|
+
import type { FormGroup, FormInputs } from './types.js';
|
|
2
2
|
type $$ComponentProps = {
|
|
3
|
-
inputs
|
|
3
|
+
inputs?: FormInputs;
|
|
4
|
+
groups?: FormGroup[];
|
|
4
5
|
action: string;
|
|
5
6
|
buttonText?: string;
|
|
6
7
|
onsubmitstart?: () => void;
|
|
@@ -3,4 +3,4 @@ export { default as Input } from './Input.svelte';
|
|
|
3
3
|
export { default as Select } from './Select.svelte';
|
|
4
4
|
export { default as Switch } from './Switch.svelte';
|
|
5
5
|
export { default as SearchableSelect } from './SearchableSelect.svelte';
|
|
6
|
-
export type { InputProps, FormInputs, FormInputsPartial } from './types.js';
|
|
6
|
+
export type { InputProps, FormInputs, FormInputsPartial, FormGroup } from './types.js';
|