@yakad/ui 1.3.106 → 1.3.108
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/Card/Card.module.css +0 -1
- package/dist/WithDropdawn/WithDropdawn.d.ts +13 -0
- package/dist/WithDropdawn/WithDropdawn.js +56 -0
- package/dist/{InteractiveSurface/InteractiveSurface.d.ts → WithInteractions/WithInteractions.d.ts} +2 -2
- package/dist/{InteractiveSurface/InteractiveSurface.js → WithInteractions/WithInteractions.js} +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CardProps } from "../";
|
|
3
|
+
export interface WithDropdawnProps extends CardProps {
|
|
4
|
+
trigger?: "onClick" | "onRightClick";
|
|
5
|
+
dropdawnChildren?: React.ReactElement;
|
|
6
|
+
children?: React.ReactElement<{
|
|
7
|
+
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare const WithDropdawn: {
|
|
11
|
+
({ trigger, dropdawnChildren, style, children, ...restProps }: WithDropdawnProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
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, cloneElement } from "react";
|
|
15
|
+
import { Card, WithInteractions } from "../";
|
|
16
|
+
export const WithDropdawn = (_a) => {
|
|
17
|
+
var { trigger = "onClick", dropdawnChildren, style, children } = _a, restProps = __rest(_a, ["trigger", "dropdawnChildren", "style", "children"]);
|
|
18
|
+
const toggleElementRef = useRef(null);
|
|
19
|
+
const dropdawnRef = useRef(null);
|
|
20
|
+
const [showDropdawn, setShowDropdawn] = useState(false);
|
|
21
|
+
const [top, setTop] = useState(0);
|
|
22
|
+
const [left, setLeft] = useState(0);
|
|
23
|
+
const toggleShowDropdawn = () => setShowDropdawn((prev) => !prev);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (toggleElementRef.current && dropdawnRef.current) {
|
|
26
|
+
const buttonRect = toggleElementRef.current.getBoundingClientRect();
|
|
27
|
+
const dropdawnRect = dropdawnRef.current.getBoundingClientRect();
|
|
28
|
+
const padding = 10;
|
|
29
|
+
let top = buttonRect.bottom + padding;
|
|
30
|
+
let left = buttonRect.left + buttonRect.width / 2 - dropdawnRect.width / 2;
|
|
31
|
+
// Prevent overflow bottom
|
|
32
|
+
if (top + dropdawnRect.height > window.innerHeight) {
|
|
33
|
+
top = buttonRect.top - dropdawnRect.height - padding;
|
|
34
|
+
}
|
|
35
|
+
// Prevent overflow right
|
|
36
|
+
if (left + dropdawnRect.width > window.innerWidth - padding) {
|
|
37
|
+
left = window.innerWidth - dropdawnRect.width - padding;
|
|
38
|
+
}
|
|
39
|
+
// Prevent overflow left
|
|
40
|
+
if (left < padding) {
|
|
41
|
+
left = padding;
|
|
42
|
+
}
|
|
43
|
+
setTop(top);
|
|
44
|
+
setLeft(left);
|
|
45
|
+
}
|
|
46
|
+
}, [showDropdawn, dropdawnChildren]);
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { ref: toggleElementRef, onRightClick: () => trigger === "onRightClick" && setShowDropdawn(true), children: children &&
|
|
48
|
+
cloneElement(children, {
|
|
49
|
+
onClick: (e) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
(_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
52
|
+
trigger === "onClick" && toggleShowDropdawn();
|
|
53
|
+
},
|
|
54
|
+
}) }), _jsx(WithInteractions, { onOutsideClick: () => setShowDropdawn(false), children: _jsx(Card, Object.assign({ ref: dropdawnRef }, restProps, { style: Object.assign({ position: "fixed", top: top, left: left, maxWidth: "calc(100% - 4rem)", maxHeight: "min(50vh, 50rem)", zIndex: 2, visibility: showDropdawn ? "visible" : "hidden" }, style), children: dropdawnChildren })) })] }));
|
|
55
|
+
};
|
|
56
|
+
WithDropdawn.displayName = "WithDropdawn";
|
package/dist/{InteractiveSurface/InteractiveSurface.d.ts → WithInteractions/WithInteractions.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export interface
|
|
2
|
+
export interface WithInteractionsProps {
|
|
3
3
|
onRightClick?: (e: MouseEvent) => void;
|
|
4
4
|
onTap?: (e: TouchEvent) => void;
|
|
5
5
|
onDoubleTap?: (e: TouchEvent) => void;
|
|
@@ -20,4 +20,4 @@ export interface InteractiveSurfaceProps {
|
|
|
20
20
|
onMouseHoverLeave?: (e: MouseEvent) => void;
|
|
21
21
|
children?: React.ReactElement;
|
|
22
22
|
}
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const WithInteractions: import("react").ForwardRefExoticComponent<WithInteractionsProps & import("react").RefAttributes<HTMLElement>>;
|
package/dist/{InteractiveSurface/InteractiveSurface.js → WithInteractions/WithInteractions.js}
RENAMED
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
import { mergeRefs } from "@yakad/lib";
|
|
14
14
|
import { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef, } from "react";
|
|
15
|
-
export const
|
|
15
|
+
export const WithInteractions = forwardRef((_a, forwardedRef) => {
|
|
16
16
|
var _b;
|
|
17
17
|
var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibile, onHidden, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibile", "onHidden", "onMouseHoverStart", "onMouseHoverLeave"]);
|
|
18
18
|
const localRef = useRef(null);
|
|
@@ -216,3 +216,4 @@ export const InteractiveSurface = forwardRef((_a, forwardedRef) => {
|
|
|
216
216
|
return null;
|
|
217
217
|
return cloneElement(children, Object.assign(Object.assign({}, restProps), { ref: mergeRefs(localRef, forwardedRef, (_b = children.props) === null || _b === void 0 ? void 0 : _b.ref) }));
|
|
218
218
|
});
|
|
219
|
+
WithInteractions.displayName = "WithInteractions";
|
package/dist/index.d.ts
CHANGED
|
@@ -28,4 +28,5 @@ export * from "./RadioGroup/RadioGroup";
|
|
|
28
28
|
export * from "./RadioButton/RadioButton";
|
|
29
29
|
export * from "./CodeBox/CodeBox";
|
|
30
30
|
export * from "./Display/Display";
|
|
31
|
-
export * from "./
|
|
31
|
+
export * from "./WithInteractions/WithInteractions";
|
|
32
|
+
export * from "./WithDropdawn/WithDropdawn";
|
package/dist/index.js
CHANGED
|
@@ -33,4 +33,5 @@ export * from "./RadioButton/RadioButton";
|
|
|
33
33
|
export * from "./CodeBox/CodeBox";
|
|
34
34
|
// Utilities
|
|
35
35
|
export * from "./Display/Display";
|
|
36
|
-
export * from "./
|
|
36
|
+
export * from "./WithInteractions/WithInteractions";
|
|
37
|
+
export * from "./WithDropdawn/WithDropdawn";
|