@hrnec06/react_utils 1.11.1 → 1.11.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
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactUtils } from "@hrnec06/util";
|
|
2
|
+
|
|
3
|
+
type DragFieldProps = ReactUtils.Props<{
|
|
4
|
+
children?: React.ReactNode,
|
|
5
|
+
onHover?: (item: string) => void,
|
|
6
|
+
onDrop?: (item: string) => void,
|
|
7
|
+
}>;
|
|
8
|
+
export default function DragField({}: DragFieldProps)
|
|
9
|
+
{
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Nullable, ReactUtils } from "@hrnec06/util";
|
|
2
|
+
import useTransition from "../../../hooks/useTransition";
|
|
3
|
+
import useSyncRef, { useSyncRefAuto } from "../../../hooks/useSyncRef";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
|
|
7
|
+
type SmoothExpanderProps = ReactUtils.Props<{
|
|
8
|
+
open?: boolean
|
|
9
|
+
}, HTMLDivElement>;
|
|
10
|
+
export default function SmoothExpander({
|
|
11
|
+
open = false,
|
|
12
|
+
children,
|
|
13
|
+
...props
|
|
14
|
+
}: SmoothExpanderProps)
|
|
15
|
+
{
|
|
16
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div
|
|
20
|
+
{...props}
|
|
21
|
+
|
|
22
|
+
className={clsx(
|
|
23
|
+
"overflow-hidden transition-all relative",
|
|
24
|
+
)}
|
|
25
|
+
|
|
26
|
+
style={{
|
|
27
|
+
height: open && ref.current ? ref.current.clientHeight : 0
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
<div
|
|
31
|
+
ref={ref}
|
|
32
|
+
className="absolute top-0 left-0"
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ import ShadowRoot from "./components/ShadowRoot/ShadowRoot";
|
|
|
32
32
|
|
|
33
33
|
import Tooltip from "./components/UI/Tooltip/Tooltip";
|
|
34
34
|
import ErrorBoundary from "./components/UI/ErrorBoundary/ErrorBoundary";
|
|
35
|
+
import SmoothExpander from "./components/UI/SmoothExpander/SmoothExpander";
|
|
35
36
|
|
|
36
37
|
import * as util from './lib/utils';
|
|
37
38
|
import ContextError from "./lib/errors/ContextError";
|
|
@@ -76,6 +77,7 @@ export {
|
|
|
76
77
|
// UI
|
|
77
78
|
Tooltip,
|
|
78
79
|
ErrorBoundary,
|
|
80
|
+
SmoothExpander,
|
|
79
81
|
|
|
80
82
|
// Shadow root
|
|
81
83
|
ShadowRoot,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Optional } from "@hrnec06/util";
|
|
2
|
+
import { Context, createContext, useContext } from "react";
|
|
3
|
+
import ContextError from "./errors/ContextError";
|
|
4
|
+
|
|
5
|
+
interface ContextReturn<T> {
|
|
6
|
+
context: Context<Optional<T>>,
|
|
7
|
+
useContext: () => T
|
|
8
|
+
}
|
|
9
|
+
export default function createOptionalContext<T>(name: string): ContextReturn<T>
|
|
10
|
+
{
|
|
11
|
+
const context = createContext<Optional<T>>(undefined);
|
|
12
|
+
|
|
13
|
+
function useCtx(): T
|
|
14
|
+
{
|
|
15
|
+
const ctx: Optional<T> = useContext(context);
|
|
16
|
+
|
|
17
|
+
if (!ctx)
|
|
18
|
+
throw new ContextError(name);
|
|
19
|
+
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
context: context,
|
|
25
|
+
useContext: useCtx
|
|
26
|
+
}
|
|
27
|
+
}
|