@yakad/ui 1.3.106 → 1.3.107
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/WithDropdawn/WithDropdawn.d.ts +10 -0
- package/dist/WithDropdawn/WithDropdawn.js +43 -0
- package/dist/{InteractiveSurface/InteractiveSurface.d.ts → WithInteractions/WithInteractions.d.ts} +2 -2
- package/dist/{InteractiveSurface/InteractiveSurface.js → WithInteractions/WithInteractions.js} +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface WithDropdawnProps {
|
|
3
|
+
trigger?: "onClick" | "onRightClick";
|
|
4
|
+
dropdawnstyle?: React.CSSProperties;
|
|
5
|
+
dropdawnchildren?: React.ReactElement;
|
|
6
|
+
children?: React.ReactElement<{
|
|
7
|
+
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare const WithDropdawn: ({ trigger, dropdawnchildren, dropdawnstyle, children, }: WithDropdawnProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState, useEffect, cloneElement } from "react";
|
|
4
|
+
import { WithInteractions } from "../";
|
|
5
|
+
export const WithDropdawn = ({ trigger = "onClick", dropdawnchildren, dropdawnstyle, children, }) => {
|
|
6
|
+
const toggleElementRef = useRef(null);
|
|
7
|
+
const dropdawnRef = useRef(null);
|
|
8
|
+
const [showDropdawn, setShowDropdawn] = useState(false);
|
|
9
|
+
const [top, setTop] = useState(0);
|
|
10
|
+
const [left, setLeft] = useState(0);
|
|
11
|
+
const toggleShowDropdawn = () => setShowDropdawn((prev) => !prev);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (toggleElementRef.current && dropdawnRef.current) {
|
|
14
|
+
const buttonRect = toggleElementRef.current.getBoundingClientRect();
|
|
15
|
+
const dropdawnRect = dropdawnRef.current.getBoundingClientRect();
|
|
16
|
+
const padding = 10;
|
|
17
|
+
let top = buttonRect.bottom + padding;
|
|
18
|
+
let left = buttonRect.left + buttonRect.width / 2 - dropdawnRect.width / 2;
|
|
19
|
+
// Prevent overflow bottom
|
|
20
|
+
if (top + dropdawnRect.height > window.innerHeight) {
|
|
21
|
+
top = buttonRect.top - dropdawnRect.height - padding;
|
|
22
|
+
}
|
|
23
|
+
// Prevent overflow right
|
|
24
|
+
if (left + dropdawnRect.width > window.innerWidth - padding) {
|
|
25
|
+
left = window.innerWidth - dropdawnRect.width - padding;
|
|
26
|
+
}
|
|
27
|
+
// Prevent overflow left
|
|
28
|
+
if (left < padding) {
|
|
29
|
+
left = padding;
|
|
30
|
+
}
|
|
31
|
+
setTop(top);
|
|
32
|
+
setLeft(left);
|
|
33
|
+
}
|
|
34
|
+
}, [showDropdawn, dropdawnchildren]);
|
|
35
|
+
return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { ref: toggleElementRef, onRightClick: () => trigger === "onRightClick" && setShowDropdawn(true), children: children &&
|
|
36
|
+
cloneElement(children, {
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
(_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
40
|
+
trigger === "onClick" && toggleShowDropdawn();
|
|
41
|
+
},
|
|
42
|
+
}) }), _jsx(WithInteractions, { onOutsideClick: () => setShowDropdawn(false), children: _jsx("div", { ref: dropdawnRef, style: Object.assign({ position: "fixed", top: top, left: left, maxWidth: "calc(100% - 4rem)", maxHeight: "min(50vh, 50rem)", zIndex: 2, visibility: showDropdawn ? "visible" : "hidden" }, dropdawnstyle), children: dropdawnchildren }) })] }));
|
|
43
|
+
};
|
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);
|
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";
|