@hrnec06/react_utils 1.8.0 → 1.9.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hrnec06/react_utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "React utilities",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"typescript": "^5.8.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hrnec06/util": "^1.6.
|
|
29
|
+
"@hrnec06/util": "^1.6.2",
|
|
30
30
|
"clsx": "^2.1.1",
|
|
31
31
|
"lucide-react": "^0.525.0",
|
|
32
32
|
"react": "^19.1.0",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Nullable, ReactUtils, RecordValues } from "@hrnec06/util";
|
|
2
|
+
import React, { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import useDefaultValue from "../../hooks/useDefaultValue";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
|
|
6
|
+
type ShadowRootProps = ReactUtils.Props<{
|
|
7
|
+
children?: React.ReactNode,
|
|
8
|
+
shadowConfig?: ShadowRootInit,
|
|
9
|
+
}, HTMLDivElement>
|
|
10
|
+
export default function ShadowRoot({
|
|
11
|
+
children,
|
|
12
|
+
shadowConfig,
|
|
13
|
+
...props
|
|
14
|
+
}: ShadowRootProps)
|
|
15
|
+
{
|
|
16
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
17
|
+
const shadowAttached = useRef(false);
|
|
18
|
+
|
|
19
|
+
const [shadow, setShadow] = useState<Nullable<ShadowRoot>>(null);
|
|
20
|
+
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
if (!ref.current || shadowAttached.current) return;
|
|
23
|
+
|
|
24
|
+
const shadow = ref.current.attachShadow(shadowConfig ?? { mode: 'open' });
|
|
25
|
+
setShadow(shadow);
|
|
26
|
+
|
|
27
|
+
shadowAttached.current = true;
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
{...props}
|
|
33
|
+
|
|
34
|
+
ref={ref}
|
|
35
|
+
>
|
|
36
|
+
{
|
|
37
|
+
shadow ? createPortal(children, shadow) : null
|
|
38
|
+
}
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,8 @@ import Dialog from "./components/Dialog/Dialog";
|
|
|
26
26
|
|
|
27
27
|
import ContextMenu from "./components/ContextMenu/ContextMenu";
|
|
28
28
|
|
|
29
|
+
import ShadowRoot from "./components/ShadowRoot/ShadowRoot";
|
|
30
|
+
|
|
29
31
|
import * as util from './lib/utils';
|
|
30
32
|
import ContextError from "./lib/errors/ContextError";
|
|
31
33
|
|
|
@@ -63,6 +65,9 @@ export {
|
|
|
63
65
|
Dialog,
|
|
64
66
|
ContextMenu,
|
|
65
67
|
|
|
68
|
+
// Shadow root
|
|
69
|
+
ShadowRoot,
|
|
70
|
+
|
|
66
71
|
// Utilities
|
|
67
72
|
util,
|
|
68
73
|
ContextError
|