@yakad/ui 2.0.1 → 2.0.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/dist/Label/Label.d.ts +8 -0
- package/dist/{Spacer/Spacer.js → Label/Label.js} +9 -6
- package/dist/Separator/Separator.d.ts +9 -0
- package/dist/Separator/Separator.js +24 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -4
- package/package.json +2 -1
- package/dist/Dropdown/Dropdown.d.ts +0 -8
- package/dist/Dropdown/Dropdown.js +0 -99
- package/dist/Dropdown/Dropdown.module.css +0 -39
- package/dist/Popup/Popup.d.ts +0 -8
- package/dist/Popup/Popup.js +0 -40
- package/dist/Popup/Popup.module.css +0 -15
- package/dist/Spacer/Spacer.d.ts +0 -5
- package/dist/Spacer/Spacer.module.css +0 -5
- package/dist/WithOverlay/WithOverlay.d.ts +0 -15
- package/dist/WithOverlay/WithOverlay.js +0 -40
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
3
|
+
import { type VariantProps } from "class-variance-authority";
|
|
4
|
+
declare const labelVariants: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
5
|
+
interface LabelProps extends React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>, VariantProps<typeof labelVariants> {
|
|
6
|
+
}
|
|
7
|
+
declare const Label: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLLabelElement>>;
|
|
8
|
+
export { Label, labelVariants };
|
|
@@ -10,10 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
13
|
+
import React from "react";
|
|
14
|
+
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
15
|
+
import { cva } from "class-variance-authority";
|
|
16
|
+
const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
|
|
17
|
+
const Label = React.forwardRef((_a, ref) => {
|
|
16
18
|
var { className } = _a, restProps = __rest(_a, ["className"]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
return (_jsx(LabelPrimitive.Root, Object.assign({ ref: ref, className: labelVariants({ className }) }, restProps)));
|
|
20
|
+
});
|
|
21
|
+
Label.displayName = LabelPrimitive.Root.displayName;
|
|
22
|
+
export { Label, labelVariants };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
|
3
|
+
import { type VariantProps } from "class-variance-authority";
|
|
4
|
+
declare const separatorVariants: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
5
|
+
export interface SeparatorProps extends React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>, VariantProps<typeof separatorVariants> {
|
|
6
|
+
ref?: React.Ref<React.ElementRef<typeof SeparatorPrimitive.Root>>;
|
|
7
|
+
}
|
|
8
|
+
export declare function Separator({ orientation, decorative, className, ref, ...restProps }: SeparatorProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
|
14
|
+
import { cva } from "class-variance-authority";
|
|
15
|
+
const separatorVariants = cva("shrink-0 bg-border");
|
|
16
|
+
export function Separator(_a) {
|
|
17
|
+
var { orientation = "horizontal", decorative = true, className, ref } = _a, restProps = __rest(_a, ["orientation", "decorative", "className", "ref"]);
|
|
18
|
+
return (_jsx(SeparatorPrimitive.Root, Object.assign({ ref: ref, orientation: orientation, decorative: decorative, className: separatorVariants({
|
|
19
|
+
className: [
|
|
20
|
+
orientation === "horizontal" ? "h-px w-full" : "h-full w-px",
|
|
21
|
+
className,
|
|
22
|
+
],
|
|
23
|
+
}) }, restProps)));
|
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from "./Stack/Stack";
|
|
|
9
9
|
export * from "./GridContainer/GridContainer";
|
|
10
10
|
export * from "./GridItem/GridItem";
|
|
11
11
|
export * from "./Card/Card";
|
|
12
|
-
export * from "./
|
|
12
|
+
export * from "./Separator/Separator";
|
|
13
13
|
export * from "./Hr/Hr";
|
|
14
14
|
export * from "./List/List";
|
|
15
15
|
export * from "./ListItem/ListItem";
|
|
@@ -17,6 +17,7 @@ export * from "./Table/Table";
|
|
|
17
17
|
export * from "./Button/Button";
|
|
18
18
|
export * from "./SvgIcon/SvgIcon";
|
|
19
19
|
export * from "./Text/Text";
|
|
20
|
+
export * from "./Label/Label";
|
|
20
21
|
export * from "./Form/Form";
|
|
21
22
|
export * from "./Input/Input";
|
|
22
23
|
export * from "./CheckBox/CheckBox";
|
|
@@ -25,9 +26,6 @@ export * from "./RadioGroup/RadioGroup";
|
|
|
25
26
|
export * from "./RadioButton/RadioButton";
|
|
26
27
|
export * from "./CodeBox/CodeBox";
|
|
27
28
|
export * from "./Display/Display";
|
|
28
|
-
export * from "./WithOverlay/WithOverlay";
|
|
29
29
|
export * from "./RenderByScroll/RenderByScroll";
|
|
30
30
|
export * from "./ActiveOnVisible/ActiveOnVisible";
|
|
31
|
-
export * from "./Dropdown/Dropdown";
|
|
32
|
-
export * from "./Popup/Popup";
|
|
33
31
|
export * from "./Avatar/Avatar";
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export * from "./GridContainer/GridContainer";
|
|
|
11
11
|
export * from "./GridItem/GridItem";
|
|
12
12
|
export * from "./Card/Card"; // Stack Based
|
|
13
13
|
// Theme & Styling
|
|
14
|
-
export * from "./
|
|
14
|
+
export * from "./Separator/Separator";
|
|
15
15
|
export * from "./Hr/Hr";
|
|
16
16
|
// UI Components
|
|
17
17
|
export * from "./List/List";
|
|
@@ -20,6 +20,7 @@ export * from "./Table/Table";
|
|
|
20
20
|
export * from "./Button/Button";
|
|
21
21
|
export * from "./SvgIcon/SvgIcon";
|
|
22
22
|
export * from "./Text/Text";
|
|
23
|
+
export * from "./Label/Label";
|
|
23
24
|
// Form Components
|
|
24
25
|
export * from "./Form/Form";
|
|
25
26
|
export * from "./Input/Input";
|
|
@@ -30,10 +31,7 @@ export * from "./RadioButton/RadioButton";
|
|
|
30
31
|
export * from "./CodeBox/CodeBox";
|
|
31
32
|
// Utilities
|
|
32
33
|
export * from "./Display/Display"; // Stack Based
|
|
33
|
-
export * from "./WithOverlay/WithOverlay";
|
|
34
34
|
export * from "./RenderByScroll/RenderByScroll"; // Stack Based
|
|
35
35
|
export * from "./ActiveOnVisible/ActiveOnVisible"; // Stack Based
|
|
36
36
|
// Overlays
|
|
37
|
-
export * from "./Dropdown/Dropdown"; // Card Based
|
|
38
|
-
export * from "./Popup/Popup"; // Card Based
|
|
39
37
|
export * from "./Avatar/Avatar";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakad/ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Natiq",
|
|
6
6
|
"description": "UI components for NextJS/React",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@material/material-color-utilities": "^0.4.0",
|
|
37
|
+
"@radix-ui/react-separator": "^1.1.15",
|
|
37
38
|
"@yakad/lib": "1.0.23",
|
|
38
39
|
"@yakad/symbols": "1.0.42",
|
|
39
40
|
"@yakad/use-interactions": "1.0.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CardProps, OverlayProps } from "..";
|
|
3
|
-
export interface DropdownProps extends CardProps, OverlayProps {
|
|
4
|
-
teleport?: boolean;
|
|
5
|
-
ref?: React.Ref<HTMLDivElement>;
|
|
6
|
-
}
|
|
7
|
-
export declare function Dropdown({ fullWidthOnParentDemand, // Def in Card is True
|
|
8
|
-
blur, level, triggerref, onClose, className, style, children, teleport, ref, ...restProps }: DropdownProps): import("react").JSX.Element;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useRef, useState, useEffect, useImperativeHandle } from "react";
|
|
15
|
-
import classNames from "classnames";
|
|
16
|
-
import { Card } from "..";
|
|
17
|
-
import styles from "./Dropdown.module.css";
|
|
18
|
-
import { createPortal } from "react-dom";
|
|
19
|
-
import { useOnOutsideClick } from "@yakad/use-interactions";
|
|
20
|
-
export function Dropdown(_a) {
|
|
21
|
-
var { fullWidthOnParentDemand = false, // Def in Card is True
|
|
22
|
-
blur, level = "high", triggerref, onClose, className, style, children, teleport = false, ref } = _a, restProps = __rest(_a, ["fullWidthOnParentDemand", "blur", "level", "triggerref", "onClose", "className", "style", "children", "teleport", "ref"]);
|
|
23
|
-
const fallbackTriggerRef = useRef(null);
|
|
24
|
-
const dropdownRef = useRef(null);
|
|
25
|
-
const placementTargetRef = triggerref || fallbackTriggerRef;
|
|
26
|
-
// Let the parent access our DOM node
|
|
27
|
-
useImperativeHandle(ref, () => dropdownRef.current);
|
|
28
|
-
const [arrowPosition, setArrowPosition] = useState({
|
|
29
|
-
top: 0,
|
|
30
|
-
left: 0,
|
|
31
|
-
});
|
|
32
|
-
const [dropdownPosition, setDropdownPosition] = useState({
|
|
33
|
-
top: 0,
|
|
34
|
-
left: 0,
|
|
35
|
-
});
|
|
36
|
-
const [isPlacedAbove, setIsPlacedAbove] = useState(false);
|
|
37
|
-
const [isPlaced, setIsPlaced] = useState(false);
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
document.body.style.overflow = "hidden";
|
|
40
|
-
return () => {
|
|
41
|
-
document.body.style.overflow = "initial";
|
|
42
|
-
};
|
|
43
|
-
}, []);
|
|
44
|
-
const doTeleport = () => {
|
|
45
|
-
const portalRoot = document.getElementsByClassName("portalRoot")[0] || document;
|
|
46
|
-
const t = portalRoot && createPortal(dropdown(), portalRoot);
|
|
47
|
-
return t;
|
|
48
|
-
};
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if ((placementTargetRef === null || placementTargetRef === void 0 ? void 0 : placementTargetRef.current) && dropdownRef.current) {
|
|
51
|
-
const placementTarget = placementTargetRef.current.getBoundingClientRect();
|
|
52
|
-
const dropdownRect = dropdownRef.current.getBoundingClientRect();
|
|
53
|
-
const padding = 10;
|
|
54
|
-
let dropdownY = placementTarget.bottom + padding;
|
|
55
|
-
let dropdownXPos = placementTarget.left + placementTarget.width / 2;
|
|
56
|
-
let arrowY = dropdownY;
|
|
57
|
-
const arrowX = dropdownXPos;
|
|
58
|
-
// Prevent overflow bottom
|
|
59
|
-
if (dropdownY + dropdownRect.height > window.innerHeight &&
|
|
60
|
-
placementTarget.top > dropdownRect.height) {
|
|
61
|
-
dropdownY = placementTarget.top - padding;
|
|
62
|
-
arrowY = placementTarget.top - padding;
|
|
63
|
-
setIsPlacedAbove(true);
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
setIsPlacedAbove(false);
|
|
67
|
-
// Prevent overflow right
|
|
68
|
-
if (dropdownXPos + dropdownRect.width / 2 >
|
|
69
|
-
window.innerWidth - padding) {
|
|
70
|
-
dropdownXPos =
|
|
71
|
-
window.innerWidth - dropdownRect.width / 2 - padding;
|
|
72
|
-
}
|
|
73
|
-
// Prevent overflow left
|
|
74
|
-
if (dropdownXPos - dropdownRect.width / 2 < padding) {
|
|
75
|
-
dropdownXPos = dropdownRect.width / 2 + padding;
|
|
76
|
-
}
|
|
77
|
-
setDropdownPosition({
|
|
78
|
-
top: dropdownY,
|
|
79
|
-
left: dropdownXPos,
|
|
80
|
-
});
|
|
81
|
-
setArrowPosition({
|
|
82
|
-
top: arrowY,
|
|
83
|
-
left: arrowX,
|
|
84
|
-
});
|
|
85
|
-
setIsPlaced(true);
|
|
86
|
-
}
|
|
87
|
-
}, [children, placementTargetRef]);
|
|
88
|
-
useOnOutsideClick(() => {
|
|
89
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
90
|
-
}, dropdownRef);
|
|
91
|
-
const dropdown = () => (_jsxs(_Fragment, { children: [!triggerref && _jsx("div", { ref: fallbackTriggerRef }), _jsx(Card, Object.assign({ ref: dropdownRef, fullWidthOnParentDemand: fullWidthOnParentDemand, blur: blur, level: level }, restProps, { className: classNames(styles.dropdownCard, { [styles.isPlacedAbove]: isPlacedAbove }, className), style: Object.assign({ top: dropdownPosition.top, left: dropdownPosition.left, visibility: isPlaced ? "visible" : "hidden" }, style), children: children })), _jsx("span", { className: classNames(styles.arrow, {
|
|
92
|
-
[styles.isPlacedAbove]: isPlacedAbove,
|
|
93
|
-
}, { [styles.blur]: blur }), style: {
|
|
94
|
-
top: arrowPosition.top,
|
|
95
|
-
left: arrowPosition.left,
|
|
96
|
-
visibility: isPlaced ? "visible" : "hidden",
|
|
97
|
-
} })] }));
|
|
98
|
-
return teleport ? doTeleport() : dropdown();
|
|
99
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
.dropdownCard {
|
|
2
|
-
position: fixed;
|
|
3
|
-
min-width: 6rem;
|
|
4
|
-
min-height: 10rem;
|
|
5
|
-
max-width: calc(100vw - 10rem);
|
|
6
|
-
max-height: min(50vh, 40rem);
|
|
7
|
-
transform: translate(-50%, 1rem);
|
|
8
|
-
overflow-x: auto;
|
|
9
|
-
visibility: hidden;
|
|
10
|
-
z-index: 4;
|
|
11
|
-
}
|
|
12
|
-
.dropdownCard.isPlacedAbove {
|
|
13
|
-
transform: translate(-50%, calc(-100% - 1rem));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* Arrow */
|
|
17
|
-
.arrow {
|
|
18
|
-
position: fixed;
|
|
19
|
-
width: 0;
|
|
20
|
-
height: 0;
|
|
21
|
-
border-left: 0.8rem solid transparent;
|
|
22
|
-
border-right: 0.8rem solid transparent;
|
|
23
|
-
border-bottom: 1rem solid
|
|
24
|
-
rgb(var(--surfaceContainerHighestColor, 230 224 233));
|
|
25
|
-
transform: translate(-50%, calc(-100% + 1rem));
|
|
26
|
-
visibility: hidden;
|
|
27
|
-
z-index: 4;
|
|
28
|
-
}
|
|
29
|
-
.arrow.isPlacedAbove {
|
|
30
|
-
transform: translate(-50%, -1rem) rotate(180deg);
|
|
31
|
-
}
|
|
32
|
-
.arrow.blur {
|
|
33
|
-
border-bottom: 1rem solid
|
|
34
|
-
color-mix(
|
|
35
|
-
in srgb,
|
|
36
|
-
rgb(var(--surfaceContainerHighestColor, 230 224 233)) 85%,
|
|
37
|
-
transparent
|
|
38
|
-
);
|
|
39
|
-
}
|
package/dist/Popup/Popup.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CardProps, OverlayProps } from "..";
|
|
3
|
-
export interface PopupProps extends CardProps, OverlayProps {
|
|
4
|
-
heading?: string;
|
|
5
|
-
teleport?: boolean;
|
|
6
|
-
ref?: React.Ref<HTMLDivElement>;
|
|
7
|
-
}
|
|
8
|
-
export declare function Popup({ align, onClose, heading, className, children, teleport, ref, ...restProps }: PopupProps): import("react").JSX.Element;
|
package/dist/Popup/Popup.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useEffect, useImperativeHandle } from "react";
|
|
15
|
-
import classNames from "classnames";
|
|
16
|
-
import { Material } from "@yakad/symbols";
|
|
17
|
-
import { Button, Card, Row, Screen, Spacer, Stack, Text, } from "..";
|
|
18
|
-
import styles from "./Popup.module.css";
|
|
19
|
-
import { createPortal } from "react-dom";
|
|
20
|
-
import { useOnOutsideClick } from "@yakad/use-interactions";
|
|
21
|
-
export function Popup(_a) {
|
|
22
|
-
var { align, onClose, heading, className, children, teleport = false, ref } = _a, restProps = __rest(_a, ["align", "onClose", "heading", "className", "children", "teleport", "ref"]);
|
|
23
|
-
const localRef = useOnOutsideClick(() => {
|
|
24
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
25
|
-
});
|
|
26
|
-
const doTeleport = () => {
|
|
27
|
-
const portalRoot = document.getElementsByClassName("portalRoot")[0] || document;
|
|
28
|
-
const t = portalRoot && createPortal(popup(), portalRoot);
|
|
29
|
-
return t;
|
|
30
|
-
};
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
document.body.style.overflow = "hidden";
|
|
33
|
-
return () => {
|
|
34
|
-
document.body.style.overflow = "initial";
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
useImperativeHandle(ref, () => localRef.current);
|
|
38
|
-
const popup = () => (_jsx(Screen, { align: "center", className: styles.popupscreen, children: _jsxs(Card, Object.assign({ ref: localRef }, restProps, { className: classNames(styles.popup, className), children: [_jsxs(Row, { style: { marginBottom: "2rem" }, children: [_jsx(Text, { variant: "heading4", children: heading }), _jsx(Spacer, {}), _jsx(Button, { title: "Close", icon: _jsx(Material, { icon: "close" }), onClick: onClose })] }), _jsx(Stack, { align: align, style: { width: "100%", overflowY: "auto" }, children: children })] })) }));
|
|
39
|
-
return teleport ? doTeleport() : popup();
|
|
40
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
.popupscreen {
|
|
2
|
-
position: fixed;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
background-color: rgba(var(--surfaceContainerColor, 243 237 247), 0.2);
|
|
6
|
-
backdrop-filter: blur(0.2rem);
|
|
7
|
-
z-index: 4;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.popup {
|
|
11
|
-
width: 90%;
|
|
12
|
-
max-width: 60rem;
|
|
13
|
-
min-height: 10rem;
|
|
14
|
-
max-height: 90vh;
|
|
15
|
-
}
|
package/dist/Spacer/Spacer.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RefObject } from "react";
|
|
2
|
-
import { Dropdown, DropdownProps, Popup, PopupProps, StackProps } from "..";
|
|
3
|
-
export interface OverlayProps {
|
|
4
|
-
triggerref?: RefObject<HTMLElement | null>;
|
|
5
|
-
onClose?: () => void;
|
|
6
|
-
}
|
|
7
|
-
type AllowedOverlays = React.ReactElement<PopupProps, typeof Popup> | React.ReactElement<DropdownProps, typeof Dropdown>;
|
|
8
|
-
export interface WithOverlayProps extends StackProps {
|
|
9
|
-
trigger?: "onClick" | "onRightClick";
|
|
10
|
-
overlay?: AllowedOverlays;
|
|
11
|
-
children?: React.ReactElement;
|
|
12
|
-
ref?: React.Ref<HTMLDivElement>;
|
|
13
|
-
}
|
|
14
|
-
export declare function WithOverlay({ trigger, overlay, children, onClick, ref, ...restProps }: WithOverlayProps): import("react").JSX.Element;
|
|
15
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useState, useRef, useImperativeHandle, cloneElement, } from "react";
|
|
15
|
-
import { Stack, } from "..";
|
|
16
|
-
import { useOnRightClick } from "@yakad/use-interactions";
|
|
17
|
-
export function WithOverlay(_a) {
|
|
18
|
-
var { trigger = "onClick", overlay, children, onClick, ref } = _a, restProps = __rest(_a, ["trigger", "overlay", "children", "onClick", "ref"]);
|
|
19
|
-
// Get Triggers ref and send to Overlay
|
|
20
|
-
const localRef = useRef(null);
|
|
21
|
-
const [showOverlay, setShowOverlay] = useState(false);
|
|
22
|
-
useOnRightClick(() => {
|
|
23
|
-
setShowOverlay(true);
|
|
24
|
-
}, localRef);
|
|
25
|
-
const onClickHandler = (e) => {
|
|
26
|
-
trigger === "onClick" && setShowOverlay((prev) => !prev);
|
|
27
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
28
|
-
};
|
|
29
|
-
// Let the parent access our DOM node
|
|
30
|
-
useImperativeHandle(ref, () => localRef.current);
|
|
31
|
-
const clonedOverlay = cloneElement(overlay, {
|
|
32
|
-
triggerref: localRef,
|
|
33
|
-
onClose: () => {
|
|
34
|
-
var _a, _b;
|
|
35
|
-
(_b = overlay === null || overlay === void 0 ? void 0 : (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
36
|
-
setShowOverlay(false);
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
return (_jsxs(_Fragment, { children: [_jsx(Stack, Object.assign({ ref: localRef }, restProps, { onClick: onClickHandler, children: children })), showOverlay && clonedOverlay] }));
|
|
40
|
-
}
|