@splendidlabz/svelte 0.4.0 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/actions/index.js +2 -5
- package/actions/portal.js +1 -1
- package/actions/scroll-observer.js +1 -1
- package/common.js +1 -1
- package/components/Accordion/Accordion.svelte +67 -60
- package/components/Breadcrumbs/Crumb.svelte +1 -1
- package/components/Breadcrumbs/CrumbCustom.svelte +1 -1
- package/components/{BrowserFrame.svelte → BrowserFrame/BrowserFrame.svelte} +1 -1
- package/components/BrowserFrame/index.js +3 -0
- package/components/ContentList/ContentList-old.svelte +1 -1
- package/components/ContentList/ContentList.svelte +1 -1
- package/components/Copyright.svelte +19 -0
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +21 -15
- package/components/Disclosure/Drawer/DrawerContent.svelte +92 -128
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +38 -20
- package/components/Disclosure/Dropdown/DropdownTrigger.svelte +1 -1
- package/components/Disclosure/Modal/exit-intent.js +1 -1
- package/components/Disclosure/Popover/PopoverCloseButton.svelte +1 -1
- package/components/Disclosure/disclosure.svelte.js +432 -0
- package/components/FancyList/FancyList.svelte +1 -1
- package/components/Form/Checkbox.svelte +3 -3
- package/components/Form/Checkboxes.svelte +1 -1
- package/components/Form/Combobox/combobox.js +6 -5
- package/components/Form/Radio.svelte +3 -3
- package/components/Form/Radios.svelte +1 -1
- package/components/Form/Select.svelte +4 -4
- package/components/Form/TextInput.svelte +88 -65
- package/components/Form/Textarea.svelte +87 -64
- package/components/Highlight.svelte +46 -0
- package/components/Icon/Icon.svelte +43 -0
- package/components/Icon/index.js +2 -0
- package/components/PerspectiveHover/PerspectiveHover.svelte +1 -1
- package/components/PerspectiveHover/perspective-hover.js +1 -1
- package/components/Portal.svelte +1 -1
- package/components/Spotlight/PointerPosition.js +1 -1
- package/components/Spotlight/Spotlight.svelte +1 -1
- package/components/Tabs/tabs.js +8 -11
- package/components/Video.svelte +1 -1
- package/components/Vimeo.svelte +1 -1
- package/components/Youtube.svelte +1 -1
- package/components/_shared/accessibility.js +1 -0
- package/components/effects/index.js +0 -0
- package/index.js +7 -4
- package/package.json +11 -12
- package/utils/index.js +2 -0
- package/utils/merge-opts.js +5 -0
- package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +0 -198
- package/components/Resizer/draggable.js +0 -23
- package/components/SVG/SVG.svelte +0 -120
- package/components/Tabs-Old/Tab.svelte +0 -9
- package/components/Tabs-Old/Tablist.svelte +0 -13
- package/components/Tabs-Old/Tabpanel.svelte +0 -10
- package/components/Tabs-Old/Tabpanels.svelte +0 -14
- package/components/Tabs-Old/Tabs.svelte +0 -83
- package/components/Tabs-Old/index.js +0 -7
- package/components/Tabs-Old/tabs.js +0 -306
- package/components/_shared/key.js +0 -1
- /package/components/{BrowserWithTabs.svelte → BrowserFrame/BrowserWithTabs.svelte} +0 -0
- /package/{components/_shared → utils}/transitions.js +0 -0
|
@@ -1,32 +1,50 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { splitObject } from '@splendidlabz/utils'
|
|
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'
|
|
4
9
|
import { defaultDrawerTriggerOpts } from './drawer.js'
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
const p = $props()
|
|
12
|
+
const defaultOpts = {
|
|
13
|
+
'aria-haspopup': 'dialog',
|
|
14
|
+
}
|
|
15
|
+
const opts = mergeOpts(defaultDrawerTriggerOpts, defaultOpts, p)
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
const {
|
|
18
|
+
class: klass,
|
|
19
|
+
icon,
|
|
20
|
+
iconClass,
|
|
21
|
+
target,
|
|
22
|
+
'aria-haspopup': ariaPopup,
|
|
23
|
+
children,
|
|
24
|
+
...restProps
|
|
25
|
+
} = opts
|
|
15
26
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
const { picked: triggerOpts, ...remaining } = splitObject(
|
|
28
|
+
restProps,
|
|
29
|
+
DISCLOSURE_TRIGGER_OPT_KEYS,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
let show = $state(false)
|
|
20
33
|
</script>
|
|
21
34
|
|
|
22
35
|
<button
|
|
36
|
+
{...remaining}
|
|
23
37
|
{target}
|
|
24
|
-
class="
|
|
38
|
+
class="button drawer-trigger {klass}"
|
|
25
39
|
aria-haspopup={ariaPopup}
|
|
26
|
-
use:disclosureTrigger={{
|
|
27
|
-
|
|
40
|
+
use:disclosureTrigger={{
|
|
41
|
+
state: { show },
|
|
42
|
+
options: triggerOpts,
|
|
43
|
+
}}
|
|
28
44
|
>
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
|
|
45
|
+
{#if children}
|
|
46
|
+
{@render children()}
|
|
47
|
+
{:else if icon}
|
|
48
|
+
<Icon class={iconClass} {icon} />
|
|
49
|
+
{/if}
|
|
32
50
|
</button>
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Focusable,
|
|
3
|
+
addListeners,
|
|
4
|
+
isTab,
|
|
5
|
+
manageFocus,
|
|
6
|
+
removeListeners,
|
|
7
|
+
trapFocus,
|
|
8
|
+
} from '@splendidlabz/utils/dom'
|
|
9
|
+
import { delay, omitEmpty } from '@splendidlabz/utils'
|
|
10
|
+
|
|
11
|
+
// ========================================
|
|
12
|
+
// Default Options
|
|
13
|
+
// ========================================
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} DisclosureTriggerOpts
|
|
16
|
+
* @property {boolean} showOnHover - Show disclosure content on hover.
|
|
17
|
+
* @property {boolean} showOnFocus - Show disclosure content on focus.
|
|
18
|
+
* @property {number} hoverCloseDelay - Delay in milliseconds before closing disclosure content on mouse leave.
|
|
19
|
+
* @property {boolean} closeOthers - Close other disclosures when opening this disclosure.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_DISCLOSURE_TRIGGER_OPTS = {
|
|
22
|
+
showOnClick: true,
|
|
23
|
+
showOnHover: false,
|
|
24
|
+
showOnFocus: false,
|
|
25
|
+
hoverCloseDelay: 120,
|
|
26
|
+
closeOthers: true,
|
|
27
|
+
// shiftTabBackToContent: true,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const DISCLOSURE_TRIGGER_OPT_KEYS = Object.keys(
|
|
31
|
+
DEFAULT_DISCLOSURE_TRIGGER_OPTS,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} DisclosureContentOpts
|
|
36
|
+
* @property {boolean} closeOnOutsideClick - Close disclosure content when clicking outside of contentNode and triggerNode.
|
|
37
|
+
* @property {boolean} closeOnEscapeButton - Close disclosure content when pressing the escape key.
|
|
38
|
+
* @property {boolean} preventBodyScroll - Prevent body from scrolling when disclosure content is open.
|
|
39
|
+
* @property {boolean} trapFocus - Trap focus within disclosure content.
|
|
40
|
+
* @property {(string|HTMLElement)} focusTargetWhenOpening - Focus target when disclosure content is opened. Can be 'first', 'content', or an HTMLElement.
|
|
41
|
+
*/
|
|
42
|
+
export const DEFAULT_DISCLOSURE_CONTENT_OPTS = {
|
|
43
|
+
closeOnOutsideClick: true,
|
|
44
|
+
closeOnEscapeButton: true,
|
|
45
|
+
focusManagement: 'manage', // false, `manage`, `trap`
|
|
46
|
+
focusWhenOpen: 'content', // || false, 'first', 'content'. TODO: HTMLElement
|
|
47
|
+
focusWhenClose: 'trigger', // false
|
|
48
|
+
usePortal: true,
|
|
49
|
+
useModal: false,
|
|
50
|
+
useTriggerWidth: false,
|
|
51
|
+
// inertOthers: false,
|
|
52
|
+
// preventBodyScroll: false,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const DISCLOSURE_CONTENT_OPT_KEYS = Object.keys(
|
|
56
|
+
DEFAULT_DISCLOSURE_CONTENT_OPTS,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
// ========================================
|
|
60
|
+
// Shared state
|
|
61
|
+
// ========================================
|
|
62
|
+
const disclosures = $state([])
|
|
63
|
+
|
|
64
|
+
export function getDisclosure(id) {
|
|
65
|
+
return disclosures.find(d => d.id === id)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function initDisclosure(part, disclosureInfo) {
|
|
69
|
+
const { id } = disclosureInfo
|
|
70
|
+
let d = getDisclosure(id)
|
|
71
|
+
if (!d) {
|
|
72
|
+
disclosures.push(disclosureInfo)
|
|
73
|
+
return getDisclosure(id)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// If trigger or content is already initialized, don't re-init
|
|
77
|
+
if (part === 'trigger' && d.nodes.trigger) return d
|
|
78
|
+
if (part === 'content' && d.nodes.content) return d
|
|
79
|
+
|
|
80
|
+
// Initialize new info from trigger or content
|
|
81
|
+
d.state = { ...d.state, ...omitEmpty(disclosureInfo.state) }
|
|
82
|
+
d.options = { ...d.options, ...omitEmpty(disclosureInfo.options) }
|
|
83
|
+
d.nodes = {
|
|
84
|
+
...d.nodes,
|
|
85
|
+
...omitEmpty(disclosureInfo.nodes, { shallow: true }),
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return d
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ========================================
|
|
92
|
+
// Actions
|
|
93
|
+
// ========================================
|
|
94
|
+
/**
|
|
95
|
+
* Disclosure Trigger
|
|
96
|
+
* @prop {HTMLElement} node - The trigger element.
|
|
97
|
+
* @prop {DisclosureTriggerOpts} props - The trigger options.
|
|
98
|
+
*/
|
|
99
|
+
export function disclosureTrigger(node, props = {}) {
|
|
100
|
+
const id = node.getAttribute('target')
|
|
101
|
+
const disclosureInfo = {
|
|
102
|
+
id,
|
|
103
|
+
state: { show: false, ...omitEmpty(props.state) },
|
|
104
|
+
nodes: { trigger: node },
|
|
105
|
+
options: {
|
|
106
|
+
...DEFAULT_DISCLOSURE_TRIGGER_OPTS,
|
|
107
|
+
...props.options,
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let d = initDisclosure('trigger', disclosureInfo)
|
|
112
|
+
node.setAttribute('aria-expanded', d.state.show)
|
|
113
|
+
|
|
114
|
+
const listeners = [
|
|
115
|
+
{
|
|
116
|
+
event: 'click',
|
|
117
|
+
node,
|
|
118
|
+
handler: handleClick,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
event: 'keydown',
|
|
122
|
+
node,
|
|
123
|
+
handler: closeOnEscapeButton,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
event: 'keydown',
|
|
127
|
+
node,
|
|
128
|
+
handler: tabOntoContent,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
event: 'pointerenter',
|
|
132
|
+
node,
|
|
133
|
+
handler: handlePointerEnter,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
event: 'pointerleave',
|
|
137
|
+
node,
|
|
138
|
+
handler: handlePointerLeave,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
event: 'focusin',
|
|
142
|
+
node,
|
|
143
|
+
handler: handleFocusIn,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
event: 'focusout',
|
|
147
|
+
node,
|
|
148
|
+
handler: handleFocusOut,
|
|
149
|
+
},
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
function handleClick(event) {
|
|
153
|
+
if (d.options.showOnClick) {
|
|
154
|
+
if (d.state.show === false) return open(d)
|
|
155
|
+
if (d.state.show === true) return close(d)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function closeOnEscapeButton(event) {
|
|
160
|
+
if (d.options.closeOnEscapeButton) {
|
|
161
|
+
if (event.key === 'Escape') close(d)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function tabOntoContent(event) {
|
|
166
|
+
if (d.state.show === false) return
|
|
167
|
+
console.log('tabOntoContent')
|
|
168
|
+
if (isTab(event)) {
|
|
169
|
+
event.preventDefault()
|
|
170
|
+
d.nodes.contentFocusables.first?.focus()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// function backToDisclosureContent(event) {
|
|
175
|
+
// if (d.options.shiftTabBackToContent === false) return
|
|
176
|
+
// if (isShiftTab(event) && d.state.show === true) {
|
|
177
|
+
// setTimeout(_ => {
|
|
178
|
+
// d.nodes.content.focus({ preventScroll: true })
|
|
179
|
+
// }, 0)
|
|
180
|
+
// }
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
function handlePointerEnter(event) {
|
|
184
|
+
if (d.options.showOnHover) {
|
|
185
|
+
d.state.pointerLocation = 'trigger'
|
|
186
|
+
open(d)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function handlePointerLeave(event) {
|
|
191
|
+
if (d.options.showOnHover) {
|
|
192
|
+
d.state.pointerLocation = null
|
|
193
|
+
|
|
194
|
+
await delay(d.options.hoverCloseDelay)
|
|
195
|
+
if (d.state.pointerLocation === null) {
|
|
196
|
+
d.state.isMouseOut = true
|
|
197
|
+
close(d)
|
|
198
|
+
d.state.isMouseOut = false
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function handleFocusIn(event) {
|
|
204
|
+
if (d.options.showOnFocus) open(d)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function handleFocusOut() {
|
|
208
|
+
if (d.options.showOnFocus) close(d)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
addListeners(listeners)
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
destroy() {
|
|
215
|
+
removeListeners(listeners)
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Disclosure Content action.
|
|
222
|
+
* Disclosure content will only activate when d.state.show is updated to true
|
|
223
|
+
* @prop {HTMLElement} node - The trigger element.
|
|
224
|
+
* @prop {DisclosureContentOpts} props - The trigger options.
|
|
225
|
+
*/
|
|
226
|
+
export function disclosureContent(node, props = {}) {
|
|
227
|
+
const id = node.getAttribute('id')
|
|
228
|
+
const contentFocusables = Focusable(node)
|
|
229
|
+
|
|
230
|
+
const disclosureInfo = {
|
|
231
|
+
id,
|
|
232
|
+
state: omitEmpty(props.state),
|
|
233
|
+
nodes: { content: node, contentFocusables },
|
|
234
|
+
options: {
|
|
235
|
+
...DEFAULT_DISCLOSURE_CONTENT_OPTS,
|
|
236
|
+
...omitEmpty(props.options),
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Initialize the disclosure
|
|
241
|
+
let d = initDisclosure('content', disclosureInfo)
|
|
242
|
+
contentOpeningActions(d)
|
|
243
|
+
|
|
244
|
+
// Add event listeners
|
|
245
|
+
const listeners = [
|
|
246
|
+
{
|
|
247
|
+
event: 'click',
|
|
248
|
+
node: document,
|
|
249
|
+
handler: handleOutsideClick,
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
{
|
|
253
|
+
event: 'keydown',
|
|
254
|
+
node,
|
|
255
|
+
handler: handleKeydown,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
event: 'mouseenter',
|
|
259
|
+
node,
|
|
260
|
+
handler: handleMouseEnter,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
event: 'mouseleave',
|
|
264
|
+
node,
|
|
265
|
+
handler: handleMouseLeave,
|
|
266
|
+
},
|
|
267
|
+
]
|
|
268
|
+
|
|
269
|
+
addListeners(listeners)
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
destroy() {
|
|
273
|
+
removeListeners(listeners)
|
|
274
|
+
},
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ========================
|
|
278
|
+
// Event Listeners
|
|
279
|
+
// ========================
|
|
280
|
+
// Close if click is outside of contentNode and triggerNode
|
|
281
|
+
function handleOutsideClick(event) {
|
|
282
|
+
if (d.options.closeOnOutsideClick === false) return
|
|
283
|
+
if (d.nodes.content.contains(event.target)) return
|
|
284
|
+
if (d.nodes.trigger.contains(event.target)) return
|
|
285
|
+
// Only close if state is currently set to show
|
|
286
|
+
if (d.state.show) {
|
|
287
|
+
if (d.options.closeOthers) close(d)
|
|
288
|
+
else if (!clickedOnOtherDisclosureNodes(event.target, d.id)) close(d)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function handleKeydown(event) {
|
|
293
|
+
const { focusManagement } = d.options
|
|
294
|
+
|
|
295
|
+
if (focusManagement === 'trap') {
|
|
296
|
+
trapFocus({ event, focusables: d.nodes.contentFocusables })
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (focusManagement === 'manage') {
|
|
300
|
+
manageFocus({
|
|
301
|
+
event,
|
|
302
|
+
triggerNode: d.nodes.trigger,
|
|
303
|
+
contentNode: d.nodes.content,
|
|
304
|
+
focusables: d.nodes.contentFocusables,
|
|
305
|
+
shouldFocusTriggerWhenTabbingOut: d.options.focusTriggerWhenTabbingOut,
|
|
306
|
+
onLeave(direction) {
|
|
307
|
+
if (direction === 'forward') close(d)
|
|
308
|
+
},
|
|
309
|
+
})
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (d.options.closeOnEscapeButton) closeOnEscape(event)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function closeOnEscape(event) {
|
|
316
|
+
if (event.key === 'Escape') close(d, { shouldFocusTrigger: true })
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function handleMouseEnter() {
|
|
320
|
+
if (!d.options.showOnHover) return
|
|
321
|
+
d.state.pointerLocation = 'content'
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function handleMouseLeave() {
|
|
325
|
+
if (!d.options.showOnHover) return
|
|
326
|
+
d.state.pointerLocation = null
|
|
327
|
+
close(d)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ========================================
|
|
332
|
+
// Methods
|
|
333
|
+
// ========================================
|
|
334
|
+
export function open(d) {
|
|
335
|
+
if (d.state.show) return
|
|
336
|
+
d.state.show = true
|
|
337
|
+
|
|
338
|
+
const { trigger } = d.nodes
|
|
339
|
+
trigger.setAttribute('aria-expanded', d.state.show)
|
|
340
|
+
if (d.options.closeOthers) closeOthersExcept(d.id)
|
|
341
|
+
|
|
342
|
+
// Note: The rest of the opening actions are handled openingActions after we retrieve disclosureContent props
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function contentOpeningActions(d) {
|
|
346
|
+
const { content: node, contentFocusables } = d.nodes
|
|
347
|
+
const { focusWhenOpen, usePortal, useModal, useTriggerWidth } = d.options
|
|
348
|
+
node.setAttribute('tabindex', '-1')
|
|
349
|
+
|
|
350
|
+
if (useTriggerWidth) {
|
|
351
|
+
const { width: triggerWidth } = d.nodes.trigger.getBoundingClientRect()
|
|
352
|
+
node.style.width = triggerWidth + 'px'
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Re-introduce useModal, stopBodyScroll, allowBodyScroll, inertOthers, etc later when working on modal or elements that causes scroll
|
|
356
|
+
// if (useModal) {
|
|
357
|
+
// inertOthers(d)
|
|
358
|
+
// stopBodyScroll(d)
|
|
359
|
+
// }
|
|
360
|
+
|
|
361
|
+
// Set focus.
|
|
362
|
+
// This requires timeout. Otherwise focus is set too early.
|
|
363
|
+
setTimeout(_ => {
|
|
364
|
+
if (focusWhenOpen) {
|
|
365
|
+
if (focusWhenOpen === 'content') node.focus()
|
|
366
|
+
if (focusWhenOpen === 'first') contentFocusables.first?.focus()
|
|
367
|
+
if (focusWhenOpen === 'second') contentFocusables[1]?.focus()
|
|
368
|
+
}
|
|
369
|
+
// Dispatch an open event when all is done
|
|
370
|
+
d.nodes.content.dispatchEvent(new CustomEvent('open'))
|
|
371
|
+
}, 0)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export function close(d, { shouldFocusWhenClosing = true } = {}) {
|
|
375
|
+
if (!d.state.show) return
|
|
376
|
+
d.state.show = false
|
|
377
|
+
|
|
378
|
+
const { trigger, content } = d.nodes
|
|
379
|
+
const { isMouseOut } = d.state
|
|
380
|
+
const { focusWhenClose } = d.options
|
|
381
|
+
trigger.setAttribute('aria-expanded', d.state.show)
|
|
382
|
+
|
|
383
|
+
// Handle Inert and bodyscroll later
|
|
384
|
+
// revertInert(d)
|
|
385
|
+
// if (d.options.preventBodyScroll) revertPreventBodyScroll()
|
|
386
|
+
|
|
387
|
+
// Decide whether to focus on trigger
|
|
388
|
+
if (focusWhenClose === false) shouldFocusWhenClosing = false
|
|
389
|
+
// Mouseout can cause focus to jump around
|
|
390
|
+
if (isMouseOut) shouldFocusWhenClosing = false
|
|
391
|
+
|
|
392
|
+
// Focuses on trigger
|
|
393
|
+
if (shouldFocusWhenClosing) trigger.focus()
|
|
394
|
+
|
|
395
|
+
// Dispatch close event when all is done
|
|
396
|
+
// Checks content to ensure content node is present before dispatching event.
|
|
397
|
+
if (content) content.dispatchEvent(new CustomEvent('close'))
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function closeOthersExcept(id) {
|
|
401
|
+
disclosures.forEach(d => {
|
|
402
|
+
if (d.id !== id) close(d, { shouldFocusWhenClosing: false })
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function clickedOnOtherDisclosureNodes(target, id) {
|
|
407
|
+
const disclosures = getDisclosures()
|
|
408
|
+
return disclosures.some(d => {
|
|
409
|
+
if (d.id === id) return false
|
|
410
|
+
if (d.nodes.trigger?.contains(target)) return true
|
|
411
|
+
if (d.nodes.content?.contains(target)) return true
|
|
412
|
+
return false
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function makeOthersInert(d) {
|
|
417
|
+
const bodyChildren = getChildrenElements(document.body)
|
|
418
|
+
// Disclosures are often placed inside Portal divs — not directly on the body element — so we need to account for portals.
|
|
419
|
+
const elementsToInert = bodyChildren.filter(
|
|
420
|
+
child => !isAncestor(child, d.nodes.content),
|
|
421
|
+
)
|
|
422
|
+
elementsToInert.forEach(el => el.setAttribute('inert', ''))
|
|
423
|
+
d.state.inertElements = elementsToInert
|
|
424
|
+
// Apparently, no need to updateDisclosure before reverting Inert later.
|
|
425
|
+
// (Probably cos close() updates disclosure first).
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function revertInert(d) {
|
|
429
|
+
d.state.inertElements?.forEach(el => {
|
|
430
|
+
if (el.removeAttribute) el.removeAttribute('inert', '')
|
|
431
|
+
})
|
|
432
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { toTitle } from '@splendidlabz/utils'
|
|
3
3
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
-
import SVG from '../
|
|
4
|
+
import SVG from '../Icon/Icon.svelte'
|
|
5
5
|
import TextInput from './TextInput.svelte'
|
|
6
6
|
let klass = ''
|
|
7
7
|
export { klass as class }
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
<div class="Checkbox {klass}" class:checked class:disabled class:readonly>
|
|
40
40
|
<div class="Checkmark">
|
|
41
41
|
<input
|
|
42
|
-
class="
|
|
42
|
+
class="input {fieldClass}"
|
|
43
43
|
type="checkbox"
|
|
44
44
|
{id}
|
|
45
45
|
{name}
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
</div>
|
|
72
72
|
|
|
73
73
|
{#if label}
|
|
74
|
-
<label class="
|
|
74
|
+
<label class="label {labelClass}" for={id}>{label}</label>
|
|
75
75
|
{/if}
|
|
76
76
|
|
|
77
77
|
{#if hasInput}
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// inputInstance.indeterminate = true
|
|
31
31
|
</script>
|
|
32
32
|
|
|
33
|
-
<fieldset class="
|
|
33
|
+
<fieldset class="fieldset {klass}" on:change bind:this={ref} {...$$restProps}>
|
|
34
34
|
{#if legend}
|
|
35
35
|
<legend class="Legend {legendClass}">{legend}</legend>
|
|
36
36
|
{/if}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { omitEmpty } from '@splendidlabz/utils'
|
|
2
1
|
import {
|
|
3
2
|
addListeners,
|
|
4
3
|
getSiblingElements,
|
|
@@ -8,13 +7,15 @@ import {
|
|
|
8
7
|
randomString,
|
|
9
8
|
removeListeners,
|
|
10
9
|
} from '@splendidlabz/utils/dom'
|
|
11
|
-
import { getDisclosure } from '../../Disclosure/disclosure-store.js'
|
|
12
10
|
import {
|
|
13
11
|
close as closeDisclosure,
|
|
14
12
|
open as openDisclosure,
|
|
15
13
|
} from '../../Disclosure/disclosure.js'
|
|
16
14
|
import { initCombobox, updateCombobox } from './combobox-store.js'
|
|
17
15
|
|
|
16
|
+
import { getDisclosure } from '../../Disclosure/disclosure-store.js'
|
|
17
|
+
import { omitEmpty } from '@splendidlabz/utils'
|
|
18
|
+
|
|
18
19
|
// Shifted focusTriggerOnClose to disclosureContent
|
|
19
20
|
export const DEFAULT_COMBOBOX_INPUT_OPTIONS = {
|
|
20
21
|
disclosure: {
|
|
@@ -141,9 +142,9 @@ export function listboxTrigger() {}
|
|
|
141
142
|
/**
|
|
142
143
|
* Initializes a listbox component on the given DOM node with the specified properties.
|
|
143
144
|
* @param {HTMLElement} node - The DOM node to which the listbox behavior will be attached.
|
|
144
|
-
* @param {Object} [
|
|
145
|
-
* @param {boolean} [
|
|
146
|
-
* @param {Function} [
|
|
145
|
+
* @param {Object} [passedProps={}] - An optional object containing properties to configure the listbox.
|
|
146
|
+
* @param {boolean} [passedProps.multiple=false] - If true, allows multiple selections; otherwise, only one item can be selected.
|
|
147
|
+
* @param {Function} [passedProps.onSelect] - A callback function that is called when an item is selected.
|
|
147
148
|
*/
|
|
148
149
|
export function listbox(node, props = {}) {
|
|
149
150
|
const id = node.getAttribute('id')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { toTitle } from '@splendidlabz/utils'
|
|
3
3
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
-
import SVG from '../
|
|
4
|
+
import SVG from '../Icon/Icon.svelte'
|
|
5
5
|
import TextInput from './TextInput.svelte'
|
|
6
6
|
|
|
7
7
|
let klass = ''
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
<div class="Radio {klass}" class:checked class:disabled class:readonly>
|
|
36
36
|
<div class="Radiomark">
|
|
37
37
|
<input
|
|
38
|
-
class="
|
|
38
|
+
class="input {fieldClass}"
|
|
39
39
|
type="radio"
|
|
40
40
|
{id}
|
|
41
41
|
{name}
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
</div>
|
|
61
61
|
|
|
62
62
|
{#if label}
|
|
63
|
-
<label class="
|
|
63
|
+
<label class="label {labelClass}" for={id}> {label} </label>
|
|
64
64
|
{/if}
|
|
65
65
|
|
|
66
66
|
{#if hasInput}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
checked = radios.find(radio => radio.checked)?.value
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
|
-
<fieldset class="
|
|
34
|
+
<fieldset class="fieldset {klass}" bind:this={ref} {...$$restProps}>
|
|
35
35
|
{#if legend}
|
|
36
36
|
<legend class="Legend {legendClass}">{legend}</legend>
|
|
37
37
|
{/if}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { toTitle } from '@splendidlabz/utils'
|
|
3
3
|
import { randomString } from '@splendidlabz/utils/dom'
|
|
4
|
-
import SVG from '../
|
|
4
|
+
import SVG from '../Icon/Icon.svelte'
|
|
5
5
|
import Hidden from './Hidden.svelte'
|
|
6
6
|
|
|
7
7
|
let klass = ''
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
}
|
|
67
67
|
</script>
|
|
68
68
|
|
|
69
|
-
<div class="
|
|
70
|
-
<label class="
|
|
71
|
-
<div class="
|
|
69
|
+
<div class="text-field Select {klass}">
|
|
70
|
+
<label class="label" for={id}>{label}</label>
|
|
71
|
+
<div class="input-group items-center" class:Stack={!multiple}>
|
|
72
72
|
{#if !multiple}
|
|
73
73
|
<select {...props} bind:value={selected} on:change {...$$restProps}>
|
|
74
74
|
{#each items as option}
|