@yakad/ui 1.3.105 → 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} +3 -3
- package/dist/{InteractiveSurface/InteractiveSurface.js → WithInteractions/WithInteractions.js} +7 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +2 -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;
|
|
@@ -18,6 +18,6 @@ export interface InteractiveSurfaceProps extends React.HTMLAttributes<HTMLDivEle
|
|
|
18
18
|
onHidden?: () => void;
|
|
19
19
|
onMouseHoverStart?: (e: MouseEvent) => void;
|
|
20
20
|
onMouseHoverLeave?: (e: MouseEvent) => void;
|
|
21
|
-
children?: React.
|
|
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
|
@@ -10,9 +10,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
-
import {
|
|
14
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
15
|
-
export const
|
|
13
|
+
import { mergeRefs } from "@yakad/lib";
|
|
14
|
+
import { cloneElement, forwardRef, isValidElement, useEffect, useImperativeHandle, useRef, } from "react";
|
|
15
|
+
export const WithInteractions = forwardRef((_a, forwardedRef) => {
|
|
16
|
+
var _b;
|
|
16
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"]);
|
|
17
18
|
const localRef = useRef(null);
|
|
18
19
|
// Let the parent access our DOM node
|
|
@@ -211,5 +212,7 @@ export const InteractiveSurface = forwardRef((_a, forwardedRef) => {
|
|
|
211
212
|
onMouseHoverStart,
|
|
212
213
|
onMouseHoverLeave,
|
|
213
214
|
]);
|
|
214
|
-
|
|
215
|
+
if (!isValidElement(children))
|
|
216
|
+
return null;
|
|
217
|
+
return cloneElement(children, Object.assign(Object.assign({}, restProps), { ref: mergeRefs(localRef, forwardedRef, (_b = children.props) === null || _b === void 0 ? void 0 : _b.ref) }));
|
|
215
218
|
});
|
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";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakad/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.107",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Natiq",
|
|
6
6
|
"description": "UI components for NextJS/React",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"prepublishOnly": "npm run test && npm run build && npm run typecheck"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@yakad/lib": "1.0.22",
|
|
34
35
|
"@yakad/symbols": "1.0.25",
|
|
35
36
|
"classnames": "2.5.1"
|
|
36
37
|
},
|