@splendidlabz/svelte 4.3.0 → 4.4.0
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 +23 -2
- package/components/Breadcrumbs/Breadcrumbs.svelte +10 -9
- package/components/Breadcrumbs/Crumb.svelte +2 -1
- package/components/ContentList/ContentList.svelte +1 -1
- package/components/Disclosure/Disclosure/DisclosureContent.svelte +5 -7
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +4 -6
- package/components/Disclosure/Disclosure/Old/DisclosureContentOld.svelte +97 -0
- package/components/Disclosure/Disclosure/Old/DisclosureTriggerOld.svelte +51 -0
- package/components/Disclosure/Drawer/DrawerContent.svelte +3 -3
- package/components/Disclosure/Drawer/drawer.js +0 -26
- package/components/Disclosure/DrawerNew/DrawerContent.svelte +34 -4
- package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +7 -4
- package/components/Disclosure/ModalNew/ModalContent.svelte +1 -1
- package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +3 -2
- package/components/Disclosure/disclosure.js +41 -40
- package/components/SVG/SVG.svelte +46 -0
- package/components/SVG/SVGGradient.svelte +37 -0
- package/components/SVG/index.js +2 -1
- package/package.json +3 -3
- package/actions/resize-observer.js +0 -43
- package/actions/scroll-observer.js +0 -47
- package/components/Disclosure/Disclosure/disclosure-popover.svelte.js +0 -7
- package/components/Disclosure/DisclosureNew/DisclosureCloseButton.svelte +0 -38
- package/components/Disclosure/DisclosureNew/DisclosureContent.svelte +0 -53
- package/components/Disclosure/DisclosureNew/DisclosureTrigger.svelte +0 -79
- package/components/Disclosure/DisclosureNew/disclosures.svelte.js +0 -55
- package/components/Disclosure/DisclosureNew/index.js +0 -5
- package/components/Disclosure/Drawer/DrawerNew.svelte +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @splendidlabz/svelte
|
|
2
2
|
|
|
3
|
+
## 4.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7466ea7: - Reworked Drawer to include disclosure type
|
|
8
|
+
- Improved breadcrumbs with customizable divider icons and classes
|
|
9
|
+
- Add `SVGGradient` component
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- Updated dependencies [7466ea7]
|
|
15
|
+
- @splendidlabz/utils@1.8.2
|
|
16
|
+
- @splendidlabz/styles@4.3.0
|
|
17
|
+
|
|
18
|
+
## 4.3.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @splendidlabz/utils@1.8.1
|
|
24
|
+
- @splendidlabz/styles@4.2.2
|
|
25
|
+
|
|
3
26
|
## 4.3.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
|
@@ -281,7 +304,6 @@
|
|
|
281
304
|
### Patch Changes
|
|
282
305
|
|
|
283
306
|
- a9128f4: Major work on Forms and Form element controls in this patch.
|
|
284
|
-
|
|
285
307
|
- Ensure `Form` works with normal `POST` request when `onSubmit` is not defined. Also included `felte` library for form validation in the future.
|
|
286
308
|
- `TextInput` must now take in either a `label` or `placeholder`.
|
|
287
309
|
- Add disabled and readonly styles to TextInput and its label
|
|
@@ -291,7 +313,6 @@
|
|
|
291
313
|
- Add disabled and readonly styles to checkbox and its label
|
|
292
314
|
|
|
293
315
|
There's some work on the internal `disclosure` action and stores as well.
|
|
294
|
-
|
|
295
316
|
- Change default `focusTarget` to `null` to facilitate usage in other components.
|
|
296
317
|
- Remove the need to pass in default `disclosure` options. This is now handled in the disclosure store automatically.
|
|
297
318
|
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
class: klass = '',
|
|
11
|
+
ulClass = '',
|
|
11
12
|
|
|
12
13
|
// Slots
|
|
13
14
|
children,
|
|
@@ -20,12 +21,14 @@
|
|
|
20
21
|
crumbs: [],
|
|
21
22
|
labelCase: 'title',
|
|
22
23
|
divider: 'tabler:chevron-right',
|
|
24
|
+
dividerClass: '',
|
|
23
25
|
ariaCurrentType: 'page',
|
|
24
26
|
startingDepth: 0,
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const opts = mergeOpts(defaultOptions, rest)
|
|
28
|
-
const { startingDepth, ariaCurrentType, labelCase } =
|
|
30
|
+
const { startingDepth, ariaCurrentType, labelCase, divider, dividerClass } =
|
|
31
|
+
opts
|
|
29
32
|
|
|
30
33
|
let trailingSlash = $derived(hasTrailingSlash(pathname))
|
|
31
34
|
let crumbs = $derived(
|
|
@@ -53,6 +56,8 @@
|
|
|
53
56
|
return {
|
|
54
57
|
label: crumb,
|
|
55
58
|
labelCase,
|
|
59
|
+
divider: crumb.divider || divider,
|
|
60
|
+
dividerClass: crumb.dividerClass || dividerClass,
|
|
56
61
|
href:
|
|
57
62
|
'/' +
|
|
58
63
|
urlArray.slice(0, index + 1).join('/') +
|
|
@@ -65,12 +70,12 @@
|
|
|
65
70
|
</script>
|
|
66
71
|
|
|
67
72
|
<nav class={`breadcrumbs ${klass}`} aria-label="Breadcrumbs">
|
|
68
|
-
<ul>
|
|
73
|
+
<ul class={ulClass}>
|
|
69
74
|
{#if before}
|
|
70
75
|
<li class="crumb">
|
|
71
76
|
{@render before?.()}
|
|
72
77
|
<span class="crumb-divider">
|
|
73
|
-
<Icon icon={
|
|
78
|
+
<Icon class={dividerClass} icon={divider} />
|
|
74
79
|
</span>
|
|
75
80
|
</li>
|
|
76
81
|
{/if}
|
|
@@ -78,12 +83,8 @@
|
|
|
78
83
|
{#if children}
|
|
79
84
|
{@render children()}
|
|
80
85
|
{:else}
|
|
81
|
-
{#each crumbs as crumb
|
|
82
|
-
<Crumb
|
|
83
|
-
{...crumb}
|
|
84
|
-
divider={opts.divider}
|
|
85
|
-
isLast={index === crumbs.length - 1}
|
|
86
|
-
/>
|
|
86
|
+
{#each crumbs as crumb (crumb.href)}
|
|
87
|
+
<Crumb {...crumb} />
|
|
87
88
|
{/each}
|
|
88
89
|
{/if}
|
|
89
90
|
{@render after?.()}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
ariaCurrentType = 'page',
|
|
11
11
|
isLast = null,
|
|
12
12
|
divider = 'tabler:chevron-right',
|
|
13
|
+
dividerClass = '',
|
|
13
14
|
href = '',
|
|
14
15
|
labelCase = 'title',
|
|
15
16
|
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
{@render Snippet.block(before)}
|
|
46
47
|
<a class={aClass} {href}>{label}</a>
|
|
47
48
|
<div class="crumb-divider">
|
|
48
|
-
<Icon icon={divider} />
|
|
49
|
+
<Icon class={dividerClass} icon={divider} />
|
|
49
50
|
</div>
|
|
50
51
|
{/if}
|
|
51
52
|
</li>
|
|
@@ -26,14 +26,12 @@
|
|
|
26
26
|
'aria-labelledBy': ariaLabelledBy,
|
|
27
27
|
'aria-describedby': ariaDescribedBy,
|
|
28
28
|
componentName = 'DisclosureContent',
|
|
29
|
+
|
|
29
30
|
portal = true,
|
|
30
31
|
scrollToAnchor = false,
|
|
31
32
|
|
|
32
33
|
// Slots
|
|
33
34
|
children,
|
|
34
|
-
|
|
35
|
-
// Event handlers are spread directly into ...rest
|
|
36
|
-
// Custom events are onopen and onclose
|
|
37
35
|
...restProps
|
|
38
36
|
} = p
|
|
39
37
|
|
|
@@ -71,14 +69,14 @@
|
|
|
71
69
|
{#snippet dc()}
|
|
72
70
|
<div
|
|
73
71
|
{...remaining}
|
|
72
|
+
bind:this={ref}
|
|
74
73
|
{id}
|
|
75
74
|
class="disclosure-content {klass}"
|
|
76
|
-
{
|
|
77
|
-
bind:this={ref}
|
|
78
|
-
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
75
|
+
aria-describedby={ariaDescribedBy}
|
|
79
76
|
aria-label={ariaLabel}
|
|
80
77
|
aria-labelledby={ariaLabelledBy}
|
|
81
|
-
|
|
78
|
+
{role}
|
|
79
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
82
80
|
transition:applyTransition|global={transitionOpts}
|
|
83
81
|
>
|
|
84
82
|
{#if children}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
disclosureTrigger,
|
|
7
7
|
} from '../disclosure.svelte.js'
|
|
8
8
|
|
|
9
|
-
let { show = $bindable(false), ...p } = $props()
|
|
9
|
+
let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
|
|
10
10
|
|
|
11
11
|
const {
|
|
12
12
|
class: klass = '',
|
|
@@ -28,16 +28,14 @@
|
|
|
28
28
|
|
|
29
29
|
if (!target)
|
|
30
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
31
|
</script>
|
|
35
32
|
|
|
36
33
|
<button
|
|
37
34
|
{...rest}
|
|
38
|
-
{
|
|
39
|
-
class="button {klass}"
|
|
35
|
+
class="button disclosure-trigger {klass}"
|
|
40
36
|
aria-haspopup={ariaHasPopup}
|
|
37
|
+
data-show={show}
|
|
38
|
+
{target}
|
|
41
39
|
use:disclosureTrigger={{
|
|
42
40
|
state: { show },
|
|
43
41
|
options: triggerOpts,
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import {
|
|
4
|
+
hasAccessibleName,
|
|
5
|
+
markActiveAnchorIn,
|
|
6
|
+
scrollToElement,
|
|
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
|
+
scrollToElement(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>
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
{#snippet drawerContent({ portal = false } = {})}
|
|
68
68
|
<DisclosureContent
|
|
69
69
|
{...rest}
|
|
70
|
-
componentName="DrawerContent"
|
|
71
70
|
{id}
|
|
72
71
|
{style}
|
|
73
|
-
{portal}
|
|
74
|
-
{placement}
|
|
75
72
|
class="drawer-content {klass}"
|
|
73
|
+
componentName="DrawerContent"
|
|
74
|
+
{placement}
|
|
75
|
+
{portal}
|
|
76
76
|
bind:ref
|
|
77
77
|
/>
|
|
78
78
|
{/snippet}
|
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
export const DRAWER_CONTENT_OPTS = {
|
|
2
|
-
position: 'fixed',
|
|
3
|
-
placement: 'left',
|
|
4
|
-
backdrop: true,
|
|
5
|
-
blurBackdrop: true,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const DRAWER_POSITION_OPTS = {
|
|
9
|
-
static: {
|
|
10
|
-
placement: 'top',
|
|
11
|
-
transition: 'slide',
|
|
12
|
-
closeOnOutsideClick: false,
|
|
13
|
-
closeOnEscapeButton: false,
|
|
14
|
-
},
|
|
15
|
-
absolute: {
|
|
16
|
-
placement: 'top',
|
|
17
|
-
transition: 'slide',
|
|
18
|
-
},
|
|
19
|
-
fixed: {
|
|
20
|
-
transition: 'fly',
|
|
21
|
-
focusManagement: 'trap',
|
|
22
|
-
inertOthers: true,
|
|
23
|
-
preventBodyScroll: true,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
1
|
// Use logical properties straight up
|
|
28
2
|
export function getTBLRValues({ placement, position }) {
|
|
29
3
|
const style = { position }
|
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { delay } from '@splendidlabz/utils'
|
|
2
|
+
import { delay, splitObject, toStyleString } from '@splendidlabz/utils'
|
|
3
3
|
import { getParentElement } from '@splendidlabz/utils/dom'
|
|
4
4
|
import { onMount } from 'svelte'
|
|
5
5
|
import { mergeEntry, setEntry } from '../../../actions/sync.svelte.js'
|
|
6
|
+
import { TRANSITION_OPT_KEYS } from '../../../utils/transitions.js'
|
|
7
|
+
import DisclosureContent from '../Disclosure/DisclosureContent.svelte'
|
|
6
8
|
import ModalContent from '../ModalNew/ModalContent.svelte'
|
|
7
9
|
import PopoverContent from '../PopoverNew/PopoverContent.svelte'
|
|
10
|
+
import { getTBLRValues } from './drawer.js'
|
|
8
11
|
|
|
9
12
|
let {
|
|
10
13
|
class: klass = '',
|
|
11
14
|
type = 'modal',
|
|
12
15
|
ref = $bindable(null),
|
|
16
|
+
style,
|
|
17
|
+
position,
|
|
18
|
+
placement,
|
|
13
19
|
...p
|
|
14
20
|
} = $props()
|
|
15
21
|
|
|
16
|
-
const {
|
|
22
|
+
const { picked: transitionOpts, omitted } = splitObject(
|
|
23
|
+
p,
|
|
24
|
+
TRANSITION_OPT_KEYS,
|
|
25
|
+
)
|
|
26
|
+
const { id, ...rest } = omitted
|
|
17
27
|
const useReferenceBoundaries = type === 'popover'
|
|
18
28
|
|
|
29
|
+
// Using DisclosureContent for relative position for nice slide effect.
|
|
30
|
+
// Can potentially do this for absolute position too
|
|
31
|
+
let disclosureContentProps = {}
|
|
32
|
+
if (position === 'relative') {
|
|
33
|
+
type = 'disclosure'
|
|
34
|
+
const TBLR = getTBLRValues({ placement, position })
|
|
35
|
+
const styleString = toStyleString(TBLR) + style
|
|
36
|
+
disclosureContentProps = {
|
|
37
|
+
portal: false,
|
|
38
|
+
style: styleString,
|
|
39
|
+
placement,
|
|
40
|
+
transition: 'slide',
|
|
41
|
+
...transitionOpts,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
19
45
|
let referenceNode = $state(null)
|
|
20
46
|
setEntry(id, { type })
|
|
21
47
|
|
|
@@ -27,19 +53,23 @@
|
|
|
27
53
|
|
|
28
54
|
const propsToPass = {
|
|
29
55
|
id,
|
|
56
|
+
style,
|
|
57
|
+
placement,
|
|
30
58
|
...rest,
|
|
31
|
-
componentName: '
|
|
59
|
+
componentName: 'DrawerContent',
|
|
32
60
|
class: `drawer-content ${klass}`,
|
|
33
61
|
}
|
|
34
62
|
</script>
|
|
35
63
|
|
|
36
64
|
{#if type === 'modal'}
|
|
37
65
|
<ModalContent bind:ref {...propsToPass} />
|
|
38
|
-
{:else}
|
|
66
|
+
{:else if type === 'popover'}
|
|
39
67
|
<PopoverContent
|
|
40
68
|
{referenceNode}
|
|
41
69
|
{useReferenceBoundaries}
|
|
42
70
|
bind:ref
|
|
43
71
|
{...propsToPass}
|
|
44
72
|
/>
|
|
73
|
+
{:else if type === 'disclosure'}
|
|
74
|
+
<DisclosureContent bind:ref {...propsToPass} {...disclosureContentProps} />
|
|
45
75
|
{/if}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { getEntry } from '../../../actions/sync.svelte.js'
|
|
3
|
+
import DisclosureTrigger from '../Disclosure/DisclosureTrigger.svelte'
|
|
3
4
|
import ModalTrigger from '../ModalNew/ModalTrigger.svelte'
|
|
4
5
|
import PopoverTrigger from '../PopoverNew/PopoverTrigger.svelte'
|
|
5
|
-
let { show = $bindable(false), target, ...p } = $props()
|
|
6
6
|
|
|
7
|
+
let { show = $bindable(false), target, ...p } = $props()
|
|
7
8
|
const sync = $derived(getEntry(target))
|
|
8
9
|
const type = $derived(sync?.type)
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
12
|
{#if type === 'modal'}
|
|
12
|
-
<ModalTrigger {...p} {
|
|
13
|
-
{:else}
|
|
14
|
-
<PopoverTrigger {...p} {
|
|
13
|
+
<ModalTrigger {...p} {show} {target} />
|
|
14
|
+
{:else if type === 'popover'}
|
|
15
|
+
<PopoverTrigger {...p} {show} {target} />
|
|
16
|
+
{:else if type === 'disclosure'}
|
|
17
|
+
<DisclosureTrigger {...p} {show} {target} />
|
|
15
18
|
{/if}
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
import { delay } from '@splendidlabz/utils'
|
|
3
3
|
import { onMount } from 'svelte'
|
|
4
4
|
import Icon from '../../Icon/Icon.svelte'
|
|
5
|
+
|
|
5
6
|
let { show = $bindable(null), ref = $bindable(null), ...p } = $props()
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
|
-
componentName = 'PopoverTrigger',
|
|
9
9
|
class: klass = '',
|
|
10
|
+
componentName = 'PopoverTrigger',
|
|
10
11
|
icon = 'tabler:menu',
|
|
11
12
|
iconClass,
|
|
12
13
|
|
|
13
14
|
// Props
|
|
14
15
|
target,
|
|
15
|
-
actions,
|
|
16
|
+
// actions, // Don't think I used this
|
|
16
17
|
|
|
17
18
|
// Slots
|
|
18
19
|
children,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { delay, omitEmpty } from '@splendidlabz/utils'
|
|
1
2
|
import {
|
|
2
3
|
Focusable,
|
|
3
4
|
addListeners,
|
|
@@ -8,7 +9,6 @@ import {
|
|
|
8
9
|
removeListeners,
|
|
9
10
|
trapFocus,
|
|
10
11
|
} from '@splendidlabz/utils/dom'
|
|
11
|
-
import { delay, omitEmpty } from '@splendidlabz/utils'
|
|
12
12
|
import {
|
|
13
13
|
getDisclosure as getD,
|
|
14
14
|
getDisclosures,
|
|
@@ -45,14 +45,21 @@ export const DISCLOSURE_TRIGGER_OPT_KEYS = Object.keys(
|
|
|
45
45
|
* @property {(string|HTMLElement)} focusTargetWhenOpening - Focus target when disclosure content is opened. Can be 'first', 'content', or an HTMLElement.
|
|
46
46
|
*/
|
|
47
47
|
export const DEFAULT_DISCLOSURE_CONTENT_OPTS = {
|
|
48
|
-
|
|
49
|
-
closeOnEscapeButton: true,
|
|
48
|
+
lightDismiss: true,
|
|
50
49
|
focusManagement: 'manage', // false, `manage`, `trap`
|
|
51
|
-
focusTargetWhenOpening: 'content', // || false, 'first', 'content'.
|
|
50
|
+
focusTargetWhenOpening: 'content', // || false, 'first', 'content'.
|
|
52
51
|
focusTriggerOnClose: true,
|
|
53
52
|
inertOthers: false,
|
|
54
53
|
preventBodyScroll: false,
|
|
55
54
|
useAutoWidth: false,
|
|
55
|
+
onclick: null,
|
|
56
|
+
onkeydown: null,
|
|
57
|
+
ontoggle: null,
|
|
58
|
+
onbeforetoggle: null,
|
|
59
|
+
onopen: null,
|
|
60
|
+
onbeforeopen: null,
|
|
61
|
+
onclose: null,
|
|
62
|
+
onbeforeclose: null,
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
export const DISCLOSURE_CONTENT_OPT_KEYS = Object.keys(
|
|
@@ -66,6 +73,7 @@ export const DISCLOSURE_CONTENT_OPT_KEYS = Object.keys(
|
|
|
66
73
|
* @prop {DisclosureTriggerOpts} props - The trigger options.
|
|
67
74
|
*/
|
|
68
75
|
export function disclosureTrigger(node, props = {}) {
|
|
76
|
+
console.log('dt running')
|
|
69
77
|
const targetId = node.getAttribute('target')
|
|
70
78
|
|
|
71
79
|
const disclosureInfo = {
|
|
@@ -97,12 +105,6 @@ export function disclosureTrigger(node, props = {}) {
|
|
|
97
105
|
node,
|
|
98
106
|
handler: tabOntoContent,
|
|
99
107
|
},
|
|
100
|
-
// Testing with removing this feature
|
|
101
|
-
// {
|
|
102
|
-
// event: 'keydown',
|
|
103
|
-
// node,
|
|
104
|
-
// handler: backToDisclosureContent,
|
|
105
|
-
// },
|
|
106
108
|
{
|
|
107
109
|
event: 'pointerenter',
|
|
108
110
|
node,
|
|
@@ -127,35 +129,26 @@ export function disclosureTrigger(node, props = {}) {
|
|
|
127
129
|
|
|
128
130
|
function handleClick(event) {
|
|
129
131
|
if (d.options.showOnClick) {
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
+
const { show } = d.state
|
|
133
|
+
if (show === false) return open(d)
|
|
134
|
+
if (show === true) return close(d)
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
function closeOnEscapeButton(event) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
const { lightDismiss } = d.options
|
|
140
|
+
if (event.key !== 'Escape') return
|
|
141
|
+
if (lightDismiss) return close(d)
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
function tabOntoContent(event) {
|
|
142
145
|
if (d.state.show === false) return
|
|
143
|
-
console.log('tabOntoContent')
|
|
144
146
|
if (isTab(event)) {
|
|
145
147
|
event.preventDefault()
|
|
146
148
|
d.nodes.contentFocusables.first?.focus()
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
// function backToDisclosureContent(event) {
|
|
151
|
-
// if (d.options.shiftTabBackToContent === false) return
|
|
152
|
-
// if (isShiftTab(event) && d.state.show === true) {
|
|
153
|
-
// setTimeout(_ => {
|
|
154
|
-
// d.nodes.content.focus({ preventScroll: true })
|
|
155
|
-
// }, 0)
|
|
156
|
-
// }
|
|
157
|
-
// }
|
|
158
|
-
|
|
159
152
|
function handlePointerEnter(event) {
|
|
160
153
|
if (d.options.showOnHover) {
|
|
161
154
|
d.state.pointerLocation = 'trigger'
|
|
@@ -200,6 +193,8 @@ export function disclosureTrigger(node, props = {}) {
|
|
|
200
193
|
* @prop {DisclosureContentOpts} props - The trigger options.
|
|
201
194
|
*/
|
|
202
195
|
export function disclosureContent(node, props = {}) {
|
|
196
|
+
console.log('dc running')
|
|
197
|
+
|
|
203
198
|
const disclosureContentID = node.getAttribute('id')
|
|
204
199
|
const contentFocusables = Focusable(node)
|
|
205
200
|
|
|
@@ -222,7 +217,7 @@ export function disclosureContent(node, props = {}) {
|
|
|
222
217
|
// Opening actions
|
|
223
218
|
node.setAttribute('tabindex', '-1')
|
|
224
219
|
|
|
225
|
-
const { focusTargetWhenOpening, useAutoWidth } = d.options
|
|
220
|
+
const { focusTargetWhenOpening, useAutoWidth, onopen, ontoggle } = d.options
|
|
226
221
|
|
|
227
222
|
if (d.options.inertOthers) makeOthersInert(d)
|
|
228
223
|
if (d.options.preventBodyScroll) preventBodyScroll()
|
|
@@ -235,13 +230,16 @@ export function disclosureContent(node, props = {}) {
|
|
|
235
230
|
// Setting focus requires timeout. Otherwise, it won't work.
|
|
236
231
|
setTimeout(_ => {
|
|
237
232
|
if (focusTargetWhenOpening) {
|
|
238
|
-
|
|
239
|
-
if (
|
|
240
|
-
if (
|
|
233
|
+
const target = focusTargetWhenOpening
|
|
234
|
+
if (target === 'content') node.focus()
|
|
235
|
+
if (target === 'first') contentFocusables.first?.focus()
|
|
236
|
+
if (target === 'second') contentFocusables[1]?.focus()
|
|
237
|
+
if (target instanceof HTMLElement) target.focus()
|
|
241
238
|
}
|
|
242
239
|
|
|
243
|
-
//
|
|
244
|
-
|
|
240
|
+
// Run opening functions
|
|
241
|
+
if (typeof onopen === 'function') onopen(d)
|
|
242
|
+
if (typeof ontoggle === 'function') ontoggle(d)
|
|
245
243
|
}, 0)
|
|
246
244
|
|
|
247
245
|
// Add event listeners
|
|
@@ -251,11 +249,6 @@ export function disclosureContent(node, props = {}) {
|
|
|
251
249
|
node: document,
|
|
252
250
|
handler: handleOutsideClick,
|
|
253
251
|
},
|
|
254
|
-
// {
|
|
255
|
-
// event: 'keydown',
|
|
256
|
-
// node: document,
|
|
257
|
-
// handler: closeAllOnEscape,
|
|
258
|
-
// },
|
|
259
252
|
{
|
|
260
253
|
event: 'keydown',
|
|
261
254
|
node,
|
|
@@ -286,7 +279,7 @@ export function disclosureContent(node, props = {}) {
|
|
|
286
279
|
// ========================
|
|
287
280
|
// Close if click is outside of contentNode and triggerNode
|
|
288
281
|
function handleOutsideClick(event) {
|
|
289
|
-
if (d.options.
|
|
282
|
+
if (d.options.lightDismiss === false) return
|
|
290
283
|
if (d.nodes.content.contains(event.target)) return
|
|
291
284
|
if (d.nodes.trigger.contains(event.target)) return
|
|
292
285
|
// Only close if state is currently set to show
|
|
@@ -323,7 +316,7 @@ export function disclosureContent(node, props = {}) {
|
|
|
323
316
|
})
|
|
324
317
|
}
|
|
325
318
|
|
|
326
|
-
if (d.options.
|
|
319
|
+
if (d.options.lightDismiss) closeOnEscape(event)
|
|
327
320
|
}
|
|
328
321
|
|
|
329
322
|
function closeOnEscape(event) {
|
|
@@ -346,6 +339,9 @@ export function disclosureContent(node, props = {}) {
|
|
|
346
339
|
// Methods
|
|
347
340
|
// ========================
|
|
348
341
|
export function open(d) {
|
|
342
|
+
const { onbeforeopen, onbeforetoggle } = d.options
|
|
343
|
+
if (typeof onbeforeopen === 'function') onbeforeopen(d)
|
|
344
|
+
if (typeof onbeforetoggle === 'function') onbeforetoggle(d)
|
|
349
345
|
if (d.state.show === true) return
|
|
350
346
|
d.state.show = true
|
|
351
347
|
const { trigger } = d.nodes
|
|
@@ -360,10 +356,13 @@ export function open(d) {
|
|
|
360
356
|
}
|
|
361
357
|
|
|
362
358
|
export function close(d, { shouldFocusTrigger = false } = {}) {
|
|
359
|
+
const { onbeforeclose, onbeforetoggle, onclose, ontoggle } = d.options
|
|
360
|
+
if (typeof onbeforeclose === 'function') onbeforeclose(d)
|
|
361
|
+
if (typeof onbeforetoggle === 'function') onbeforetoggle(d)
|
|
363
362
|
if (d.state.show === false) return
|
|
364
363
|
d.state.show = false
|
|
365
364
|
|
|
366
|
-
const { trigger
|
|
365
|
+
const { trigger } = d.nodes
|
|
367
366
|
trigger.setAttribute('aria-expanded', d.state.show)
|
|
368
367
|
revertInert(d)
|
|
369
368
|
|
|
@@ -371,7 +370,9 @@ export function close(d, { shouldFocusTrigger = false } = {}) {
|
|
|
371
370
|
|
|
372
371
|
// Dispatch a close event
|
|
373
372
|
// If check because we can close disclosure content so quickly in some implementations it hasn't been opened yet. Example: Combobox.
|
|
374
|
-
if (
|
|
373
|
+
if (typeof onclose === 'function') onclose(d)
|
|
374
|
+
if (typeof ontoggle === 'function') ontoggle(d)
|
|
375
|
+
// if (content) content.dispatchEvent(new CustomEvent('close'))
|
|
375
376
|
|
|
376
377
|
// If it's mouse out, we no need to change focus back to trigger. Only bring focus back to trigger when using keyboard events, and only when necessary
|
|
377
378
|
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Inline SVG renderer for files under `/src/svg` or `/src/svgs`.
|
|
4
|
+
*
|
|
5
|
+
* - Renders the raw SVG content via `import.meta.glob` lookups.
|
|
6
|
+
* - No slot support; `children` is intentionally dropped.
|
|
7
|
+
*
|
|
8
|
+
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* <!-- Renders /src/svg/logo.svg -->
|
|
11
|
+
* <SVG icon="logo" class="w-6 h-6" />
|
|
12
|
+
* @example
|
|
13
|
+
* <!-- Use DOM parser when the SVG needs runtime DOM APIs -->
|
|
14
|
+
* <SVG icon="spinner" parser="dom" style={{ color: 'rebeccapurple' }} />
|
|
15
|
+
* @throws {Error} icon property is required
|
|
16
|
+
* @throws {Error} When the requested SVG file cannot be found
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {object} SVGProps
|
|
21
|
+
* @property {string} icon - Basename of the SVG file (without .svg)
|
|
22
|
+
* @property {object|string} [style] - Inline styles. Object is converted with `toStyleString`
|
|
23
|
+
* @property {"naive"|"dom"} [parser="naive"] - Parsing strategy
|
|
24
|
+
* @property {*} [children] - Ignored; component does not support slots
|
|
25
|
+
*/
|
|
2
26
|
import { toStyleString } from '@splendidlabz/utils'
|
|
3
27
|
import { onMount } from 'svelte'
|
|
4
28
|
import { domParser, naiveParser } from './parser.js'
|
|
29
|
+
/** @type {SVGProps} */
|
|
5
30
|
const {
|
|
6
31
|
icon,
|
|
7
32
|
style,
|
|
@@ -45,5 +70,26 @@
|
|
|
45
70
|
}
|
|
46
71
|
</script>
|
|
47
72
|
|
|
73
|
+
<!--
|
|
74
|
+
@component
|
|
75
|
+
Inline SVG renderer for files under `/src/svg` or `/src/svgs`.
|
|
76
|
+
|
|
77
|
+
- Props:
|
|
78
|
+
- icon (string, required): Basename of the SVG file (without .svg)
|
|
79
|
+
- style (object|string, optional): Inline styles; objects are converted with `toStyleString`
|
|
80
|
+
- parser ("naive"|"dom", optional, default "naive"): Parsing strategy
|
|
81
|
+
- Slots: none
|
|
82
|
+
- Events: none
|
|
83
|
+
- Errors:
|
|
84
|
+
- Throws if `icon` is missing
|
|
85
|
+
- Throws if the SVG file cannot be found
|
|
86
|
+
|
|
87
|
+
Usage:
|
|
88
|
+
```svelte
|
|
89
|
+
<SVG icon="logo" class="w-6 h-6" />
|
|
90
|
+
<SVG icon="spinner" parser="dom" style={{ color: 'rebeccapurple' }} />
|
|
91
|
+
```
|
|
92
|
+
-->
|
|
93
|
+
|
|
48
94
|
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
49
95
|
{@html svg}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
const {
|
|
3
|
+
id,
|
|
4
|
+
angle,
|
|
5
|
+
stops = 2, // Or an array with the actual stop percentages
|
|
6
|
+
} = $props()
|
|
7
|
+
|
|
8
|
+
const _stops = (Array.isArray(stops) ? stops : Array(stops).fill({})).map(
|
|
9
|
+
(stop, index) => ({
|
|
10
|
+
offset: stop.offset || `${(index * 100) / (stops - 1)}%`,
|
|
11
|
+
'stop-color': stop.color || `var(--gradient-stop-${index + 1})`,
|
|
12
|
+
}),
|
|
13
|
+
)
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<!-- Inspiration -->
|
|
17
|
+
<!-- https://fvsch.com/svg-gradient-fill -->
|
|
18
|
+
<svg
|
|
19
|
+
style="position:absolute; width:0; height:0; overflow:hidden"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
focusable="false"
|
|
22
|
+
height="0"
|
|
23
|
+
width="0"
|
|
24
|
+
>
|
|
25
|
+
<defs>
|
|
26
|
+
<linearGradient
|
|
27
|
+
{id}
|
|
28
|
+
gradientTransform="rotate({angle} 0.5 0.5)"
|
|
29
|
+
x2="0"
|
|
30
|
+
y1="1"
|
|
31
|
+
>
|
|
32
|
+
{#each _stops as stop (stop.offset)}
|
|
33
|
+
<stop {...stop}></stop>
|
|
34
|
+
{/each}
|
|
35
|
+
</linearGradient>
|
|
36
|
+
</defs>
|
|
37
|
+
</svg>
|
package/components/SVG/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.4.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint . --fix",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@floating-ui/dom": "^1.6.13",
|
|
23
23
|
"@iconify/svelte": "^4.2.0",
|
|
24
|
-
"@splendidlabz/styles": "4.
|
|
25
|
-
"@splendidlabz/utils": "1.8.
|
|
24
|
+
"@splendidlabz/styles": "4.3.0",
|
|
25
|
+
"@splendidlabz/utils": "1.8.2",
|
|
26
26
|
"autosuggest-highlight": "^3.3.4",
|
|
27
27
|
"lodash-es": "^4.17.21",
|
|
28
28
|
"node-html-parser": "^7.0.1"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
// TODO: Move to Utils/Dom
|
|
3
|
-
// Components to update before switching: Switcheroo, Masonry
|
|
4
|
-
// Can also use breakpointsObserver for Switcheroo instead.
|
|
5
|
-
import { notEmpty } from '@splendidlabz/utils'
|
|
6
|
-
|
|
7
|
-
export function resizeObserver(node, options) {
|
|
8
|
-
// We set the option here to prevent observer from being created unless necessary.
|
|
9
|
-
if (!options.observe) return
|
|
10
|
-
|
|
11
|
-
const observer = new ResizeObserver(observerFn)
|
|
12
|
-
|
|
13
|
-
function observerFn(entries) {
|
|
14
|
-
for (const entry of entries) {
|
|
15
|
-
if (options.callback) {
|
|
16
|
-
options.callback({ node, entry, observer })
|
|
17
|
-
} else {
|
|
18
|
-
node.dispatchEvent(
|
|
19
|
-
new CustomEvent('resize', {
|
|
20
|
-
detail: { node, entry, observer },
|
|
21
|
-
}),
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
observer.observe(node)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
destroy() {
|
|
31
|
-
observer.unobserve(node)
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Need to change Switcheroo before we remove this.
|
|
37
|
-
export function createBreakpointArray(breakpoints) {
|
|
38
|
-
if (notEmpty(breakpoints)) {
|
|
39
|
-
return Object.entries(breakpoints).map(([key, value]) => {
|
|
40
|
-
return { breakpoint: parseFloat(key), value }
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
|
|
3
|
-
// TODO: Move to Utils/Dom
|
|
4
|
-
/**
|
|
5
|
-
* Scroll Observer
|
|
6
|
-
* @param {Number} threshold Float between 0 to 1. When to fire a threshold event.
|
|
7
|
-
* @param {Number} tolerance Float between 0 to 1. Tolerance for event firing.
|
|
8
|
-
*/
|
|
9
|
-
export function scrollObserver(
|
|
10
|
-
node,
|
|
11
|
-
{
|
|
12
|
-
threshold = 0, // Float between 0 to 1.
|
|
13
|
-
tolerance = 0.1, // Float between 0 to 1. Tolerance for event firing
|
|
14
|
-
} = {},
|
|
15
|
-
) {
|
|
16
|
-
let prevScrollTop = 0
|
|
17
|
-
|
|
18
|
-
function observe(event) {
|
|
19
|
-
const { documentElement } = document
|
|
20
|
-
const scrollTop = documentElement.scrollTop
|
|
21
|
-
const scrollDirection = scrollTop > prevScrollTop ? 'down' : 'up'
|
|
22
|
-
const scrollPercent =
|
|
23
|
-
scrollTop / (documentElement.scrollHeight - documentElement.clientHeight)
|
|
24
|
-
|
|
25
|
-
if (scrollDirection === 'down') {
|
|
26
|
-
node.dispatchEvent(new CustomEvent('scrolldown'))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (scrollDirection === 'up') {
|
|
30
|
-
node.dispatchEvent(new CustomEvent('scrollUp'))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (scrollPercent > threshold && scrollPercent < threshold + tolerance) {
|
|
34
|
-
node.dispatchEvent(new CustomEvent(`${scrollDirection}:threshold`))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
prevScrollTop = scrollTop
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
node.addEventListener('scroll', observe)
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
destroy() {
|
|
44
|
-
node.removeEventListener('scroll', observe)
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import Icon from '../../Icon/Icon.svelte'
|
|
3
|
-
|
|
4
|
-
let { ref = $bindable(null), ...p } = $props()
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
class: klass = '',
|
|
8
|
-
icon = 'tabler:x',
|
|
9
|
-
iconClass = '',
|
|
10
|
-
target = null,
|
|
11
|
-
children,
|
|
12
|
-
...rest
|
|
13
|
-
} = p
|
|
14
|
-
|
|
15
|
-
const targetAction = target ? 'hide' : null
|
|
16
|
-
|
|
17
|
-
function closeDrawer() {
|
|
18
|
-
const popover =
|
|
19
|
-
document.querySelector(`[#"${target}"]`) || ref.closest('[popover]')
|
|
20
|
-
popover.hidePopover()
|
|
21
|
-
}
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
<button
|
|
25
|
-
{...rest}
|
|
26
|
-
aria-label="Close"
|
|
27
|
-
class="button-icon {klass}"
|
|
28
|
-
popovertarget={target}
|
|
29
|
-
popovertargetaction={targetAction}
|
|
30
|
-
bind:this={ref}
|
|
31
|
-
onclick={closeDrawer}
|
|
32
|
-
>
|
|
33
|
-
{#if children}
|
|
34
|
-
{@render children()}
|
|
35
|
-
{:else}
|
|
36
|
-
<Icon class={iconClass} {icon} />
|
|
37
|
-
{/if}
|
|
38
|
-
</button>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { hasAccessibleName } from '@splendidlabz/utils/dom'
|
|
3
|
-
let {
|
|
4
|
-
class: klass = '',
|
|
5
|
-
as = 'dialog',
|
|
6
|
-
ref = $bindable(null),
|
|
7
|
-
...p
|
|
8
|
-
} = $props()
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
componentName = 'DisclosureContent',
|
|
12
|
-
'aria-label': ariaLabel,
|
|
13
|
-
'aria-labelledBy': ariaLabelledBy,
|
|
14
|
-
'aria-describedby': ariaDescribedBy,
|
|
15
|
-
|
|
16
|
-
// Props
|
|
17
|
-
id,
|
|
18
|
-
// scrollToAnchor = false,
|
|
19
|
-
|
|
20
|
-
// Slots
|
|
21
|
-
children,
|
|
22
|
-
...rest
|
|
23
|
-
} = p
|
|
24
|
-
|
|
25
|
-
if (!id) throw new Error(`${componentName} requires an id`)
|
|
26
|
-
|
|
27
|
-
// Accessible name warning
|
|
28
|
-
if (as === 'dialog' && !hasAccessibleName(ariaLabel, ariaLabelledBy)) {
|
|
29
|
-
console.warn(
|
|
30
|
-
`${componentName} (id: ${id}) is a dialog and should have an accessible name. Please add an accessible name with aria-label or aria-labelledby.`,
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
// Choose to use either a dialog or a popover
|
|
34
|
-
// Having both results in confusing styles (for now)
|
|
35
|
-
if (modal) {
|
|
36
|
-
popover = 'null'
|
|
37
|
-
klass = `modal ${klass}`
|
|
38
|
-
}
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<!-- Snippets -->
|
|
42
|
-
<svelte:element
|
|
43
|
-
this={as}
|
|
44
|
-
{...rest}
|
|
45
|
-
{id}
|
|
46
|
-
{popover}
|
|
47
|
-
class={klass}
|
|
48
|
-
aria-label={ariaLabel}
|
|
49
|
-
aria-labelledby={ariaLabelledBy}
|
|
50
|
-
aria-describedby={ariaDescribedBy}
|
|
51
|
-
>
|
|
52
|
-
{#if children}{@render children()}{/if}
|
|
53
|
-
</svelte:element>
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import Icon from '../../Icon/Icon.svelte'
|
|
3
|
-
import { disclosureTrigger } from './disclosures.svelte.js'
|
|
4
|
-
|
|
5
|
-
let {
|
|
6
|
-
show = $bindable(false),
|
|
7
|
-
type = 'popover',
|
|
8
|
-
ref = $bindable(null),
|
|
9
|
-
...p
|
|
10
|
-
} = $props()
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
componentName = 'Trigger',
|
|
14
|
-
class: klass = '',
|
|
15
|
-
icon = 'tabler:menu',
|
|
16
|
-
iconClass,
|
|
17
|
-
|
|
18
|
-
// Props
|
|
19
|
-
target,
|
|
20
|
-
'aria-haspopup': ariaHasPopup = 'dialog',
|
|
21
|
-
|
|
22
|
-
// Slots
|
|
23
|
-
children,
|
|
24
|
-
|
|
25
|
-
// Event listeners
|
|
26
|
-
onclick = null,
|
|
27
|
-
...rest
|
|
28
|
-
} = p
|
|
29
|
-
|
|
30
|
-
if (!target) {
|
|
31
|
-
throw new Error(`${componentName} must contain a target property`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let popoverProps = {}
|
|
35
|
-
let modalProps = {}
|
|
36
|
-
|
|
37
|
-
if (type === 'popover') {
|
|
38
|
-
popoverProps = {
|
|
39
|
-
popovertarget: target,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (type === 'modal') {
|
|
44
|
-
modalProps = {
|
|
45
|
-
// Popover target get aria-expanded and aria-haspopup inferred via popover API.
|
|
46
|
-
'aria-expanded': show,
|
|
47
|
-
'aria-haspopup': ariaHasPopup,
|
|
48
|
-
onclick: handleClick,
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Show modal
|
|
53
|
-
function handleClick(event) {
|
|
54
|
-
const dialog = document.querySelector(`#${target}`)
|
|
55
|
-
dialog.showModal()
|
|
56
|
-
show = true
|
|
57
|
-
if (onclick) onclick(event)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const opts = {}
|
|
61
|
-
|
|
62
|
-
// TODO: Test creating an IconSnippet to render the icon vs contents
|
|
63
|
-
// <script module> currently breaks when prettier is enabled. So, ¯\_(ツ)_/¯ if we can ever do that.
|
|
64
|
-
</script>
|
|
65
|
-
|
|
66
|
-
<button
|
|
67
|
-
{...rest}
|
|
68
|
-
bind:this={ref}
|
|
69
|
-
class="button {klass}"
|
|
70
|
-
{...popoverProps}
|
|
71
|
-
{...modalProps}
|
|
72
|
-
use:disclosureTrigger={{ id: target, state: { show }, options: opts }}
|
|
73
|
-
>
|
|
74
|
-
{#if children}
|
|
75
|
-
{@render children()}
|
|
76
|
-
{:else if icon}
|
|
77
|
-
<Icon class={iconClass} {icon} />
|
|
78
|
-
{/if}
|
|
79
|
-
</button>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { omitEmpty } from '@splendidlabz/utils'
|
|
2
|
-
// ========================================
|
|
3
|
-
// Shared state
|
|
4
|
-
// ========================================
|
|
5
|
-
const disclosures = $state([])
|
|
6
|
-
|
|
7
|
-
export function getDisclosure(id) {
|
|
8
|
-
return disclosures.find(d => d.id === id)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function initDisclosure(part, info) {
|
|
12
|
-
const { id } = info
|
|
13
|
-
const d = getDisclosure(id)
|
|
14
|
-
if (!d) {
|
|
15
|
-
disclosures.push(info)
|
|
16
|
-
console.log(disclosures)
|
|
17
|
-
return getDisclosure(id)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// If trigger or content is already initialized, don't re-init
|
|
21
|
-
// if (part === 'trigger' && d.nodes.trigger) return d
|
|
22
|
-
// if (part === 'content' && d.nodes.content) return d
|
|
23
|
-
|
|
24
|
-
// Initialize new info from trigger or content
|
|
25
|
-
d.state = { ...d.state, ...omitEmpty(info.state) }
|
|
26
|
-
d.options = { ...d.options, ...omitEmpty(info.options) }
|
|
27
|
-
// d.nodes = {
|
|
28
|
-
// ...d.nodes,
|
|
29
|
-
// ...omitEmpty(info.nodes, { shallow: true }),
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
return d
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function disclosureTrigger(node, props = {}) {
|
|
36
|
-
const { id } = props
|
|
37
|
-
const info = {
|
|
38
|
-
id,
|
|
39
|
-
// nodes: { trigger: node },
|
|
40
|
-
state: props.state,
|
|
41
|
-
options: props.options,
|
|
42
|
-
}
|
|
43
|
-
initDisclosure('trigger', info)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// export function disclosureContent(node, props = {}) {
|
|
47
|
-
// const { id } = props
|
|
48
|
-
// const info = {
|
|
49
|
-
// id,
|
|
50
|
-
// // nodes: { content: node },
|
|
51
|
-
// state: props.state,
|
|
52
|
-
// options: props.options,
|
|
53
|
-
// }
|
|
54
|
-
// initDisclosure('content', info)
|
|
55
|
-
// }
|
|
File without changes
|