@splendidlabz/svelte 4.4.0 → 4.5.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/components/Disclosure/Disclosure/DisclosureContent.svelte +1 -1
  3. package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +30 -3
  4. package/components/Disclosure/Disclosure/disclosure.svelte.js +61 -79
  5. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +14 -30
  6. package/components/Disclosure/Drawer/DrawerContent.svelte +58 -74
  7. package/components/Disclosure/Drawer/DrawerTrigger.svelte +13 -6
  8. package/components/Disclosure/Drawer/drawer.js +3 -1
  9. package/components/Disclosure/Drawer/index.js +6 -2
  10. package/components/Disclosure/Modal/ModalContent.svelte +122 -32
  11. package/components/Disclosure/Modal/ModalTrigger.svelte +63 -6
  12. package/components/Disclosure/Modal/index.js +2 -2
  13. package/components/Disclosure/Popover/PopoverContent.svelte +109 -97
  14. package/components/Disclosure/Popover/PopoverTrigger.svelte +67 -22
  15. package/components/Disclosure/Popover/floating.js +278 -117
  16. package/components/Disclosure/Popover/index.js +3 -2
  17. package/components/Disclosure/index.js +3 -7
  18. package/components/Disclosure/shared.js +1 -0
  19. package/components/DisclosureOld/Drawer/DrawerCloseButton.svelte +37 -0
  20. package/components/DisclosureOld/Drawer/DrawerContent.svelte +92 -0
  21. package/components/DisclosureOld/Drawer/DrawerTrigger.svelte +11 -0
  22. package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/drawer.js +0 -26
  23. package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/index.js +2 -6
  24. package/components/DisclosureOld/Modal/ModalContent.svelte +42 -0
  25. package/components/DisclosureOld/Modal/ModalTrigger.svelte +11 -0
  26. package/components/DisclosureOld/Modal/index.js +5 -0
  27. package/components/{Disclosure → DisclosureOld}/Popover/PopoverCloseButton.svelte +4 -1
  28. package/components/DisclosureOld/Popover/PopoverContent.svelte +107 -0
  29. package/components/DisclosureOld/Popover/PopoverTrigger.svelte +33 -0
  30. package/components/DisclosureOld/Popover/floating.js +171 -0
  31. package/components/DisclosureOld/Popover/index.js +5 -0
  32. package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipTrigger.svelte +1 -1
  33. package/components/{Disclosure → DisclosureOld}/disclosure.js +3 -0
  34. package/components/Form/Combobox/AutocompleteInput.svelte +3 -3
  35. package/components/Form/Combobox/AutocompleteOptions.svelte +5 -5
  36. package/components/Form/Combobox/TimepickerInput.svelte +7 -7
  37. package/components/Form/Combobox/TimepickerOptions.svelte +7 -7
  38. package/components/Form/Combobox/autocomplete.js +2 -2
  39. package/components/Form/Combobox/combobox.js +2 -2
  40. package/package.json +3 -3
  41. package/components/Disclosure/DrawerNew/DrawerCloseButton.svelte +0 -21
  42. package/components/Disclosure/DrawerNew/DrawerContent.svelte +0 -75
  43. package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +0 -18
  44. package/components/Disclosure/ModalNew/ModalContent.svelte +0 -132
  45. package/components/Disclosure/ModalNew/ModalTrigger.svelte +0 -68
  46. package/components/Disclosure/ModalNew/index.js +0 -5
  47. package/components/Disclosure/PopoverNew/PopoverContent.svelte +0 -119
  48. package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +0 -78
  49. package/components/Disclosure/PopoverNew/floating.js +0 -332
  50. package/components/Disclosure/PopoverNew/index.js +0 -6
  51. package/components/Disclosure/state.svelte.js +0 -138
  52. /package/components/Disclosure/{ModalNew → Modal}/ModalClose.svelte +0 -0
  53. /package/components/Disclosure/{PopoverNew → Popover}/Popover.svelte +0 -0
  54. /package/components/Disclosure/{PopoverNew → Popover}/PopoverClose.svelte +0 -0
  55. /package/components/{Disclosure → DisclosureOld}/Drawer/Drawer.svelte +0 -0
  56. /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownContent.svelte +0 -0
  57. /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownTrigger.svelte +0 -0
  58. /package/components/{Disclosure → DisclosureOld}/Dropdown/dropdown.js +0 -0
  59. /package/components/{Disclosure → DisclosureOld}/Dropdown/index.js +0 -0
  60. /package/components/{Disclosure → DisclosureOld}/Modal/Modal.svelte +0 -0
  61. /package/components/{Disclosure → DisclosureOld}/Modal/ModalCloseButton.svelte +0 -0
  62. /package/components/{Disclosure → DisclosureOld}/Modal/exit-intent.js +0 -0
  63. /package/components/{Disclosure → DisclosureOld}/Modal/modal.js +0 -0
  64. /package/components/{Disclosure/Disclosure → DisclosureOld}/Old/DisclosureContentOld.svelte +0 -0
  65. /package/components/{Disclosure/Disclosure → DisclosureOld}/Old/DisclosureTriggerOld.svelte +0 -0
  66. /package/components/{Disclosure → DisclosureOld}/Popover/popover.js +0 -0
  67. /package/components/{Disclosure → DisclosureOld}/Popover/references/FollowTheMouse.svelte +0 -0
  68. /package/components/{Disclosure → DisclosureOld}/Tooltip/Tooltip.svelte +0 -0
  69. /package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipContent.svelte +0 -0
  70. /package/components/{Disclosure → DisclosureOld}/Tooltip/index.js +0 -0
  71. /package/components/{Disclosure → DisclosureOld}/Tooltip/tooltip.js +0 -0
  72. /package/components/{Disclosure → DisclosureOld}/disclosure-store.js +0 -0
  73. /package/components/{Disclosure → DisclosureOld}/disclosure.svelte.js +0 -0
@@ -1,171 +1,332 @@
1
1
  import {
2
- arrow,
2
+ arrow as arrowFn,
3
3
  autoUpdate,
4
4
  computePosition,
5
5
  flip,
6
- offset,
6
+ offset as offsetFn,
7
7
  shift,
8
8
  } from '@floating-ui/dom'
9
- import { mix, splitUnit } from '@splendidlabz/utils'
10
- import { em, rem } from '@splendidlabz/utils/dom'
9
+ import { mix, splitUnit, toRadians } from '@splendidlabz/utils'
10
+ import { getCSSVar, setCSSVar, toPx } from '@splendidlabz/utils/dom'
11
11
 
12
12
  // TODO: Add inline for tooltips
13
- export const DEFAULT_FLOATING_CONTENT_OPTS = {
13
+ export const FLOATING_OPTS = {
14
14
  placement: 'top',
15
15
  strategy: 'absolute',
16
- offset: '0.5rem',
16
+ offset: '0',
17
17
  arrow: false,
18
- arrowWidth: '0.6rem',
19
- arrowDelta: 0,
20
- inline: false,
18
+ arrowHeight: 0,
19
+ arrowRadius: '5px',
20
+ boxStyle: 'standard', // standard, fancy
21
+ useReferenceBoundaries: false,
21
22
  }
22
23
 
23
- export const FLOATING_CONTENT_OPT_KEYS = Object.keys(
24
- DEFAULT_FLOATING_CONTENT_OPTS,
25
- )
24
+ export const FLOATING_OPTS_KEYS = Object.keys(FLOATING_OPTS)
25
+
26
+ export function initFloating(options) {
27
+ options = mix(FLOATING_OPTS, options)
28
+ const {
29
+ referenceNode,
30
+ floatingNode,
31
+ boxStyle,
32
+ arrow,
33
+ strategy,
34
+ placement,
35
+ arrowRadius,
36
+ offset: offsetValue,
37
+ } = options
38
+ let _cleanup = null
26
39
 
27
- export function floatingContent(node, options) {
28
- const floatingNode = node
29
- const referenceNode = document.querySelector(`[target="${node.id}"]`)
30
- let arrowNode
40
+ // Determine box style and apply styles as necessary.
41
+ applyBoxStyles(options)
31
42
 
32
- options = mix(DEFAULT_FLOATING_CONTENT_OPTS, options)
43
+ // Get necessary values
44
+ const borderWidth = toPx(
45
+ getCSSVar(floatingNode, 'border-width'),
46
+ floatingNode,
47
+ )
48
+ const borderRadius = toPx(
49
+ getCSSVar(floatingNode, 'border-radius'),
50
+ floatingNode,
51
+ )
33
52
 
34
- if (options.arrow) {
35
- arrowNode = node.querySelector('.PopoverArrow')
36
- arrowNode.style.width = calculateArrowWidth(options.arrowWidth) + 'px'
53
+ // Create arrow node — used for both styles
54
+ const arrowNode = document.createElement('div')
55
+ const arrowClass = 'popover-content-arrow'
56
+ const arrowHeight = resolveArrowHeight(options)
57
+ const arrowWidth = getArrowWidth({ ...options, arrowHeight })
58
+
59
+ const arrowProps = {
60
+ arrow,
61
+ arrowNode,
62
+ arrowWidth,
63
+ arrowHeight,
64
+ arrowRadius,
37
65
  }
38
66
 
39
- const offsetValue = calculateOffsetValue({ ...options, arrowNode })
67
+ applyArrowStyles({ boxStyle, ...arrowProps })
68
+ arrowNode.classList.add(arrowClass)
69
+ if (arrow) floatingNode.appendChild(arrowNode)
40
70
 
41
- options.middleware = [
42
- offset(offsetValue),
43
- // options.middleware.push(inline()), // Should be placed here. Padding option might be useful.
44
- flip({ fallbackAxisSideDirection: 'start' }),
45
- shift(),
46
- ]
71
+ // Calculate offset
72
+ const offset = calculateOffset({
73
+ floatingNode,
74
+ boxStyle,
75
+ arrow,
76
+ borderWidth,
77
+ offsetValue,
78
+ arrowHeight,
79
+ })
47
80
 
48
- if (options.arrow) {
49
- options.middleware.push(arrow({ element: arrowNode }))
81
+ // Create floating options
82
+ const floatingOpts = {
83
+ strategy,
84
+ placement,
85
+ middleware: [
86
+ offsetFn(offset),
87
+ flip({ fallbackAxisSideDirection: 'start' }),
88
+ shift(),
89
+ arrow && arrowFn({ element: arrowNode }),
90
+ ],
50
91
  }
51
92
 
52
- autoUpdate(referenceNode, floatingNode, () => {
53
- computePosition(referenceNode, floatingNode, options).then(
54
- middlewareState => {
55
- const { x, y } = middlewareState
56
- // Position Popover
57
- Object.assign(floatingNode.style, {
58
- left: `${x}px`,
59
- top: `${y}px`,
60
- })
61
-
62
- if (options.arrow) {
63
- const arrowPosStyle = calculateArrowPosition({
64
- middlewareState,
65
- floatingNode,
66
- arrowNode,
67
- arrowDelta: options.arrowDelta,
68
- })
69
- Object.assign(arrowNode.style, arrowPosStyle)
70
- }
71
- },
72
- )
73
- })
74
- }
93
+ return {
94
+ // Update floating position.
95
+ // Run when mounting.
96
+ update() {
97
+ _cleanup = autoUpdate(referenceNode, floatingNode, _ => {
98
+ computePosition(referenceNode, floatingNode, floatingOpts).then(
99
+ middlewareState => {
100
+ const { x, y } = middlewareState
75
101
 
76
- function calculateOffsetValue({ offset, arrow, arrowNode }) {
77
- // SSR Ready
78
- if (typeof window === 'undefined') return
79
- if (!offset) offset = 0
102
+ // Position Popover
103
+ Object.assign(floatingNode.style, {
104
+ left: `${x}px`,
105
+ top: `${y}px`,
106
+ })
80
107
 
81
- const [value, unit] = splitUnit(offset)
108
+ if (!arrow) return
82
109
 
83
- let finalValue = 0
110
+ // Position arrow
111
+ positionArrow({
112
+ ...options,
113
+ ...arrowProps,
114
+ borderWidth,
115
+ borderRadius,
116
+ middlewareState,
117
+ })
118
+ },
119
+ )
120
+ })
121
+ },
84
122
 
85
- if (unit === 'rem') finalValue = value * rem()
86
- if (unit === 'em') finalValue = value * em()
87
- if (unit === 'px') finalValue = value
88
- if (!unit) finalValue = value // Default to px offsets
123
+ // Cleanup autoupdate.
124
+ // Run when dismounting.
125
+ cleanup() {
126
+ if (_cleanup) _cleanup()
127
+ },
128
+ }
129
+ }
89
130
 
90
- if (!arrow) return finalValue
131
+ function applyBoxStyles({
132
+ referenceNode,
133
+ floatingNode,
134
+ strategy,
135
+ boxStyle,
136
+ placement,
137
+ arrow,
138
+ useReferenceBoundaries,
139
+ }) {
140
+ floatingNode.style.position = strategy
141
+ floatingNode.style.overflow = 'visible' // Users can specify max-height on the popover content to enable scrolling.
91
142
 
92
- // Arrow Offset compensation
93
- const arrowWidth = arrowNode.offsetWidth
94
- const half = arrowWidth / 2
95
- const arrowOffsetCompensation = Math.floor(Math.sqrt(half * half * 2))
143
+ if (useReferenceBoundaries) {
144
+ const { width, height } = referenceNode.getBoundingClientRect()
96
145
 
97
- return finalValue + arrowOffsetCompensation
98
- }
146
+ if (['top', 'bottom'].includes(placement)) {
147
+ floatingNode.style.width = `${width}px`
148
+ }
99
149
 
100
- function calculateArrowWidth(givenWidth) {
101
- const remValue = rem()
102
- const [value, unit] = splitUnit(givenWidth)
103
- let finalValue = 0
150
+ if (['left', 'right'].includes(placement)) {
151
+ floatingNode.style.height = `${height}px`
152
+ }
153
+ }
154
+
155
+ if (boxStyle === 'fancy') {
156
+ if (!arrow) floatingNode.classList.add('fancybox')
157
+ else {
158
+ const side = getArrowSide(placement)
159
+ floatingNode.classList.add('fancybox-arrow', `arrow-${side}`)
160
+ }
161
+ }
162
+ }
104
163
 
105
- if (unit === 'rem') finalValue = value * remValue
106
- if (unit === 'px') finalValue = value
107
- if (!unit) finalValue = value // Default to px offsets
164
+ function resolveArrowHeight({ floatingNode, arrow, arrowHeight, boxStyle }) {
165
+ if (!arrow) return 0
166
+ if (boxStyle === 'standard') return toPx(arrowHeight, floatingNode)
108
167
 
109
- return finalValue
168
+ // Fancy box style
169
+ if (arrowHeight) {
170
+ const h = toPx(arrowHeight, floatingNode)
171
+ setCSSVar(floatingNode, '--h', `${h}px`)
172
+ return h
173
+ } else {
174
+ const h = getCSSVar(floatingNode, '--h')
175
+ return toPx(h, floatingNode)
176
+ }
110
177
  }
111
178
 
112
- function calculateArrowPosition({
113
- middlewareState,
114
- floatingNode,
115
- arrowNode,
116
- arrowDelta,
117
- }) {
118
- const { placement, middlewareData } = middlewareState
179
+ function getArrowWidth({ boxStyle, floatingNode, arrowHeight }) {
180
+ // Standard box is a square, so it must use the same value for both width and height
181
+ if (boxStyle === 'standard') return arrowHeight
182
+
183
+ // Fancy box can have different width and height values depending on the angle used. Downside is the arrow will never be rounded.
119
184
 
120
- let x = middlewareData.arrow?.x
121
- let y = middlewareData.arrow?.y
185
+ let [angle, unit] = splitUnit(getCSSVar(floatingNode, '--a'))
186
+ if (unit === 'deg') angle = toRadians(angle)
187
+ return Math.tan(angle / 2) * arrowHeight * 2
188
+ }
122
189
 
123
- const staticSide = {
190
+ function getArrowSide(placement) {
191
+ const side = {
124
192
  top: 'bottom',
125
193
  right: 'left',
126
194
  bottom: 'top',
127
195
  left: 'right',
128
196
  }[placement.split('-')[0]]
197
+ return side
198
+ }
129
199
 
130
- // Calculates arrow direction
131
- let rotate = 45
132
- // prettier-ignore
133
- switch (staticSide) {
134
- case 'top': rotate = 45; break;
135
- case 'right': rotate = 135; break;
136
- case 'bottom': rotate = 225; break;
137
- case 'left': rotate = 315; break;
200
+ function applyArrowStyles({
201
+ arrowNode,
202
+ arrowWidth,
203
+ arrowHeight,
204
+ arrowRadius,
205
+ boxStyle,
206
+ }) {
207
+ // Need to check which borders and radius to remove
208
+ const styles = {
209
+ width: `${arrowWidth}px`,
210
+ height: `${arrowHeight}px`,
211
+ position: 'absolute',
212
+ borderRadius: '0',
213
+ borderTopRightRadius: arrowRadius,
214
+ borderWidth: 'inherit',
215
+ borderColor: 'inherit',
216
+ borderLeftWidth: '0',
217
+ borderBottomWidth: '0',
218
+ background: 'inherit',
138
219
  }
139
220
 
140
- // Calculates maximum X and Y on cross-axis
141
- const { width, height } = floatingNode.getBoundingClientRect()
142
- const borderRadius = parseFloat(getComputedStyle(floatingNode).borderRadius)
143
- const borderWidth = parseFloat(getComputedStyle(floatingNode).borderWidth)
144
- const arrowWidth = arrowNode.offsetWidth
221
+ if (boxStyle === 'fancy') {
222
+ Object.assign(styles, { opacity: '0' })
223
+ }
145
224
 
146
- if (x || x === 0) {
147
- const startEdge = borderRadius
148
- const endEdge = width - borderRadius - arrowWidth
225
+ Object.assign(arrowNode.style, styles)
226
+ }
149
227
 
150
- if (x <= startEdge) x = startEdge
151
- if (x >= endEdge) x = endEdge
228
+ function calculateOffset({
229
+ floatingNode,
230
+ boxStyle,
231
+ offsetValue,
232
+ borderWidth,
233
+ arrow,
234
+ arrowHeight,
235
+ }) {
236
+ let offset = toPx(offsetValue, floatingNode)
237
+ if (!arrow) return offset
238
+
239
+ if (boxStyle === 'standard') {
240
+ const arrowHypotenuse = Math.sqrt(arrowHeight ** 2 + borderWidth ** 2)
241
+ offset += Math.floor(arrowHypotenuse / 2)
152
242
  }
243
+ if (boxStyle === 'fancy') offset += arrowHeight
244
+ return offset
245
+ }
246
+
247
+ function positionArrow({
248
+ floatingNode,
249
+ middlewareState,
250
+ arrowNode,
251
+ arrowWidth,
252
+ arrowHeight,
253
+ borderWidth,
254
+ borderRadius,
255
+ boxStyle,
256
+ }) {
257
+ const { placement } = middlewareState
258
+ const { x, y } = middlewareState.middlewareData.arrow
259
+ const { width, height } = floatingNode.getBoundingClientRect()
260
+
261
+ // Do nothing if popover is not opened yet
262
+ if (!(width || height)) return
263
+ // Do nothing if no arrow data
264
+ if (!(x || y)) return
265
+
266
+ const side = getArrowSide(placement)
267
+
268
+ if (boxStyle === 'standard') {
269
+ // Rotate arrow box
270
+ let rotate = 45
271
+ // prettier-ignore
272
+ switch (side) {
273
+ case 'top': rotate = -45; break;
274
+ case 'right': rotate = 45; break;
275
+ case 'bottom': rotate = 135; break;
276
+ case 'left': rotate = 225; break;
277
+ }
278
+
279
+ const adjusted = { x, y }
280
+ const safetySpace = 3
281
+
282
+ if (x || x === 0) {
283
+ const startEdge = borderRadius + safetySpace
284
+ const endEdge = width - borderRadius - arrowWidth - safetySpace
153
285
 
154
- if (y || y === 0) {
155
- const startEdge = borderRadius
156
- const endEdge = height - borderRadius - arrowWidth
286
+ if (x <= startEdge) adjusted.x = startEdge
287
+ if (x >= endEdge) adjusted.x = endEdge
288
+ }
157
289
 
158
- if (y <= startEdge) y = startEdge
159
- if (y >= endEdge) y = endEdge
290
+ if (y || y === 0) {
291
+ const startEdge = borderRadius + safetySpace
292
+ const endEdge = height - borderRadius - arrowWidth - safetySpace
293
+
294
+ if (y <= startEdge) adjusted.y = startEdge
295
+ if (y >= endEdge) adjusted.y = endEdge
296
+ }
297
+
298
+ const arrowCrossOffset = Math.ceil((arrowHeight + borderWidth) / 2)
299
+
300
+ // prettier-ignore
301
+ Object.assign(arrowNode.style, {
302
+ left: x ? `${adjusted.x}px` : '',
303
+ top: y ? `${adjusted.y}px` : '',
304
+ [side]: `-${arrowCrossOffset}px`,
305
+ transform: `rotate(${rotate}deg)`,
306
+ })
160
307
  }
161
308
 
162
- // Centers the arrow on the static side
163
- const staticSideOffset = Math.round((arrowNode.offsetWidth + borderWidth) / 2)
309
+ if (boxStyle === 'fancy') {
310
+ if (x) arrowNode.style.left = `${x}px`
311
+ if (y) arrowNode.style.top = `${y}px`
164
312
 
165
- return {
166
- left: x != null ? `${x}px` : '',
167
- top: y != null ? `${y}px` : '',
168
- [staticSide]: `-${staticSideOffset + arrowDelta}px`,
169
- transform: `rotate(${rotate}deg)`,
313
+ let arrowCenter, arrowPosition
314
+ if (x) {
315
+ arrowCenter = x + arrowWidth / 2
316
+ arrowPosition = ((arrowCenter + borderWidth) / width) * 100
317
+ }
318
+ if (y) {
319
+ arrowCenter = y + arrowWidth / 2
320
+ arrowPosition = ((arrowCenter + borderWidth) / height) * 100
321
+ }
322
+
323
+ floatingNode.classList.remove(
324
+ 'arrow-top',
325
+ 'arrow-right',
326
+ 'arrow-bottom',
327
+ 'arrow-left',
328
+ )
329
+ floatingNode.classList.add(`arrow-${side}`)
330
+ setCSSVar(floatingNode, '--arrow-position', `${arrowPosition}%`)
170
331
  }
171
332
  }
@@ -1,5 +1,6 @@
1
- import PopoverCloseButton from './PopoverCloseButton.svelte'
1
+ import Popover from './Popover.svelte'
2
+ import PopoverClose from './PopoverClose.svelte'
2
3
  import PopoverContent from './PopoverContent.svelte'
3
4
  import PopoverTrigger from './PopoverTrigger.svelte'
4
5
 
5
- export { PopoverTrigger, PopoverCloseButton, PopoverContent }
6
+ export { Popover, PopoverClose, PopoverContent, PopoverTrigger }
@@ -1,7 +1,3 @@
1
- export * from './DrawerNew'
2
- export * from './ModalNew'
3
- export * from './PopoverNew'
4
- // export * from './Drawer'
5
- // export * from './Dropdown'
6
- // export * from './Popover'
7
- // export * from './DisclosureNew'
1
+ export * from './Drawer'
2
+ export * from './Modal'
3
+ export * from './Popover'
@@ -1,4 +1,5 @@
1
1
  import { dispatchEvent } from '@splendidlabz/utils/dom'
2
+
2
3
  export function getTrigger(selector) {
3
4
  return document.querySelector(selector)
4
5
  }
@@ -0,0 +1,37 @@
1
+ <script>
2
+ import Icon from '../../Icon/Icon.svelte'
3
+ import { close, getDisclosure } from '../disclosure.svelte.js'
4
+
5
+ const {
6
+ class: klass = '',
7
+ icon = 'tabler:x',
8
+ iconClass = '',
9
+ target = '',
10
+ children,
11
+ ...rest
12
+ } = $props()
13
+
14
+ let button = null
15
+
16
+ function closeDrawer() {
17
+ const id =
18
+ document.querySelector(`${target}`)?.id ||
19
+ button.closest('.drawer-content').id
20
+ const d = getDisclosure(id)
21
+ close(d, { shouldFocusWhenClosing: true })
22
+ }
23
+ </script>
24
+
25
+ <button
26
+ bind:this={button}
27
+ class="drawer-close-button {klass}"
28
+ aria-label="Close dialog"
29
+ {...rest}
30
+ onclick={closeDrawer}
31
+ >
32
+ {#if children}
33
+ {@render children()}
34
+ {:else}
35
+ <Icon class={iconClass} {icon} />
36
+ {/if}
37
+ </button>
@@ -0,0 +1,92 @@
1
+ <script>
2
+ import { splitObject, toStyleString } from '@splendidlabz/utils'
3
+ import {
4
+ TRANSITION_OPT_KEYS,
5
+ applyTransition,
6
+ mergeOpts,
7
+ } from '../../../utils/index.js'
8
+ import Portal from '../../Portal.svelte'
9
+ import { getDisclosure } from '../disclosure.svelte.js'
10
+ import DisclosureContent from '../Disclosure/DisclosureContent.svelte'
11
+ import {
12
+ DRAWER_CONTENT_OPTS,
13
+ DRAWER_POSITION_OPTS,
14
+ getTBLRValues,
15
+ } from './drawer.js'
16
+
17
+ let {
18
+ ref = $bindable(null),
19
+ position = DRAWER_CONTENT_OPTS.position,
20
+ ...p
21
+ } = $props()
22
+
23
+ const opts = mergeOpts(DRAWER_CONTENT_OPTS, DRAWER_POSITION_OPTS[position], p)
24
+
25
+ const {
26
+ id,
27
+ class: klass = '',
28
+ style: styleString = '',
29
+ backdropClass = '',
30
+ portal = true,
31
+ placement,
32
+ backdrop,
33
+ blurBackdrop,
34
+
35
+ // Slots
36
+ ...rest
37
+ } = opts
38
+
39
+ const { picked: transitionOpts } = splitObject(rest, TRANSITION_OPT_KEYS)
40
+
41
+ const TBLR = getTBLRValues({ placement, position })
42
+ const style = toStyleString(TBLR) + styleString
43
+
44
+ let d = $derived(getDisclosure(id))
45
+ let show = $derived(d?.state.show)
46
+
47
+ // Temp remove push transition
48
+ // Replace transition string with our custom push transition
49
+ // if (options?.transition === 'push') options.transition = push
50
+ //
51
+ // NOTE: FLY transition seems to be broken...
52
+ </script>
53
+
54
+ {#snippet drawerBackdrop()}
55
+ <div
56
+ class="drawer-backdrop {backdropClass} "
57
+ class:backdrop-blur={backdrop && blurBackdrop}
58
+ transition:applyTransition|global={{
59
+ ...transitionOpts,
60
+ transition: 'fade',
61
+ }}
62
+ >
63
+ {@render drawerContent()}
64
+ </div>
65
+ {/snippet}
66
+
67
+ {#snippet drawerContent({ portal = false } = {})}
68
+ <DisclosureContent
69
+ {...rest}
70
+ {id}
71
+ {style}
72
+ class="drawer-content {klass}"
73
+ componentName="DrawerContent"
74
+ {placement}
75
+ {portal}
76
+ bind:ref
77
+ />
78
+ {/snippet}
79
+
80
+ {#if show}
81
+ {#if position === 'fixed'}
82
+ {#if opts.portal}
83
+ <Portal>{@render drawerBackdrop()}</Portal>
84
+ {:else}
85
+ {@render drawerBackdrop()}
86
+ {/if}
87
+ {/if}
88
+
89
+ {#if position === 'absolute' || position === 'static'}
90
+ {@render drawerContent()}
91
+ {/if}
92
+ {/if}
@@ -0,0 +1,11 @@
1
+ <script>
2
+ import DisclosureTrigger from '../Disclosure/DisclosureTrigger.svelte'
3
+
4
+ const { class: klass = '', ...rest } = $props()
5
+ </script>
6
+
7
+ <DisclosureTrigger
8
+ {...rest}
9
+ componentName="DrawerTrigger"
10
+ class="drawer-trigger {klass}"
11
+ />
@@ -1,29 +1,3 @@
1
- export const DRAWER_CONTENT_OPTS = {
2
- position: 'fixed',
3
- placement: 'left',
4
- backdrop: true,
5
- blurBackdrop: true,
6
- }
7
-
8
- export const DRAWER_POSITION_OPTS = {
9
- static: {
10
- placement: 'top',
11
- transition: 'slide',
12
- closeOnOutsideClick: false,
13
- closeOnEscapeButton: false,
14
- },
15
- absolute: {
16
- placement: 'top',
17
- transition: 'slide',
18
- },
19
- fixed: {
20
- transition: 'fly',
21
- focusManagement: 'trap',
22
- inertOthers: true,
23
- preventBodyScroll: true,
24
- },
25
- }
26
-
27
1
  // Use logical properties straight up
28
2
  export function getTBLRValues({ placement, position }) {
29
3
  const style = { position }
@@ -1,10 +1,6 @@
1
+ import Drawer from './Drawer.svelte'
1
2
  import DrawerCloseButton from './DrawerCloseButton.svelte'
2
3
  import DrawerContent from './DrawerContent.svelte'
3
4
  import DrawerTrigger from './DrawerTrigger.svelte'
4
5
 
5
- export {
6
- DrawerContent as Drawer,
7
- DrawerCloseButton,
8
- DrawerContent,
9
- DrawerTrigger,
10
- }
6
+ export { Drawer, DrawerCloseButton, DrawerContent, DrawerTrigger }