@splendidlabz/svelte 4.3.1 → 4.5.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 +29 -0
- 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 +6 -8
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +34 -9
- package/components/Disclosure/Disclosure/disclosure.svelte.js +61 -79
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +14 -30
- package/components/Disclosure/Drawer/DrawerContent.svelte +58 -74
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +13 -6
- package/components/Disclosure/Drawer/drawer.js +3 -27
- package/components/Disclosure/Drawer/index.js +6 -2
- package/components/Disclosure/Modal/ModalContent.svelte +122 -32
- package/components/Disclosure/Modal/ModalTrigger.svelte +63 -6
- package/components/Disclosure/Modal/index.js +2 -2
- package/components/Disclosure/Popover/PopoverContent.svelte +109 -97
- package/components/Disclosure/Popover/PopoverTrigger.svelte +67 -22
- package/components/Disclosure/Popover/floating.js +278 -117
- package/components/Disclosure/Popover/index.js +3 -2
- package/components/Disclosure/index.js +3 -7
- package/components/Disclosure/shared.js +1 -0
- package/components/DisclosureOld/Drawer/DrawerCloseButton.svelte +37 -0
- package/components/DisclosureOld/Drawer/DrawerContent.svelte +92 -0
- package/components/DisclosureOld/Drawer/DrawerTrigger.svelte +11 -0
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/drawer.js +0 -26
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/index.js +2 -6
- package/components/DisclosureOld/Modal/ModalContent.svelte +42 -0
- package/components/DisclosureOld/Modal/ModalTrigger.svelte +11 -0
- package/components/DisclosureOld/Modal/index.js +5 -0
- package/components/DisclosureOld/Old/DisclosureContentOld.svelte +97 -0
- package/components/DisclosureOld/Old/DisclosureTriggerOld.svelte +51 -0
- package/components/{Disclosure → DisclosureOld}/Popover/PopoverCloseButton.svelte +4 -1
- package/components/DisclosureOld/Popover/PopoverContent.svelte +107 -0
- package/components/DisclosureOld/Popover/PopoverTrigger.svelte +33 -0
- package/components/DisclosureOld/Popover/floating.js +171 -0
- package/components/DisclosureOld/Popover/index.js +5 -0
- package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipTrigger.svelte +1 -1
- package/components/{Disclosure → DisclosureOld}/disclosure.js +44 -40
- package/components/Form/Combobox/AutocompleteInput.svelte +3 -3
- package/components/Form/Combobox/AutocompleteOptions.svelte +5 -5
- package/components/Form/Combobox/TimepickerInput.svelte +7 -7
- package/components/Form/Combobox/TimepickerOptions.svelte +7 -7
- package/components/Form/Combobox/autocomplete.js +2 -2
- package/components/Form/Combobox/combobox.js +2 -2
- 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/components/Disclosure/DrawerNew/DrawerCloseButton.svelte +0 -21
- package/components/Disclosure/DrawerNew/DrawerContent.svelte +0 -45
- package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +0 -15
- package/components/Disclosure/ModalNew/ModalContent.svelte +0 -132
- package/components/Disclosure/ModalNew/ModalTrigger.svelte +0 -68
- package/components/Disclosure/ModalNew/index.js +0 -5
- package/components/Disclosure/PopoverNew/PopoverContent.svelte +0 -119
- package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +0 -77
- package/components/Disclosure/PopoverNew/floating.js +0 -332
- package/components/Disclosure/PopoverNew/index.js +0 -6
- package/components/Disclosure/state.svelte.js +0 -138
- /package/components/Disclosure/{ModalNew → Modal}/ModalClose.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/Popover.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/PopoverClose.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Drawer/Drawer.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownTrigger.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/dropdown.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/Modal.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/ModalCloseButton.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/exit-intent.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/modal.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/popover.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/references/FollowTheMouse.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/Tooltip.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/tooltip.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/disclosure-store.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/disclosure.svelte.js +0 -0
|
@@ -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
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getEntry } from '../../../actions/sync.svelte.js'
|
|
3
|
-
import ModalClose from '../ModalNew/ModalClose.svelte'
|
|
4
|
-
import PopoverClose from '../PopoverNew/PopoverClose.svelte'
|
|
5
|
-
|
|
6
|
-
const { class: klass = '', target, ...p } = $props()
|
|
7
|
-
|
|
8
|
-
let sync = $derived(getEntry(target))
|
|
9
|
-
let type = $derived(sync?.type)
|
|
10
|
-
|
|
11
|
-
const propsToPass = {
|
|
12
|
-
target,
|
|
13
|
-
class: `drawer-close-button ${klass}`,
|
|
14
|
-
}
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
{#if type === 'popover'}
|
|
18
|
-
<PopoverClose {...propsToPass} {...p} />
|
|
19
|
-
{:else}
|
|
20
|
-
<ModalClose {...propsToPass} {...p} />
|
|
21
|
-
{/if}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { delay } from '@splendidlabz/utils'
|
|
3
|
-
import { getParentElement } from '@splendidlabz/utils/dom'
|
|
4
|
-
import { onMount } from 'svelte'
|
|
5
|
-
import { mergeEntry, setEntry } from '../../../actions/sync.svelte.js'
|
|
6
|
-
import ModalContent from '../ModalNew/ModalContent.svelte'
|
|
7
|
-
import PopoverContent from '../PopoverNew/PopoverContent.svelte'
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
class: klass = '',
|
|
11
|
-
type = 'modal',
|
|
12
|
-
ref = $bindable(null),
|
|
13
|
-
...p
|
|
14
|
-
} = $props()
|
|
15
|
-
|
|
16
|
-
const { id, ...rest } = p
|
|
17
|
-
const useReferenceBoundaries = type === 'popover'
|
|
18
|
-
|
|
19
|
-
let referenceNode = $state(null)
|
|
20
|
-
setEntry(id, { type })
|
|
21
|
-
|
|
22
|
-
onMount(async _ => {
|
|
23
|
-
await delay(0)
|
|
24
|
-
mergeEntry(id, { drawer: ref })
|
|
25
|
-
if (useReferenceBoundaries) referenceNode = getParentElement(ref)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const propsToPass = {
|
|
29
|
-
id,
|
|
30
|
-
...rest,
|
|
31
|
-
componentName: 'Drawer',
|
|
32
|
-
class: `drawer-content ${klass}`,
|
|
33
|
-
}
|
|
34
|
-
</script>
|
|
35
|
-
|
|
36
|
-
{#if type === 'modal'}
|
|
37
|
-
<ModalContent bind:ref {...propsToPass} />
|
|
38
|
-
{:else}
|
|
39
|
-
<PopoverContent
|
|
40
|
-
{referenceNode}
|
|
41
|
-
{useReferenceBoundaries}
|
|
42
|
-
bind:ref
|
|
43
|
-
{...propsToPass}
|
|
44
|
-
/>
|
|
45
|
-
{/if}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getEntry } from '../../../actions/sync.svelte.js'
|
|
3
|
-
import ModalTrigger from '../ModalNew/ModalTrigger.svelte'
|
|
4
|
-
import PopoverTrigger from '../PopoverNew/PopoverTrigger.svelte'
|
|
5
|
-
let { show = $bindable(false), target, ...p } = $props()
|
|
6
|
-
|
|
7
|
-
const sync = $derived(getEntry(target))
|
|
8
|
-
const type = $derived(sync?.type)
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
{#if type === 'modal'}
|
|
12
|
-
<ModalTrigger {...p} {target} {show} />
|
|
13
|
-
{:else}
|
|
14
|
-
<PopoverTrigger {...p} {target} {show} />
|
|
15
|
-
{/if}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
checkForAccessibleName,
|
|
4
|
-
markActiveAnchorIn,
|
|
5
|
-
scrollToElement,
|
|
6
|
-
} from '@splendidlabz/utils/dom'
|
|
7
|
-
import { getTrigger, passEventToTrigger } from '../shared.js'
|
|
8
|
-
let { ref = $bindable(null), ...p } = $props()
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
componentName = 'Modal',
|
|
12
|
-
id,
|
|
13
|
-
class: klass = '',
|
|
14
|
-
'aria-label': ariaLabel,
|
|
15
|
-
'aria-labelledBy': ariaLabelledBy,
|
|
16
|
-
'aria-describedby': ariaDescribedBy,
|
|
17
|
-
placement = 'center',
|
|
18
|
-
|
|
19
|
-
// Props
|
|
20
|
-
scrollToAnchor = false,
|
|
21
|
-
lightDismiss = true,
|
|
22
|
-
|
|
23
|
-
// Event listeners
|
|
24
|
-
onclick = null,
|
|
25
|
-
onbeforetoggle = null,
|
|
26
|
-
onbeforeopen = null,
|
|
27
|
-
onbeforeclose = null,
|
|
28
|
-
ontoggle = null,
|
|
29
|
-
onopen = null,
|
|
30
|
-
onclose = null,
|
|
31
|
-
onkeydown = null,
|
|
32
|
-
|
|
33
|
-
// Slots
|
|
34
|
-
children,
|
|
35
|
-
...rest
|
|
36
|
-
} = p
|
|
37
|
-
|
|
38
|
-
const placementClass = {
|
|
39
|
-
top: 'fixed-topfull',
|
|
40
|
-
bottom: 'fixed-bottomfull',
|
|
41
|
-
left: 'fixed-leftfull',
|
|
42
|
-
right: 'fixed-rightfull',
|
|
43
|
-
center: '',
|
|
44
|
-
}[placement]
|
|
45
|
-
|
|
46
|
-
const transitionClass = {
|
|
47
|
-
top: 'fly-from-top',
|
|
48
|
-
bottom: 'fly-from-bottom',
|
|
49
|
-
left: 'fly-from-left',
|
|
50
|
-
right: 'fly-from-right',
|
|
51
|
-
center: '',
|
|
52
|
-
}[placement]
|
|
53
|
-
|
|
54
|
-
// ========================
|
|
55
|
-
// Checks
|
|
56
|
-
// ========================
|
|
57
|
-
if (!id) throw new Error(`${componentName} requires an id`)
|
|
58
|
-
checkForAccessibleName({
|
|
59
|
-
name: `${componentName} (id: ${id})`,
|
|
60
|
-
ariaLabel,
|
|
61
|
-
ariaLabelledBy,
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
let trigger = $state(null)
|
|
65
|
-
// ========================================
|
|
66
|
-
// Event Listeners
|
|
67
|
-
// ========================================
|
|
68
|
-
function beforetoggle(event) {
|
|
69
|
-
if (!trigger) trigger = getTrigger(`[data-modal-trigger="${id}"]`)
|
|
70
|
-
passEventToTrigger(event, trigger)
|
|
71
|
-
|
|
72
|
-
const { newState } = event
|
|
73
|
-
if (newState === 'open' && onbeforeopen) onbeforeopen(event)
|
|
74
|
-
if (newState === 'close' && onbeforeclose) onbeforeclose(event)
|
|
75
|
-
if (onbeforetoggle) onbeforetoggle(event)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function handleToggle(event) {
|
|
79
|
-
passEventToTrigger(event, trigger)
|
|
80
|
-
|
|
81
|
-
const { newState } = event
|
|
82
|
-
if (newState === 'open' && scrollToAnchor) {
|
|
83
|
-
const anchor = markActiveAnchorIn(ref)
|
|
84
|
-
scrollToElement(anchor)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (newState === 'open' && onopen) onopen(event)
|
|
88
|
-
if (newState === 'close' && onclose) onclose(event)
|
|
89
|
-
if (ontoggle) ontoggle(event)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function handleClick(event) {
|
|
93
|
-
// Don't activate any clicks from within the modal
|
|
94
|
-
if (event.target !== ref) return
|
|
95
|
-
|
|
96
|
-
// Calculates whether to light dismiss based on clicked location
|
|
97
|
-
if (lightDismiss) {
|
|
98
|
-
const { x, y } = event
|
|
99
|
-
// https://codepen.io/aslhnates/pen/KKKpmpd?editors=0010
|
|
100
|
-
if (clickOutsideRect(ref, { x, y })) ref.close('click')
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (onclick) onclick(event)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function handleKeydown(event) {
|
|
107
|
-
if (lightDismiss && event.key === 'Escape') ref.close('Escape')
|
|
108
|
-
if (onkeydown) onkeydown(event)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function clickOutsideRect(element, clickedPos) {
|
|
112
|
-
const { x, y } = clickedPos
|
|
113
|
-
const rect = element.getBoundingClientRect()
|
|
114
|
-
return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom
|
|
115
|
-
}
|
|
116
|
-
</script>
|
|
117
|
-
|
|
118
|
-
<dialog
|
|
119
|
-
{...rest}
|
|
120
|
-
bind:this={ref}
|
|
121
|
-
{id}
|
|
122
|
-
class="modal-content {placementClass} {transitionClass} {klass}"
|
|
123
|
-
aria-describedby={ariaDescribedBy}
|
|
124
|
-
aria-label={ariaLabel}
|
|
125
|
-
aria-labelledby={ariaLabelledBy}
|
|
126
|
-
onbeforetoggle={beforetoggle}
|
|
127
|
-
onclick={handleClick}
|
|
128
|
-
onkeydown={handleKeydown}
|
|
129
|
-
ontoggle={handleToggle}
|
|
130
|
-
>
|
|
131
|
-
{#if children}{@render children()}{/if}
|
|
132
|
-
</dialog>
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
data-modal-trigger={target}
|
|
59
|
-
data-show={show}
|
|
60
|
-
onclick={handleClick}
|
|
61
|
-
ontoggle={handleToggle}
|
|
62
|
-
>
|
|
63
|
-
{#if children}
|
|
64
|
-
{@render children()}
|
|
65
|
-
{:else if icon}
|
|
66
|
-
<Icon class={iconClass} {icon} />
|
|
67
|
-
{/if}
|
|
68
|
-
</button>
|
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
onopen = null,
|
|
32
|
-
onclose = null,
|
|
33
|
-
|
|
34
|
-
// Slots
|
|
35
|
-
children,
|
|
36
|
-
...rest
|
|
37
|
-
} = p
|
|
38
|
-
|
|
39
|
-
// ========================
|
|
40
|
-
// Checks
|
|
41
|
-
// ========================
|
|
42
|
-
if (!id) throw new Error(`${componentName} requires an id`)
|
|
43
|
-
|
|
44
|
-
// Accessible name warning
|
|
45
|
-
checkForAccessibleName({
|
|
46
|
-
name: `${componentName} (id: ${id})`,
|
|
47
|
-
ariaLabel,
|
|
48
|
-
ariaLabelledBy,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
// ========================================
|
|
52
|
-
// Logic
|
|
53
|
-
// ========================================
|
|
54
|
-
let trigger = null
|
|
55
|
-
let floating = null
|
|
56
|
-
|
|
57
|
-
const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
|
|
58
|
-
|
|
59
|
-
// ========================================
|
|
60
|
-
// Event Listeners
|
|
61
|
-
// ========================================
|
|
62
|
-
function beforetoggle(event) {
|
|
63
|
-
if (!trigger) trigger = getTrigger(`[popovertarget="${id}"]`)
|
|
64
|
-
passEventToTrigger(event, trigger)
|
|
65
|
-
|
|
66
|
-
const { newState } = event
|
|
67
|
-
|
|
68
|
-
if (newState === 'open') {
|
|
69
|
-
// Initialize floating.
|
|
70
|
-
if (!floating) {
|
|
71
|
-
floating = initFloating({
|
|
72
|
-
referenceNode: referenceNode || trigger,
|
|
73
|
-
floatingNode: ref,
|
|
74
|
-
...floatingOpts,
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
floating.update()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Calculate position before showing
|
|
81
|
-
if (onbeforetoggle) onbeforetoggle(event)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function handleToggle(event) {
|
|
85
|
-
passEventToTrigger(event, trigger)
|
|
86
|
-
const { newState } = event
|
|
87
|
-
|
|
88
|
-
// Send open event
|
|
89
|
-
if (newState === 'open') {
|
|
90
|
-
if (onopen) onopen(event)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (newState === 'closed') {
|
|
94
|
-
floating.cleanup()
|
|
95
|
-
// Send close event
|
|
96
|
-
if (onclose) onclose(event)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Send toggle event
|
|
100
|
-
if (ontoggle) ontoggle(event)
|
|
101
|
-
}
|
|
102
|
-
</script>
|
|
103
|
-
|
|
104
|
-
<!-- Snippets -->
|
|
105
|
-
<svelte:element
|
|
106
|
-
this={as}
|
|
107
|
-
bind:this={ref}
|
|
108
|
-
{...rest}
|
|
109
|
-
{id}
|
|
110
|
-
class="{klass} popover-content"
|
|
111
|
-
aria-describedby={ariaDescribedBy}
|
|
112
|
-
aria-label={ariaLabel}
|
|
113
|
-
aria-labelledby={ariaLabelledBy}
|
|
114
|
-
onbeforetoggle={beforetoggle}
|
|
115
|
-
ontoggle={handleToggle}
|
|
116
|
-
{popover}
|
|
117
|
-
>
|
|
118
|
-
{#if children}{@render children()}{/if}
|
|
119
|
-
</svelte:element>
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { delay } from '@splendidlabz/utils'
|
|
3
|
-
import { onMount } from 'svelte'
|
|
4
|
-
import Icon from '../../Icon/Icon.svelte'
|
|
5
|
-
let { show = $bindable(null), 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
|
-
onopen = null,
|
|
24
|
-
onclose = null,
|
|
25
|
-
...rest
|
|
26
|
-
} = p
|
|
27
|
-
|
|
28
|
-
let popover = $state(null)
|
|
29
|
-
|
|
30
|
-
if (!target)
|
|
31
|
-
throw new Error(`${componentName} must contain a target property`)
|
|
32
|
-
|
|
33
|
-
onMount(async _ => {
|
|
34
|
-
await delay(0) // Gives time for popover to mount
|
|
35
|
-
if (show) handleClick()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// ========================================
|
|
39
|
-
// Event Listeners
|
|
40
|
-
// ========================================
|
|
41
|
-
function handleClick(event) {
|
|
42
|
-
if (!popover) popover = document.querySelector(`#${target}`)
|
|
43
|
-
popover.togglePopover()
|
|
44
|
-
if (onclick) onclick(event)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Allows trigger to know whether the popover is open or closed
|
|
48
|
-
function handleToggle(event) {
|
|
49
|
-
const { newState } = event.detail
|
|
50
|
-
if (newState === 'open') {
|
|
51
|
-
show = true
|
|
52
|
-
if (onopen) onopen(event)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (newState === 'closed') {
|
|
56
|
-
show = false
|
|
57
|
-
if (onclose) onclose(event)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (ontoggle) ontoggle(event)
|
|
61
|
-
}
|
|
62
|
-
</script>
|
|
63
|
-
|
|
64
|
-
<button
|
|
65
|
-
{...rest}
|
|
66
|
-
bind:this={ref}
|
|
67
|
-
class="button popover-trigger {klass}"
|
|
68
|
-
data-show={show}
|
|
69
|
-
ontoggle={handleToggle}
|
|
70
|
-
popovertarget={target}
|
|
71
|
-
>
|
|
72
|
-
{#if children}
|
|
73
|
-
{@render children()}
|
|
74
|
-
{:else if icon}
|
|
75
|
-
<Icon class={iconClass} {icon} />
|
|
76
|
-
{/if}
|
|
77
|
-
</button>
|