@splendidlabz/svelte 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +3 -0
- package/CHANGELOG.md +91 -0
- package/actions/breakpoint-observer.js +71 -0
- package/actions/index.js +6 -0
- package/actions/portal.js +20 -0
- package/actions/resize-observer.js +43 -0
- package/actions/scroll-observer.js +47 -0
- package/common.js +21 -0
- package/components/Accordion/Accordion.svelte +108 -0
- package/components/Accordion/index.js +3 -0
- package/components/Breadcrumbs/Breadcrumbs.svelte +69 -0
- package/components/Breadcrumbs/Crumb.svelte +37 -0
- package/components/Breadcrumbs/CrumbCustom.svelte +14 -0
- package/components/Breadcrumbs/index.js +5 -0
- package/components/BrowserFrame.svelte +37 -0
- package/components/BrowserWithTabs.svelte +28 -0
- package/components/CQChecker/CQChecker.astro +20 -0
- package/components/CQChecker/CQChecker.svelte +89 -0
- package/components/Callout/Callout.svelte +17 -0
- package/components/Callout/index.js +3 -0
- package/components/Codepen/Codepen.astro +29 -0
- package/components/Codepen/Codepen.svelte +24 -0
- package/components/Codepen/index.js +3 -0
- package/components/ContentList/ContentList-old.svelte +117 -0
- package/components/ContentList/ContentList.svelte +68 -0
- package/components/ContentList/index.js +3 -0
- package/components/Disclosure/Drawer/Drawer.svelte +35 -0
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +31 -0
- package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +198 -0
- package/components/Disclosure/Drawer/DrawerContent.svelte +164 -0
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +32 -0
- package/components/Disclosure/Drawer/drawer.js +112 -0
- package/components/Disclosure/Drawer/index.js +6 -0
- package/components/Disclosure/Dropdown/DropdownContent.svelte +15 -0
- package/components/Disclosure/Dropdown/DropdownTrigger.svelte +14 -0
- package/components/Disclosure/Dropdown/dropdown.js +4 -0
- package/components/Disclosure/Dropdown/index.js +4 -0
- package/components/Disclosure/Modal/ModalContent.svelte +3 -0
- package/components/Disclosure/Modal/ModalTrigger.svelte +33 -0
- package/components/Disclosure/Modal/exit-intent.js +17 -0
- package/components/Disclosure/Modal/modal.js +13 -0
- package/components/Disclosure/Popover/PopoverCloseButton.svelte +29 -0
- package/components/Disclosure/Popover/PopoverContent.svelte +107 -0
- package/components/Disclosure/Popover/PopoverTrigger.svelte +33 -0
- package/components/Disclosure/Popover/floating.js +171 -0
- package/components/Disclosure/Popover/index.js +5 -0
- package/components/Disclosure/Popover/popover.js +18 -0
- package/components/Disclosure/Popover/references/FollowTheMouse.svelte +45 -0
- package/components/Disclosure/Tooltip/Tooltip.svelte +14 -0
- package/components/Disclosure/Tooltip/TooltipContent.svelte +7 -0
- package/components/Disclosure/Tooltip/TooltipTrigger.svelte +33 -0
- package/components/Disclosure/Tooltip/index.js +5 -0
- package/components/Disclosure/Tooltip/tooltip.js +22 -0
- package/components/Disclosure/disclosure-store.js +48 -0
- package/components/Disclosure/disclosure.js +439 -0
- package/components/Disclosure/index.js +3 -0
- package/components/Disclosure/state.svelte.js +138 -0
- package/components/FancyList/FancyList.svelte +49 -0
- package/components/FancyList/index.js +3 -0
- package/components/Form/Button.svelte +24 -0
- package/components/Form/Checkbox.svelte +80 -0
- package/components/Form/Checkboxes.svelte +48 -0
- package/components/Form/Combobox/AutocompleteInput.svelte +63 -0
- package/components/Form/Combobox/AutocompleteOptions.svelte +74 -0
- package/components/Form/Combobox/TimepickerInput.svelte +81 -0
- package/components/Form/Combobox/TimepickerOptions.svelte +100 -0
- package/components/Form/Combobox/autocomplete-matching.js +114 -0
- package/components/Form/Combobox/autocomplete.js +393 -0
- package/components/Form/Combobox/combobox-store.js +65 -0
- package/components/Form/Combobox/combobox.js +359 -0
- package/components/Form/Combobox/index.js +14 -0
- package/components/Form/Combobox/timepicker.js +119 -0
- package/components/Form/Form.svelte +62 -0
- package/components/Form/Hidden.svelte +16 -0
- package/components/Form/Radio.svelte +69 -0
- package/components/Form/Radios.svelte +50 -0
- package/components/Form/Select.svelte +127 -0
- package/components/Form/Switch.svelte +50 -0
- package/components/Form/TextInput.svelte +87 -0
- package/components/Form/Textarea.svelte +103 -0
- package/components/Form/check.svg +3 -0
- package/components/Form/index.js +12 -0
- package/components/Highlight/Highlight.svelte +27 -0
- package/components/Highlight/_Highlight.scss +19 -0
- package/components/Highlight/index.js +2 -0
- package/components/Image.svelte +24 -0
- package/components/InteractiveRegion/InteractiveRegion.svelte +47 -0
- package/components/InteractiveRegion/index.js +3 -0
- package/components/List/Lia.svelte +12 -0
- package/components/List/NestedListItem.svelte +50 -0
- package/components/List/index.js +3 -0
- package/components/Markdown/Markdown.svelte +35 -0
- package/components/Masonry/Masonry.svelte +79 -0
- package/components/Masonry/index.js +3 -0
- package/components/PerspectiveHover/PerspectiveHover.svelte +10 -0
- package/components/PerspectiveHover/perspective-hover.js +46 -0
- package/components/Populate/ConditionalPopulate.svelte +33 -0
- package/components/Populate/Populate.svelte +45 -0
- package/components/Populate/actions.js +29 -0
- package/components/Populate/get-value.js +17 -0
- package/components/Populate/index.js +4 -0
- package/components/Portal.svelte +27 -0
- package/components/PushToLocalStorage.svelte +30 -0
- package/components/Resizer/Resizer.svelte +32 -0
- package/components/Resizer/draggable.js +23 -0
- package/components/Resizer/index.js +3 -0
- package/components/Resizer/resizer.js +133 -0
- package/components/SVG/SVG.svelte +120 -0
- package/components/Scrambler/Scrambler.svelte +27 -0
- package/components/Scrambler/index.js +3 -0
- package/components/Spotlight/PointerPosition.js +32 -0
- package/components/Spotlight/Spotlight.svelte +9 -0
- package/components/Status.svelte +27 -0
- package/components/Switcheroo/Switcheroo.svelte +71 -0
- package/components/Switcheroo/index.js +3 -0
- package/components/Table/RowGroup.svelte +8 -0
- package/components/Table/Table.svelte +23 -0
- package/components/Table/Td.svelte +20 -0
- package/components/Table/Th.svelte +27 -0
- package/components/Table/Thead.svelte +8 -0
- package/components/Table/Tr.svelte +8 -0
- package/components/Table/index.js +17 -0
- package/components/Table/table.js +35 -0
- package/components/Tabs/Tab.svelte +12 -0
- package/components/Tabs/Tablist.svelte +62 -0
- package/components/Tabs/Tabpanel.svelte +10 -0
- package/components/Tabs/Tabpanels.svelte +12 -0
- package/components/Tabs/index.js +6 -0
- package/components/Tabs/tab-store.js +60 -0
- package/components/Tabs/tabs.js +364 -0
- package/components/Tabs-Old/Tab.svelte +9 -0
- package/components/Tabs-Old/Tablist.svelte +13 -0
- package/components/Tabs-Old/Tabpanel.svelte +10 -0
- package/components/Tabs-Old/Tabpanels.svelte +14 -0
- package/components/Tabs-Old/Tabs.svelte +83 -0
- package/components/Tabs-Old/index.js +7 -0
- package/components/Tabs-Old/tabs.js +306 -0
- package/components/Textwall/Repeat.svelte +10 -0
- package/components/Textwall/Textwall.svelte +30 -0
- package/components/Textwall/index.js +4 -0
- package/components/Typewriter/Typewriter.svelte +70 -0
- package/components/Typewriter/index.js +3 -0
- package/components/Video.svelte +46 -0
- package/components/Vimeo.svelte +18 -0
- package/components/Wrapper.svelte +22 -0
- package/components/Youtube.svelte +15 -0
- package/components/_shared/accessibility.js +9 -0
- package/components/_shared/key.js +1 -0
- package/components/_shared/transitions.js +48 -0
- package/components/_shared/use-actions.js +31 -0
- package/index.js +35 -0
- package/jsconfig.json +5 -0
- package/package.json +39 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
export default function PointerPosition(node) {
|
|
3
|
+
node.addEventListener('pointerenter', enter)
|
|
4
|
+
node.addEventListener('pointerleave', leave)
|
|
5
|
+
node.addEventListener('pointermove', setXY)
|
|
6
|
+
|
|
7
|
+
// Get mouse X and Y coordinates from the element
|
|
8
|
+
function setXY(event) {
|
|
9
|
+
const boundingRect = node.getBoundingClientRect()
|
|
10
|
+
const x = event.clientX - boundingRect.left
|
|
11
|
+
const y = event.clientY - boundingRect.top
|
|
12
|
+
|
|
13
|
+
node.style.setProperty('--x', `${x}`)
|
|
14
|
+
node.style.setProperty('--y', `${y}`)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function enter(event) {
|
|
18
|
+
node.setAttribute('active', true)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function leave(event) {
|
|
22
|
+
node.removeAttribute('active')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
destroy() {
|
|
27
|
+
node.addEventListener('pointerenter', enter)
|
|
28
|
+
node.addEventListener('pointerleave', leave)
|
|
29
|
+
node.addEventListener('pointermove', setXY)
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
let klass = ''
|
|
3
|
+
export { klass as class }
|
|
4
|
+
export let status = null
|
|
5
|
+
|
|
6
|
+
$: {
|
|
7
|
+
if (typeof status === 'number') {
|
|
8
|
+
switch (true) {
|
|
9
|
+
case status >= 200 && status < 300:
|
|
10
|
+
status = 'success'
|
|
11
|
+
break
|
|
12
|
+
case status >= 300 && status < 400:
|
|
13
|
+
status = 'redirect'
|
|
14
|
+
break
|
|
15
|
+
case status >= 400:
|
|
16
|
+
status = 'error'
|
|
17
|
+
break
|
|
18
|
+
default:
|
|
19
|
+
status = 'info'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div class="Status {status && `Status-${status}`} Prose {klass}">
|
|
26
|
+
<slot />
|
|
27
|
+
</div>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { resizeObserver } from '../../actions'
|
|
3
|
+
import { notEmpty } from '@splendidlabz/utils'
|
|
4
|
+
import { getElement } from '@splendidlabz/utils/dom'
|
|
5
|
+
|
|
6
|
+
let klass = ''
|
|
7
|
+
export { klass as class }
|
|
8
|
+
export let breakpoints = {}
|
|
9
|
+
|
|
10
|
+
let currentTarget = 'origin'
|
|
11
|
+
let originalLocationRef = null
|
|
12
|
+
let switcherooContentRef = null
|
|
13
|
+
|
|
14
|
+
let _breakpoints = {}
|
|
15
|
+
let shouldObserve = notEmpty(breakpoints)
|
|
16
|
+
// TODO: Update Switcheroo to use createBreakpointArray
|
|
17
|
+
|
|
18
|
+
// Converts user-provided breakpoints object into an array for easier internal usage. Currently only accept px breakpoint values.
|
|
19
|
+
if (breakpoints) {
|
|
20
|
+
shouldObserve = true
|
|
21
|
+
_breakpoints = Object.entries(breakpoints).map(([key, value]) => {
|
|
22
|
+
return { breakpoint: parseFloat(key), value }
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function observe(event) {
|
|
27
|
+
const { entry } = event.detail
|
|
28
|
+
const { width } = entry.contentRect
|
|
29
|
+
if (!shouldObserve) return
|
|
30
|
+
|
|
31
|
+
for (let i = _breakpoints.length - 1; i >= 0; i--) {
|
|
32
|
+
const { breakpoint, value } = _breakpoints[i]
|
|
33
|
+
const { target } = value
|
|
34
|
+
if (width >= breakpoint) {
|
|
35
|
+
if (currentTarget === target) break
|
|
36
|
+
else {
|
|
37
|
+
currentTarget = target
|
|
38
|
+
switchTo(target)
|
|
39
|
+
}
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function switchTo(target) {
|
|
46
|
+
// Place in origin
|
|
47
|
+
if (target === 'origin') {
|
|
48
|
+
originalLocationRef.appendChild(switcherooContentRef)
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Place in target
|
|
53
|
+
const targetElement = getElement(target)
|
|
54
|
+
targetElement.appendChild(switcherooContentRef)
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<svelte:body
|
|
59
|
+
use:resizeObserver={{ observe: shouldObserve }}
|
|
60
|
+
on:resize={observe}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
<div
|
|
64
|
+
class="Switcheroo {klass}"
|
|
65
|
+
bind:this={originalLocationRef}
|
|
66
|
+
{...$$restProps}
|
|
67
|
+
>
|
|
68
|
+
<div class="SwitcherooContent" bind:this={switcherooContentRef}>
|
|
69
|
+
<slot />
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { table, createCellAlignmentClasses } from './table'
|
|
3
|
+
import { notEmpty } from '@splendidlabz/utils'
|
|
4
|
+
|
|
5
|
+
let klass = null
|
|
6
|
+
export { klass as class }
|
|
7
|
+
export let role = 'table' // Or grid
|
|
8
|
+
|
|
9
|
+
// Make it super easy for users to align the grid items
|
|
10
|
+
// Usage: { 2: 'right', 3: 'right' }
|
|
11
|
+
export let alignments = {}
|
|
12
|
+
|
|
13
|
+
let alignmentClass = ''
|
|
14
|
+
if (notEmpty(alignments)) {
|
|
15
|
+
alignmentClass = createCellAlignmentClasses(alignments)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Future options here will include sortable tables, etc. Maybe do Filtration here and Pagination here as well just for the kick of it?
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div {role} class="Table {klass} {alignmentClass}" {...$$restProps} use:table>
|
|
22
|
+
<slot />
|
|
23
|
+
</div>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
let klass = ''
|
|
3
|
+
export { klass as class }
|
|
4
|
+
export let role = 'cell'
|
|
5
|
+
export let colspan = 1
|
|
6
|
+
export let rowspan = 1
|
|
7
|
+
|
|
8
|
+
let ariaColspan = colspan === 1 ? null : colspan
|
|
9
|
+
let ariaRowspan = rowspan === 1 ? null : rowspan
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<div
|
|
13
|
+
{role}
|
|
14
|
+
class="Cell Td {klass}"
|
|
15
|
+
aria-colspan={ariaColspan}
|
|
16
|
+
aria-rowspan={ariaRowspan}
|
|
17
|
+
{...$$restProps}
|
|
18
|
+
>
|
|
19
|
+
<slot />
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
let klass = null
|
|
3
|
+
export { klass as class }
|
|
4
|
+
export let scope = 'col' // Or row
|
|
5
|
+
export let colspan = 1
|
|
6
|
+
export let rowspan = 1
|
|
7
|
+
|
|
8
|
+
let ariaColspan = colspan === 1 ? null : colspan
|
|
9
|
+
let ariaRowspan = rowspan === 1 ? null : rowspan
|
|
10
|
+
|
|
11
|
+
let role
|
|
12
|
+
$: {
|
|
13
|
+
if (scope === 'col') role = 'columnheader'
|
|
14
|
+
else if (scope === 'row') role = 'rowheader'
|
|
15
|
+
else if (scope === 'rowgroup') role = 'rowheader'
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div
|
|
20
|
+
{role}
|
|
21
|
+
class="Cell Th {klass}"
|
|
22
|
+
aria-colspan={ariaColspan}
|
|
23
|
+
aria-rowspan={ariaRowspan}
|
|
24
|
+
{...$$restProps}
|
|
25
|
+
>
|
|
26
|
+
<slot />
|
|
27
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import RowGroup from './RowGroup.svelte'
|
|
2
|
+
import Table from './Table.svelte'
|
|
3
|
+
import Td from './Td.svelte'
|
|
4
|
+
import Th from './Th.svelte'
|
|
5
|
+
import Tr from './Tr.svelte'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
Table,
|
|
9
|
+
Td,
|
|
10
|
+
Th,
|
|
11
|
+
Tr,
|
|
12
|
+
RowGroup,
|
|
13
|
+
// Alias for rowgroups
|
|
14
|
+
RowGroup as Tbody,
|
|
15
|
+
RowGroup as Thead,
|
|
16
|
+
RowGroup as Tfood,
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function table(node) {
|
|
2
|
+
const table = node
|
|
3
|
+
const tableRole = table.getAttribute('role')
|
|
4
|
+
const cells = Array.from(
|
|
5
|
+
node.querySelectorAll('[role="cell"], [role="gridcell"]'),
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
// Set correct role for each cell in the table, depending on whether [role="table"] or [role="grid"] is set on the table
|
|
9
|
+
cells.forEach(cell => {
|
|
10
|
+
if (tableRole === 'table') cell.setAttribute('role', 'cell')
|
|
11
|
+
else if (tableRole === 'grid') cell.setAttribute('role', 'gridcell')
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createCellAlignmentClasses(alignments) {
|
|
16
|
+
const alignmentGroups = {
|
|
17
|
+
right: [],
|
|
18
|
+
center: [],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (const key in alignments) {
|
|
22
|
+
alignmentGroups[alignments[key]].push(`:nth-child(${key})`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let classes = ''
|
|
26
|
+
for (const alignment in alignmentGroups) {
|
|
27
|
+
const tailwindAlignment =
|
|
28
|
+
alignment === 'right' ? 'text-right' : 'text-center'
|
|
29
|
+
if (alignmentGroups[alignment].length > 0) {
|
|
30
|
+
classes += `[&_:is(.Cell):where(${alignmentGroups[alignment].join(',')})]:${tailwindAlignment} `
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return classes.trim()
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let klass = ''
|
|
3
|
+
export let active = null
|
|
4
|
+
export { klass as class }
|
|
5
|
+
|
|
6
|
+
// Easier API for users
|
|
7
|
+
if (active === false) active = null
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<button aria-selected={active} class="Tab {klass}" role="tab" {...$$restProps}>
|
|
11
|
+
<slot />
|
|
12
|
+
</button>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { preferHorizontalScroll as preferHorizontalScrollAction } from '@splendidlabz/utils/actions'
|
|
3
|
+
import { breakpointObserver } from '../../actions/breakpoint-observer.js'
|
|
4
|
+
import { tabs } from './tab-store.js'
|
|
5
|
+
import { tablist, updatePlacement } from './tabs.js'
|
|
6
|
+
|
|
7
|
+
export let klass = ''
|
|
8
|
+
export { klass as class }
|
|
9
|
+
|
|
10
|
+
export let target = null
|
|
11
|
+
export let options = {}
|
|
12
|
+
export let style = ''
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
breakpoints,
|
|
16
|
+
breakpointType,
|
|
17
|
+
placement: initialPlacement,
|
|
18
|
+
scrollable = true,
|
|
19
|
+
preferHorizontalScroll = true,
|
|
20
|
+
preserveOutlines = true,
|
|
21
|
+
...rest
|
|
22
|
+
} = options
|
|
23
|
+
|
|
24
|
+
let placement = initialPlacement || 'top'
|
|
25
|
+
|
|
26
|
+
let tab
|
|
27
|
+
$: tab = $tabs.find(t => t.id === target)
|
|
28
|
+
|
|
29
|
+
function breakpointCB({ value }) {
|
|
30
|
+
placement = value.placement
|
|
31
|
+
updatePlacement(tab, value.placement)
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div
|
|
36
|
+
role="tablist"
|
|
37
|
+
{target}
|
|
38
|
+
class="Tablist {klass}"
|
|
39
|
+
class:Tablist-top={placement === 'top'}
|
|
40
|
+
class:Tablist-left={placement === 'left'}
|
|
41
|
+
class:Tablist-right={placement === 'right'}
|
|
42
|
+
class:Scrollable-horizontal={placement === 'top' && scrollable}
|
|
43
|
+
class:Scrollable-preferHorizontalScroll={placement === 'top' &&
|
|
44
|
+
preferHorizontalScroll}
|
|
45
|
+
class:Scrollable-preserveOutlines={preserveOutlines}
|
|
46
|
+
{style}
|
|
47
|
+
{...$$restProps}
|
|
48
|
+
use:tablist={{
|
|
49
|
+
state: { placement },
|
|
50
|
+
options: rest,
|
|
51
|
+
}}
|
|
52
|
+
on:tab-change
|
|
53
|
+
use:breakpointObserver={{
|
|
54
|
+
breakpoints,
|
|
55
|
+
breakpointType,
|
|
56
|
+
callback: breakpointCB,
|
|
57
|
+
}}
|
|
58
|
+
use:preferHorizontalScrollAction
|
|
59
|
+
>
|
|
60
|
+
<!-- Need to add callback to breakpoint opts -->
|
|
61
|
+
<slot />
|
|
62
|
+
</div>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { get, writable } from 'svelte/store'
|
|
2
|
+
|
|
3
|
+
import { omitEmpty } from '@splendidlabz/utils'
|
|
4
|
+
|
|
5
|
+
export const tabs = writable([])
|
|
6
|
+
const { update } = tabs
|
|
7
|
+
|
|
8
|
+
export function getTabs() {
|
|
9
|
+
return get(tabs)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTab(id) {
|
|
13
|
+
return get(tabs).find(tab => tab.id === id)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function addTab({ id, state = {}, nodes = {}, options = {} }) {
|
|
17
|
+
update(tabs => {
|
|
18
|
+
const tab = { id, state, options, nodes }
|
|
19
|
+
return [...tabs, tab]
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function updateTab({ id, state = {}, nodes = {}, options = {} }) {
|
|
24
|
+
update(tabs => {
|
|
25
|
+
const index = tabs.findIndex(t => t.id === id)
|
|
26
|
+
const tab = tabs[index]
|
|
27
|
+
|
|
28
|
+
omitEmpty(nodes, { shallow: true })
|
|
29
|
+
|
|
30
|
+
tab.state = { ...tab.state, ...omitEmpty(state) }
|
|
31
|
+
tab.nodes = { ...tab.nodes, ...nodes }
|
|
32
|
+
tab.options = { ...tab.options, ...omitEmpty(options) }
|
|
33
|
+
|
|
34
|
+
return tabs.with(index, tab)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function initTab({ id, state = {}, nodes = {}, options = {} }) {
|
|
39
|
+
const tab = getTab(id)
|
|
40
|
+
|
|
41
|
+
state = omitEmpty(state)
|
|
42
|
+
options = omitEmpty(options)
|
|
43
|
+
|
|
44
|
+
// Update the tab with given state, nodes, and options
|
|
45
|
+
if (!tab) {
|
|
46
|
+
// Add the tab with given state, nodes, and options
|
|
47
|
+
addTab({ id, state, nodes, options })
|
|
48
|
+
} else {
|
|
49
|
+
// Defensive check for length
|
|
50
|
+
// If length doesn't exist, component has not initialized tablist or tabpanel yet. Once it does, we can check whether the length is consistent.
|
|
51
|
+
// if (tab.state.length && tab.state.length !== state.length) {
|
|
52
|
+
// throw new Error(
|
|
53
|
+
// 'Number of tabs must be the same as the number of tabpanels. Please check.',
|
|
54
|
+
// )
|
|
55
|
+
// }
|
|
56
|
+
updateTab({ id: tab.id, state, nodes, options })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return getTab(id)
|
|
60
|
+
}
|