winduum 2.2.28 → 3.0.0-next.2
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/package.json +7 -4
- package/src/base/reset.css +4 -0
- package/src/common.js +9 -1
- package/src/components/carousel/content.css +1 -0
- package/src/components/carousel/index.js +58 -192
- package/src/components/details/default.css +14 -0
- package/src/components/details/index.css +1 -0
- package/src/components/dialog/content.css +8 -2
- package/src/components/dialog/default.css +16 -2
- package/src/components/dialog/drawer.css +20 -0
- package/src/components/dialog/index.css +1 -0
- package/src/components/dialog/index.js +5 -80
- package/src/components/dialog/readme.md +1 -5
- package/src/components/drawer/content.css +2 -1
- package/src/components/drawer/default.css +13 -31
- package/src/components/drawer/index.css +3 -0
- package/src/components/drawer/index.js +68 -50
- package/src/components/drawer/keyframes/default.css +9 -0
- package/src/components/drawer/noscript.css +32 -0
- package/src/components/drawer/nosnap.css +32 -0
- package/src/components/drawer/props/content.css +2 -2
- package/src/components/drawer/props/default.css +6 -0
- package/src/components/drawer/scroller.css +32 -0
- package/src/components/index.css +1 -0
- package/src/components/popover/content.css +5 -94
- package/src/components/popover/default.css +15 -2
- package/src/components/popover/index.css +1 -0
- package/src/components/popover/index.d.ts +14 -18
- package/src/components/popover/index.js +40 -80
- package/src/components/popover/props/content.css +1 -2
- package/src/components/popover/props/default.css +4 -0
- package/src/components/popover/readme.md +1 -2
- package/src/components/tooltip/default.css +8 -8
- package/src/supports.js +10 -0
- package/tailwindcss/utilities/index.css +1 -0
- package/tailwindcss/utilities/position.css +179 -0
- package/types/index.d.ts +15 -46
- package/src/components/details/index.d.ts +0 -9
- package/src/components/details/index.js +0 -78
- package/src/components/dialog/index.d.ts +0 -13
|
@@ -1,85 +1,103 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { supportsScrollInitialTarget } from '/src/supports.js'
|
|
2
|
+
import { nextRepaint } from '/src/common.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* @param {
|
|
5
|
-
* @
|
|
6
|
-
* @param {'top' | 'left'} direction
|
|
7
|
-
* @returns void
|
|
5
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
6
|
+
* @returns boolean
|
|
8
7
|
*/
|
|
9
|
-
export const
|
|
10
|
-
|
|
8
|
+
export const isVerticalDrawer = (placement) => {
|
|
9
|
+
return ['top', 'bottom'].includes(placement)
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* @param {HTMLElement | Element} element
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
14
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
15
|
+
* @param {boolean} reverse
|
|
16
|
+
* @param {'auto' | 'instant'} behavior
|
|
17
17
|
* @returns void
|
|
18
18
|
*/
|
|
19
|
-
export const
|
|
20
|
-
|
|
19
|
+
export const scrollDrawer = (element, placement, reverse = false, behavior = 'auto') => {
|
|
20
|
+
const [direction, distance, closedDistance] = drawerProperties(element, placement)
|
|
21
|
+
|
|
22
|
+
element.scroll({ [direction]: reverse ? closedDistance : distance, behavior })
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* @param {HTMLElement | Element} element
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {'top' | 'left'} direction
|
|
27
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
27
28
|
* @returns void
|
|
28
29
|
*/
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
export const showDrawer = async (element, placement) => {
|
|
31
|
+
if (!supportsScrollInitialTarget) {
|
|
32
|
+
scrollDrawer(element, placement, true, 'instant')
|
|
33
|
+
await nextRepaint()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
scrollDrawer(element, placement)
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/**
|
|
35
40
|
* @param {HTMLElement | Element} element
|
|
36
|
-
* @param {'
|
|
37
|
-
* @param {string} snapClass
|
|
41
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
38
42
|
* @returns void
|
|
39
43
|
*/
|
|
40
|
-
export const
|
|
41
|
-
element
|
|
42
|
-
element.inert = state === 'close'
|
|
43
|
-
element.dispatchEvent(new CustomEvent(`x-drawer:${state}`))
|
|
44
|
+
export const closeDrawer = (element, placement) => {
|
|
45
|
+
scrollDrawer(element, placement, true)
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
49
|
-
* @
|
|
49
|
+
* @param {HTMLElement | Element} element
|
|
50
|
+
* @param {HTMLElement | Element} contentElement
|
|
51
|
+
* @param {AbortSignal} signal
|
|
52
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
53
|
+
* @returns void
|
|
50
54
|
*/
|
|
51
|
-
export const
|
|
52
|
-
|
|
55
|
+
export const drawerEvents = (element, contentElement, placement, signal) => {
|
|
56
|
+
element.addEventListener('cancel', (event) => {
|
|
57
|
+
const scroller = element.firstElementChild
|
|
58
|
+
|
|
59
|
+
if (scroller.scrollHeight > 0 || scroller.scrollWidth > 0) event.preventDefault()
|
|
60
|
+
|
|
61
|
+
closeDrawer(scroller, placement)
|
|
62
|
+
}, { signal })
|
|
63
|
+
|
|
64
|
+
element.addEventListener('click', ({ target }) => {
|
|
65
|
+
if (!contentElement.contains(target) && !contentElement.isEqualNode(target))
|
|
66
|
+
closeDrawer(element.firstElementChild, placement)
|
|
67
|
+
}, { signal })
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
/**
|
|
56
71
|
* @param {HTMLDialogElement | Element} element
|
|
57
|
-
* @param {
|
|
58
|
-
* @returns
|
|
72
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
73
|
+
* @returns IntersectionObserver
|
|
59
74
|
*/
|
|
60
|
-
export const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
opacityRatio: 1,
|
|
65
|
-
scrollOpen: 0,
|
|
66
|
-
scrollClose: element.scrollWidth - element.clientWidth,
|
|
67
|
-
scrollSize: element.scrollWidth - element.clientWidth,
|
|
68
|
-
scrollDirection: element.scrollLeft,
|
|
69
|
-
...options,
|
|
70
|
-
}
|
|
75
|
+
export const drawerObserver = (element, placement) => {
|
|
76
|
+
const visibleThreshold = 1 / (
|
|
77
|
+
isVerticalDrawer(placement) ? window.innerHeight : window.innerWidth
|
|
78
|
+
)
|
|
71
79
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
return new IntersectionObserver((entries) => {
|
|
81
|
+
if (entries.at(-1).intersectionRatio < visibleThreshold) element.close()
|
|
82
|
+
}, {
|
|
83
|
+
root: element,
|
|
84
|
+
threshold: [visibleThreshold, 1],
|
|
85
|
+
},
|
|
75
86
|
)
|
|
87
|
+
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
/**
|
|
90
|
+
* @param {HTMLElement | Element} element
|
|
91
|
+
* @param {'left' | 'right' | 'top' | 'bottom'} placement
|
|
92
|
+
* @returns {['top' | 'left', number, number]}
|
|
93
|
+
*/
|
|
94
|
+
export const drawerProperties = (element, placement) => {
|
|
95
|
+
const [openedDistance, closedDistance] = {
|
|
96
|
+
left: [0, element.offsetWidth],
|
|
97
|
+
right: [element.offsetWidth, 0],
|
|
98
|
+
top: [0, element.offsetHeight],
|
|
99
|
+
bottom: [element.offsetHeight, 0],
|
|
100
|
+
}[placement]
|
|
80
101
|
|
|
81
|
-
|
|
82
|
-
toggleDrawerAttributes(element, 'close', options.snapClass)
|
|
83
|
-
element.close && element.close()
|
|
84
|
-
}
|
|
102
|
+
return [isVerticalDrawer(placement) ? 'top' : 'left', openedDistance, closedDistance]
|
|
85
103
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.x-drawer {
|
|
2
|
+
@media (scripting: none) {
|
|
3
|
+
--x-drawer-backdrop-opacity: 1;
|
|
4
|
+
|
|
5
|
+
width: fit-content;
|
|
6
|
+
height: fit-content;
|
|
7
|
+
transition-property: var(--default-transition-property);
|
|
8
|
+
transition-timing-function: var(--ease-in-out);
|
|
9
|
+
transition-duration: var(--default-transition-duration);
|
|
10
|
+
transition-behavior: allow-discrete;
|
|
11
|
+
|
|
12
|
+
&::backdrop {
|
|
13
|
+
transition: inherit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&:not([open]) {
|
|
17
|
+
&::backdrop {
|
|
18
|
+
opacity: 0%;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@starting-style {
|
|
23
|
+
&[open] {
|
|
24
|
+
opacity: 0%;
|
|
25
|
+
|
|
26
|
+
&::backdrop {
|
|
27
|
+
opacity: 0%;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.x-drawer {
|
|
2
|
+
&:is(.no-snap) {
|
|
3
|
+
--x-drawer-backdrop-opacity: 1;
|
|
4
|
+
|
|
5
|
+
width: fit-content;
|
|
6
|
+
height: fit-content;
|
|
7
|
+
transition-property: var(--default-transition-property);
|
|
8
|
+
transition-timing-function: var(--ease-in-out);
|
|
9
|
+
transition-duration: var(--default-transition-duration);
|
|
10
|
+
transition-behavior: allow-discrete;
|
|
11
|
+
|
|
12
|
+
&::backdrop {
|
|
13
|
+
transition: inherit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&:not([open]) {
|
|
17
|
+
&::backdrop {
|
|
18
|
+
opacity: 0%;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@starting-style {
|
|
23
|
+
&[open] {
|
|
24
|
+
opacity: 0%;
|
|
25
|
+
|
|
26
|
+
&::backdrop {
|
|
27
|
+
opacity: 0%;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
--x-drawer-content-background-color: var(--color-body-primary);
|
|
4
4
|
--x-drawer-content-padding-block: 2rem;
|
|
5
5
|
--x-drawer-content-padding-inline: 1.5rem;
|
|
6
|
-
--x-drawer-content-inline-size:
|
|
7
|
-
--x-drawer-content-block-size:
|
|
6
|
+
--x-drawer-content-inline-size: 50dvw;
|
|
7
|
+
--x-drawer-content-block-size: 100dvh;
|
|
8
8
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.x-drawer-scroller {
|
|
2
|
+
display: flex;
|
|
3
|
+
width: inherit;
|
|
4
|
+
height: inherit;
|
|
5
|
+
overflow: auto clip;
|
|
6
|
+
scrollbar-width: none;
|
|
7
|
+
scroll-behavior: smooth;
|
|
8
|
+
-webkit-overflow-scrolling: touch;
|
|
9
|
+
overscroll-behavior: none;
|
|
10
|
+
scroll-snap-type: x mandatory;
|
|
11
|
+
scroll-timeline: --x-drawer-backdrop x;
|
|
12
|
+
|
|
13
|
+
&::-webkit-scrollbar {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&::after {
|
|
18
|
+
content: "";
|
|
19
|
+
min-inline-size: 100dvw;
|
|
20
|
+
scroll-snap-align: end;
|
|
21
|
+
scroll-initial-target: nearest;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&:where(.snap-y) {
|
|
25
|
+
overflow: clip auto;
|
|
26
|
+
scroll-timeline: --x-drawer-backdrop y;
|
|
27
|
+
|
|
28
|
+
&::after {
|
|
29
|
+
min-block-size: 100dvh;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/components/index.css
CHANGED
|
@@ -2,103 +2,14 @@
|
|
|
2
2
|
background-color: var(--x-popover-content-background-color);
|
|
3
3
|
border-radius: var(--x-popover-content-border-radius);
|
|
4
4
|
padding: var(--x-popover-content-padding-block) var(--x-popover-content-padding-inline);
|
|
5
|
-
|
|
6
|
-
transition-property: var(--default-transition-property);
|
|
7
|
-
transition-timing-function: var(--ease-in-out);
|
|
8
|
-
transition-duration: var(--default-transition-duration);
|
|
9
|
-
transform:
|
|
10
|
-
translate(var(--tw-translate-x, 0), var(--tw-translate-y, 0))
|
|
11
|
-
scaleX(var(--tw-scale-x, 1)) scaleY(var(--tw-scale-y, 1));
|
|
5
|
+
transition: inherit;
|
|
12
6
|
will-change: transform;
|
|
13
|
-
inline-size: max-content;
|
|
14
|
-
position: absolute;
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
transform-origin: top;
|
|
8
|
+
@starting-style {
|
|
9
|
+
scale: var(--x-popover-content-starting-scale);
|
|
19
10
|
}
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
&:where(.bottom-end) {
|
|
26
|
-
inset-inline-end: 0;
|
|
27
|
-
transform-origin: top right;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
&:where(.right) {
|
|
31
|
-
inset-block-start: 0;
|
|
32
|
-
inset-inline-start: 100%;
|
|
33
|
-
transform-origin: left;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
&:where(.right-start) {
|
|
37
|
-
transform-origin: left top;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
&:where(.right-end) {
|
|
41
|
-
inset-block: auto 0;
|
|
42
|
-
transform-origin: left bottom;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
&:where(.left) {
|
|
46
|
-
inset-block-start: 0;
|
|
47
|
-
inset-inline-end: 100%;
|
|
48
|
-
transform-origin: right;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
&:where(.left-start) {
|
|
52
|
-
transform-origin: right top;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
&:where(.left-end) {
|
|
56
|
-
inset-block: auto 0;
|
|
57
|
-
transform-origin: right bottom;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
&:where(.top) {
|
|
61
|
-
inset-block-end: 100%;
|
|
62
|
-
transform-origin: bottom;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
&:where(.top-start) {
|
|
66
|
-
transform-origin: bottom left;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
&:where(.top-end) {
|
|
70
|
-
inset-inline-end: 0;
|
|
71
|
-
transform-origin: bottom right;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
&:where(.inline-center) {
|
|
75
|
-
--tw-translate-x: -50%;
|
|
76
|
-
|
|
77
|
-
inset-inline-start: 50%;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
&:where(.block-center) {
|
|
81
|
-
--tw-translate-y: -50%;
|
|
82
|
-
|
|
83
|
-
inset-block-start: 50%;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
&[popover]:not([data-open]) {
|
|
87
|
-
--tw-scale-x: var(--x-popover-content-scale-x);
|
|
88
|
-
--tw-scale-y: var(--x-popover-content-scale-y);
|
|
89
|
-
|
|
90
|
-
opacity: 0%;
|
|
91
|
-
pointer-events: none;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
&:not([popover]) {
|
|
95
|
-
.trigger-focus:not(:focus, :focus-within) > &,
|
|
96
|
-
.trigger-hover:not(:hover) > & {
|
|
97
|
-
--tw-scale-x: var(--x-popover-content-scale-x);
|
|
98
|
-
--tw-scale-y: var(--x-popover-content-scale-y);
|
|
99
|
-
|
|
100
|
-
opacity: 0%;
|
|
101
|
-
visibility: hidden;
|
|
102
|
-
}
|
|
12
|
+
:where(.x-popover:not(:popover-open)) > & {
|
|
13
|
+
scale: var(--x-popover-content-starting-scale);
|
|
103
14
|
}
|
|
104
15
|
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
.x-popover {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
transition-property: var(--default-transition-property);
|
|
3
|
+
transition-timing-function: var(--ease-in-out);
|
|
4
|
+
transition-duration: var(--default-transition-duration);
|
|
5
|
+
transition-behavior: allow-discrete;
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: auto;
|
|
8
|
+
container-type: anchored;
|
|
9
|
+
|
|
10
|
+
@starting-style {
|
|
11
|
+
opacity: var(--x-popover-starting-opacity);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&:not(:popover-open) {
|
|
15
|
+
opacity: var(--x-popover-starting-opacity);
|
|
16
|
+
}
|
|
4
17
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ComputePositionConfig } from '@floating-ui/dom'
|
|
2
|
+
import type { Placement } from '@floating-ui/utils'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
offset?: OffsetOptions
|
|
10
|
-
flip?: FlipOptions
|
|
11
|
-
shift?: ShiftOptions
|
|
12
|
-
}
|
|
4
|
+
export declare function computePositionPopover(
|
|
5
|
+
referenceElement: HTMLElement,
|
|
6
|
+
floatingElement: HTMLElement & { $currentPlacement?: string },
|
|
7
|
+
placement: Placement,
|
|
8
|
+
options?: ComputePositionConfig | boolean
|
|
9
|
+
): Promise<void>
|
|
13
10
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export function togglePopover(element: HTMLElement | Element, options?: ShowPopoverOptions): Promise<void>
|
|
11
|
+
export declare function autoUpdatePopover(
|
|
12
|
+
referenceElement: HTMLElement,
|
|
13
|
+
floatingElement: HTMLElement,
|
|
14
|
+
placement: Placement,
|
|
15
|
+
options?: ComputePositionConfig | boolean
|
|
16
|
+
): Promise<() => void>
|
|
@@ -1,93 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { supportsAnchor } from '../../common.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @param {HTMLElement
|
|
5
|
-
* @param {HTMLElement
|
|
6
|
-
* @param {import(
|
|
7
|
-
* @
|
|
4
|
+
* @param {HTMLElement} referenceElement
|
|
5
|
+
* @param {HTMLElement & { _currentPlacement?: import('@floating-ui/utils').Placement }} floatingElement
|
|
6
|
+
* @param {import('@floating-ui/utils').Placement} placement
|
|
7
|
+
* @param {import('@floating-ui/dom').ComputePositionConfig | boolean} [options={}]
|
|
8
|
+
* @returns {Promise<void>}
|
|
8
9
|
*/
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export const computePositionPopover = async (
|
|
11
|
+
referenceElement,
|
|
12
|
+
floatingElement,
|
|
13
|
+
placement,
|
|
14
|
+
options = {},
|
|
15
|
+
) => {
|
|
16
|
+
const { computePosition, flip } = await import('@floating-ui/dom')
|
|
17
|
+
|
|
18
|
+
const autoUpdate = options === true
|
|
19
|
+
const middleware = autoUpdate ? [flip()] : []
|
|
20
|
+
|
|
21
|
+
floatingElement.classList.remove(floatingElement._currentPlacement ?? placement)
|
|
22
|
+
floatingElement.style.setProperty('--anchor-size', !supportsAnchor ? `${referenceElement.offsetWidth}px` : '')
|
|
23
|
+
|
|
24
|
+
await computePosition(referenceElement, floatingElement, {
|
|
25
|
+
middleware,
|
|
26
|
+
placement,
|
|
27
|
+
...(autoUpdate ? {} : options),
|
|
17
28
|
}).then(({ x, y, placement }) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
popoverElement._placement = placement
|
|
23
|
-
popoverElement.classList.add(popoverElement._placement)
|
|
29
|
+
floatingElement.style.inset = !supportsAnchor ? `${y}px auto auto ${x}px` : ''
|
|
30
|
+
floatingElement.classList.add(placement)
|
|
31
|
+
floatingElement._currentPlacement = placement
|
|
24
32
|
})
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
|
-
* @param {HTMLElement
|
|
29
|
-
* @param {
|
|
30
|
-
* @
|
|
36
|
+
* @param {HTMLElement} referenceElement
|
|
37
|
+
* @param {HTMLElement} floatingElement
|
|
38
|
+
* @param {import('@floating-ui/utils').Placement} placement
|
|
39
|
+
* @param {import('@floating-ui/dom').ComputePositionConfig | boolean} [options={}]
|
|
40
|
+
* @returns {Promise<() => void>}
|
|
31
41
|
*/
|
|
32
|
-
export const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
popoverElement.hidePopover && popoverElement.hidePopover()
|
|
39
|
-
|
|
40
|
-
element.ariaExpanded = 'false'
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {HTMLElement | Element} element
|
|
45
|
-
* @param {import("./").ShowPopoverOptions} options
|
|
46
|
-
* @returns Promise<void>
|
|
47
|
-
*/
|
|
48
|
-
export const showPopover = async (element, options) => {
|
|
49
|
-
options = {
|
|
50
|
-
openAttribute: 'data-open',
|
|
51
|
-
compute: true,
|
|
52
|
-
...options,
|
|
53
|
-
}
|
|
54
|
-
|
|
42
|
+
export const autoUpdatePopover = async (
|
|
43
|
+
referenceElement,
|
|
44
|
+
floatingElement,
|
|
45
|
+
placement,
|
|
46
|
+
options = {},
|
|
47
|
+
) => {
|
|
55
48
|
const { autoUpdate } = await import('@floating-ui/dom')
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
element.ariaExpanded = 'true'
|
|
60
|
-
|
|
61
|
-
if (!element.ariaHasPopup) (element.ariaHasPopup = 'dialog')
|
|
62
|
-
if (!popoverElement.role) (popoverElement.role = element.ariaHasPopup)
|
|
63
|
-
|
|
64
|
-
popoverElement.showPopover && popoverElement.showPopover()
|
|
65
|
-
|
|
66
|
-
await nextRepaint()
|
|
67
|
-
|
|
68
|
-
popoverElement.setAttribute(options?.openAttribute, '')
|
|
69
|
-
|
|
70
|
-
if (!options.compute) {
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
popoverElement._cleanup = autoUpdate(
|
|
75
|
-
element,
|
|
76
|
-
popoverElement,
|
|
77
|
-
async () => await computePopover(options.anchorSelector ? document.querySelector(options.anchorSelector) : element, popoverElement, options),
|
|
50
|
+
return autoUpdate(referenceElement, floatingElement, () =>
|
|
51
|
+
computePositionPopover(referenceElement, floatingElement, placement, options),
|
|
78
52
|
)
|
|
79
53
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @param {HTMLElement | Element} element
|
|
83
|
-
* @param {import("./").ShowPopoverOptions} options
|
|
84
|
-
* @returns Promise<void>
|
|
85
|
-
*/
|
|
86
|
-
export const togglePopover = async (element, options) => {
|
|
87
|
-
if (element.ariaExpanded !== 'true') {
|
|
88
|
-
await showPopover(element, options)
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
await hidePopover(element)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -4,6 +4,5 @@
|
|
|
4
4
|
--x-popover-content-border-radius: var(--radius-xl);
|
|
5
5
|
--x-popover-content-padding-block: calc(var(--spacing) * 2);
|
|
6
6
|
--x-popover-content-padding-inline: calc(var(--spacing) * 2);
|
|
7
|
-
--x-popover-content-scale
|
|
8
|
-
--x-popover-content-scale-x: 0.75;
|
|
7
|
+
--x-popover-content-starting-scale: 0.75;
|
|
9
8
|
}
|
|
@@ -14,9 +14,8 @@ Include CSS either globally or to your component _([you can't use TailwindCSS la
|
|
|
14
14
|
or modular (you can use your own props or CSS)
|
|
15
15
|
|
|
16
16
|
```css
|
|
17
|
-
@import "winduum/src/components/popover/props/
|
|
17
|
+
@import "winduum/src/components/popover/props/default.css" layer(components);
|
|
18
18
|
@import "winduum/src/components/popover/default.css" layer(components);
|
|
19
|
-
@import "winduum/src/components/popover/content.css" layer(components);
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
### Local imports
|