noph-ui 0.4.2 → 0.4.3
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 +26 -11
- package/dist/menu/Menu.svelte.d.ts +1 -1
- package/dist/menu/types.d.ts +3 -0
- package/package.json +1 -1
package/dist/menu/Menu.svelte
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
import { generateUUIDv4 } from '../utils.js'
|
|
3
3
|
import type { MenuProps } from './types.ts'
|
|
4
4
|
|
|
5
|
-
let {
|
|
5
|
+
let {
|
|
6
|
+
anchor,
|
|
7
|
+
children,
|
|
8
|
+
element = $bindable(),
|
|
9
|
+
showPopover = $bindable(),
|
|
10
|
+
hidePopover = $bindable(),
|
|
11
|
+
...attributes
|
|
12
|
+
}: MenuProps = $props()
|
|
6
13
|
|
|
7
14
|
let clientWidth = $state(0)
|
|
8
15
|
let clientHeight = $state(0)
|
|
@@ -10,30 +17,38 @@
|
|
|
10
17
|
let innerWidth = $state(0)
|
|
11
18
|
let scrollY = $state(0)
|
|
12
19
|
let scrollX = $state(0)
|
|
13
|
-
let popoverElement: HTMLDivElement | undefined = $state()
|
|
14
20
|
let anchorId = anchor?.style.getPropertyValue('anchor-name')
|
|
21
|
+
|
|
22
|
+
showPopover = () => {
|
|
23
|
+
element?.showPopover()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
hidePopover = () => {
|
|
27
|
+
element?.hidePopover()
|
|
28
|
+
}
|
|
29
|
+
|
|
15
30
|
const refreshValues = () => {
|
|
16
|
-
if (
|
|
31
|
+
if (element && anchor && !('anchorName' in document.documentElement.style)) {
|
|
17
32
|
const anchorRect = anchor.getBoundingClientRect()
|
|
18
33
|
if (anchorRect.bottom + clientHeight > innerHeight && anchorRect.top - clientHeight > 0) {
|
|
19
|
-
|
|
34
|
+
element.style.top = `${anchorRect.top - clientHeight - 2}px`
|
|
20
35
|
} else {
|
|
21
|
-
|
|
36
|
+
element.style.top = `${anchorRect.bottom + 2}px`
|
|
22
37
|
}
|
|
23
38
|
const left = anchorRect.left + anchorRect.width / 2 - clientWidth / 2
|
|
24
39
|
if (left > innerWidth - clientWidth) {
|
|
25
|
-
|
|
40
|
+
element.style.left = `${innerWidth - clientWidth - 8}px`
|
|
26
41
|
} else if (left < 8) {
|
|
27
|
-
|
|
42
|
+
element.style.left = '8px'
|
|
28
43
|
} else {
|
|
29
|
-
|
|
44
|
+
element.style.left = `${anchorRect.left + anchorRect.width / 2 - clientWidth / 2}px`
|
|
30
45
|
}
|
|
31
46
|
}
|
|
32
47
|
}
|
|
33
48
|
$effect(refreshValues)
|
|
34
49
|
|
|
35
50
|
$effect(() => {
|
|
36
|
-
if (anchor &&
|
|
51
|
+
if (anchor && element) {
|
|
37
52
|
if (!('anchorName' in document.documentElement.style)) {
|
|
38
53
|
anchor.addEventListener('click', () => {
|
|
39
54
|
refreshValues()
|
|
@@ -47,7 +62,7 @@
|
|
|
47
62
|
)
|
|
48
63
|
} else if (!anchorId) {
|
|
49
64
|
const generatedId = `--${generateUUIDv4()}`
|
|
50
|
-
|
|
65
|
+
element.style.setProperty('position-anchor', generatedId)
|
|
51
66
|
anchor.style.setProperty('anchor-name', generatedId)
|
|
52
67
|
}
|
|
53
68
|
}
|
|
@@ -63,7 +78,7 @@
|
|
|
63
78
|
/>
|
|
64
79
|
|
|
65
80
|
<div
|
|
66
|
-
bind:this={
|
|
81
|
+
bind:this={element}
|
|
67
82
|
bind:clientWidth
|
|
68
83
|
bind:clientHeight
|
|
69
84
|
{...attributes}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { MenuProps } from './types.ts';
|
|
2
|
-
declare const Menu: import("svelte").Component<MenuProps, {}, "">;
|
|
2
|
+
declare const Menu: import("svelte").Component<MenuProps, {}, "element" | "showPopover" | "hidePopover">;
|
|
3
3
|
type Menu = ReturnType<typeof Menu>;
|
|
4
4
|
export default Menu;
|
package/dist/menu/types.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import type { HTMLAttributes, HTMLAnchorAttributes, HTMLButtonAttributes } from
|
|
|
3
3
|
export interface MenuProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
4
|
children: Snippet;
|
|
5
5
|
anchor?: HTMLElement | undefined;
|
|
6
|
+
showPopover?: () => void;
|
|
7
|
+
hidePopover?: () => void;
|
|
8
|
+
element?: HTMLDivElement;
|
|
6
9
|
}
|
|
7
10
|
interface ButtonProps extends HTMLButtonAttributes {
|
|
8
11
|
selected?: boolean;
|