@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
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
+
|
|
3
4
|
import DrawerCloseButton from './DrawerCloseButton.svelte'
|
|
4
5
|
import DrawerContent from './DrawerContent.svelte'
|
|
5
6
|
import DrawerTrigger from './DrawerTrigger.svelte'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export let id = ''
|
|
14
|
-
export let triggerOptions = {}
|
|
15
|
-
export let contentOptions = {}
|
|
8
|
+
const {
|
|
9
|
+
id = randomString(8),
|
|
10
|
+
triggerOptions = {},
|
|
11
|
+
contentOptions = {},
|
|
12
|
+
closeButtonOptions = {},
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
// Slots
|
|
15
|
+
trigger,
|
|
16
|
+
contentHeader,
|
|
17
|
+
content,
|
|
18
|
+
} = $props()
|
|
18
19
|
</script>
|
|
19
20
|
|
|
20
|
-
<DrawerTrigger
|
|
21
|
-
|
|
22
|
-
class={triggerClass}
|
|
23
|
-
icon={triggerIcon}
|
|
24
|
-
options={triggerOptions}
|
|
25
|
-
>
|
|
26
|
-
<slot name="trigger" />
|
|
21
|
+
<DrawerTrigger target={id} {...triggerOptions}>
|
|
22
|
+
{#if trigger}{@render trigger()}{/if}
|
|
27
23
|
</DrawerTrigger>
|
|
28
24
|
|
|
29
|
-
<DrawerContent {id}
|
|
30
|
-
<div class="
|
|
31
|
-
|
|
32
|
-
<DrawerCloseButton
|
|
25
|
+
<DrawerContent {id} {...contentOptions}>
|
|
26
|
+
<div class="horizontal">
|
|
27
|
+
{#if contentHeader}{@render contentHeader()}{/if}
|
|
28
|
+
<DrawerCloseButton {...closeButtonOptions} />
|
|
33
29
|
</div>
|
|
34
|
-
|
|
30
|
+
{#if content}{@render content()}{/if}
|
|
35
31
|
</DrawerContent>
|
|
@@ -1,116 +1,80 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { splitObject, toStyleString } from '@splendidlabz/utils'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
8
|
-
import { mergeOpts, transit } from '../../../utils/index.js'
|
|
4
|
+
TRANSITION_OPT_KEYS,
|
|
5
|
+
applyTransition,
|
|
6
|
+
mergeOpts,
|
|
7
|
+
} from '../../../utils/index.js'
|
|
9
8
|
import Portal from '../../Portal.svelte'
|
|
9
|
+
import { getDisclosure } from '../disclosure.svelte.js'
|
|
10
|
+
import DisclosureContent from '../Disclosure/DisclosureContent.svelte'
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
getDisclosure,
|
|
14
|
-
} from '../disclosure.svelte.js'
|
|
15
|
-
import {
|
|
16
|
-
defaultDrawerContentOpts,
|
|
17
|
-
defaultDrawerPositionOpts,
|
|
12
|
+
DRAWER_CONTENT_OPTS,
|
|
13
|
+
DRAWER_POSITION_OPTS,
|
|
18
14
|
getTBLRValues,
|
|
19
|
-
getTransitionXY,
|
|
20
15
|
} from './drawer.js'
|
|
21
16
|
|
|
22
|
-
|
|
17
|
+
let {
|
|
18
|
+
ref = $bindable(null),
|
|
19
|
+
position = DRAWER_CONTENT_OPTS.position,
|
|
20
|
+
...p
|
|
21
|
+
} = $props()
|
|
22
|
+
|
|
23
|
+
const opts = mergeOpts(DRAWER_CONTENT_OPTS, DRAWER_POSITION_OPTS[position], p)
|
|
23
24
|
|
|
24
25
|
const {
|
|
25
|
-
class: klass,
|
|
26
|
-
style: styleString,
|
|
27
|
-
backdropClass,
|
|
28
26
|
id,
|
|
29
|
-
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'aria-describedby': ariaDescribedBy,
|
|
33
|
-
children,
|
|
27
|
+
class: klass = '',
|
|
28
|
+
style: styleString = '',
|
|
29
|
+
backdropClass = '',
|
|
34
30
|
portal = true,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// But they're spread into ...rest
|
|
39
|
-
...rest
|
|
40
|
-
} = p
|
|
31
|
+
placement,
|
|
32
|
+
backdrop,
|
|
33
|
+
blurBackdrop,
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
rest.position || defaultDrawerContentOpts.position
|
|
46
|
-
],
|
|
47
|
-
rest,
|
|
48
|
-
)
|
|
35
|
+
// Slots
|
|
36
|
+
...rest
|
|
37
|
+
} = opts
|
|
49
38
|
|
|
50
|
-
const { picked:
|
|
51
|
-
opts,
|
|
52
|
-
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
53
|
-
)
|
|
39
|
+
const { picked: transitionOpts } = splitObject(rest, TRANSITION_OPT_KEYS)
|
|
54
40
|
|
|
55
|
-
const { placement, position, backdrop, blurBackdrop, scrollToAnchor } = opts
|
|
56
41
|
const TBLR = getTBLRValues({ placement, position })
|
|
57
42
|
const style = toStyleString(TBLR) + styleString
|
|
58
43
|
|
|
59
|
-
// Accessible name warning
|
|
60
|
-
if (role === 'dialog' && !hasLabel(ariaLabel, ariaLabelledBy)) {
|
|
61
|
-
console.warn(
|
|
62
|
-
`DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let ref = $state(null)
|
|
67
44
|
let d = $derived(getDisclosure(id))
|
|
68
45
|
let show = $derived(d?.state.show)
|
|
69
46
|
|
|
70
|
-
$effect(_ => {
|
|
71
|
-
if (show && ref && scrollToAnchor) {
|
|
72
|
-
const anchor = markActiveAnchorIn(ref)
|
|
73
|
-
goToElement(anchor)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
|
|
77
47
|
// Temp remove push transition
|
|
78
48
|
// Replace transition string with our custom push transition
|
|
79
49
|
// if (options?.transition === 'push') options.transition = push
|
|
50
|
+
//
|
|
51
|
+
// NOTE: FLY transition seems to be broken...
|
|
80
52
|
</script>
|
|
81
53
|
|
|
82
54
|
{#snippet drawerBackdrop()}
|
|
83
55
|
<div
|
|
84
|
-
class="{backdropClass}
|
|
56
|
+
class="drawer-backdrop {backdropClass} "
|
|
85
57
|
class:backdrop-blur={backdrop && blurBackdrop}
|
|
86
|
-
transition:
|
|
58
|
+
transition:applyTransition|global={{
|
|
59
|
+
...transitionOpts,
|
|
60
|
+
transition: 'fade',
|
|
61
|
+
}}
|
|
87
62
|
>
|
|
88
63
|
{@render drawerContent()}
|
|
89
64
|
</div>
|
|
90
65
|
{/snippet}
|
|
91
66
|
|
|
92
|
-
{#snippet drawerContent()}
|
|
93
|
-
<
|
|
67
|
+
{#snippet drawerContent({ portal = false } = {})}
|
|
68
|
+
<DisclosureContent
|
|
69
|
+
{...rest}
|
|
70
|
+
componentName="DrawerContent"
|
|
94
71
|
{id}
|
|
95
|
-
{...remaining}
|
|
96
|
-
class="drawer-content {klass}"
|
|
97
|
-
{role}
|
|
98
72
|
{style}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
transition:transit|global={{
|
|
105
|
-
placement,
|
|
106
|
-
...getTransitionXY(placement),
|
|
107
|
-
...opts,
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
{#if children}
|
|
111
|
-
{@render children()}
|
|
112
|
-
{/if}
|
|
113
|
-
</div>
|
|
73
|
+
{portal}
|
|
74
|
+
{placement}
|
|
75
|
+
class="drawer-content {klass}"
|
|
76
|
+
bind:ref
|
|
77
|
+
/>
|
|
114
78
|
{/snippet}
|
|
115
79
|
|
|
116
80
|
{#if show}
|
|
File without changes
|
|
@@ -1,50 +1,11 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
3
|
-
import { mergeOpts } from '../../../utils'
|
|
4
|
-
import Icon from '../../Icon/Icon.svelte'
|
|
5
|
-
import {
|
|
6
|
-
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
7
|
-
disclosureTrigger,
|
|
8
|
-
} from '../disclosure.svelte.js'
|
|
9
|
-
import { defaultDrawerTriggerOpts } from './drawer.js'
|
|
2
|
+
import DisclosureTrigger from '../Disclosure/DisclosureTrigger.svelte'
|
|
10
3
|
|
|
11
|
-
const
|
|
12
|
-
const defaultOpts = {
|
|
13
|
-
'aria-haspopup': 'dialog',
|
|
14
|
-
}
|
|
15
|
-
const opts = mergeOpts(defaultDrawerTriggerOpts, defaultOpts, p)
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
class: klass,
|
|
19
|
-
icon,
|
|
20
|
-
iconClass,
|
|
21
|
-
target,
|
|
22
|
-
'aria-haspopup': ariaPopup,
|
|
23
|
-
children,
|
|
24
|
-
...restProps
|
|
25
|
-
} = opts
|
|
26
|
-
|
|
27
|
-
const { picked: triggerOpts, ...remaining } = splitObject(
|
|
28
|
-
restProps,
|
|
29
|
-
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
let show = $state(false)
|
|
4
|
+
const { class: klass = '', ...rest } = $props()
|
|
33
5
|
</script>
|
|
34
6
|
|
|
35
|
-
<
|
|
36
|
-
{...
|
|
37
|
-
|
|
38
|
-
class="
|
|
39
|
-
|
|
40
|
-
use:disclosureTrigger={{
|
|
41
|
-
state: { show },
|
|
42
|
-
options: triggerOpts,
|
|
43
|
-
}}
|
|
44
|
-
>
|
|
45
|
-
{#if children}
|
|
46
|
-
{@render children()}
|
|
47
|
-
{:else if icon}
|
|
48
|
-
<Icon class={iconClass} {icon} />
|
|
49
|
-
{/if}
|
|
50
|
-
</button>
|
|
7
|
+
<DisclosureTrigger
|
|
8
|
+
{...rest}
|
|
9
|
+
componentName="DrawerTrigger"
|
|
10
|
+
class="drawer-trigger {klass}"
|
|
11
|
+
/>
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
export const
|
|
2
|
-
closeOthers: true,
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export const defaultDrawerContentOpts = {
|
|
1
|
+
export const DRAWER_CONTENT_OPTS = {
|
|
6
2
|
position: 'fixed',
|
|
7
3
|
placement: 'left',
|
|
8
4
|
backdrop: true,
|
|
9
5
|
blurBackdrop: true,
|
|
10
|
-
scrollToAnchor: false,
|
|
11
|
-
portal: true,
|
|
12
6
|
}
|
|
13
7
|
|
|
14
|
-
export const
|
|
8
|
+
export const DRAWER_POSITION_OPTS = {
|
|
15
9
|
static: {
|
|
16
10
|
placement: 'top',
|
|
17
11
|
transition: 'slide',
|
|
@@ -48,65 +42,3 @@ export function getTBLRValues({ placement, position }) {
|
|
|
48
42
|
if (placement === 'right') style.insetInlineEnd = 0
|
|
49
43
|
return style
|
|
50
44
|
}
|
|
51
|
-
|
|
52
|
-
export function getTransitionXY(placement) {
|
|
53
|
-
if (placement === 'top') return { x: 0, y: '-100%' }
|
|
54
|
-
if (placement === 'bottom') return { x: 0, y: '100%' }
|
|
55
|
-
if (placement === 'left') return { x: '-100%', y: 0 }
|
|
56
|
-
if (placement === 'right') return { x: '100%', y: 0 }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Push Transition
|
|
60
|
-
export function push(node, params) {
|
|
61
|
-
const { placement } = params
|
|
62
|
-
const { width, height } = node.getBoundingClientRect()
|
|
63
|
-
const canvasNode = document.querySelector('.Canvas')
|
|
64
|
-
|
|
65
|
-
if (!width && !height) return
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
...params,
|
|
69
|
-
tick(t, u) {
|
|
70
|
-
const transformValues = getPushTransformValues({
|
|
71
|
-
t,
|
|
72
|
-
u,
|
|
73
|
-
placement,
|
|
74
|
-
width,
|
|
75
|
-
height,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
node.style.transform = transformValues.node
|
|
79
|
-
canvasNode.style.transform = transformValues.canvas
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function getPushTransformValues({ t, u, placement, width, height }) {
|
|
85
|
-
if (placement === 'right') {
|
|
86
|
-
return {
|
|
87
|
-
node: `translateX(${u * width}px)`,
|
|
88
|
-
canvas: `translateX(${-1 * t * width}px)`,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (placement === 'left') {
|
|
93
|
-
return {
|
|
94
|
-
node: `translateX(${-1 * u * width}px)`,
|
|
95
|
-
canvas: `translateX(${t * width}px)`,
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (placement === 'top') {
|
|
100
|
-
return {
|
|
101
|
-
node: `translateY(${-1 * u * height}px)`,
|
|
102
|
-
canvas: `translateY(${t * height}px)`,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (placement === 'bottom') {
|
|
107
|
-
return {
|
|
108
|
-
node: `translateY(${u * height}px)`,
|
|
109
|
-
canvas: `translateY(${-1 * t * height}px)`,
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { delay } from '@splendidlabz/utils'
|
|
3
|
+
import { getParentElement } from '@splendidlabz/utils/dom'
|
|
4
|
+
import { onMount } from 'svelte'
|
|
5
|
+
import { getEntry, mergeEntry } from '../../../actions/sync.svelte.js'
|
|
6
|
+
import Modal from '../ModalNew/Modal.svelte'
|
|
7
|
+
import Popover from '../PopoverNew/Popover.svelte'
|
|
8
|
+
|
|
9
|
+
let { class: klass = '', ref = $bindable(null), ...p } = $props()
|
|
10
|
+
const { id, position, useReferenceBoundaries, ...rest } = p
|
|
11
|
+
|
|
12
|
+
const localRef = $state(null)
|
|
13
|
+
if (!ref) ref = () => localRef
|
|
14
|
+
|
|
15
|
+
let referenceNode = $state(null)
|
|
16
|
+
|
|
17
|
+
const sync = $derived(getEntry(id))
|
|
18
|
+
const type = $derived(sync?.type)
|
|
19
|
+
|
|
20
|
+
onMount(async _ => {
|
|
21
|
+
await delay(0)
|
|
22
|
+
mergeEntry(id, { drawer: ref })
|
|
23
|
+
if (useReferenceBoundaries) referenceNode = getParentElement(ref)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const propsToPass = {
|
|
27
|
+
id,
|
|
28
|
+
position,
|
|
29
|
+
...rest,
|
|
30
|
+
componentName: 'Drawer',
|
|
31
|
+
class: `drawer ${klass}`,
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
{#if type === 'modal'}
|
|
36
|
+
<Modal bind:ref {...propsToPass} />
|
|
37
|
+
{:else}
|
|
38
|
+
<Popover bind:ref {...propsToPass} {referenceNode} {useReferenceBoundaries} />
|
|
39
|
+
{/if}
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getEntry, setEntry } from '../../../actions/sync.svelte.js'
|
|
3
|
+
import ModalTrigger from '../ModalNew/ModalTrigger.svelte'
|
|
4
|
+
import PopoverTrigger from '../PopoverNew/PopoverTrigger.svelte'
|
|
5
|
+
|
|
6
|
+
let { show = $bindable(false), type = 'modal', target, ...p } = $props()
|
|
7
|
+
|
|
8
|
+
setEntry(target, { type })
|
|
9
|
+
const sync = $derived(getEntry(target))
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
{#if type === 'modal'}
|
|
13
|
+
<ModalTrigger {...p} {target} {show} />
|
|
14
|
+
{:else}
|
|
15
|
+
<PopoverTrigger {...p} {target} {show} />
|
|
16
|
+
{/if}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
// Use logical properties straight up
|
|
28
|
+
export function getTBLRValues({ placement, position }) {
|
|
29
|
+
const style = { position }
|
|
30
|
+
|
|
31
|
+
if (placement === 'top' || placement === 'bottom') {
|
|
32
|
+
style.insetInline = 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (placement === 'left' || placement === 'right') {
|
|
36
|
+
style.insetBlock = 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (placement === 'top') style.insetBlockStart = 0
|
|
40
|
+
if (placement === 'bottom') style.insetBlockEnd = 0
|
|
41
|
+
if (placement === 'left') style.insetInlineStart = 0
|
|
42
|
+
if (placement === 'right') style.insetInlineEnd = 0
|
|
43
|
+
return style
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
+
import ModalCloseButton from './ModalCloseButton.svelte'
|
|
4
|
+
import ModalContent from './ModalContent.svelte'
|
|
5
|
+
import ModalTrigger from './ModalTrigger.svelte'
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
id = randomString(8),
|
|
9
|
+
triggerOptions = {},
|
|
10
|
+
contentOptions = {},
|
|
11
|
+
closeButtonOptions = {},
|
|
12
|
+
|
|
13
|
+
// Slots
|
|
14
|
+
trigger,
|
|
15
|
+
contentHeader,
|
|
16
|
+
content,
|
|
17
|
+
} = $props()
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<ModalTrigger target={id} {...triggerOptions}>
|
|
21
|
+
{#if trigger}{@render trigger()}{/if}
|
|
22
|
+
</ModalTrigger>
|
|
23
|
+
|
|
24
|
+
<ModalContent {id} {...contentOptions}>
|
|
25
|
+
<div class="horizontal">
|
|
26
|
+
{#if contentHeader}{@render contentHeader()}{/if}
|
|
27
|
+
<ModalCloseButton {...closeButtonOptions} />
|
|
28
|
+
</div>
|
|
29
|
+
{#if content}{@render content()}{/if}
|
|
30
|
+
</ModalContent>
|
|
@@ -1,3 +1,42 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import { mergeOpts } from '../../../utils'
|
|
4
|
+
import {
|
|
5
|
+
TRANSITION_OPT_KEYS,
|
|
6
|
+
applyTransition,
|
|
7
|
+
} from '../../../utils/transitions.js'
|
|
8
|
+
import DisclosureContent from '../Disclosure/DisclosureContent.svelte'
|
|
9
|
+
import { MODAL_CONTENT_OPTS } from './modal.js'
|
|
10
|
+
|
|
11
|
+
let { ref = $bindable(null), ...p } = $props()
|
|
12
|
+
const opts = mergeOpts(MODAL_CONTENT_OPTS, p)
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
class: klass = '',
|
|
16
|
+
backdrop,
|
|
17
|
+
backdropClass,
|
|
18
|
+
blurBackdrop,
|
|
19
|
+
...rest
|
|
20
|
+
} = opts
|
|
21
|
+
|
|
22
|
+
const { picked: transitionOpts } = splitObject(rest, TRANSITION_OPT_KEYS)
|
|
3
23
|
</script>
|
|
24
|
+
|
|
25
|
+
{#snippet modalBackdrop()}
|
|
26
|
+
<div
|
|
27
|
+
class="modal-backdrop {backdropClass} "
|
|
28
|
+
class:backdrop-blur={backdrop && blurBackdrop}
|
|
29
|
+
transition:applyTransition|global={{
|
|
30
|
+
...transitionOpts,
|
|
31
|
+
transition: 'fade',
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
{@render modalContent()}
|
|
35
|
+
</div>
|
|
36
|
+
{/snippet}
|
|
37
|
+
|
|
38
|
+
{#snippet modalContent()}
|
|
39
|
+
<DisclosureContent class="modal-content {klass}" bind:ref {...rest} />
|
|
40
|
+
{/snippet}
|
|
41
|
+
|
|
42
|
+
{@render modalBackdrop()}
|
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
import { disclosures, initDisclosure } from '../disclosure-store.js'
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_DISCLOSURE_TRIGGER_OPTS,
|
|
6
|
-
disclosureTrigger,
|
|
7
|
-
} from '../disclosure.js'
|
|
2
|
+
import DisclosureTrigger from '../Disclosure/DisclosureTrigger.svelte'
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
export { klass as class }
|
|
11
|
-
export let target
|
|
12
|
-
export let show = false
|
|
13
|
-
export let options = {}
|
|
14
|
-
|
|
15
|
-
const opts = {
|
|
16
|
-
...DEFAULT_DISCLOSURE_TRIGGER_OPTS,
|
|
17
|
-
// ...defaultModalTriggerOpts,
|
|
18
|
-
...options,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
initDisclosure(target, opts, { show })
|
|
22
|
-
$: d = $disclosures.find(d => d.id === target)
|
|
4
|
+
const { class: klass = '', ...rest } = $props()
|
|
23
5
|
</script>
|
|
24
6
|
|
|
25
|
-
<
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{...$$restProps}
|
|
31
|
-
>
|
|
32
|
-
<slot />
|
|
33
|
-
</button>
|
|
7
|
+
<DisclosureTrigger
|
|
8
|
+
{...rest}
|
|
9
|
+
componentName="ModalTrigger"
|
|
10
|
+
class="modal-trigger {klass}"
|
|
11
|
+
/>
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const defaultModalContentOpts = {
|
|
6
|
-
trapFocus: true,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const defaultTransitionOpts = {
|
|
10
|
-
delay: 0,
|
|
11
|
-
duration: 250,
|
|
12
|
-
easing: 'cubicOut',
|
|
1
|
+
export const MODAL_CONTENT_OPTS = {
|
|
2
|
+
focusManagement: 'trap',
|
|
3
|
+
inertOthers: true, // Gotta work on this
|
|
13
4
|
}
|