@splendidlabz/svelte 4.8.2 → 4.8.4
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 +12 -0
- package/components/Accordion/Accordion.svelte +17 -21
- package/components/Breadcrumbs/Breadcrumbs.svelte +8 -19
- package/components/Breadcrumbs/Crumb.svelte +19 -14
- package/components/BrowserFrame/BrowserFrame.svelte +8 -16
- package/components/Codepen/Codepen.svelte +2 -1
- package/components/ContentList/ContentList.svelte +6 -7
- package/components/Copyright.svelte +6 -7
- package/components/Disclosure/Disclosure/DisclosureContent.svelte +21 -21
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +23 -22
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
- package/components/Disclosure/Drawer/DrawerContent.svelte +20 -18
- package/components/Disclosure/Modal/ModalCloseButton.svelte +3 -6
- package/components/Disclosure/Modal/ModalContent.svelte +18 -19
- package/components/Disclosure/Modal/ModalTrigger.svelte +9 -11
- package/components/Disclosure/Popover/PopoverCloseButton.svelte +4 -5
- package/components/Disclosure/Popover/PopoverContent.svelte +12 -23
- package/components/Disclosure/Popover/PopoverTrigger.svelte +9 -13
- package/components/FancyList/FancyList.svelte +3 -6
- package/components/Form/ButtonGroup.svelte +30 -22
- package/components/Form/Checkbox.svelte +23 -18
- package/components/Form/Checkboxes.svelte +29 -27
- package/components/Form/Form.svelte +3 -6
- package/components/Form/Radio.svelte +11 -14
- package/components/Form/Radios.svelte +27 -27
- package/components/Form/Select.svelte +48 -60
- package/components/Form/TextInput.svelte +13 -15
- package/components/Form/Textarea.svelte +13 -20
- package/components/Image/Figure.svelte +13 -0
- package/components/Image/Image-old.svelte +58 -0
- package/components/Image/Image.svelte +41 -0
- package/components/Image/Picture.svelte +71 -0
- package/components/Image/image.js +61 -0
- package/components/LocalStorage/LocalStoragePush.svelte +1 -2
- package/components/LocalStorage/LocalStorageRemove.svelte +1 -2
- package/components/Markdown/Markdown.spec.js +47 -0
- package/components/Markdown/Markdown.svelte +1 -10
- package/components/Resizer/Resizer.svelte +24 -23
- package/components/SVG/SVG.svelte +23 -21
- package/components/SVG/SVGGradient.svelte +7 -5
- package/components/Scrambler/Scrambler.svelte +1 -2
- package/components/Status.svelte +1 -3
- package/components/Tabs/Tablist.svelte +7 -8
- package/components/Tabs/Tabpanels.svelte +5 -1
- package/components/Tabs/Tabs.svelte +2 -3
- package/components/Youtube.svelte +7 -10
- package/package.json +6 -1
- package/test-utils.js +44 -0
- package/utils/index.js +1 -0
- package/utils/init.js +3 -0
- package/vitest.config.js +8 -0
- package/components/Image.svelte +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @splendidlabz/svelte
|
|
2
2
|
|
|
3
|
+
## 4.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Cleanup all locally state reference errors
|
|
8
|
+
|
|
9
|
+
## 4.8.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Remove redundant `<p>` tag stripping in `Markdown` components. The `markdown-it` `renderInline` method never produces `<p>` tags, so the `.replace('<p>', '').replace('</p>', '')` calls after it were dead code.
|
|
14
|
+
|
|
3
15
|
## 4.8.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
-
import { applyTransition,
|
|
3
|
+
import { applyTransition, init } from '../../utils/index.js'
|
|
4
4
|
import { reloadScripts } from '../../utils/loadscripts.js'
|
|
5
5
|
import { IconSnippet } from '../Icon/IconSnippet.svelte'
|
|
6
6
|
import { MarkdownSnippet } from '../Markdown/MarkdownSnippet.svelte'
|
|
7
7
|
|
|
8
|
-
const p = $props()
|
|
9
|
-
const DEFAULT_OPTIONS = {
|
|
10
|
-
titleTag: 'h3',
|
|
11
|
-
icon: 'tabler:chevron-right',
|
|
12
|
-
iconPosition: 'end',
|
|
13
|
-
transition: 'slide',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const opts = mergeOpts(DEFAULT_OPTIONS, p)
|
|
17
|
-
|
|
18
|
-
// Classes
|
|
19
8
|
const {
|
|
20
9
|
id = randomString(9),
|
|
21
10
|
class: klass,
|
|
22
11
|
titleClass,
|
|
23
12
|
contentClass,
|
|
24
13
|
buttonClass,
|
|
25
|
-
icon,
|
|
14
|
+
icon = 'tabler:chevron-right',
|
|
26
15
|
iconClass,
|
|
16
|
+
iconPosition = 'end',
|
|
27
17
|
closeOthers = false,
|
|
28
18
|
useMarkdown = true,
|
|
29
|
-
|
|
19
|
+
titleTag = 'h3',
|
|
20
|
+
transition = 'slide',
|
|
21
|
+
title,
|
|
22
|
+
content,
|
|
23
|
+
children,
|
|
24
|
+
} = $props()
|
|
30
25
|
|
|
31
26
|
let show = $state(false)
|
|
32
|
-
const { title, content, children } = opts
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
init(() => {
|
|
29
|
+
if (!title) console.warn('Accordion: No title provided')
|
|
30
|
+
if (!content && !children) console.warn('Accordion: No content provided')
|
|
31
|
+
})
|
|
36
32
|
|
|
37
33
|
// ========================================
|
|
38
34
|
// Event Handlers
|
|
@@ -66,7 +62,7 @@
|
|
|
66
62
|
|
|
67
63
|
<!-- Accordion HTML -->
|
|
68
64
|
<div class="accordion {klass}" class:open={show}>
|
|
69
|
-
<svelte:element this={
|
|
65
|
+
<svelte:element this={titleTag} class="accordion-title {titleClass}">
|
|
70
66
|
<button
|
|
71
67
|
class="accordion-button {buttonClass}"
|
|
72
68
|
aria-controls={id}
|
|
@@ -75,7 +71,7 @@
|
|
|
75
71
|
onkeydown={handleKeydown}
|
|
76
72
|
>
|
|
77
73
|
<!-- Icon (if start) -->
|
|
78
|
-
{#if
|
|
74
|
+
{#if iconPosition === 'start'}
|
|
79
75
|
{@render IconSnippet.block({ icon, iconClass })}
|
|
80
76
|
{/if}
|
|
81
77
|
|
|
@@ -83,7 +79,7 @@
|
|
|
83
79
|
{@render MarkdownSnippet.inline(title, useMarkdown)}
|
|
84
80
|
|
|
85
81
|
<!-- Icon (if end) -->
|
|
86
|
-
{#if
|
|
82
|
+
{#if iconPosition === 'end'}
|
|
87
83
|
{@render IconSnippet.block({ icon, iconClass })}
|
|
88
84
|
{/if}
|
|
89
85
|
</button>
|
|
@@ -95,7 +91,7 @@
|
|
|
95
91
|
class="accordion-content {contentClass}"
|
|
96
92
|
use:reloadScripts
|
|
97
93
|
transition:applyTransition={{
|
|
98
|
-
transition
|
|
94
|
+
transition,
|
|
99
95
|
}}
|
|
100
96
|
>
|
|
101
97
|
{@render MarkdownSnippet.block(content || children, useMarkdown)}
|
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { onMount } from 'svelte'
|
|
3
|
-
import { mergeOpts } from '../../utils'
|
|
4
3
|
import Icon from '../Icon/Icon.svelte'
|
|
5
4
|
import Crumb from './Crumb.svelte'
|
|
6
5
|
|
|
7
|
-
let {
|
|
8
|
-
|
|
9
|
-
const {
|
|
6
|
+
let {
|
|
7
|
+
pathname = $bindable(''),
|
|
10
8
|
class: klass = '',
|
|
11
9
|
ulClass = '',
|
|
10
|
+
labelCase = 'title',
|
|
11
|
+
divider = 'tabler:chevron-right',
|
|
12
|
+
dividerClass = '',
|
|
13
|
+
ariaCurrentType = 'page',
|
|
14
|
+
startingDepth = 0,
|
|
12
15
|
|
|
13
16
|
// Slots
|
|
14
17
|
children,
|
|
15
18
|
before,
|
|
16
19
|
after,
|
|
17
|
-
|
|
18
|
-
} = p
|
|
19
|
-
|
|
20
|
-
const defaultOptions = {
|
|
21
|
-
crumbs: [],
|
|
22
|
-
labelCase: 'title',
|
|
23
|
-
divider: 'tabler:chevron-right',
|
|
24
|
-
dividerClass: '',
|
|
25
|
-
ariaCurrentType: 'page',
|
|
26
|
-
startingDepth: 0,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const opts = mergeOpts(defaultOptions, rest)
|
|
30
|
-
const { startingDepth, ariaCurrentType, labelCase, divider, dividerClass } =
|
|
31
|
-
opts
|
|
20
|
+
} = $props()
|
|
32
21
|
|
|
33
22
|
let trailingSlash = $derived(hasTrailingSlash(pathname))
|
|
34
23
|
let crumbs = $derived(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { toLower, toSentence, toTitle, toUpper } from '@splendidlabz/utils'
|
|
3
|
+
import { init } from '../../utils'
|
|
3
4
|
import Icon from '../Icon/Icon.svelte'
|
|
4
5
|
import { Snippet } from '../_Shared/Snippet.svelte'
|
|
5
6
|
|
|
@@ -13,28 +14,32 @@
|
|
|
13
14
|
dividerClass = '',
|
|
14
15
|
href = '',
|
|
15
16
|
labelCase = 'title',
|
|
17
|
+
label: rawLabel,
|
|
16
18
|
|
|
17
19
|
// Slots
|
|
18
20
|
before,
|
|
19
21
|
|
|
20
|
-
...
|
|
22
|
+
...rest
|
|
21
23
|
} = $props()
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (labelCase === 'lower') label = toLower(label)
|
|
25
|
+
const label = $derived.by(() => {
|
|
26
|
+
if (labelCase === 'title') return toTitle(rawLabel)
|
|
27
|
+
if (labelCase === 'sentence') return toSentence(rawLabel)
|
|
28
|
+
if (labelCase === 'upper') return toUpper(rawLabel)
|
|
29
|
+
if (labelCase === 'lower') return toLower(rawLabel)
|
|
30
|
+
return rawLabel
|
|
31
|
+
})
|
|
31
32
|
|
|
32
33
|
// Check aria current type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
init(() => {
|
|
35
|
+
if (
|
|
36
|
+
!['page', 'time', 'step', 'location', 'date'].includes(ariaCurrentType)
|
|
37
|
+
) {
|
|
38
|
+
console.warn(`Invalid aria-current type: ${ariaCurrentType}`)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const current = $derived(isLast && ariaCurrentType)
|
|
38
43
|
</script>
|
|
39
44
|
|
|
40
45
|
<!-- Before slots are for custom icons -->
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
3
|
-
import { mergeOpts } from '../../utils/merge-opts.js'
|
|
4
3
|
import { Resizer } from '../Resizer/index.js'
|
|
5
4
|
import { Tab, Tablist, Tabpanels } from '../Tabs/index.js'
|
|
6
5
|
|
|
7
|
-
let {
|
|
8
|
-
|
|
6
|
+
let {
|
|
7
|
+
elem = $bindable(null),
|
|
9
8
|
|
|
10
|
-
const {
|
|
11
9
|
class: klass = '',
|
|
12
|
-
|
|
13
10
|
frameContentClass = '',
|
|
14
11
|
contentClass = '',
|
|
15
12
|
resize = null,
|
|
@@ -18,6 +15,7 @@
|
|
|
18
15
|
tablistClass = null,
|
|
19
16
|
tablistTarget = randomString(8),
|
|
20
17
|
selectedTabIndex = 0,
|
|
18
|
+
tablistItems = [],
|
|
21
19
|
|
|
22
20
|
// Tabpanels options
|
|
23
21
|
tabpanelsClass = null,
|
|
@@ -25,18 +23,12 @@
|
|
|
25
23
|
// Slots
|
|
26
24
|
children,
|
|
27
25
|
background,
|
|
28
|
-
} =
|
|
29
|
-
|
|
30
|
-
let { tablistItems = [] } = p
|
|
31
|
-
let items = $state(tablistItems || [])
|
|
26
|
+
} = $props()
|
|
32
27
|
|
|
33
|
-
const hasTabs = tablistItems.length > 0
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return tab
|
|
38
|
-
})
|
|
39
|
-
}
|
|
28
|
+
const hasTabs = $derived(tablistItems.length > 0)
|
|
29
|
+
const items = $derived(
|
|
30
|
+
tablistItems.map(tab => (typeof tab === 'string' ? { text: tab } : tab)),
|
|
31
|
+
)
|
|
40
32
|
</script>
|
|
41
33
|
|
|
42
34
|
<!-- Tabpanels -->
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
import NestedList from '../List/NestedListItem.svelte'
|
|
34
34
|
import { buildStructure, updateAriaCurrent } from './contentlist.js'
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
let {
|
|
37
37
|
selector,
|
|
38
38
|
label,
|
|
39
39
|
class: klass = '',
|
|
@@ -42,19 +42,16 @@
|
|
|
42
42
|
liClass,
|
|
43
43
|
aClass,
|
|
44
44
|
options,
|
|
45
|
-
|
|
45
|
+
includes: rawIncludes = [],
|
|
46
|
+
excludes: rawExcludes = [],
|
|
47
|
+
...rest
|
|
46
48
|
} = $props()
|
|
47
49
|
|
|
48
|
-
let { includes = [], excludes = [], ...rest } = p
|
|
49
|
-
|
|
50
50
|
const defaultOptions = {
|
|
51
51
|
includes: ['h2', 'h3', 'h4', 'h5', 'h6'],
|
|
52
52
|
excludes: ['.exclude-from-contentlist'],
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
includes = includes.concat(defaultOptions.includes)
|
|
56
|
-
excludes = excludes.concat(defaultOptions.excludes)
|
|
57
|
-
|
|
58
55
|
let ref = $state(null)
|
|
59
56
|
let elements = $state([])
|
|
60
57
|
let structure = $state([])
|
|
@@ -62,6 +59,8 @@
|
|
|
62
59
|
|
|
63
60
|
onMount(() => {
|
|
64
61
|
if (typeof window === 'undefined') return
|
|
62
|
+
const includes = rawIncludes.concat(defaultOptions.includes)
|
|
63
|
+
const excludes = rawExcludes.concat(defaultOptions.excludes)
|
|
65
64
|
const targetElement = selector ? document.querySelector(selector) : document
|
|
66
65
|
|
|
67
66
|
elements = Array.from(
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
const { class: klass, from, company = '' } = $props()
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const string = $derived.by(() => {
|
|
5
|
+
const thisYear = new Date().getFullYear()
|
|
6
|
+
if (!from) return `${thisYear}`
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
if (!fromYear) return `${thisYear}`
|
|
8
|
+
const fromYear = new Date(from).getFullYear()
|
|
10
9
|
if (fromYear === thisYear) return `${thisYear}`
|
|
11
10
|
return `${fromYear}-${thisYear}`
|
|
12
|
-
}
|
|
11
|
+
})
|
|
13
12
|
</script>
|
|
14
13
|
|
|
15
14
|
<div class={klass}>
|
|
16
15
|
<span>Copyright ©</span>
|
|
17
16
|
<span>{company}</span>
|
|
18
|
-
<span>
|
|
17
|
+
<span>{string}</span>
|
|
19
18
|
</div>
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
markActiveAnchorIn,
|
|
6
6
|
scrollToElement,
|
|
7
7
|
} from '@splendidlabz/utils/dom'
|
|
8
|
+
import { init } from '../../../utils/index.js'
|
|
8
9
|
import {
|
|
9
10
|
TRANSITION_OPT_KEYS,
|
|
10
11
|
applyTransition,
|
|
@@ -16,9 +17,8 @@
|
|
|
16
17
|
getDisclosure,
|
|
17
18
|
} from './disclosure.svelte.js'
|
|
18
19
|
|
|
19
|
-
let {
|
|
20
|
-
|
|
21
|
-
const {
|
|
20
|
+
let {
|
|
21
|
+
ref = $bindable(null),
|
|
22
22
|
class: klass,
|
|
23
23
|
id,
|
|
24
24
|
role = 'dialog',
|
|
@@ -26,33 +26,33 @@
|
|
|
26
26
|
'aria-labelledBy': ariaLabelledBy,
|
|
27
27
|
'aria-describedby': ariaDescribedBy,
|
|
28
28
|
componentName = 'DisclosureContent',
|
|
29
|
-
|
|
30
29
|
portal = true,
|
|
31
30
|
scrollToAnchor = false,
|
|
32
31
|
|
|
33
32
|
// Slots
|
|
34
33
|
children,
|
|
35
|
-
...
|
|
36
|
-
} =
|
|
34
|
+
...remainingProps
|
|
35
|
+
} = $props()
|
|
37
36
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
37
|
+
const disclosureSplit = $derived(
|
|
38
|
+
splitObject(remainingProps, DISCLOSURE_CONTENT_OPT_KEYS),
|
|
41
39
|
)
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
TRANSITION_OPT_KEYS,
|
|
40
|
+
const disclosureContentOpts = $derived(disclosureSplit.picked)
|
|
41
|
+
const transitionSplit = $derived(
|
|
42
|
+
splitObject(disclosureSplit.omitted, TRANSITION_OPT_KEYS),
|
|
46
43
|
)
|
|
44
|
+
const transitionOpts = $derived(transitionSplit.picked)
|
|
45
|
+
const remaining = $derived(transitionSplit.omitted)
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
init(() => {
|
|
48
|
+
if (!id) throw new Error(`${componentName} requires an id`)
|
|
49
|
+
// Accessible name warning
|
|
50
|
+
if (role === 'dialog' && !hasAccessibleName(ariaLabel, ariaLabelledBy)) {
|
|
51
|
+
console.warn(
|
|
52
|
+
`DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
56
|
|
|
57
57
|
let d = $derived(getDisclosure(id))
|
|
58
58
|
let show = $derived(d?.state.show)
|
|
@@ -1,42 +1,46 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import { init } from '../../../utils'
|
|
3
4
|
import Icon from '../../Icon/Icon.svelte'
|
|
4
5
|
import {
|
|
5
6
|
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
6
7
|
disclosureTrigger,
|
|
7
8
|
} from './disclosure.svelte.js'
|
|
8
9
|
|
|
9
|
-
let {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let {
|
|
11
|
+
show = $bindable(false),
|
|
12
|
+
ref = $bindable(null),
|
|
12
13
|
class: klass = '',
|
|
13
14
|
componentName = 'DisclosureTrigger',
|
|
14
15
|
icon = 'tabler:menu',
|
|
15
16
|
iconClass,
|
|
16
17
|
'aria-haspopup': ariaHasPopup = 'dialog',
|
|
17
18
|
target,
|
|
18
|
-
|
|
19
|
-
// Events
|
|
20
19
|
onopen = null,
|
|
21
20
|
onclose = null,
|
|
22
|
-
|
|
23
|
-
// Slots
|
|
24
21
|
children,
|
|
22
|
+
...remainingProps
|
|
23
|
+
} = $props()
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const triggerSplit = $derived(
|
|
26
|
+
splitObject(remainingProps, DISCLOSURE_TRIGGER_OPT_KEYS),
|
|
27
|
+
)
|
|
28
|
+
const triggerOpts = $derived(triggerSplit.picked)
|
|
29
|
+
const eventSplit = $derived(
|
|
30
|
+
splitObject(triggerSplit.omitted, [
|
|
31
|
+
'onbeforeopen',
|
|
32
|
+
'onbeforeclose',
|
|
33
|
+
'onbeforetoggle',
|
|
34
|
+
'ontoggle',
|
|
35
|
+
]),
|
|
32
36
|
)
|
|
37
|
+
const eventOpts = $derived(eventSplit.picked)
|
|
38
|
+
const final = $derived(eventSplit.omitted)
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'ontoggle',
|
|
39
|
-
])
|
|
40
|
+
init(() => {
|
|
41
|
+
if (!target)
|
|
42
|
+
throw new Error(`${componentName} must contain a target property`)
|
|
43
|
+
})
|
|
40
44
|
|
|
41
45
|
function handleOpen(data) {
|
|
42
46
|
show = true
|
|
@@ -47,9 +51,6 @@
|
|
|
47
51
|
show = false
|
|
48
52
|
if (onclose) onclose(data)
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
if (!target)
|
|
52
|
-
throw new Error(`${componentName} must contain a target property`)
|
|
53
54
|
</script>
|
|
54
55
|
|
|
55
56
|
<button
|
|
@@ -3,6 +3,7 @@
|
|
|
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 { init } from '../../../utils'
|
|
6
7
|
import { TRANSITION_OPT_KEYS } from '../../../utils/transitions.js'
|
|
7
8
|
import DisclosureContent from '../Disclosure/DisclosureContent.svelte'
|
|
8
9
|
import ModalContent from '../Modal/ModalContent.svelte'
|
|
@@ -11,40 +12,41 @@
|
|
|
11
12
|
|
|
12
13
|
let {
|
|
13
14
|
class: klass = '',
|
|
14
|
-
type = 'modal',
|
|
15
|
+
type: typeProp = 'modal',
|
|
15
16
|
ref = $bindable(null),
|
|
16
17
|
style = '',
|
|
17
18
|
position,
|
|
18
|
-
placement,
|
|
19
|
-
|
|
19
|
+
placement: placementProp,
|
|
20
|
+
id,
|
|
21
|
+
...remainingProps
|
|
20
22
|
} = $props()
|
|
21
23
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const split = $derived(splitObject(remainingProps, TRANSITION_OPT_KEYS))
|
|
25
|
+
const transitionOpts = $derived(split.picked)
|
|
26
|
+
const rest = $derived(split.omitted)
|
|
27
|
+
|
|
28
|
+
const type = $derived(position === 'relative' ? 'disclosure' : typeProp)
|
|
29
|
+
const placement = $derived(
|
|
30
|
+
position === 'relative' ? placementProp || 'top' : placementProp,
|
|
25
31
|
)
|
|
26
|
-
const
|
|
27
|
-
const useReferenceBoundaries = type === 'popover'
|
|
32
|
+
const useReferenceBoundaries = $derived(type === 'popover')
|
|
28
33
|
|
|
29
34
|
// Using DisclosureContent for relative position for nice slide effect.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (position === 'relative') {
|
|
33
|
-
type = 'disclosure'
|
|
34
|
-
placement = placement || 'top'
|
|
35
|
+
const disclosureContentProps = $derived.by(() => {
|
|
36
|
+
if (position !== 'relative') return {}
|
|
35
37
|
const TBLR = getTBLRValues({ placement, position })
|
|
36
38
|
const styleString = toStyleString(TBLR) + style
|
|
37
|
-
|
|
39
|
+
return {
|
|
38
40
|
portal: false,
|
|
39
41
|
style: styleString,
|
|
40
42
|
placement,
|
|
41
43
|
transition: 'slide',
|
|
42
44
|
...transitionOpts,
|
|
43
45
|
}
|
|
44
|
-
}
|
|
46
|
+
})
|
|
45
47
|
|
|
46
48
|
let referenceNode = $state(null)
|
|
47
|
-
setEntry(id, { type })
|
|
49
|
+
init(() => setEntry(id, { type }))
|
|
48
50
|
|
|
49
51
|
onMount(async _ => {
|
|
50
52
|
await delay(0)
|
|
@@ -52,14 +54,14 @@
|
|
|
52
54
|
if (useReferenceBoundaries) referenceNode = getParentElement(ref)
|
|
53
55
|
})
|
|
54
56
|
|
|
55
|
-
const propsToPass = {
|
|
57
|
+
const propsToPass = $derived({
|
|
56
58
|
id,
|
|
57
59
|
style,
|
|
58
60
|
placement,
|
|
59
61
|
...rest,
|
|
60
62
|
componentName: 'DrawerContent',
|
|
61
63
|
class: `drawer-content ${klass}`,
|
|
62
|
-
}
|
|
64
|
+
})
|
|
63
65
|
</script>
|
|
64
66
|
|
|
65
67
|
{#if type === 'modal'}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import Icon from '../../Icon/Icon.svelte'
|
|
3
3
|
|
|
4
|
-
let {
|
|
5
|
-
|
|
6
|
-
const {
|
|
4
|
+
let {
|
|
5
|
+
ref = $bindable(null),
|
|
7
6
|
class: klass = '',
|
|
8
7
|
icon = 'tabler:x',
|
|
9
8
|
iconClass = '',
|
|
@@ -11,11 +10,9 @@
|
|
|
11
10
|
message = null,
|
|
12
11
|
type = 'close', // close or cancel
|
|
13
12
|
children,
|
|
14
|
-
|
|
15
|
-
// Events
|
|
16
13
|
onclick = null,
|
|
17
14
|
...rest
|
|
18
|
-
} =
|
|
15
|
+
} = $props()
|
|
19
16
|
|
|
20
17
|
let dialog = $state(null)
|
|
21
18
|
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
markActiveAnchorIn,
|
|
5
5
|
scrollToElement,
|
|
6
6
|
} from '@splendidlabz/utils/dom'
|
|
7
|
+
import { init } from '../../../utils'
|
|
7
8
|
import { getTrigger, passEventToTrigger } from '../shared.js'
|
|
8
|
-
let { ref = $bindable(null), ...p } = $props()
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
let {
|
|
11
|
+
ref = $bindable(null),
|
|
11
12
|
componentName = 'ModalContent',
|
|
12
13
|
id,
|
|
13
14
|
class: klass = '',
|
|
@@ -15,12 +16,8 @@
|
|
|
15
16
|
'aria-labelledBy': ariaLabelledBy,
|
|
16
17
|
'aria-describedby': ariaDescribedBy,
|
|
17
18
|
placement = 'center',
|
|
18
|
-
|
|
19
|
-
// Props
|
|
20
19
|
scrollToAnchor = false,
|
|
21
20
|
lightDismiss = true,
|
|
22
|
-
|
|
23
|
-
// Event listeners
|
|
24
21
|
onclick = null,
|
|
25
22
|
onbeforetoggle = null,
|
|
26
23
|
onbeforeopen = null,
|
|
@@ -29,36 +26,38 @@
|
|
|
29
26
|
onopen = null,
|
|
30
27
|
onclose = null,
|
|
31
28
|
onkeydown = null,
|
|
32
|
-
|
|
33
|
-
// Slots
|
|
34
29
|
children,
|
|
35
30
|
...rest
|
|
36
|
-
} =
|
|
31
|
+
} = $props()
|
|
37
32
|
|
|
38
|
-
const
|
|
33
|
+
const placementClasses = {
|
|
39
34
|
top: 'fixed-topfull',
|
|
40
35
|
bottom: 'fixed-bottomfull',
|
|
41
36
|
left: 'fixed-leftfull',
|
|
42
37
|
right: 'fixed-rightfull',
|
|
43
38
|
center: '',
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const transitionClass = {
|
|
39
|
+
}
|
|
40
|
+
const transitionClasses = {
|
|
47
41
|
top: 'fly-from-top',
|
|
48
42
|
bottom: 'fly-from-bottom',
|
|
49
43
|
left: 'fly-from-left',
|
|
50
44
|
right: 'fly-from-right',
|
|
51
45
|
center: '',
|
|
52
|
-
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const placementClass = $derived(placementClasses[placement])
|
|
49
|
+
const transitionClass = $derived(transitionClasses[placement])
|
|
53
50
|
|
|
54
51
|
// ========================
|
|
55
52
|
// Checks
|
|
56
53
|
// ========================
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
init(() => {
|
|
55
|
+
if (!id) throw new Error(`${componentName} requires an id`)
|
|
56
|
+
checkForAccessibleName({
|
|
57
|
+
name: `${componentName} (id: ${id})`,
|
|
58
|
+
ariaLabel,
|
|
59
|
+
ariaLabelledBy,
|
|
60
|
+
})
|
|
62
61
|
})
|
|
63
62
|
|
|
64
63
|
let trigger = $state(null)
|