@yakad/ui 1.3.140 → 1.3.142
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/ActiveOnVisible/ActiveOnVisible.js +18 -5
- package/dist/Button/Button.js +2 -2
- package/dist/LoadingIcon/LoadingIcon.js +1 -1
- package/dist/{RenderByVisibility/RenderByVisibility.d.ts → RenderByScroll/RenderByScroll.d.ts} +2 -2
- package/dist/{RenderByVisibility/RenderByVisibility.js → RenderByScroll/RenderByScroll.js} +20 -15
- package/dist/WithInteractions/WithInteractions.d.ts +1 -0
- package/dist/WithInteractions/WithInteractions.js +12 -4
- package/dist/WithOverlay/WithOverlay.d.ts +1 -3
- package/dist/WithOverlay/WithOverlay.js +13 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -11,10 +11,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { Activity, forwardRef, useState } from "react";
|
|
14
|
+
import { Activity, forwardRef, useImperativeHandle, useRef, useState, } from "react";
|
|
15
15
|
import { WithInteractions } from "..";
|
|
16
|
-
export const ActiveOnVisible = forwardRef(function ActiveOnVisible(_a,
|
|
17
|
-
var { children } = _a, restProps = __rest(_a, ["children"]);
|
|
18
|
-
const
|
|
19
|
-
|
|
16
|
+
export const ActiveOnVisible = forwardRef(function ActiveOnVisible(_a, forwardedRef) {
|
|
17
|
+
var { style, children } = _a, restProps = __rest(_a, ["style", "children"]);
|
|
18
|
+
const localRef = useRef(null);
|
|
19
|
+
// Let the parent access our DOM node
|
|
20
|
+
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
21
|
+
const [boxHeight, setBoxHeight] = useState(0);
|
|
22
|
+
const isVisible = boxHeight === 0;
|
|
23
|
+
const handleOnVisible = () => {
|
|
24
|
+
setBoxHeight(0);
|
|
25
|
+
};
|
|
26
|
+
const handleOnHidden = () => {
|
|
27
|
+
if (localRef.current) {
|
|
28
|
+
const boxRect = localRef.current.getBoundingClientRect();
|
|
29
|
+
setBoxHeight(boxRect.height);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return (_jsx(WithInteractions, Object.assign({ ref: localRef }, restProps, { style: Object.assign({ height: boxHeight || "auto" }, style), onVisible: handleOnVisible, onHidden: handleOnHidden, children: _jsx(Activity, { mode: isVisible ? "visible" : "hidden", children: children }) })));
|
|
20
33
|
});
|
package/dist/Button/Button.js
CHANGED
|
@@ -16,8 +16,8 @@ import { LoadingIcon } from "..";
|
|
|
16
16
|
import styles from "./Button.module.css";
|
|
17
17
|
export const Button = forwardRef(function Button(_a, ref) {
|
|
18
18
|
var { fullWidth = false, size = "medium", variant = "text", borderStyle = "rounded", icon, iconPosition = "start", loadingPosition = "auto", loadingVariant, className, children } = _a, restProps = __rest(_a, ["fullWidth", "size", "variant", "borderStyle", "icon", "iconPosition", "loadingPosition", "loadingVariant", "className", "children"]);
|
|
19
|
-
const childrenFirst =
|
|
20
|
-
const isloadingPositionCenter =
|
|
19
|
+
const childrenFirst = iconPosition === "end";
|
|
20
|
+
const isloadingPositionCenter = !icon || loadingPosition === "center";
|
|
21
21
|
const joinedClassNames = classNames({ fullWidth: fullWidth }, styles.button, styles[variant], { [styles.loading]: loadingVariant }, { [styles.loadingPositionCenter]: isloadingPositionCenter }, styles[size], styles[borderStyle], { [styles.iconButton]: !children && icon }, className);
|
|
22
22
|
return (_jsxs("button", Object.assign({ ref: ref, className: joinedClassNames }, restProps, { children: [childrenFirst && children, loadingVariant && (_jsx("div", { className: classNames(styles.displayOnDisabled, {
|
|
23
23
|
[styles.positionCenter]: isloadingPositionCenter,
|
|
@@ -14,7 +14,7 @@ import { forwardRef } from "react";
|
|
|
14
14
|
import classNames from "classnames";
|
|
15
15
|
import styles from "./LoadingIcon.module.css";
|
|
16
16
|
export const LoadingIcon = forwardRef(function LoadingIcon(_a, ref) {
|
|
17
|
-
var { size = "medium", variant = "
|
|
17
|
+
var { size = "medium", variant = "dots", className } = _a, restProps = __rest(_a, ["size", "variant", "className"]);
|
|
18
18
|
const joinedClassNames = classNames(styles.loadingIcon, styles[size], styles[variant], className);
|
|
19
19
|
return (_jsx("div", Object.assign({ ref: ref }, restProps, { className: joinedClassNames, children: _jsx("div", {}) })));
|
|
20
20
|
});
|
package/dist/{RenderByVisibility/RenderByVisibility.d.ts → RenderByScroll/RenderByScroll.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { StackProps } from "..";
|
|
3
|
-
export interface
|
|
3
|
+
export interface RenderByScrollProps extends StackProps {
|
|
4
4
|
scrollMarginTop?: number;
|
|
5
5
|
extraRender?: number;
|
|
6
6
|
jumpToIndex?: number;
|
|
@@ -8,4 +8,4 @@ export interface RenderByVisibilityProps extends StackProps {
|
|
|
8
8
|
newChildRendered?: (index: number) => void;
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
}
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const RenderByScroll: React.ForwardRefExoticComponent<RenderByScrollProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -14,8 +14,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import React, { forwardRef, useEffect, useRef, useState } from "react";
|
|
15
15
|
import { Stack, WithInteractions } from "..";
|
|
16
16
|
const data = Array.from({ length: 78 });
|
|
17
|
-
export const
|
|
18
|
-
var { scrollMarginTop =
|
|
17
|
+
export const RenderByScroll = forwardRef(function RenderByScroll(_a, ref) {
|
|
18
|
+
var { scrollMarginTop = 8, // Sticky Header Height
|
|
19
|
+
extraRender = 5, jumpToIndex = 0, stopNewRenders, newChildRendered, style, children } = _a, restProps = __rest(_a, ["scrollMarginTop", "extraRender", "jumpToIndex", "stopNewRenders", "newChildRendered", "style", "children"]);
|
|
19
20
|
const childrenArray = React.Children.toArray(children);
|
|
20
21
|
// Scroll Zone
|
|
21
22
|
const childRefs = useRef({});
|
|
@@ -38,25 +39,28 @@ export const RenderByVisibility = forwardRef(function RenderByVisibility(_a, ref
|
|
|
38
39
|
const overRenderedOnLowSide = visibled.lowest - rendered.lowest;
|
|
39
40
|
const overRenderedOnHighSide = rendered.highest - visibled.highest;
|
|
40
41
|
// Is Visible Loading Box
|
|
41
|
-
const [
|
|
42
|
+
const [isVisibleLowSideLimitBox, setIsVisibleLowSideLimitBox] = useState(false);
|
|
42
43
|
// Render new Childs if needed
|
|
43
44
|
useEffect(() => {
|
|
44
45
|
if (!stopNewRenders) {
|
|
45
|
-
if (overRenderedOnHighSide
|
|
46
|
+
if (overRenderedOnHighSide < 1 ||
|
|
47
|
+
overRenderedOnHighSide - 1 <= overRenderedOnLowSide) {
|
|
46
48
|
if (rendered.highest < data.length &&
|
|
47
49
|
overRenderedOnHighSide < extraRender) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const newHigh = rendered.highest + 1;
|
|
51
|
+
setRendered(Object.assign(Object.assign({}, rendered), { highest: newHigh }));
|
|
52
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(newHigh);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
else {
|
|
53
56
|
if (rendered.lowest > 0 &&
|
|
54
57
|
overRenderedOnLowSide < extraRender) {
|
|
55
|
-
if (
|
|
58
|
+
if (isVisibleLowSideLimitBox) {
|
|
56
59
|
scrollTo(rendered.lowest);
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const newLow = rendered.lowest - 1;
|
|
62
|
+
setRendered(Object.assign(Object.assign({}, rendered), { lowest: newLow }));
|
|
63
|
+
newChildRendered === null || newChildRendered === void 0 ? void 0 : newChildRendered(newLow);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
}
|
|
@@ -71,17 +75,18 @@ export const RenderByVisibility = forwardRef(function RenderByVisibility(_a, ref
|
|
|
71
75
|
}
|
|
72
76
|
const timeout = setTimeout(() => {
|
|
73
77
|
scrollTo(jumpToIndex, true);
|
|
74
|
-
},
|
|
78
|
+
}, 100);
|
|
75
79
|
return () => clearTimeout(timeout);
|
|
76
80
|
// eslint-disable-next-line
|
|
77
81
|
}, [jumpToIndex]);
|
|
78
|
-
// console.log("visibled", visibled);
|
|
79
|
-
// console.log("rendered", rendered);
|
|
80
|
-
// console.log("stopNewRenders", stopNewRenders);
|
|
81
82
|
return (_jsxs(Stack, Object.assign({ ref: ref }, restProps, { style: Object.assign({ minHeight: "100vh" }, style), children: [rendered.lowest > 0 && (_jsx(WithInteractions, { style: {
|
|
83
|
+
height: "1px",
|
|
84
|
+
backgroundColor: "red",
|
|
82
85
|
marginBottom: `${scrollMarginTop}rem`,
|
|
83
|
-
}, onVisibilityChange: (v) =>
|
|
86
|
+
}, onVisibilityChange: (v) => setIsVisibleLowSideLimitBox(v) })), childrenArray.map((child, i) => i >= rendered.lowest &&
|
|
84
87
|
i <= rendered.highest && (_jsx(WithInteractions, { ref: (el) => {
|
|
85
88
|
childRefs.current[i] = el;
|
|
86
|
-
}, onVisible: () => handleOnVisible(i), style: {
|
|
89
|
+
}, onVisible: () => handleOnVisible(i), style: {
|
|
90
|
+
scrollMarginTop: `${scrollMarginTop}rem`,
|
|
91
|
+
}, children: child }, i)))] })));
|
|
87
92
|
});
|
|
@@ -18,6 +18,7 @@ export interface WithInteractionsProps extends StackProps {
|
|
|
18
18
|
onVisibilityChange?: (visible: boolean) => void;
|
|
19
19
|
onVisible?: () => void;
|
|
20
20
|
onHidden?: () => void;
|
|
21
|
+
onMouseHoverChange?: (isHover: boolean, e: MouseEvent) => void;
|
|
21
22
|
onMouseHoverStart?: (e: MouseEvent) => void;
|
|
22
23
|
onMouseHoverLeave?: (e: MouseEvent) => void;
|
|
23
24
|
children?: React.ReactNode;
|
|
@@ -14,7 +14,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
15
15
|
import { Stack } from "../Stack/Stack";
|
|
16
16
|
export const WithInteractions = forwardRef(function WithInteractions(_a, forwardedRef) {
|
|
17
|
-
var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibilityChange, onVisible, onHidden, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibilityChange", "onVisible", "onHidden", "onMouseHoverStart", "onMouseHoverLeave"]);
|
|
17
|
+
var { children, onRightClick, onTap, onDoubleTap, onOutsideClick, onSwipeLeft, onSwipeRight, onSwipeUp, onSwipeDown, onPinchIn, onPinchOut, onRotate, onScrollStart, onScrollStop, onResize, onVisibilityChange, onVisible, onHidden, onMouseHoverChange, onMouseHoverStart, onMouseHoverLeave } = _a, restProps = __rest(_a, ["children", "onRightClick", "onTap", "onDoubleTap", "onOutsideClick", "onSwipeLeft", "onSwipeRight", "onSwipeUp", "onSwipeDown", "onPinchIn", "onPinchOut", "onRotate", "onScrollStart", "onScrollStop", "onResize", "onVisibilityChange", "onVisible", "onHidden", "onMouseHoverChange", "onMouseHoverStart", "onMouseHoverLeave"]);
|
|
18
18
|
const localRef = useRef(null);
|
|
19
19
|
// Let the parent access our DOM node
|
|
20
20
|
useImperativeHandle(forwardedRef, () => localRef.current);
|
|
@@ -161,9 +161,16 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
|
|
|
161
161
|
}
|
|
162
162
|
// === On Hover Change ===
|
|
163
163
|
const hasFinePointer = window.matchMedia("(pointer: fine)").matches;
|
|
164
|
-
if (hasFinePointer &&
|
|
165
|
-
|
|
166
|
-
const
|
|
164
|
+
if (hasFinePointer &&
|
|
165
|
+
(onMouseHoverChange || onMouseHoverStart || onMouseHoverLeave)) {
|
|
166
|
+
const mouseEnter = (e) => {
|
|
167
|
+
onMouseHoverChange === null || onMouseHoverChange === void 0 ? void 0 : onMouseHoverChange(true, e);
|
|
168
|
+
onMouseHoverStart === null || onMouseHoverStart === void 0 ? void 0 : onMouseHoverStart(e);
|
|
169
|
+
};
|
|
170
|
+
const mouseLeave = (e) => {
|
|
171
|
+
onMouseHoverChange === null || onMouseHoverChange === void 0 ? void 0 : onMouseHoverChange(true, e);
|
|
172
|
+
onMouseHoverLeave === null || onMouseHoverLeave === void 0 ? void 0 : onMouseHoverLeave(e);
|
|
173
|
+
};
|
|
167
174
|
el.addEventListener("mouseenter", mouseEnter);
|
|
168
175
|
el.addEventListener("mouseleave", mouseLeave);
|
|
169
176
|
cleanupFns.push(() => {
|
|
@@ -211,6 +218,7 @@ export const WithInteractions = forwardRef(function WithInteractions(_a, forward
|
|
|
211
218
|
onVisibilityChange,
|
|
212
219
|
onVisible,
|
|
213
220
|
onHidden,
|
|
221
|
+
onMouseHoverChange,
|
|
214
222
|
onMouseHoverStart,
|
|
215
223
|
onMouseHoverLeave,
|
|
216
224
|
]);
|
|
@@ -8,9 +8,7 @@ type AllowedOverlays = React.ReactElement<PopupProps, typeof Popup> | React.Reac
|
|
|
8
8
|
export interface WithOverlayProps {
|
|
9
9
|
trigger?: "onClick" | "onRightClick";
|
|
10
10
|
overlay?: AllowedOverlays;
|
|
11
|
-
children?: React.ReactElement
|
|
12
|
-
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
13
|
-
}>;
|
|
11
|
+
children?: React.ReactElement;
|
|
14
12
|
}
|
|
15
13
|
export declare function WithOverlay({ trigger, overlay, children, }: WithOverlayProps): import("react/jsx-runtime").JSX.Element;
|
|
16
14
|
export {};
|
|
@@ -2,38 +2,27 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, cloneElement, useEffect, useRef } from "react";
|
|
4
4
|
import { WithInteractions, } from "..";
|
|
5
|
-
import { mergeRefs } from "@yakad/lib";
|
|
6
5
|
import { createPortal } from "react-dom";
|
|
7
6
|
export function WithOverlay({ trigger = "onClick", overlay, children, }) {
|
|
8
|
-
|
|
7
|
+
// Get Triggers ref and send to Overlay
|
|
9
8
|
const triggerRef = useRef(null);
|
|
10
9
|
const [showOverlay, setShowOverlay] = useState(false);
|
|
10
|
+
// Disable Body Scroll on showOverlay
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
document.body.style.overflow = showOverlay ? "hidden" : "initial";
|
|
13
13
|
return () => {
|
|
14
14
|
document.body.style.overflow = "initial";
|
|
15
15
|
};
|
|
16
16
|
}, [showOverlay]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}) }), showOverlay &&
|
|
29
|
-
overlay &&
|
|
30
|
-
createPortal(cloneElement(overlay, {
|
|
31
|
-
triggerref: triggerRef,
|
|
32
|
-
onClose: () => {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
(_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
35
|
-
setShowOverlay(false);
|
|
36
|
-
},
|
|
37
|
-
}), document.getElementsByClassName("portalRoot")[0] ||
|
|
38
|
-
document.body)] }));
|
|
17
|
+
// Teleport Overlay to portalRoot or body
|
|
18
|
+
const teleport = overlay &&
|
|
19
|
+
createPortal(cloneElement(overlay, {
|
|
20
|
+
triggerref: triggerRef,
|
|
21
|
+
onClose: () => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
(_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
24
|
+
setShowOverlay(false);
|
|
25
|
+
},
|
|
26
|
+
}), document.getElementsByClassName("portalRoot")[0] || document.body);
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx(WithInteractions, { ref: triggerRef, onRightClick: () => trigger === "onRightClick" && setShowOverlay(true), onClick: () => trigger === "onClick" && setShowOverlay(true), children: children }), showOverlay && teleport] }));
|
|
39
28
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export * from "./CodeBox/CodeBox";
|
|
|
30
30
|
export * from "./Display/Display";
|
|
31
31
|
export * from "./WithOverlay/WithOverlay";
|
|
32
32
|
export * from "./WithInteractions/WithInteractions";
|
|
33
|
-
export * from "./
|
|
33
|
+
export * from "./RenderByScroll/RenderByScroll";
|
|
34
34
|
export * from "./ActiveOnVisible/ActiveOnVisible";
|
|
35
35
|
export * from "./Dropdown/Dropdown";
|
|
36
36
|
export * from "./Popup/Popup";
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ export * from "./CodeBox/CodeBox";
|
|
|
35
35
|
export * from "./Display/Display"; // Stack Based
|
|
36
36
|
export * from "./WithOverlay/WithOverlay";
|
|
37
37
|
export * from "./WithInteractions/WithInteractions"; // Stack Based
|
|
38
|
-
export * from "./
|
|
38
|
+
export * from "./RenderByScroll/RenderByScroll"; // Stack Based
|
|
39
39
|
export * from "./ActiveOnVisible/ActiveOnVisible"; // Stack Based
|
|
40
40
|
// Overlays
|
|
41
41
|
export * from "./Dropdown/Dropdown"; // Card Based
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakad/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.142",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Natiq",
|
|
6
6
|
"description": "UI components for NextJS/React",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"classnames": "2.5.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"react": "^
|
|
40
|
-
"react-dom": "^
|
|
39
|
+
"react": "^19.2.0",
|
|
40
|
+
"react-dom": "^19.2.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/css-modules": "1.0.5",
|