@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { checkForAccessibleName } from '@splendidlabz/utils/dom'
|
|
3
|
+
import { getTrigger, passEventToTrigger } from '../shared.js'
|
|
4
|
+
let { ref = $bindable(null), ...p } = $props()
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
componentName = 'Modal',
|
|
8
|
+
id,
|
|
9
|
+
class: klass = '',
|
|
10
|
+
'aria-label': ariaLabel,
|
|
11
|
+
'aria-labelledBy': ariaLabelledBy,
|
|
12
|
+
'aria-describedby': ariaDescribedBy,
|
|
13
|
+
placement = 'center',
|
|
14
|
+
|
|
15
|
+
// Props
|
|
16
|
+
// scrollToAnchor = false,
|
|
17
|
+
lightDismiss = true, // TODO: Allow light dismiss
|
|
18
|
+
|
|
19
|
+
// Event listeners
|
|
20
|
+
onclick = null,
|
|
21
|
+
onbeforetoggle = null,
|
|
22
|
+
ontoggle = null,
|
|
23
|
+
onkeydown = null,
|
|
24
|
+
|
|
25
|
+
// Slots
|
|
26
|
+
children,
|
|
27
|
+
...rest
|
|
28
|
+
} = p
|
|
29
|
+
|
|
30
|
+
const placementClass = `fixed-${placement}full`
|
|
31
|
+
const transitionClass = `fly-from-${placement}`
|
|
32
|
+
// const animationInClass = `animation-fly-in-${placement}`
|
|
33
|
+
// const animationOutClass = `animation-fly-out-${placement}`
|
|
34
|
+
|
|
35
|
+
// ========================
|
|
36
|
+
// Checks
|
|
37
|
+
// ========================
|
|
38
|
+
if (!id) throw new Error(`${componentName} requires an id`)
|
|
39
|
+
checkForAccessibleName({
|
|
40
|
+
name: `${componentName} (id: ${id})`,
|
|
41
|
+
ariaLabel,
|
|
42
|
+
ariaLabelledBy,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
let trigger = $state(null)
|
|
46
|
+
// ========================================
|
|
47
|
+
// Event Listeners
|
|
48
|
+
// ========================================
|
|
49
|
+
function beforetoggle(event) {
|
|
50
|
+
if (!trigger) trigger = getTrigger(`[data-modal-trigger="${id}"]`)
|
|
51
|
+
passEventToTrigger(event, trigger)
|
|
52
|
+
|
|
53
|
+
// const { newState } = event
|
|
54
|
+
// if (newState === 'open') ref.classList.add(animationInClass)
|
|
55
|
+
// if (newState === 'closed') ref.classList.add(animationOutClass)
|
|
56
|
+
|
|
57
|
+
if (onbeforetoggle) onbeforetoggle(event)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function handleToggle(event) {
|
|
61
|
+
passEventToTrigger(event, trigger)
|
|
62
|
+
if (ontoggle) ontoggle(event)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleClick(event) {
|
|
66
|
+
if (lightDismiss) {
|
|
67
|
+
const { x, y } = event
|
|
68
|
+
// https://codepen.io/aslhnates/pen/KKKpmpd?editors=0010
|
|
69
|
+
if (clickOutsideRect(ref, { x, y })) ref.close('click')
|
|
70
|
+
}
|
|
71
|
+
if (onclick) onclick(event)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function handleKeydown(event) {
|
|
75
|
+
if (lightDismiss && event.key === 'Escape') ref.close('Escape')
|
|
76
|
+
if (onkeydown) onkeydown(event)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function onanimationend(event) {
|
|
80
|
+
// console.log('animationend')
|
|
81
|
+
// const classes = Array.from(ref.classList)
|
|
82
|
+
// const animationClasses = classes.filter(c => c.startsWith('animation-'))
|
|
83
|
+
// console.log(animationClasses)
|
|
84
|
+
// animationClasses.forEach(c => ref.classList.remove(c))
|
|
85
|
+
// console.log(ref.classList)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function clickOutsideRect(element, clickedPos) {
|
|
89
|
+
const { x, y } = clickedPos
|
|
90
|
+
const rect = element.getBoundingClientRect()
|
|
91
|
+
return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<dialog
|
|
96
|
+
{...rest}
|
|
97
|
+
{id}
|
|
98
|
+
bind:this={ref}
|
|
99
|
+
class="modal {placementClass} {transitionClass} {klass}"
|
|
100
|
+
aria-label={ariaLabel}
|
|
101
|
+
aria-labelledby={ariaLabelledBy}
|
|
102
|
+
aria-describedby={ariaDescribedBy}
|
|
103
|
+
ontoggle={handleToggle}
|
|
104
|
+
onbeforetoggle={beforetoggle}
|
|
105
|
+
onclick={handleClick}
|
|
106
|
+
onkeydown={handleKeydown}
|
|
107
|
+
{onanimationend}
|
|
108
|
+
>
|
|
109
|
+
{#if children}{@render children()}{/if}
|
|
110
|
+
</dialog>
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
message = null,
|
|
12
|
+
type = 'close', // close or cancel
|
|
13
|
+
children,
|
|
14
|
+
|
|
15
|
+
// Events
|
|
16
|
+
onclick = null,
|
|
17
|
+
...rest
|
|
18
|
+
} = p
|
|
19
|
+
|
|
20
|
+
let dialog = $state(null)
|
|
21
|
+
|
|
22
|
+
function closeModal(event) {
|
|
23
|
+
dialog = this.closest(`dialog`)
|
|
24
|
+
if (type === 'cancel') dialog.requestClose(message || 'cancel')
|
|
25
|
+
if (type === 'close') dialog.close(message || 'close')
|
|
26
|
+
if (onclick) onclick(event)
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<button
|
|
31
|
+
{...rest}
|
|
32
|
+
bind:this={ref}
|
|
33
|
+
class="button-icon {klass}"
|
|
34
|
+
data-modal-trigger={target}
|
|
35
|
+
onclick={closeModal}
|
|
36
|
+
>
|
|
37
|
+
{#if children}
|
|
38
|
+
{@render children()}
|
|
39
|
+
{:else}
|
|
40
|
+
<Icon class={iconClass} {icon} />
|
|
41
|
+
{/if}
|
|
42
|
+
</button>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { delay } from '@splendidlabz/utils'
|
|
3
|
+
import { onMount } from 'svelte'
|
|
4
|
+
import Icon from '../../Icon/Icon.svelte'
|
|
5
|
+
let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
componentName = 'ModalTrigger',
|
|
9
|
+
class: klass = '',
|
|
10
|
+
icon = 'tabler:menu',
|
|
11
|
+
iconClass,
|
|
12
|
+
|
|
13
|
+
// Props
|
|
14
|
+
target,
|
|
15
|
+
|
|
16
|
+
// Slots
|
|
17
|
+
children,
|
|
18
|
+
|
|
19
|
+
// Event listeners
|
|
20
|
+
onclick = null,
|
|
21
|
+
ontoggle = null,
|
|
22
|
+
...rest
|
|
23
|
+
} = p
|
|
24
|
+
|
|
25
|
+
let dialog = $state(null)
|
|
26
|
+
|
|
27
|
+
if (!target)
|
|
28
|
+
throw new Error(`${componentName} must contain a target property`)
|
|
29
|
+
|
|
30
|
+
onMount(async _ => {
|
|
31
|
+
await delay(0) // Gives time for modal to mount
|
|
32
|
+
if (show) handleClick()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// ========================================
|
|
36
|
+
// Event Listeners
|
|
37
|
+
// ========================================
|
|
38
|
+
function handleClick(event) {
|
|
39
|
+
if (!dialog) dialog = document.querySelector(`#${target}`)
|
|
40
|
+
dialog.showModal()
|
|
41
|
+
if (onclick) onclick(event)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Allows trigger to know whether the modal is open or closed
|
|
45
|
+
function handleToggle(event) {
|
|
46
|
+
const { newState, oldState } = event.detail
|
|
47
|
+
if (newState === 'open') show = true
|
|
48
|
+
if (oldState === 'closed') show = false
|
|
49
|
+
if (ontoggle) ontoggle(event)
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<button
|
|
54
|
+
{...rest}
|
|
55
|
+
bind:this={ref}
|
|
56
|
+
class="button {klass}"
|
|
57
|
+
aria-haspopup="dialog"
|
|
58
|
+
onclick={handleClick}
|
|
59
|
+
data-show={show}
|
|
60
|
+
data-modal-trigger={target}
|
|
61
|
+
ontoggle={handleToggle}
|
|
62
|
+
>
|
|
63
|
+
{#if children}
|
|
64
|
+
{@render children()}
|
|
65
|
+
{:else if icon}
|
|
66
|
+
<Icon class={iconClass} {icon} />
|
|
67
|
+
{/if}
|
|
68
|
+
</button>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import { hasAccessibleName } from '@splendidlabz/utils/dom'
|
|
3
4
|
import * as easing from 'svelte/easing'
|
|
4
5
|
import { fade } from 'svelte/transition'
|
|
5
|
-
import { hasLabel } from '../../_shared/accessibility'
|
|
6
6
|
import Portal from '../../Portal.svelte'
|
|
7
7
|
import { disclosures } from '../disclosure-store.js'
|
|
8
8
|
import {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
export let ariaDescribedBy = $$restProps['aria-describedby']
|
|
26
26
|
export let options = {}
|
|
27
27
|
|
|
28
|
-
if (!
|
|
28
|
+
if (!hasAccessibleName(ariaLabel, ariaLabelledBy)) {
|
|
29
29
|
console.warn(
|
|
30
30
|
`PopoverContent (with id: ${id}) should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
31
31
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { isInvalidAriaPopup } from '
|
|
2
|
+
import { isInvalidAriaPopup } from '../../../actions/accessibility.js'
|
|
3
3
|
import { disclosureTrigger } from '../disclosure.js'
|
|
4
4
|
import { DEFAULT_POPOVER_TRIGGER_OPTS } from './popover.js'
|
|
5
5
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import { checkForAccessibleName } from '@splendidlabz/utils/dom'
|
|
4
|
+
import { mergeOpts } from '../../../utils/merge-opts.js'
|
|
5
|
+
import { getTrigger, passEventToTrigger } from '../shared.js'
|
|
6
|
+
import { FLOATING_OPTS_KEYS, initFloating } from './floating.js'
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
class: klass = '',
|
|
10
|
+
as = 'dialog',
|
|
11
|
+
ref = $bindable(null),
|
|
12
|
+
referenceNode = $bindable(null),
|
|
13
|
+
...p
|
|
14
|
+
} = $props()
|
|
15
|
+
|
|
16
|
+
p = mergeOpts(p)
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
componentName = 'Popover',
|
|
20
|
+
'aria-label': ariaLabel,
|
|
21
|
+
'aria-labelledBy': ariaLabelledBy,
|
|
22
|
+
'aria-describedby': ariaDescribedBy,
|
|
23
|
+
|
|
24
|
+
// Props
|
|
25
|
+
id,
|
|
26
|
+
popover = 'auto', // manual, hint
|
|
27
|
+
|
|
28
|
+
// Event listeners
|
|
29
|
+
onbeforetoggle = null,
|
|
30
|
+
ontoggle = null,
|
|
31
|
+
|
|
32
|
+
// Slots
|
|
33
|
+
children,
|
|
34
|
+
...rest
|
|
35
|
+
} = p
|
|
36
|
+
|
|
37
|
+
// ========================
|
|
38
|
+
// Checks
|
|
39
|
+
// ========================
|
|
40
|
+
if (!id) throw new Error(`${componentName} requires an id`)
|
|
41
|
+
|
|
42
|
+
// Accessible name warning
|
|
43
|
+
checkForAccessibleName({
|
|
44
|
+
name: `${componentName} (id: ${id})`,
|
|
45
|
+
ariaLabel,
|
|
46
|
+
ariaLabelledBy,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// ========================================
|
|
50
|
+
// Logic
|
|
51
|
+
// ========================================
|
|
52
|
+
let trigger = null
|
|
53
|
+
let floating = null
|
|
54
|
+
|
|
55
|
+
const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
|
|
56
|
+
|
|
57
|
+
// ========================================
|
|
58
|
+
// Event Listeners
|
|
59
|
+
// ========================================
|
|
60
|
+
function beforetoggle(event) {
|
|
61
|
+
if (!trigger) trigger = getTrigger(`[popovertarget="${id}"]`)
|
|
62
|
+
passEventToTrigger(event, trigger)
|
|
63
|
+
|
|
64
|
+
const { newState } = event
|
|
65
|
+
|
|
66
|
+
if (newState === 'open') {
|
|
67
|
+
// Initialize floating.
|
|
68
|
+
if (!floating) {
|
|
69
|
+
floating = initFloating({
|
|
70
|
+
referenceNode: referenceNode || trigger,
|
|
71
|
+
floatingNode: ref,
|
|
72
|
+
...floatingOpts,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
floating.update()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Calculate position before showing
|
|
79
|
+
if (onbeforetoggle) onbeforetoggle(event)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function handleToggle(event) {
|
|
83
|
+
passEventToTrigger(event, trigger)
|
|
84
|
+
const { newState } = event
|
|
85
|
+
if (newState === 'closed') floating.cleanup()
|
|
86
|
+
if (ontoggle) ontoggle(event)
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<!-- Snippets -->
|
|
91
|
+
<svelte:element
|
|
92
|
+
this={as}
|
|
93
|
+
bind:this={ref}
|
|
94
|
+
{...rest}
|
|
95
|
+
{id}
|
|
96
|
+
{popover}
|
|
97
|
+
class={klass}
|
|
98
|
+
aria-label={ariaLabel}
|
|
99
|
+
aria-labelledby={ariaLabelledBy}
|
|
100
|
+
aria-describedby={ariaDescribedBy}
|
|
101
|
+
onbeforetoggle={beforetoggle}
|
|
102
|
+
ontoggle={handleToggle}
|
|
103
|
+
>
|
|
104
|
+
{#if children}{@render children()}{/if}
|
|
105
|
+
</svelte:element>
|
|
@@ -0,0 +1,38 @@
|
|
|
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>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { delay } from '@splendidlabz/utils'
|
|
3
|
+
import { onMount } from 'svelte'
|
|
4
|
+
import Icon from '../../Icon/Icon.svelte'
|
|
5
|
+
let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
componentName = 'PopoverTrigger',
|
|
9
|
+
class: klass = '',
|
|
10
|
+
icon = 'tabler:menu',
|
|
11
|
+
iconClass,
|
|
12
|
+
|
|
13
|
+
// Props
|
|
14
|
+
target,
|
|
15
|
+
actions,
|
|
16
|
+
|
|
17
|
+
// Slots
|
|
18
|
+
children,
|
|
19
|
+
|
|
20
|
+
// Event listeners
|
|
21
|
+
onclick = null,
|
|
22
|
+
ontoggle = null,
|
|
23
|
+
...rest
|
|
24
|
+
} = p
|
|
25
|
+
|
|
26
|
+
let popover = $state(null)
|
|
27
|
+
|
|
28
|
+
if (!target)
|
|
29
|
+
throw new Error(`${componentName} must contain a target property`)
|
|
30
|
+
|
|
31
|
+
onMount(async _ => {
|
|
32
|
+
await delay(0) // Gives time for popover to mount
|
|
33
|
+
if (show) handleClick()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// ========================================
|
|
37
|
+
// Event Listeners
|
|
38
|
+
// ========================================
|
|
39
|
+
function handleClick(event) {
|
|
40
|
+
if (!popover) popover = document.querySelector(`#${target}`)
|
|
41
|
+
popover.togglePopover()
|
|
42
|
+
if (onclick) onclick(event)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Allows trigger to know whether the popover is open or closed
|
|
46
|
+
function handleToggle(event) {
|
|
47
|
+
const { newState, oldState } = event.detail
|
|
48
|
+
if (newState === 'open') show = true
|
|
49
|
+
if (oldState === 'closed') show = false
|
|
50
|
+
if (ontoggle) ontoggle(event)
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<button
|
|
55
|
+
{...rest}
|
|
56
|
+
bind:this={ref}
|
|
57
|
+
class="button {klass}"
|
|
58
|
+
popovertarget={target}
|
|
59
|
+
data-show={show}
|
|
60
|
+
ontoggle={handleToggle}
|
|
61
|
+
>
|
|
62
|
+
{#if children}
|
|
63
|
+
{@render children()}
|
|
64
|
+
{:else if icon}
|
|
65
|
+
<Icon class={iconClass} {icon} />
|
|
66
|
+
{/if}
|
|
67
|
+
</button>
|