@splendidlabz/svelte 4.3.1 → 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.
- package/CHANGELOG.md +29 -0
- package/components/Breadcrumbs/Breadcrumbs.svelte +10 -9
- package/components/Breadcrumbs/Crumb.svelte +2 -1
- package/components/ContentList/ContentList.svelte +1 -1
- package/components/Disclosure/Disclosure/DisclosureContent.svelte +6 -8
- package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +34 -9
- package/components/Disclosure/Disclosure/disclosure.svelte.js +61 -79
- package/components/Disclosure/Drawer/DrawerCloseButton.svelte +14 -30
- package/components/Disclosure/Drawer/DrawerContent.svelte +58 -74
- package/components/Disclosure/Drawer/DrawerTrigger.svelte +13 -6
- package/components/Disclosure/Drawer/drawer.js +3 -27
- package/components/Disclosure/Drawer/index.js +6 -2
- package/components/Disclosure/Modal/ModalContent.svelte +122 -32
- package/components/Disclosure/Modal/ModalTrigger.svelte +63 -6
- package/components/Disclosure/Modal/index.js +2 -2
- package/components/Disclosure/Popover/PopoverContent.svelte +109 -97
- package/components/Disclosure/Popover/PopoverTrigger.svelte +67 -22
- package/components/Disclosure/Popover/floating.js +278 -117
- package/components/Disclosure/Popover/index.js +3 -2
- package/components/Disclosure/index.js +3 -7
- package/components/Disclosure/shared.js +1 -0
- package/components/DisclosureOld/Drawer/DrawerCloseButton.svelte +37 -0
- package/components/DisclosureOld/Drawer/DrawerContent.svelte +92 -0
- package/components/DisclosureOld/Drawer/DrawerTrigger.svelte +11 -0
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/drawer.js +0 -26
- package/components/{Disclosure/DrawerNew → DisclosureOld/Drawer}/index.js +2 -6
- package/components/DisclosureOld/Modal/ModalContent.svelte +42 -0
- package/components/DisclosureOld/Modal/ModalTrigger.svelte +11 -0
- package/components/DisclosureOld/Modal/index.js +5 -0
- package/components/DisclosureOld/Old/DisclosureContentOld.svelte +97 -0
- package/components/DisclosureOld/Old/DisclosureTriggerOld.svelte +51 -0
- package/components/{Disclosure → DisclosureOld}/Popover/PopoverCloseButton.svelte +4 -1
- package/components/DisclosureOld/Popover/PopoverContent.svelte +107 -0
- package/components/DisclosureOld/Popover/PopoverTrigger.svelte +33 -0
- package/components/DisclosureOld/Popover/floating.js +171 -0
- package/components/DisclosureOld/Popover/index.js +5 -0
- package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipTrigger.svelte +1 -1
- package/components/{Disclosure → DisclosureOld}/disclosure.js +44 -40
- package/components/Form/Combobox/AutocompleteInput.svelte +3 -3
- package/components/Form/Combobox/AutocompleteOptions.svelte +5 -5
- package/components/Form/Combobox/TimepickerInput.svelte +7 -7
- package/components/Form/Combobox/TimepickerOptions.svelte +7 -7
- package/components/Form/Combobox/autocomplete.js +2 -2
- package/components/Form/Combobox/combobox.js +2 -2
- package/components/SVG/SVG.svelte +46 -0
- package/components/SVG/SVGGradient.svelte +37 -0
- package/components/SVG/index.js +2 -1
- package/package.json +3 -3
- package/actions/resize-observer.js +0 -43
- package/actions/scroll-observer.js +0 -47
- package/components/Disclosure/Disclosure/disclosure-popover.svelte.js +0 -7
- package/components/Disclosure/DisclosureNew/DisclosureCloseButton.svelte +0 -38
- package/components/Disclosure/DisclosureNew/DisclosureContent.svelte +0 -53
- package/components/Disclosure/DisclosureNew/DisclosureTrigger.svelte +0 -79
- package/components/Disclosure/DisclosureNew/disclosures.svelte.js +0 -55
- package/components/Disclosure/DisclosureNew/index.js +0 -5
- package/components/Disclosure/Drawer/DrawerNew.svelte +0 -0
- package/components/Disclosure/DrawerNew/DrawerCloseButton.svelte +0 -21
- package/components/Disclosure/DrawerNew/DrawerContent.svelte +0 -45
- package/components/Disclosure/DrawerNew/DrawerTrigger.svelte +0 -15
- package/components/Disclosure/ModalNew/ModalContent.svelte +0 -132
- package/components/Disclosure/ModalNew/ModalTrigger.svelte +0 -68
- package/components/Disclosure/ModalNew/index.js +0 -5
- package/components/Disclosure/PopoverNew/PopoverContent.svelte +0 -119
- package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +0 -77
- package/components/Disclosure/PopoverNew/floating.js +0 -332
- package/components/Disclosure/PopoverNew/index.js +0 -6
- package/components/Disclosure/state.svelte.js +0 -138
- /package/components/Disclosure/{ModalNew → Modal}/ModalClose.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/Popover.svelte +0 -0
- /package/components/Disclosure/{PopoverNew → Popover}/PopoverClose.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Drawer/Drawer.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/DropdownTrigger.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/dropdown.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Dropdown/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/Modal.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/ModalCloseButton.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/exit-intent.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Modal/modal.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/popover.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Popover/references/FollowTheMouse.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/Tooltip.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/TooltipContent.svelte +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/index.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/Tooltip/tooltip.js +0 -0
- /package/components/{Disclosure → DisclosureOld}/disclosure-store.js +0 -0
- /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 {
|
|
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
|
|
13
|
+
export const FLOATING_OPTS = {
|
|
14
14
|
placement: 'top',
|
|
15
15
|
strategy: 'absolute',
|
|
16
|
-
offset: '0
|
|
16
|
+
offset: '0',
|
|
17
17
|
arrow: false,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
arrowHeight: 0,
|
|
19
|
+
arrowRadius: '5px',
|
|
20
|
+
boxStyle: 'standard', // standard, fancy
|
|
21
|
+
useReferenceBoundaries: false,
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export const
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
67
|
+
applyArrowStyles({ boxStyle, ...arrowProps })
|
|
68
|
+
arrowNode.classList.add(arrowClass)
|
|
69
|
+
if (arrow) floatingNode.appendChild(arrowNode)
|
|
40
70
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
// Calculate offset
|
|
72
|
+
const offset = calculateOffset({
|
|
73
|
+
floatingNode,
|
|
74
|
+
boxStyle,
|
|
75
|
+
arrow,
|
|
76
|
+
borderWidth,
|
|
77
|
+
offsetValue,
|
|
78
|
+
arrowHeight,
|
|
79
|
+
})
|
|
47
80
|
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
// Position Popover
|
|
103
|
+
Object.assign(floatingNode.style, {
|
|
104
|
+
left: `${x}px`,
|
|
105
|
+
top: `${y}px`,
|
|
106
|
+
})
|
|
80
107
|
|
|
81
|
-
|
|
108
|
+
if (!arrow) return
|
|
82
109
|
|
|
83
|
-
|
|
110
|
+
// Position arrow
|
|
111
|
+
positionArrow({
|
|
112
|
+
...options,
|
|
113
|
+
...arrowProps,
|
|
114
|
+
borderWidth,
|
|
115
|
+
borderRadius,
|
|
116
|
+
middlewareState,
|
|
117
|
+
})
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
},
|
|
84
122
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
123
|
+
// Cleanup autoupdate.
|
|
124
|
+
// Run when dismounting.
|
|
125
|
+
cleanup() {
|
|
126
|
+
if (_cleanup) _cleanup()
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
}
|
|
89
130
|
|
|
90
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
}
|
|
146
|
+
if (['top', 'bottom'].includes(placement)) {
|
|
147
|
+
floatingNode.style.width = `${width}px`
|
|
148
|
+
}
|
|
99
149
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
if (
|
|
107
|
-
if (
|
|
164
|
+
function resolveArrowHeight({ floatingNode, arrow, arrowHeight, boxStyle }) {
|
|
165
|
+
if (!arrow) return 0
|
|
166
|
+
if (boxStyle === 'standard') return toPx(arrowHeight, floatingNode)
|
|
108
167
|
|
|
109
|
-
|
|
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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
121
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
const endEdge = width - borderRadius - arrowWidth
|
|
225
|
+
Object.assign(arrowNode.style, styles)
|
|
226
|
+
}
|
|
149
227
|
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
286
|
+
if (x <= startEdge) adjusted.x = startEdge
|
|
287
|
+
if (x >= endEdge) adjusted.x = endEdge
|
|
288
|
+
}
|
|
157
289
|
|
|
158
|
-
if (y
|
|
159
|
-
|
|
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
|
-
|
|
163
|
-
|
|
309
|
+
if (boxStyle === 'fancy') {
|
|
310
|
+
if (x) arrowNode.style.left = `${x}px`
|
|
311
|
+
if (y) arrowNode.style.top = `${y}px`
|
|
164
312
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
|
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 {
|
|
6
|
+
export { Popover, PopoverClose, PopoverContent, PopoverTrigger }
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
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'
|
|
@@ -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}
|
|
@@ -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 }
|