noph-ui 0.12.5 → 0.12.7
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/dist/menu/Menu.svelte
CHANGED
|
@@ -23,21 +23,33 @@
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const refreshValues = () => {
|
|
26
|
-
if (element && anchor
|
|
27
|
-
const docClientWidth = document.documentElement.clientWidth
|
|
26
|
+
if (element && anchor) {
|
|
28
27
|
const anchorRect = anchor.getBoundingClientRect()
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
let maxHeight: number
|
|
29
|
+
if (innerHeight - anchorRect.bottom > anchorRect.top) {
|
|
30
|
+
maxHeight = innerHeight - anchorRect.bottom
|
|
31
31
|
} else {
|
|
32
|
-
|
|
32
|
+
maxHeight = anchorRect.top
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
element.style.maxHeight =
|
|
35
|
+
maxHeight > innerHeight - anchorRect.height
|
|
36
|
+
? `${innerHeight - anchorRect.height - 20}px`
|
|
37
|
+
: `${maxHeight - 20}px`
|
|
38
|
+
if (!('anchorName' in document.documentElement.style)) {
|
|
39
|
+
const docClientWidth = document.documentElement.clientWidth
|
|
40
|
+
if (anchorRect.bottom + clientHeight > innerHeight && anchorRect.top - clientHeight > 0) {
|
|
41
|
+
element.style.top = `${anchorRect.top - clientHeight - 2}px`
|
|
42
|
+
} else {
|
|
43
|
+
element.style.top = `${anchorRect.bottom + 2}px`
|
|
44
|
+
}
|
|
45
|
+
const left = anchorRect.left + anchorRect.width / 2 - clientWidth / 2
|
|
46
|
+
if (left < 2) {
|
|
47
|
+
element.style.left = '2px'
|
|
48
|
+
} else if (left > docClientWidth - clientWidth) {
|
|
49
|
+
element.style.left = `${docClientWidth - clientWidth - 4}px`
|
|
50
|
+
} else {
|
|
51
|
+
element.style.left = `${anchorRect.left + anchorRect.width / 2 - clientWidth / 2}px`
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
55
|
}
|
|
@@ -45,17 +57,17 @@
|
|
|
45
57
|
|
|
46
58
|
$effect(() => {
|
|
47
59
|
if (anchor && element) {
|
|
60
|
+
window.addEventListener(
|
|
61
|
+
'scroll',
|
|
62
|
+
() => {
|
|
63
|
+
refreshValues()
|
|
64
|
+
},
|
|
65
|
+
{ passive: true },
|
|
66
|
+
)
|
|
48
67
|
if (!('anchorName' in document.documentElement.style)) {
|
|
49
68
|
anchor.addEventListener('click', () => {
|
|
50
69
|
refreshValues()
|
|
51
70
|
})
|
|
52
|
-
window.addEventListener(
|
|
53
|
-
'scroll',
|
|
54
|
-
() => {
|
|
55
|
-
refreshValues()
|
|
56
|
-
},
|
|
57
|
-
{ passive: true },
|
|
58
|
-
)
|
|
59
71
|
} else if (!anchor.style.getPropertyValue('anchor-name')) {
|
|
60
72
|
const generatedId = `--${crypto.randomUUID()}`
|
|
61
73
|
element.style.setProperty('position-anchor', generatedId)
|
|
@@ -71,22 +83,6 @@
|
|
|
71
83
|
bind:this={element}
|
|
72
84
|
bind:clientWidth
|
|
73
85
|
bind:clientHeight
|
|
74
|
-
ontoggle={(event) => {
|
|
75
|
-
const { newState, currentTarget } = event
|
|
76
|
-
if (newState === 'open') {
|
|
77
|
-
const rect = currentTarget.getBoundingClientRect()
|
|
78
|
-
const viewportHeight = innerHeight
|
|
79
|
-
|
|
80
|
-
if (rect.bottom > viewportHeight && rect.top < viewportHeight / 2) {
|
|
81
|
-
const maxHeight = viewportHeight - rect.top - 18
|
|
82
|
-
currentTarget.style.maxHeight = `${maxHeight}px`
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (newState === 'closed') {
|
|
86
|
-
currentTarget.style.maxHeight = '80dvh'
|
|
87
|
-
}
|
|
88
|
-
attributes.ontoggle?.(event)
|
|
89
|
-
}}
|
|
90
86
|
popover="auto"
|
|
91
87
|
class={['np-menu', attributes.class]}
|
|
92
88
|
role="menu"
|
|
@@ -104,7 +100,7 @@
|
|
|
104
100
|
padding: 0.5rem 0;
|
|
105
101
|
box-shadow: var(--np-elevation-2);
|
|
106
102
|
margin: var(--np-menu-margin, 2px);
|
|
107
|
-
|
|
103
|
+
inset: auto;
|
|
108
104
|
scrollbar-color: var(--np-color-on-surface-variant) transparent;
|
|
109
105
|
scrollbar-width: thin;
|
|
110
106
|
transition:
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
.np-tooltip[popover] {
|
|
93
93
|
width: max-content;
|
|
94
94
|
margin: 4px 0;
|
|
95
|
+
inset: auto;
|
|
95
96
|
background: var(--np-color-inverse-surface);
|
|
96
97
|
color: var(--np-color-inverse-on-surface);
|
|
97
98
|
padding: 0.25rem 0.5rem;
|
|
@@ -106,15 +107,12 @@
|
|
|
106
107
|
opacity 0.3s ease;
|
|
107
108
|
justify-self: var(--np-tooltip-justify-self, anchor-center);
|
|
108
109
|
position-area: var(--np-tooltip-position-area, top);
|
|
109
|
-
position-try
|
|
110
|
+
position-try: normal flip-block;
|
|
110
111
|
}
|
|
111
112
|
.np-tooltip:popover-open {
|
|
112
113
|
opacity: 1;
|
|
113
114
|
animation: scaleIn 0.3s ease;
|
|
114
115
|
}
|
|
115
|
-
@position-try --np-tooltip-position-fallback {
|
|
116
|
-
position-area: var(--np-tooltip-position-area-fallback, bottom);
|
|
117
|
-
}
|
|
118
116
|
|
|
119
117
|
@keyframes scaleIn {
|
|
120
118
|
from {
|