@splendidlabz/svelte 3.0.0-alpha.3 → 3.0.0-alpha.8
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/CHANGELOG.md +40 -0
- package/actions/index.js +2 -0
- package/actions/sync.svelte.js +21 -0
- package/actions/use-actions.js +27 -0
- package/{components/_shared/use-actions.js → actions/use-transition.js} +1 -0
- package/components/Accordion/Accordion.svelte +3 -3
- package/components/Disclosure/Disclosure/DisclosureCloseButton.svelte +37 -0
- package/components/Disclosure/Disclosure/DisclosureContent.svelte +97 -0
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +51 -0
- package/components/Disclosure/Disclosure/disclosure-popover.svelte.js +7 -0
- package/components/Disclosure/Disclosure/disclosure.svelte.js +461 -0
- package/components/Disclosure/Disclosure/index.js +4 -0
- package/components/Disclosure/DisclosureNew/DisclosureCloseButton.svelte +38 -0
- package/components/Disclosure/DisclosureNew/DisclosureContent.svelte +53 -0
- package/components/Disclosure/DisclosureNew/DisclosureTrigger.svelte +79 -0
- package/components/Disclosure/DisclosureNew/disclosures.svelte.js +55 -0
- package/components/Disclosure/DisclosureNew/index.js +5 -0
- package/components/Disclosure/Drawer/Drawer.svelte +18 -22
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
- package/components/Disclosure/Drawer/DrawerContent.svelte +41 -77
- package/components/Disclosure/Drawer/DrawerNew.svelte +0 -0
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +7 -46
- package/components/Disclosure/Drawer/drawer.js +2 -70
- package/components/Disclosure/DrawerNew/Drawer.svelte +39 -0
- package/components/Disclosure/DrawerNew/DrawerClose.svelte +0 -0
- package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +16 -0
- package/components/Disclosure/DrawerNew/drawer.js +44 -0
- package/components/Disclosure/DrawerNew/index.js +5 -0
- package/components/Disclosure/Modal/Modal.svelte +30 -0
- package/components/Disclosure/Modal/ModalCloseButton.svelte +7 -0
- package/components/Disclosure/Modal/ModalContent.svelte +40 -1
- package/components/Disclosure/Modal/ModalTrigger.svelte +7 -29
- package/components/Disclosure/Modal/index.js +5 -0
- package/components/Disclosure/Modal/modal.js +3 -12
- package/components/Disclosure/ModalNew/Modal.svelte +110 -0
- package/components/Disclosure/ModalNew/ModalClose.svelte +42 -0
- package/components/Disclosure/ModalNew/ModalTrigger.svelte +68 -0
- package/components/Disclosure/ModalNew/index.js +5 -0
- package/components/Disclosure/Popover/PopoverContent.svelte +2 -2
- package/components/Disclosure/Popover/PopoverTrigger.svelte +1 -1
- package/components/Disclosure/PopoverNew/Popover.svelte +105 -0
- package/components/Disclosure/PopoverNew/PopoverClose.svelte +38 -0
- package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +67 -0
- package/components/Disclosure/PopoverNew/floating.js +329 -0
- package/components/Disclosure/PopoverNew/index.js +5 -0
- package/components/Disclosure/disclosure.js +1 -1
- package/components/Disclosure/disclosure.svelte.js +3 -3
- package/components/Disclosure/index.js +7 -3
- package/components/Disclosure/shared.js +9 -0
- package/components/Form/Checkbox.svelte +72 -57
- package/components/Form/Checkboxes.svelte +42 -24
- package/components/Form/HiddenInput.svelte +1 -1
- package/components/Form/Radio.svelte +62 -45
- package/components/Form/Radios.svelte +42 -24
- package/components/Form/Select.svelte +125 -77
- package/components/Form/SelectOld2.svelte +127 -0
- package/components/Form/TextInput.svelte +1 -1
- package/components/Form/Textarea.svelte +1 -1
- package/components/Icon/IconSnippet.svelte +7 -0
- package/components/Portal.svelte +8 -5
- package/eslint.config.js +2 -0
- package/package.json +6 -6
- package/svelte.config.js +5 -0
- package/utils/merge-opts.js +9 -1
- package/utils/transitions.js +75 -4
- package/.eslintrc.cjs +0 -3
- package/components/_shared/accessibility.js +0 -10
|
@@ -1,68 +1,85 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
2
|
+
import { toSentence } from '@splendidlabz/utils'
|
|
3
3
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
4
|
import SVG from '../Icon/Icon.svelte'
|
|
5
5
|
import TextInput from './TextInput.svelte'
|
|
6
6
|
|
|
7
|
-
let
|
|
8
|
-
|
|
7
|
+
let {
|
|
8
|
+
label = null,
|
|
9
|
+
group = $bindable(null),
|
|
10
|
+
ref = $bindable(null),
|
|
11
|
+
checked = $bindable(false),
|
|
12
|
+
...p
|
|
13
|
+
} = $props()
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const {
|
|
16
|
+
class: klass = '',
|
|
17
|
+
icon = null,
|
|
18
|
+
iconClass = null,
|
|
19
|
+
fieldClass = '',
|
|
20
|
+
labelClass = '',
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export let disabled = null
|
|
22
|
-
export let ref = null
|
|
23
|
-
export let group = null
|
|
24
|
-
export let hasInput = false
|
|
22
|
+
id = randomString(8),
|
|
23
|
+
name,
|
|
24
|
+
value = null,
|
|
25
|
+
readonly = null,
|
|
26
|
+
disabled = null,
|
|
27
|
+
hasInput = false,
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
// Event listeners
|
|
30
|
+
onchange = null,
|
|
31
|
+
|
|
32
|
+
...rest
|
|
33
|
+
} = p
|
|
27
34
|
|
|
28
35
|
if (!name) throw new Error('Radio requires a name')
|
|
29
36
|
if (!value) throw new Error('Radio requires a value')
|
|
30
37
|
|
|
31
38
|
// Create label if not provided
|
|
32
|
-
if (!label && label !== '') label =
|
|
39
|
+
if (!label && label !== '') label = toSentence(value)
|
|
40
|
+
|
|
41
|
+
// Sends the checked value upwards
|
|
42
|
+
function handleChange(event) {
|
|
43
|
+
checked = ref.checked
|
|
44
|
+
if (onchange) onchange(event)
|
|
45
|
+
}
|
|
33
46
|
</script>
|
|
34
47
|
|
|
35
|
-
<div class="
|
|
36
|
-
<div class="
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
<div class="radio {klass}" class:checked class:disabled class:readonly>
|
|
49
|
+
<div class="group">
|
|
50
|
+
<div class="radiomark-container">
|
|
51
|
+
<input
|
|
52
|
+
{...rest}
|
|
53
|
+
class="input {fieldClass}"
|
|
54
|
+
type="radio"
|
|
55
|
+
{id}
|
|
56
|
+
{name}
|
|
57
|
+
{checked}
|
|
58
|
+
disabled={disabled || readonly}
|
|
59
|
+
{value}
|
|
60
|
+
bind:group
|
|
61
|
+
bind:this={ref}
|
|
62
|
+
onchange={handleChange}
|
|
63
|
+
/>
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
{#if readonly && checked}
|
|
66
|
+
<input type="hidden" {name} {value} {checked} />
|
|
67
|
+
{/if}
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
{#if icon}
|
|
70
|
+
<SVG class="radiomark {iconClass}" {icon} />
|
|
71
|
+
{:else}
|
|
72
|
+
<svg class="radiomark" viewBox="0 0 24 24">
|
|
73
|
+
<circle cx="12" cy="12" r="5" />
|
|
74
|
+
</svg>
|
|
75
|
+
{/if}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
{#if label}
|
|
79
|
+
<label class="label {labelClass}" for={id}> {label} </label>
|
|
59
80
|
{/if}
|
|
60
81
|
</div>
|
|
61
82
|
|
|
62
|
-
{#if label}
|
|
63
|
-
<label class="label {labelClass}" for={id}> {label} </label>
|
|
64
|
-
{/if}
|
|
65
|
-
|
|
66
83
|
{#if hasInput}
|
|
67
84
|
<TextInput name="{name}-input" />
|
|
68
85
|
{/if}
|
|
@@ -1,49 +1,67 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import Radio from './Radio.svelte'
|
|
3
3
|
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
let {
|
|
5
|
+
legend = '',
|
|
6
|
+
legendClass = '',
|
|
7
|
+
label = '',
|
|
8
|
+
labelClass = '',
|
|
9
|
+
items = $bindable([]),
|
|
10
|
+
radios = $bindable([]),
|
|
11
|
+
ref = $bindable(null),
|
|
12
|
+
checked = $bindable(null),
|
|
13
|
+
...p
|
|
14
|
+
} = $props()
|
|
15
|
+
|
|
16
|
+
// Let users use either items or radios
|
|
17
|
+
if (radios.length) items = radios
|
|
18
|
+
if (!items.length && !radios.length) {
|
|
19
|
+
console.warn('No radios or items provided to <Radios />')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Let users use either label or legend
|
|
23
|
+
if (label) legend = label
|
|
24
|
+
if (labelClass) legendClass = labelClass
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
class: klass = '',
|
|
28
|
+
radiosClass = '',
|
|
29
|
+
icon,
|
|
30
|
+
iconClass = '',
|
|
31
|
+
name,
|
|
32
|
+
disabled = null,
|
|
33
|
+
readonly = null,
|
|
34
|
+
...rest
|
|
35
|
+
} = p
|
|
36
|
+
|
|
37
|
+
const radioProps = {
|
|
20
38
|
icon,
|
|
21
39
|
iconClass,
|
|
22
40
|
disabled,
|
|
23
41
|
readonly,
|
|
24
42
|
}
|
|
25
43
|
|
|
26
|
-
|
|
44
|
+
items = items.map(radio => {
|
|
27
45
|
if (typeof radio === 'string') radio = { value: radio }
|
|
28
46
|
return { ref: null, ...radio }
|
|
29
47
|
})
|
|
30
48
|
|
|
31
|
-
checked =
|
|
49
|
+
checked = items.find(radio => radio.checked)?.value
|
|
32
50
|
</script>
|
|
33
51
|
|
|
34
|
-
<fieldset class="fieldset {klass}" bind:this={ref}
|
|
52
|
+
<fieldset {...rest} class="fieldset {klass}" bind:this={ref}>
|
|
35
53
|
{#if legend}
|
|
36
|
-
<legend class="
|
|
54
|
+
<legend class="legend {legendClass}">{legend}</legend>
|
|
37
55
|
{/if}
|
|
38
56
|
|
|
39
|
-
<div class="
|
|
40
|
-
{#each
|
|
57
|
+
<div class="radios {radiosClass}">
|
|
58
|
+
{#each items as radio}
|
|
41
59
|
<Radio
|
|
42
|
-
{...
|
|
60
|
+
{...radioProps}
|
|
43
61
|
{...radio}
|
|
44
62
|
{name}
|
|
45
|
-
bind:ref={radio.ref}
|
|
46
63
|
bind:group={checked}
|
|
64
|
+
bind:ref={radio.ref}
|
|
47
65
|
/>
|
|
48
66
|
{/each}
|
|
49
67
|
</div>
|
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { toTitle } from '@splendidlabz/utils'
|
|
3
3
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
import Icon from '../Icon/Icon.svelte'
|
|
5
|
+
import HiddenInput from './HiddenInput.svelte'
|
|
6
|
+
|
|
7
|
+
// TODO: Test Binding
|
|
8
|
+
let {
|
|
9
|
+
name = '',
|
|
10
|
+
items = $bindable([]),
|
|
11
|
+
options = $bindable([]),
|
|
12
|
+
selected = $bindable(null),
|
|
13
|
+
ref = $bindable(null),
|
|
14
|
+
...p
|
|
15
|
+
} = $props()
|
|
16
|
+
|
|
17
|
+
// Allows users to use either options or items the property
|
|
18
|
+
if (options.length) items = options
|
|
19
|
+
|
|
20
|
+
if (!options.length && !items.length) {
|
|
21
|
+
console.error('Select requires items to be passed in.')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
// Classes
|
|
26
|
+
class: klass = '',
|
|
27
|
+
icon = null,
|
|
28
|
+
iconClass = null,
|
|
29
|
+
label = '',
|
|
30
|
+
labelClass,
|
|
31
|
+
labelVisible = true,
|
|
32
|
+
hint = null,
|
|
33
|
+
hintClass,
|
|
34
|
+
fieldClass = null,
|
|
35
|
+
|
|
36
|
+
// Options and props
|
|
37
|
+
id = randomString(8),
|
|
38
|
+
required = null,
|
|
39
|
+
readonly = null,
|
|
40
|
+
disabled = null,
|
|
41
|
+
multiple = null,
|
|
42
|
+
size = 0, // Number of lines to show, useful for multiselect, 0, but show 4 lines by default.
|
|
43
|
+
...rest
|
|
44
|
+
} = p
|
|
45
|
+
|
|
46
|
+
const single = !multiple
|
|
47
|
+
const hintId = hint ? id + '-hint' : ''
|
|
48
|
+
const describedBy = `${hintId}`.trim() || null
|
|
49
|
+
|
|
50
|
+
// ========================================
|
|
51
|
+
// Some Checks & Normalizations
|
|
52
|
+
// ========================================
|
|
53
|
+
// Fixes multiple name and selected values
|
|
27
54
|
if (multiple) {
|
|
28
55
|
if (!name.endsWith('[]')) name = name += '[]'
|
|
29
56
|
if (!Array.isArray(selected)) selected = []
|
|
@@ -39,9 +66,7 @@
|
|
|
39
66
|
if (selected.includes(option.value)) option.selected = true
|
|
40
67
|
if (option.selected && !selected.includes(option.value))
|
|
41
68
|
selected.push(option.value)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!multiple) {
|
|
69
|
+
} else {
|
|
45
70
|
if (option.value === selected) option.selected = true
|
|
46
71
|
if (option.selected) selected = option.value
|
|
47
72
|
}
|
|
@@ -50,78 +75,101 @@
|
|
|
50
75
|
})
|
|
51
76
|
|
|
52
77
|
// If none selected, preselect first item that is not disabled. (Single only)
|
|
53
|
-
if (!multiple && !selected) {
|
|
78
|
+
setSelected: if (!multiple && !selected) {
|
|
54
79
|
const firstNotDisabled = items.findIndex(item => !item.disabled)
|
|
80
|
+
if (firstNotDisabled === -1) break setSelected
|
|
55
81
|
const s = items[firstNotDisabled] || items[0]
|
|
56
82
|
s.selected = true
|
|
57
83
|
selected = s.value
|
|
58
84
|
}
|
|
59
85
|
|
|
60
|
-
|
|
86
|
+
// Properties for the select element
|
|
87
|
+
const properties = {
|
|
88
|
+
...rest,
|
|
61
89
|
id,
|
|
62
90
|
name,
|
|
63
91
|
required,
|
|
64
92
|
size,
|
|
93
|
+
class: 'input ' + fieldClass,
|
|
65
94
|
disabled: disabled || readonly,
|
|
66
95
|
}
|
|
67
96
|
</script>
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
{#snippet select()}
|
|
99
|
+
<select
|
|
100
|
+
{...properties}
|
|
101
|
+
bind:value={selected}
|
|
102
|
+
bind:this={ref}
|
|
103
|
+
aria-describedby={describedBy}
|
|
104
|
+
>
|
|
105
|
+
{#each items as option}
|
|
106
|
+
{@const { label: optionLabel, value, ...optionRest } = option}
|
|
107
|
+
<option {...optionRest} {value}>{optionLabel}</option>
|
|
108
|
+
{/each}
|
|
109
|
+
</select>
|
|
110
|
+
{/snippet}
|
|
111
|
+
|
|
112
|
+
<!-- Svelte requires multiple to be passed as a standard attribute for it to bind to an array value, hence the duplication here -->
|
|
113
|
+
{#snippet selectMultiple()}
|
|
114
|
+
<select
|
|
115
|
+
{...properties}
|
|
116
|
+
bind:value={selected}
|
|
117
|
+
bind:this={ref}
|
|
118
|
+
aria-describedby={describedBy}
|
|
119
|
+
multiple
|
|
120
|
+
>
|
|
121
|
+
{#each items as option}
|
|
122
|
+
{@const { label: optionLabel, value, ...optionRest } = option}
|
|
123
|
+
<option {...optionRest} {value}>{optionLabel}</option>
|
|
124
|
+
{/each}
|
|
125
|
+
</select>
|
|
126
|
+
{/snippet}
|
|
127
|
+
|
|
128
|
+
{#snippet selectIcon()}
|
|
129
|
+
{#if icon}
|
|
130
|
+
<Icon class={iconClass} {icon} />
|
|
131
|
+
{:else}
|
|
132
|
+
<svg class={iconClass} width="24" height="24" viewBox="0 0 24 24">
|
|
133
|
+
<path
|
|
134
|
+
d="M8 9L12 5L16 9M16 15L12 19L8 15"
|
|
135
|
+
stroke="currentcolor"
|
|
136
|
+
stroke-width="2"
|
|
137
|
+
stroke-linecap="round"
|
|
138
|
+
stroke-linejoin="round"
|
|
139
|
+
/>
|
|
140
|
+
</svg>
|
|
141
|
+
{/if}
|
|
142
|
+
{/snippet}
|
|
143
|
+
|
|
144
|
+
<div class="input-container select {klass}">
|
|
145
|
+
{#if label && labelVisible}
|
|
146
|
+
<label class="label input-meta {labelClass}" for={id}>{label}</label>
|
|
147
|
+
{/if}
|
|
148
|
+
{#if hint}
|
|
149
|
+
<div id={hintId} class="hint input-meta {hintClass}">{hint}</div>
|
|
150
|
+
{/if}
|
|
151
|
+
|
|
152
|
+
<div class="input-group items-center stack" class:disabled class:readonly>
|
|
153
|
+
<!-- Single Select -->
|
|
154
|
+
{#if single}
|
|
155
|
+
{@render select()}
|
|
81
156
|
{#if readonly}
|
|
82
|
-
<
|
|
157
|
+
<HiddenInput {name} value={selected} />
|
|
83
158
|
{/if}
|
|
84
|
-
{:else}
|
|
85
|
-
<!-- Svelte requires multiple to be passed as a standard attribute for it to bind to an array value, hence the duplication here. -->
|
|
86
|
-
<select
|
|
87
|
-
{...props}
|
|
88
|
-
multiple
|
|
89
|
-
bind:value={selected}
|
|
90
|
-
on:change
|
|
91
|
-
bind:this={ref}
|
|
92
|
-
{...$$restProps}
|
|
93
|
-
>
|
|
94
|
-
{#each items as option}
|
|
95
|
-
{@const { label: optionLabel, ...rest } = option}
|
|
96
|
-
<option {...rest} value={option.value}>
|
|
97
|
-
{optionLabel}
|
|
98
|
-
</option>
|
|
99
|
-
{/each}
|
|
100
|
-
</select>
|
|
101
159
|
|
|
160
|
+
<div class="pos-right pointer-events-none z-[3]">
|
|
161
|
+
{@render selectIcon()}
|
|
162
|
+
</div>
|
|
163
|
+
{/if}
|
|
164
|
+
|
|
165
|
+
<!-- Multi Select -->
|
|
166
|
+
{#if multiple}
|
|
167
|
+
{@render selectMultiple()}
|
|
102
168
|
{#if readonly}
|
|
103
169
|
{#each selected as item}
|
|
104
|
-
<
|
|
170
|
+
<HiddenInput {name} value={item} />
|
|
105
171
|
{/each}
|
|
106
172
|
{/if}
|
|
107
173
|
{/if}
|
|
108
|
-
|
|
109
|
-
{#if !multiple}
|
|
110
|
-
<div class="Pos-right pointer-events-none" class:disabled class:readonly>
|
|
111
|
-
{#if icon}
|
|
112
|
-
<SVG class={iconClass} {icon} />
|
|
113
|
-
{:else}
|
|
114
|
-
<svg class={iconClass} width="24" height="24" viewBox="0 0 24 24">
|
|
115
|
-
<path
|
|
116
|
-
d="M8 9L12 5L16 9M16 15L12 19L8 15"
|
|
117
|
-
stroke="currentcolor"
|
|
118
|
-
stroke-width="2"
|
|
119
|
-
stroke-linecap="round"
|
|
120
|
-
stroke-linejoin="round"
|
|
121
|
-
/>
|
|
122
|
-
</svg>
|
|
123
|
-
{/if}
|
|
124
|
-
</div>
|
|
125
|
-
{/if}
|
|
126
174
|
</div>
|
|
127
175
|
</div>
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { toTitle } from '@splendidlabz/utils'
|
|
3
|
+
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
+
import SVG from '../Icon/Icon.svelte'
|
|
5
|
+
import Hidden from './Hidden.svelte'
|
|
6
|
+
|
|
7
|
+
let klass = ''
|
|
8
|
+
export { klass as class }
|
|
9
|
+
export let icon = null // tabler-selector, ph:caret-up-down
|
|
10
|
+
export let iconClass = null
|
|
11
|
+
|
|
12
|
+
export let label = ''
|
|
13
|
+
export let id = ''
|
|
14
|
+
export let name
|
|
15
|
+
export let selected = null
|
|
16
|
+
export let items = []
|
|
17
|
+
export let required = null
|
|
18
|
+
export let readonly = null
|
|
19
|
+
export let disabled = null
|
|
20
|
+
export let multiple = null
|
|
21
|
+
export let size = 0 // Number of lines to show, useful for multiselect, 0, but show 4 lines by default.
|
|
22
|
+
export let ref = null
|
|
23
|
+
|
|
24
|
+
id = id || randomString(8)
|
|
25
|
+
|
|
26
|
+
// Autofix multiple
|
|
27
|
+
if (multiple) {
|
|
28
|
+
if (!name.endsWith('[]')) name = name += '[]'
|
|
29
|
+
if (!Array.isArray(selected)) selected = []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Normalize items
|
|
33
|
+
items = items.map(option => {
|
|
34
|
+
if (typeof option === 'string') option = { value: option }
|
|
35
|
+
if (!option.label) option.label = toTitle(option.value)
|
|
36
|
+
|
|
37
|
+
// Updated selected & item.selected
|
|
38
|
+
if (multiple) {
|
|
39
|
+
if (selected.includes(option.value)) option.selected = true
|
|
40
|
+
if (option.selected && !selected.includes(option.value))
|
|
41
|
+
selected.push(option.value)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!multiple) {
|
|
45
|
+
if (option.value === selected) option.selected = true
|
|
46
|
+
if (option.selected) selected = option.value
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return option
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// If none selected, preselect first item that is not disabled. (Single only)
|
|
53
|
+
if (!multiple && !selected) {
|
|
54
|
+
const firstNotDisabled = items.findIndex(item => !item.disabled)
|
|
55
|
+
const s = items[firstNotDisabled] || items[0]
|
|
56
|
+
s.selected = true
|
|
57
|
+
selected = s.value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const props = {
|
|
61
|
+
id,
|
|
62
|
+
name,
|
|
63
|
+
required,
|
|
64
|
+
size,
|
|
65
|
+
disabled: disabled || readonly,
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<div class="text-field Select {klass}">
|
|
70
|
+
<label class="label" for={id}>{label}</label>
|
|
71
|
+
<div class="input-group items-center" class:Stack={!multiple}>
|
|
72
|
+
{#if !multiple}
|
|
73
|
+
<select {...props} bind:value={selected} on:change {...$$restProps}>
|
|
74
|
+
{#each items as option}
|
|
75
|
+
{@const { label: optionLabel, ...rest } = option}
|
|
76
|
+
<option {...rest} value={option.value}>
|
|
77
|
+
{optionLabel}
|
|
78
|
+
</option>
|
|
79
|
+
{/each}
|
|
80
|
+
</select>
|
|
81
|
+
{#if readonly}
|
|
82
|
+
<Hidden {name} value={selected} />
|
|
83
|
+
{/if}
|
|
84
|
+
{:else}
|
|
85
|
+
<!-- Svelte requires multiple to be passed as a standard attribute for it to bind to an array value, hence the duplication here. -->
|
|
86
|
+
<select
|
|
87
|
+
{...props}
|
|
88
|
+
multiple
|
|
89
|
+
bind:value={selected}
|
|
90
|
+
on:change
|
|
91
|
+
bind:this={ref}
|
|
92
|
+
{...$$restProps}
|
|
93
|
+
>
|
|
94
|
+
{#each items as option}
|
|
95
|
+
{@const { label: optionLabel, ...rest } = option}
|
|
96
|
+
<option {...rest} value={option.value}>
|
|
97
|
+
{optionLabel}
|
|
98
|
+
</option>
|
|
99
|
+
{/each}
|
|
100
|
+
</select>
|
|
101
|
+
|
|
102
|
+
{#if readonly}
|
|
103
|
+
{#each selected as item}
|
|
104
|
+
<Hidden {name} value={item} />
|
|
105
|
+
{/each}
|
|
106
|
+
{/if}
|
|
107
|
+
{/if}
|
|
108
|
+
|
|
109
|
+
{#if !multiple}
|
|
110
|
+
<div class="Pos-right pointer-events-none" class:disabled class:readonly>
|
|
111
|
+
{#if icon}
|
|
112
|
+
<SVG class={iconClass} {icon} />
|
|
113
|
+
{:else}
|
|
114
|
+
<svg class={iconClass} width="24" height="24" viewBox="0 0 24 24">
|
|
115
|
+
<path
|
|
116
|
+
d="M8 9L12 5L16 9M16 15L12 19L8 15"
|
|
117
|
+
stroke="currentcolor"
|
|
118
|
+
stroke-width="2"
|
|
119
|
+
stroke-linecap="round"
|
|
120
|
+
stroke-linejoin="round"
|
|
121
|
+
/>
|
|
122
|
+
</svg>
|
|
123
|
+
{/if}
|
|
124
|
+
</div>
|
|
125
|
+
{/if}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
+
import { useActions } from '../../actions/use-actions'
|
|
3
4
|
import { mergeOpts } from '../../utils'
|
|
4
|
-
import { useActions } from '../_shared/use-actions'
|
|
5
5
|
|
|
6
6
|
let { value = $bindable(''), ref = $bindable(null), ...p } = $props()
|
|
7
7
|
const {
|
package/components/Portal.svelte
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { onDestroy, onMount } from 'svelte'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const {
|
|
5
|
+
class: klass = '', // Allows you to specify portal class
|
|
6
|
+
target = null, // CSS Selector
|
|
7
|
+
children,
|
|
8
|
+
...rest
|
|
9
|
+
} = $props()
|
|
7
10
|
|
|
8
11
|
let portal
|
|
9
12
|
let portalParent
|
|
@@ -22,6 +25,6 @@
|
|
|
22
25
|
})
|
|
23
26
|
</script>
|
|
24
27
|
|
|
25
|
-
<div class="
|
|
26
|
-
|
|
28
|
+
<div {...rest} class="portal {klass}" bind:this={portal}>
|
|
29
|
+
{@render children()}
|
|
27
30
|
</div>
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-alpha.
|
|
4
|
+
"version": "3.0.0-alpha.8",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint . --fix",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"@floating-ui/dom": "^1.6.13",
|
|
20
20
|
"@iconify/svelte": "^4.2.0",
|
|
21
21
|
"@splendidlabz/layouts": "*",
|
|
22
|
-
"@splendidlabz/styles": "3.0.0-alpha.
|
|
23
|
-
"@splendidlabz/utils": "1.5.0-alpha.
|
|
22
|
+
"@splendidlabz/styles": "3.0.0-alpha.7",
|
|
23
|
+
"@splendidlabz/utils": "1.5.0-alpha.3",
|
|
24
24
|
"autosuggest-highlight": "^3.3.4",
|
|
25
25
|
"lodash-es": "^4.17.21",
|
|
26
26
|
"node-html-parser": "^7.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@splendidlabz/eslint-config": "
|
|
30
|
-
"svelte": "^5.
|
|
31
|
-
"vitest": "^3.
|
|
29
|
+
"@splendidlabz/eslint-config": "2.0.0-alpha.0",
|
|
30
|
+
"svelte": "^5.25.6",
|
|
31
|
+
"vitest": "^3.1.1"
|
|
32
32
|
}
|
|
33
33
|
}
|