@joyautomation/salt 0.1.2 → 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.
- package/dist/components/forms/Form.svelte +55 -18
- package/dist/components/forms/Form.svelte.d.ts +3 -2
- package/dist/components/forms/Switch.svelte +104 -0
- package/dist/components/forms/Switch.svelte.d.ts +7 -0
- package/dist/components/forms/index.d.ts +2 -1
- package/dist/components/forms/index.js +1 -0
- package/dist/components/forms/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -2,35 +2,40 @@
|
|
|
2
2
|
import { enhance } from '$app/forms'
|
|
3
3
|
import Input from './Input.svelte'
|
|
4
4
|
import Select from './Select.svelte'
|
|
5
|
-
import
|
|
5
|
+
import Switch from './Switch.svelte'
|
|
6
|
+
import type { FormGroup, FormInputs } from './types.js'
|
|
6
7
|
import { slide } from 'svelte/transition'
|
|
7
8
|
|
|
8
9
|
const {
|
|
9
10
|
inputs: propInputs,
|
|
11
|
+
groups: propGroups,
|
|
10
12
|
action,
|
|
11
13
|
buttonText = 'Submit',
|
|
12
14
|
onsubmitstart,
|
|
13
15
|
onsubmitend
|
|
14
16
|
}: {
|
|
15
|
-
inputs
|
|
17
|
+
inputs?: FormInputs
|
|
18
|
+
groups?: FormGroup[]
|
|
16
19
|
action: string
|
|
17
20
|
buttonText?: string
|
|
18
21
|
onsubmitstart?: () => void
|
|
19
22
|
onsubmitend?: () => void
|
|
20
23
|
} = $props()
|
|
21
24
|
|
|
22
|
-
let
|
|
25
|
+
let groups = $state(propGroups ?? [{ rows: propInputs ?? [] }])
|
|
23
26
|
let submitting = $state(false)
|
|
24
27
|
|
|
25
28
|
$effect(() => {
|
|
26
|
-
|
|
29
|
+
groups = propGroups ?? [{ rows: propInputs ?? [] }]
|
|
27
30
|
})
|
|
28
31
|
|
|
32
|
+
const allInputs = $derived(groups.flatMap((g) => g.rows))
|
|
33
|
+
|
|
29
34
|
const valid = $derived(
|
|
30
|
-
|
|
35
|
+
allInputs.every((row) =>
|
|
31
36
|
row.every((input) => {
|
|
32
37
|
return input.validations.every(([validation]) => {
|
|
33
|
-
return !validation(input.value,
|
|
38
|
+
return !validation(input.value, allInputs)
|
|
34
39
|
})
|
|
35
40
|
})
|
|
36
41
|
)
|
|
@@ -51,18 +56,32 @@
|
|
|
51
56
|
}
|
|
52
57
|
}}
|
|
53
58
|
>
|
|
54
|
-
{#each
|
|
55
|
-
<
|
|
56
|
-
{#
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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}
|
|
63
82
|
</div>
|
|
64
83
|
{/each}
|
|
65
|
-
</
|
|
84
|
+
</fieldset>
|
|
66
85
|
{/each}
|
|
67
86
|
<button class="button--primary" disabled={!valid || submitting}>
|
|
68
87
|
{#if submitting}
|
|
@@ -80,11 +99,29 @@
|
|
|
80
99
|
<style>.form {
|
|
81
100
|
display: flex;
|
|
82
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;
|
|
83
119
|
}
|
|
84
|
-
|
|
120
|
+
|
|
121
|
+
.form__row {
|
|
85
122
|
display: flex;
|
|
86
123
|
}
|
|
87
|
-
.
|
|
124
|
+
.form__row > * {
|
|
88
125
|
flex-grow: 1;
|
|
89
126
|
}
|
|
90
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;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { FormInputs, InputProps } from './types.js'
|
|
3
|
+
|
|
4
|
+
let {
|
|
5
|
+
id,
|
|
6
|
+
name,
|
|
7
|
+
label,
|
|
8
|
+
value = $bindable('false'),
|
|
9
|
+
validations,
|
|
10
|
+
inputs
|
|
11
|
+
}: InputProps & { inputs?: FormInputs } = $props()
|
|
12
|
+
|
|
13
|
+
const checked = $derived(value === 'true')
|
|
14
|
+
|
|
15
|
+
function toggle() {
|
|
16
|
+
value = value === 'true' ? 'false' : 'true'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function handleKeydown(e: KeyboardEvent) {
|
|
20
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
21
|
+
e.preventDefault()
|
|
22
|
+
toggle()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div class="switch-field">
|
|
28
|
+
{#if label != null}
|
|
29
|
+
<label for={id}>{label}</label>
|
|
30
|
+
{/if}
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
{id}
|
|
34
|
+
class="switch"
|
|
35
|
+
class:switch--active={checked}
|
|
36
|
+
onclick={toggle}
|
|
37
|
+
onkeydown={handleKeydown}
|
|
38
|
+
role="switch"
|
|
39
|
+
aria-checked={checked}
|
|
40
|
+
aria-label={label ?? name}
|
|
41
|
+
>
|
|
42
|
+
<span class="switch__slider"></span>
|
|
43
|
+
</button>
|
|
44
|
+
<input {name} type="hidden" value={checked} />
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<style>.switch-field {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: calc(var(--spacing-unit) * 2);
|
|
51
|
+
}
|
|
52
|
+
.switch-field > label {
|
|
53
|
+
color: var(--theme-text);
|
|
54
|
+
font-family: var(--theme-font-basic, inherit);
|
|
55
|
+
font-size: var(--text-sm);
|
|
56
|
+
line-height: var(--text-sm-lh);
|
|
57
|
+
text-transform: capitalize;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.switch {
|
|
61
|
+
position: relative;
|
|
62
|
+
display: inline-block;
|
|
63
|
+
width: 40px;
|
|
64
|
+
height: 24px;
|
|
65
|
+
border: none;
|
|
66
|
+
background: none;
|
|
67
|
+
padding: 0;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.switch__slider {
|
|
73
|
+
position: absolute;
|
|
74
|
+
top: 0;
|
|
75
|
+
left: 0;
|
|
76
|
+
right: 0;
|
|
77
|
+
bottom: 0;
|
|
78
|
+
background-color: var(--theme-neutral-400);
|
|
79
|
+
border-radius: 12px;
|
|
80
|
+
transition: background-color 0.2s ease;
|
|
81
|
+
}
|
|
82
|
+
.switch__slider::before {
|
|
83
|
+
content: "";
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: 2px;
|
|
86
|
+
left: 2px;
|
|
87
|
+
width: 20px;
|
|
88
|
+
height: 20px;
|
|
89
|
+
background-color: white;
|
|
90
|
+
border-radius: 50%;
|
|
91
|
+
transition: transform 0.2s ease;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.switch--active .switch__slider {
|
|
95
|
+
background-color: var(--theme-primary);
|
|
96
|
+
}
|
|
97
|
+
.switch--active .switch__slider::before {
|
|
98
|
+
transform: translateX(16px);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.switch:focus-visible .switch__slider {
|
|
102
|
+
outline: 2px solid var(--theme-primary);
|
|
103
|
+
outline-offset: 2px;
|
|
104
|
+
}</style>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FormInputs, InputProps } from './types.js';
|
|
2
|
+
type $$ComponentProps = InputProps & {
|
|
3
|
+
inputs?: FormInputs;
|
|
4
|
+
};
|
|
5
|
+
declare const Switch: import("svelte").Component<$$ComponentProps, {}, "value">;
|
|
6
|
+
type Switch = ReturnType<typeof Switch>;
|
|
7
|
+
export default Switch;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Form } from './Form.svelte';
|
|
2
2
|
export { default as Input } from './Input.svelte';
|
|
3
3
|
export { default as Select } from './Select.svelte';
|
|
4
|
+
export { default as Switch } from './Switch.svelte';
|
|
4
5
|
export { default as SearchableSelect } from './SearchableSelect.svelte';
|
|
5
|
-
export type { InputProps, FormInputs, FormInputsPartial } from './types.js';
|
|
6
|
+
export type { InputProps, FormInputs, FormInputsPartial, FormGroup } from './types.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as Form } from './Form.svelte';
|
|
2
2
|
export { default as Input } from './Input.svelte';
|
|
3
3
|
export { default as Select } from './Select.svelte';
|
|
4
|
+
export { default as Switch } from './Switch.svelte';
|
|
4
5
|
export { default as SearchableSelect } from './SearchableSelect.svelte';
|