@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,164 @@
|
|
|
1
|
+
<!-- Drawers are not working currently because we changed the Disclosure implementation. -->
|
|
2
|
+
<script>
|
|
3
|
+
import { splitObject, toStyleString } from '@splendidlabz/utils'
|
|
4
|
+
import { goToElement, markActiveAnchorIn } from '@splendidlabz/utils/dom'
|
|
5
|
+
import Portal from '../../Portal.svelte'
|
|
6
|
+
import { hasLabel } from '../../_shared/accessibility'
|
|
7
|
+
import { transit } from '../../_shared/transitions.js'
|
|
8
|
+
import { disclosures } from '../disclosure-store.js'
|
|
9
|
+
import {
|
|
10
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
11
|
+
disclosureContent,
|
|
12
|
+
} from '../disclosure.js'
|
|
13
|
+
import {
|
|
14
|
+
defaultDrawerContentOpts,
|
|
15
|
+
defaultDrawerPositionOpts,
|
|
16
|
+
getTBLRValues,
|
|
17
|
+
getTransitionXY,
|
|
18
|
+
} from './drawer.js'
|
|
19
|
+
|
|
20
|
+
let klass = ''
|
|
21
|
+
let styleString = ''
|
|
22
|
+
export { klass as class }
|
|
23
|
+
export { styleString as style }
|
|
24
|
+
export let backdropClass = ''
|
|
25
|
+
|
|
26
|
+
export let id
|
|
27
|
+
export let role = 'dialog'
|
|
28
|
+
export let ariaLabel = $$restProps['aria-label']
|
|
29
|
+
export let ariaLabelledBy = $$restProps['aria-labelledby']
|
|
30
|
+
export let ariaDescribedBy = $$restProps['aria-describedby']
|
|
31
|
+
export let options = {}
|
|
32
|
+
|
|
33
|
+
let ref
|
|
34
|
+
if (role === 'dialog' && !hasLabel(ariaLabel, ariaLabelledBy)) {
|
|
35
|
+
console.warn(
|
|
36
|
+
`DrawerContent (with id: ${id}) is a dialog and should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Merge options
|
|
41
|
+
options = {
|
|
42
|
+
...defaultDrawerContentOpts,
|
|
43
|
+
...defaultDrawerPositionOpts[
|
|
44
|
+
options.position || defaultDrawerContentOpts.position
|
|
45
|
+
],
|
|
46
|
+
...options,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Temp remove push transition
|
|
50
|
+
// Replace transition string with our custom push transition
|
|
51
|
+
// if (options?.transition === 'push') options.transition = push
|
|
52
|
+
|
|
53
|
+
const { placement, position, backdrop, blurBackdrop, scrollToAnchor } =
|
|
54
|
+
options
|
|
55
|
+
const TBLR = getTBLRValues({ placement, position })
|
|
56
|
+
const style = toStyleString(TBLR) + styleString
|
|
57
|
+
|
|
58
|
+
const { picked: disclosureContentOpts } = splitObject(
|
|
59
|
+
options,
|
|
60
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
let d
|
|
64
|
+
$: d = $disclosures.find(d => d.id === id)
|
|
65
|
+
$: if (d?.state.show === true && ref && scrollToAnchor) {
|
|
66
|
+
const anchor = markActiveAnchorIn(ref)
|
|
67
|
+
goToElement(anchor)
|
|
68
|
+
}
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<!-- Note: We temporarily add aria-label and aria-labelledby properties only because {...$$restProps} breaks transitions — it stops inward transition from working from working. No idea why. -->
|
|
72
|
+
{#if d?.state.show}
|
|
73
|
+
{#if position === 'fixed'}
|
|
74
|
+
{#if options.portal}
|
|
75
|
+
<Portal>
|
|
76
|
+
<div
|
|
77
|
+
class={backdropClass}
|
|
78
|
+
class:DrawerBackdrop={backdrop}
|
|
79
|
+
class:DrawerBackdrop-blur={backdrop && blurBackdrop}
|
|
80
|
+
transition:transit|global={options}
|
|
81
|
+
>
|
|
82
|
+
<!-- Ideally we put this inside a Snippet in Svelte 5. Right now we have no choice but to copy-paste between different types of drawers -->
|
|
83
|
+
<div
|
|
84
|
+
{id}
|
|
85
|
+
class="DrawerContent {klass}"
|
|
86
|
+
{role}
|
|
87
|
+
{style}
|
|
88
|
+
bind:this={ref}
|
|
89
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
90
|
+
aria-label={ariaLabel}
|
|
91
|
+
aria-labelledby={ariaLabelledBy}
|
|
92
|
+
aria-describedby={ariaDescribedBy}
|
|
93
|
+
on:open
|
|
94
|
+
on:close
|
|
95
|
+
transition:transit|global={{
|
|
96
|
+
placement,
|
|
97
|
+
...getTransitionXY(placement),
|
|
98
|
+
...options,
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<!-- Rest Props kinda breaks transition... confirmed. -->
|
|
102
|
+
<!-- {...$$restProps} -->
|
|
103
|
+
<slot />
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</Portal>
|
|
107
|
+
{:else}
|
|
108
|
+
<div
|
|
109
|
+
class={backdropClass}
|
|
110
|
+
class:DrawerBackdrop={backdrop}
|
|
111
|
+
class:DrawerBackdrop-blur={backdrop && blurBackdrop}
|
|
112
|
+
transition:transit|global={options}
|
|
113
|
+
>
|
|
114
|
+
<!-- Ideally we put this inside a Snippet in Svelte 5. Right now we have no choice but to copy-paste between different types of drawers -->
|
|
115
|
+
<di
|
|
116
|
+
{id}
|
|
117
|
+
class="DrawerContent {klass}"
|
|
118
|
+
{role}
|
|
119
|
+
{style}
|
|
120
|
+
bind:this={ref}
|
|
121
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
122
|
+
on:open
|
|
123
|
+
on:close
|
|
124
|
+
aria-label={ariaLabel}
|
|
125
|
+
aria-labelledby={ariaLabelledBy}
|
|
126
|
+
aria-describedby={ariaDescribedBy}
|
|
127
|
+
transition:transit|global={{
|
|
128
|
+
placement,
|
|
129
|
+
...getTransitionXY(placement),
|
|
130
|
+
...options,
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<!-- Rest Props kinda breaks transition... confirmed. -->
|
|
134
|
+
<!-- {...$$restProps} -->
|
|
135
|
+
<slot />
|
|
136
|
+
</di>
|
|
137
|
+
</div>
|
|
138
|
+
{/if}
|
|
139
|
+
{/if}
|
|
140
|
+
|
|
141
|
+
{#if position === 'absolute' || position === 'static'}
|
|
142
|
+
<div
|
|
143
|
+
{id}
|
|
144
|
+
class="DrawerContent {klass}"
|
|
145
|
+
{role}
|
|
146
|
+
{style}
|
|
147
|
+
bind:this={ref}
|
|
148
|
+
use:disclosureContent={{ options: disclosureContentOpts }}
|
|
149
|
+
aria-label={ariaLabel}
|
|
150
|
+
aria-labelledby={ariaLabelledBy}
|
|
151
|
+
aria-describedby={ariaDescribedBy}
|
|
152
|
+
on:open
|
|
153
|
+
on:close
|
|
154
|
+
transition:transit|global={{
|
|
155
|
+
placement,
|
|
156
|
+
...getTransitionXY(placement),
|
|
157
|
+
...options,
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
<!-- {...$$restProps} -->
|
|
161
|
+
<slot />
|
|
162
|
+
</div>
|
|
163
|
+
{/if}
|
|
164
|
+
{/if}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import SVG from '../../SVG/SVG.svelte'
|
|
3
|
+
import { disclosureTrigger } from '../disclosure.js'
|
|
4
|
+
import { defaultDrawerTriggerOpts } from './drawer.js'
|
|
5
|
+
|
|
6
|
+
let klass = ''
|
|
7
|
+
export { klass as class }
|
|
8
|
+
export let icon = null
|
|
9
|
+
export let iconClass = null
|
|
10
|
+
|
|
11
|
+
export let target
|
|
12
|
+
export let show = false
|
|
13
|
+
export let ariaPopup = $$restProps['aria-haspopup'] || 'dialog'
|
|
14
|
+
export let options = {}
|
|
15
|
+
|
|
16
|
+
const opts = {
|
|
17
|
+
...defaultDrawerTriggerOpts,
|
|
18
|
+
...options,
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<button
|
|
23
|
+
{target}
|
|
24
|
+
class="Button DrawerTrigger {klass}"
|
|
25
|
+
aria-haspopup={ariaPopup}
|
|
26
|
+
use:disclosureTrigger={{ state: { show }, options: opts }}
|
|
27
|
+
{...$$restProps}
|
|
28
|
+
>
|
|
29
|
+
<slot>
|
|
30
|
+
{#if icon}<SVG class={iconClass} {icon} />{/if}
|
|
31
|
+
</slot>
|
|
32
|
+
</button>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export const defaultDrawerTriggerOpts = {
|
|
2
|
+
closeOthers: true,
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const defaultDrawerContentOpts = {
|
|
6
|
+
position: 'fixed',
|
|
7
|
+
placement: 'left',
|
|
8
|
+
backdrop: true,
|
|
9
|
+
blurBackdrop: true,
|
|
10
|
+
scrollToAnchor: false,
|
|
11
|
+
portal: true,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const defaultDrawerPositionOpts = {
|
|
15
|
+
static: {
|
|
16
|
+
placement: 'top',
|
|
17
|
+
transition: 'slide',
|
|
18
|
+
closeOnOutsideClick: false,
|
|
19
|
+
closeOnEscapeButton: false,
|
|
20
|
+
},
|
|
21
|
+
absolute: {
|
|
22
|
+
placement: 'top',
|
|
23
|
+
transition: 'slide',
|
|
24
|
+
},
|
|
25
|
+
fixed: {
|
|
26
|
+
transition: 'fly',
|
|
27
|
+
focusManagement: 'trap',
|
|
28
|
+
inertOthers: true,
|
|
29
|
+
preventBodyScroll: true,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Use logical properties straight up
|
|
34
|
+
export function getTBLRValues({ placement, position }) {
|
|
35
|
+
const style = { position }
|
|
36
|
+
|
|
37
|
+
if (placement === 'top' || placement === 'bottom') {
|
|
38
|
+
style.insetInline = 0
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (placement === 'left' || placement === 'right') {
|
|
42
|
+
style.insetBlock = 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (placement === 'top') style.insetBlockStart = 0
|
|
46
|
+
if (placement === 'bottom') style.insetBlockEnd = 0
|
|
47
|
+
if (placement === 'left') style.insetInlineStart = 0
|
|
48
|
+
if (placement === 'right') style.insetInlineEnd = 0
|
|
49
|
+
return style
|
|
50
|
+
}
|
|
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,6 @@
|
|
|
1
|
+
import Drawer from './Drawer.svelte'
|
|
2
|
+
import DrawerCloseButton from './DrawerCloseButton.svelte'
|
|
3
|
+
import DrawerContent from './DrawerContent.svelte'
|
|
4
|
+
import DrawerTrigger from './DrawerTrigger.svelte'
|
|
5
|
+
|
|
6
|
+
export { Drawer, DrawerCloseButton, DrawerContent, DrawerTrigger }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { PopoverContent } from '../Popover'
|
|
3
|
+
import { defaultDropdownFloatingOpts } from './dropdown.js'
|
|
4
|
+
|
|
5
|
+
export let klass
|
|
6
|
+
export { klass as class }
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<PopoverContent
|
|
10
|
+
class="DropdownContent {klass}"
|
|
11
|
+
options={defaultDropdownFloatingOpts}
|
|
12
|
+
{...$$restProps}
|
|
13
|
+
>
|
|
14
|
+
<slot />
|
|
15
|
+
</PopoverContent>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { PopoverTrigger } from '../Popover'
|
|
3
|
+
import SVG from '../../SVG/SVG.svelte'
|
|
4
|
+
|
|
5
|
+
export let klass
|
|
6
|
+
export let icon = 'tabler:chevron-down'
|
|
7
|
+
|
|
8
|
+
export { klass as class }
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<PopoverTrigger class="DropdownTrigger {klass}" {...$$restProps}>
|
|
12
|
+
<slot />
|
|
13
|
+
<SVG {icon} />
|
|
14
|
+
</PopoverTrigger>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
// NOT DONE YET
|
|
3
|
+
import { disclosures, initDisclosure } from '../disclosure-store.js'
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_DISCLOSURE_TRIGGER_OPTS,
|
|
6
|
+
disclosureTrigger,
|
|
7
|
+
} from '../disclosure.js'
|
|
8
|
+
|
|
9
|
+
let klass
|
|
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)
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<button
|
|
26
|
+
{target}
|
|
27
|
+
class="Button ModalTrigger {klass}"
|
|
28
|
+
bind:this={d.nodes.triggerNode}
|
|
29
|
+
use:disclosureTrigger={{ target }}
|
|
30
|
+
{...$$restProps}
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</button>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
export default function exitIntent(node) {
|
|
3
|
+
document.addEventListener('pointerout', exiting)
|
|
4
|
+
|
|
5
|
+
function exiting(event) {
|
|
6
|
+
const { toElement, relatedTarget } = event
|
|
7
|
+
if (toElement === null && relatedTarget === null) {
|
|
8
|
+
node.dispatchEvent(new CustomEvent('exit'))
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
destroy() {
|
|
14
|
+
document.removeEventListener('pointerout', exiting)
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import SVG from '../../SVG/SVG.svelte'
|
|
3
|
+
import { close, getDisclosure } from '../disclosure.js'
|
|
4
|
+
|
|
5
|
+
export let klass = ''
|
|
6
|
+
export { klass as class }
|
|
7
|
+
export let icon = 'tabler:x'
|
|
8
|
+
export let iconClass = ''
|
|
9
|
+
export let target = null
|
|
10
|
+
|
|
11
|
+
let button = null
|
|
12
|
+
|
|
13
|
+
function handleClick() {
|
|
14
|
+
const id = target || button.closest('.PopoverContent').id
|
|
15
|
+
const d = getDisclosure(id)
|
|
16
|
+
close(d, { shouldFocusTrigger: true })
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<!-- aria-label="Close dialog" -->
|
|
21
|
+
|
|
22
|
+
<button
|
|
23
|
+
class="PopoverCloseButton Button-icon {klass}"
|
|
24
|
+
bind:this={button}
|
|
25
|
+
on:click={handleClick}
|
|
26
|
+
{...$$restProps}
|
|
27
|
+
>
|
|
28
|
+
<slot><SVG class={iconClass} {icon} /></slot>
|
|
29
|
+
</button>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
3
|
+
import * as easing from 'svelte/easing'
|
|
4
|
+
import { fade } from 'svelte/transition'
|
|
5
|
+
import { hasLabel } from '../../_shared/accessibility'
|
|
6
|
+
import Portal from '../../Portal.svelte'
|
|
7
|
+
import { disclosures } from '../disclosure-store.js'
|
|
8
|
+
import {
|
|
9
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
10
|
+
disclosureContent,
|
|
11
|
+
} from '../disclosure.js'
|
|
12
|
+
import { FLOATING_CONTENT_OPT_KEYS, floatingContent } from './floating.js'
|
|
13
|
+
import {
|
|
14
|
+
DEFAULT_POPOVER_CONTENT_OPTS,
|
|
15
|
+
DEFAULT_POPOVER_TRANSITION_OPTS,
|
|
16
|
+
} from './popover.js'
|
|
17
|
+
|
|
18
|
+
let klass = ''
|
|
19
|
+
export { klass as class }
|
|
20
|
+
|
|
21
|
+
export let id
|
|
22
|
+
export let role = 'dialog'
|
|
23
|
+
export let ariaLabel = $$restProps['aria-label']
|
|
24
|
+
export let ariaLabelledBy = $$restProps['aria-labelledby']
|
|
25
|
+
export let ariaDescribedBy = $$restProps['aria-describedby']
|
|
26
|
+
export let options = {}
|
|
27
|
+
|
|
28
|
+
if (!hasLabel(ariaLabel, ariaLabelledBy)) {
|
|
29
|
+
console.warn(
|
|
30
|
+
`PopoverContent (with id: ${id}) should have an accessible name. Please create one with aria-label or aria-labelledby.`,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const opts = {
|
|
35
|
+
...DEFAULT_POPOVER_CONTENT_OPTS.disclosure,
|
|
36
|
+
...DEFAULT_POPOVER_CONTENT_OPTS.popover,
|
|
37
|
+
...DEFAULT_POPOVER_TRANSITION_OPTS,
|
|
38
|
+
...options,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { picked: disclosureOpts } = splitObject(
|
|
42
|
+
opts,
|
|
43
|
+
DISCLOSURE_CONTENT_OPT_KEYS,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const { picked: floatingOpts } = splitObject(opts, FLOATING_CONTENT_OPT_KEYS)
|
|
47
|
+
const { picked: transitionOpts } = splitObject(
|
|
48
|
+
opts,
|
|
49
|
+
Object.keys(DEFAULT_POPOVER_TRANSITION_OPTS),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
transitionOpts.easing = easing[transitionOpts.easing]
|
|
53
|
+
|
|
54
|
+
const { portal } = opts
|
|
55
|
+
let d
|
|
56
|
+
$: d = $disclosures.find(d => d.id === id)
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
{#if d?.state.show}
|
|
60
|
+
{#if portal}
|
|
61
|
+
<Portal>
|
|
62
|
+
<div
|
|
63
|
+
{id}
|
|
64
|
+
{role}
|
|
65
|
+
tabindex="-1"
|
|
66
|
+
class={`PopoverContent ${klass}`}
|
|
67
|
+
use:floatingContent={floatingOpts}
|
|
68
|
+
use:disclosureContent={{ options: disclosureOpts }}
|
|
69
|
+
on:open
|
|
70
|
+
on:close
|
|
71
|
+
transition:fade={transitionOpts}
|
|
72
|
+
aria-label={ariaLabel}
|
|
73
|
+
aria-labelledby={ariaLabelledBy}
|
|
74
|
+
aria-describedby={ariaDescribedBy}
|
|
75
|
+
{...$$restProps}
|
|
76
|
+
>
|
|
77
|
+
<slot />
|
|
78
|
+
{#if floatingOpts.arrow}
|
|
79
|
+
<div class="PopoverArrow"></div>
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
82
|
+
</Portal>
|
|
83
|
+
{:else}
|
|
84
|
+
<div
|
|
85
|
+
{id}
|
|
86
|
+
{role}
|
|
87
|
+
tabindex="-1"
|
|
88
|
+
class={`PopoverContent ${klass}`}
|
|
89
|
+
use:floatingContent={floatingOpts}
|
|
90
|
+
use:disclosureContent={{ options: disclosureOpts }}
|
|
91
|
+
on:open
|
|
92
|
+
on:close
|
|
93
|
+
transition:fade={transitionOpts}
|
|
94
|
+
aria-label={ariaLabel}
|
|
95
|
+
aria-labelledby={ariaLabelledBy}
|
|
96
|
+
aria-describedby={ariaDescribedBy}
|
|
97
|
+
{...$$restProps}
|
|
98
|
+
>
|
|
99
|
+
<slot />
|
|
100
|
+
{#if floatingOpts.arrow}
|
|
101
|
+
<div class="PopoverArrow"></div>
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
{/if}
|
|
105
|
+
{/if}
|
|
106
|
+
|
|
107
|
+
<!-- transition:custom={transitionOptions} -->
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { isInvalidAriaPopup } from '../../_shared/accessibility.js'
|
|
3
|
+
import { disclosureTrigger } from '../disclosure.js'
|
|
4
|
+
import { DEFAULT_POPOVER_TRIGGER_OPTS } from './popover.js'
|
|
5
|
+
|
|
6
|
+
let klass = ''
|
|
7
|
+
export { klass as class }
|
|
8
|
+
|
|
9
|
+
export let target
|
|
10
|
+
export let show = false
|
|
11
|
+
export let ariaPopup = $$restProps['aria-haspopup'] || 'dialog'
|
|
12
|
+
export let options = {}
|
|
13
|
+
|
|
14
|
+
// Prevent invalid aria-haspopup values
|
|
15
|
+
if (isInvalidAriaPopup(ariaPopup)) ariaPopup = undefined
|
|
16
|
+
|
|
17
|
+
const opts = {
|
|
18
|
+
...DEFAULT_POPOVER_TRIGGER_OPTS,
|
|
19
|
+
...options,
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<button
|
|
24
|
+
{target}
|
|
25
|
+
class="Button PopoverTrigger {klass}"
|
|
26
|
+
aria-haspopup={ariaPopup}
|
|
27
|
+
aria-details={target}
|
|
28
|
+
use:disclosureTrigger={{ state: { show }, options: opts }}
|
|
29
|
+
{...$$restProps}
|
|
30
|
+
on:click
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</button>
|