@splendidlabz/svelte 3.0.0-alpha.3 → 3.0.0-alpha.5
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 +20 -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 +7 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @splendidlabz/svelte
|
|
2
2
|
|
|
3
|
+
## 3.0.0-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5fe7c51]
|
|
8
|
+
- @splendidlabz/utils@1.5.0-alpha.3
|
|
9
|
+
- @splendidlabz/styles@3.0.0-alpha.5
|
|
10
|
+
|
|
11
|
+
## 3.0.0-alpha.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 2ba13ba: - Include select element
|
|
16
|
+
- Include Checkboxes
|
|
17
|
+
- Include Radios
|
|
18
|
+
- Updated dependencies [2ba13ba]
|
|
19
|
+
- Updated dependencies [acf9faf]
|
|
20
|
+
- @splendidlabz/styles@3.0.0-alpha.4
|
|
21
|
+
- @splendidlabz/utils@1.5.0-alpha.2
|
|
22
|
+
|
|
3
23
|
## 3.0.0-alpha.3
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/actions/index.js
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteMap } from 'svelte/reactivity'
|
|
2
|
+
|
|
3
|
+
const syncStore = new SvelteMap()
|
|
4
|
+
|
|
5
|
+
export function getEntry(id) {
|
|
6
|
+
return syncStore.get(id)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function setEntry(id, value) {
|
|
10
|
+
return syncStore.set(id, value)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mergeEntry(id, value) {
|
|
14
|
+
const entry = getEntry(id)
|
|
15
|
+
if (!entry) return setEntry(id, value)
|
|
16
|
+
return syncStore.set(id, { ...entry, ...value })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function removeEntry(id) {
|
|
20
|
+
return syncStore.delete(id)
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Grabbed from https://github.com/radiofrance/svelte-component-actions/tree/main
|
|
2
|
+
export function useActions(node, actions) {
|
|
3
|
+
if (!actions) return
|
|
4
|
+
|
|
5
|
+
const actionReturns = actions.map(actionEntry => {
|
|
6
|
+
const { fn, props } = actionEntry
|
|
7
|
+
return fn(node, props)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
update(newActions) {
|
|
12
|
+
if (!newActions || newActions.length !== actionReturns.length) {
|
|
13
|
+
throw new Error('You must not change the length of an actions array.')
|
|
14
|
+
}
|
|
15
|
+
newActions.forEach((actionEntry, i) => {
|
|
16
|
+
const returnEntry = actionReturns[i]
|
|
17
|
+
const { props } = actionEntry
|
|
18
|
+
returnEntry?.update?.(props)
|
|
19
|
+
})
|
|
20
|
+
},
|
|
21
|
+
destroy() {
|
|
22
|
+
actionReturns.forEach(returnEntry => {
|
|
23
|
+
returnEntry?.destroy?.()
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
-
import {
|
|
3
|
+
import { applyTransition, mergeOpts } from '../../utils/index.js'
|
|
4
4
|
import Icon from '../Icon/Icon.svelte'
|
|
5
5
|
|
|
6
6
|
const p = $props()
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
|
|
74
74
|
<!-- The output -->
|
|
75
75
|
|
|
76
|
-
<div class="accordion {klass}" class:
|
|
76
|
+
<div class="accordion {klass}" class:open={show}>
|
|
77
77
|
<svelte:element this={opts.titleTag} class="accordion-title {titleClass}">
|
|
78
78
|
<button
|
|
79
79
|
class="accordion-button {buttonClass}"
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
<div
|
|
94
94
|
{id}
|
|
95
95
|
class="accordion-content {contentClass}"
|
|
96
|
-
transition:
|
|
96
|
+
transition:applyTransition={{
|
|
97
97
|
transition: opts.transition,
|
|
98
98
|
}}
|
|
99
99
|
>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from '../../Icon/Icon.svelte'
|
|
3
|
+
import { close, getDisclosure } from './disclosure.svelte.js'
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
class: klass = '',
|
|
7
|
+
icon = 'tabler:x',
|
|
8
|
+
iconClass = '',
|
|
9
|
+
target = '',
|
|
10
|
+
children,
|
|
11
|
+
...rest
|
|
12
|
+
} = $props()
|
|
13
|
+
|
|
14
|
+
let button = null
|
|
15
|
+
|
|
16
|
+
function closeDrawer() {
|
|
17
|
+
const id =
|
|
18
|
+
document.querySelector(`${target}`)?.id ||
|
|
19
|
+
button.closest('.disclosure-content').id
|
|
20
|
+
const d = getDisclosure(id)
|
|
21
|
+
close(d, { shouldFocusWhenClosing: true })
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<button
|
|
26
|
+
aria-label="Close"
|
|
27
|
+
class="button-icon {klass}"
|
|
28
|
+
{...rest}
|
|
29
|
+
bind:this={button}
|
|
30
|
+
onclick={closeDrawer}
|
|
31
|
+
>
|
|
32
|
+
{#if children}
|
|
33
|
+
{@render children()}
|
|
34
|
+
{:else}
|
|
35
|
+
<Icon class={iconClass} {icon} />
|
|
36
|
+
{/if}
|
|
37
|
+
</button>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import {
|
|
4
|
+
goToElement,
|
|
5
|
+
hasAccessibleName,
|
|
6
|
+
markActiveAnchorIn,
|
|
7
|
+
} from '@splendidlabz/utils/dom'
|
|
8
|
+
import {
|
|
9
|
+
TRANSITION_OPT_KEYS,
|
|
10
|
+
applyTransition,
|
|
11
|
+
} from '../../../utils/transitions.js'
|
|
12
|
+
import Portal from '../../Portal.svelte'
|
|
13
|
+
import {
|
|
14
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
15
|
+
disclosureContent,
|
|
16
|
+
getDisclosure,
|
|
17
|
+
} from '../disclosure.svelte.js'
|
|
18
|
+
|
|
19
|
+
let { ref = $bindable(null), ...p } = $props()
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
class: klass,
|
|
23
|
+
id,
|
|
24
|
+
role = 'dialog',
|
|
25
|
+
'aria-label': ariaLabel,
|
|
26
|
+
'aria-labelledBy': ariaLabelledBy,
|
|
27
|
+
'aria-describedby': ariaDescribedBy,
|
|
28
|
+
componentName = 'DisclosureContent',
|
|
29
|
+
portal = true,
|
|
30
|
+
scrollToAnchor = false,
|
|
31
|
+
|
|
32
|
+
// Slots
|
|
33
|
+
children,
|
|
34
|
+
|
|
35
|
+
// Event handlers are spread directly into ...rest
|
|
36
|
+
// Custom events are onopen and onclose
|
|
37
|
+
...restProps
|
|
38
|
+
} = p
|
|
39
|
+
|
|
40
|
+
const { picked: disclosureContentOpts, omitted: rest } = splitObject(
|
|
41
|
+
restProps,
|
|
42
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const { picked: transitionOpts, omitted: remaining } = splitObject(
|
|
46
|
+
rest,
|
|
47
|
+
TRANSITION_OPT_KEYS,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if (!id) throw new Error(`${componentName} requires an id`)
|
|
51
|
+
|
|
52
|
+
// Accessible name warning
|
|
53
|
+
if (role === 'dialog' && !hasAccessibleName(ariaLabel, ariaLabelledBy)) {
|
|
54
|
+
console.warn(
|
|
55
|
+
`DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let d = $derived(getDisclosure(id))
|
|
60
|
+
let show = $derived(d?.state.show)
|
|
61
|
+
|
|
62
|
+
$effect(_ => {
|
|
63
|
+
if (show && ref && scrollToAnchor) {
|
|
64
|
+
const anchor = markActiveAnchorIn(ref)
|
|
65
|
+
goToElement(anchor)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<!-- Snippets -->
|
|
71
|
+
{#snippet dc()}
|
|
72
|
+
<div
|
|
73
|
+
{...remaining}
|
|
74
|
+
{id}
|
|
75
|
+
class="disclosure-content {klass}"
|
|
76
|
+
{role}
|
|
77
|
+
bind:this={ref}
|
|
78
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
79
|
+
aria-label={ariaLabel}
|
|
80
|
+
aria-labelledby={ariaLabelledBy}
|
|
81
|
+
aria-describedby={ariaDescribedBy}
|
|
82
|
+
transition:applyTransition|global={transitionOpts}
|
|
83
|
+
>
|
|
84
|
+
{#if children}
|
|
85
|
+
{@render children()}
|
|
86
|
+
{/if}
|
|
87
|
+
</div>
|
|
88
|
+
{/snippet}
|
|
89
|
+
|
|
90
|
+
<!-- Render -->
|
|
91
|
+
{#if show}
|
|
92
|
+
{#if portal}
|
|
93
|
+
<Portal>{@render dc()}</Portal>
|
|
94
|
+
{:else}
|
|
95
|
+
{@render dc()}
|
|
96
|
+
{/if}
|
|
97
|
+
{/if}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import Icon from '../../Icon/Icon.svelte'
|
|
4
|
+
import {
|
|
5
|
+
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
6
|
+
disclosureTrigger,
|
|
7
|
+
} from '../disclosure.svelte.js'
|
|
8
|
+
|
|
9
|
+
let { show = $bindable(false), ...p } = $props()
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
class: klass = '',
|
|
13
|
+
componentName = 'DisclosureTrigger',
|
|
14
|
+
icon = 'tabler:menu',
|
|
15
|
+
iconClass,
|
|
16
|
+
'aria-haspopup': ariaHasPopup = 'dialog',
|
|
17
|
+
target,
|
|
18
|
+
|
|
19
|
+
// Slots
|
|
20
|
+
children,
|
|
21
|
+
...restProps
|
|
22
|
+
} = p
|
|
23
|
+
|
|
24
|
+
const { picked: triggerOpts, omitted: rest } = splitObject(
|
|
25
|
+
restProps,
|
|
26
|
+
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if (!target)
|
|
30
|
+
throw new Error(`${componentName} must contain a target property`)
|
|
31
|
+
|
|
32
|
+
// TODO: Test creating an IconSnippet to render the icon vs contents
|
|
33
|
+
// <script module> currently breaks when prettier is enabled. So, ¯\_(ツ)_/¯ if we can ever do that.
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<button
|
|
37
|
+
{...rest}
|
|
38
|
+
{target}
|
|
39
|
+
class="button {klass}"
|
|
40
|
+
aria-haspopup={ariaHasPopup}
|
|
41
|
+
use:disclosureTrigger={{
|
|
42
|
+
state: { show },
|
|
43
|
+
options: triggerOpts,
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{#if children}
|
|
47
|
+
{@render children()}
|
|
48
|
+
{:else if icon}
|
|
49
|
+
<Icon class={iconClass} {icon} />
|
|
50
|
+
{/if}
|
|
51
|
+
</button>
|