@yakad/ui 1.3.130 → 1.3.132

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.
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ fullWidth?: boolean;
3
4
  size?: "small" | "medium" | "large";
4
5
  variant?: "text" | "outlined" | "filled" | "filledtonal" | "tonal" | "elevated" | "link" | "fab";
5
6
  borderStyle?: "none" | "semi" | "squircle" | "rounded";
@@ -15,10 +15,10 @@ import classNames from "classnames";
15
15
  import { LoadingIcon } from "..";
16
16
  import styles from "./Button.module.css";
17
17
  export const Button = forwardRef(function Button(_a, ref) {
18
- var { size = "medium", variant = "text", borderStyle = "rounded", icon, iconPosition = "start", loadingPosition = "auto", loadingVariant, className, children } = _a, restProps = __rest(_a, ["size", "variant", "borderStyle", "icon", "iconPosition", "loadingPosition", "loadingVariant", "className", "children"]);
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
19
  const childrenFirst = Boolean(iconPosition === "end");
20
20
  const isloadingPositionCenter = Boolean(!icon || loadingPosition === "center");
21
- const joinedClassNames = classNames(styles.button, styles[variant], { [styles.loading]: loadingVariant }, { [styles.loadingPositionCenter]: isloadingPositionCenter }, styles[size], styles[borderStyle], { [styles.iconButton]: !children && icon }, className);
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,
24
24
  }), children: _jsx(LoadingIcon, { size: size, variant: loadingVariant }) })), icon, !childrenFirst && children] })));
@@ -2,6 +2,7 @@
2
2
  export interface DisplayOnVisibleProps extends React.HTMLAttributes<HTMLDivElement> {
3
3
  align?: "start" | "space" | "center" | "end";
4
4
  fullWidth?: boolean;
5
+ onVisibilityChange?: (visible: boolean) => void;
5
6
  onVisible?: () => void;
6
7
  onHidden?: () => void;
7
8
  children?: React.ReactNode;
@@ -17,7 +17,7 @@ import boxingStyles from "../boxing.module.css";
17
17
  import { WithInteractions } from "..";
18
18
  import styles from "./DisplayOnVisible.module.css";
19
19
  export const DisplayOnVisible = forwardRef(function DisplayOnVisible(_a, forwardedRef) {
20
- var { align, fullWidth = true, onVisible, onHidden, className, style, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "onVisible", "onHidden", "className", "style", "children"]);
20
+ var { align, fullWidth = true, onVisibilityChange, onVisible, onHidden, className, style, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "onVisibilityChange", "onVisible", "onHidden", "className", "style", "children"]);
21
21
  const localRef = useRef(null);
22
22
  // Let the parent access our DOM node
23
23
  useImperativeHandle(forwardedRef, () => localRef.current);
@@ -25,6 +25,7 @@ export const DisplayOnVisible = forwardRef(function DisplayOnVisible(_a, forward
25
25
  const isVisible = boxHeight === 0;
26
26
  const handleOnVisible = () => {
27
27
  setBoxHeight(0);
28
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(true);
28
29
  onVisible === null || onVisible === void 0 ? void 0 : onVisible();
29
30
  };
30
31
  const handleOnHidden = () => {
@@ -32,6 +33,7 @@ export const DisplayOnVisible = forwardRef(function DisplayOnVisible(_a, forward
32
33
  const boxRect = localRef.current.getBoundingClientRect();
33
34
  setBoxHeight(boxRect.height);
34
35
  }
36
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(false);
35
37
  onHidden === null || onHidden === void 0 ? void 0 : onHidden();
36
38
  };
37
39
  const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, { [styles.notVisible]: !isVisible }, className);
@@ -16,10 +16,10 @@ import classNames from "classnames";
16
16
  import { Card, WithInteractions } from "..";
17
17
  import styles from "./Dropdown.module.css";
18
18
  export const Dropdown = forwardRef(function Dropdown(_a, forwardedRef) {
19
- var { fullWidth = false, blur, level = "high", triggerRef, onClose, className, style, children } = _a, restProps = __rest(_a, ["fullWidth", "blur", "level", "triggerRef", "onClose", "className", "style", "children"]);
19
+ var { fullWidth = false, blur, level = "high", triggerref, onClose, className, style, children } = _a, restProps = __rest(_a, ["fullWidth", "blur", "level", "triggerref", "onClose", "className", "style", "children"]);
20
20
  const fallbackTriggerRef = useRef(null);
21
21
  const dropdownRef = useRef(null);
22
- const placementTargetRef = triggerRef || fallbackTriggerRef;
22
+ const placementTargetRef = triggerref || fallbackTriggerRef;
23
23
  // Let the parent access our DOM node
24
24
  useImperativeHandle(forwardedRef, () => dropdownRef.current);
25
25
  const [arrowPosition, setArrowPosition] = useState({
@@ -71,7 +71,7 @@ export const Dropdown = forwardRef(function Dropdown(_a, forwardedRef) {
71
71
  setIsPlaced(true);
72
72
  }
73
73
  }, [children, placementTargetRef]);
74
- return (_jsxs(_Fragment, { children: [!triggerRef && _jsx("div", { ref: fallbackTriggerRef }), _jsx(WithInteractions, { onOutsideClick: onClose, children: _jsx(Card, Object.assign({ ref: dropdownRef, fullWidth: fullWidth, 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, {
74
+ return (_jsxs(_Fragment, { children: [!triggerref && _jsx("div", { ref: fallbackTriggerRef }), _jsx(WithInteractions, { onOutsideClick: onClose, children: _jsx(Card, Object.assign({ ref: dropdownRef, fullWidth: fullWidth, 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, {
75
75
  [styles.isPlacedAbove]: isPlacedAbove,
76
76
  }, { [styles.blur]: blur }), style: {
77
77
  top: arrowPosition.top,
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
- type LoadingControlChildren = React.ReactElement<{
2
+ type LoadingControlV2Children = React.ReactElement<{
3
3
  index?: number;
4
4
  }>;
5
- export interface LoadingControlProps extends React.HTMLAttributes<HTMLDivElement> {
5
+ export interface LoadingControlV2Props extends React.HTMLAttributes<HTMLDivElement> {
6
6
  align?: "start" | "space" | "center" | "end";
7
7
  fullWidth?: boolean;
8
8
  loadingLimit?: number;
9
- children: LoadingControlChildren;
9
+ children: LoadingControlV2Children;
10
10
  }
11
- export declare const LoadingControl: React.ForwardRefExoticComponent<LoadingControlProps & React.RefAttributes<HTMLDivElement>>;
11
+ export declare const LoadingControlV2: React.ForwardRefExoticComponent<LoadingControlV2Props & React.RefAttributes<HTMLDivElement>>;
12
12
  export {};
@@ -15,38 +15,80 @@ import React, { forwardRef, useEffect, useState } from "react";
15
15
  import classNames from "classnames";
16
16
  import boxingStyles from "../boxing.module.css";
17
17
  import { DisplayOnVisible } from "..";
18
- export const LoadingControl = forwardRef(function LoadingControl(_a, ref) {
19
- var { align, fullWidth = true, loadingLimit = 20, className, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "loadingLimit", "className", "children"]);
20
- const [maxLoadedItem, setMaxLoadedItem] = useState(0);
21
- const [maxVisibledItem, setMaxVisibledItem] = useState(0);
18
+ export const LoadingControlV2 = forwardRef(function LoadingControlV2(_a, ref) {
19
+ var { align, fullWidth = true, loadingLimit = 200, className, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "loadingLimit", "className", "children"]);
20
+ const [maxTotalVisibledItems, setMaxTotalVisibledItems] = useState(3); // Min: default
21
+ const extraLoading = maxTotalVisibledItems * 2;
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
23
  const [loadedItems, setLoadedItems] = useState([
23
24
  React.cloneElement(children, {
24
25
  index: 0,
25
26
  }),
26
27
  ]);
27
- const handleOnVisible = (i) => {
28
- if (i && maxVisibledItem < i)
29
- setMaxVisibledItem(i);
28
+ const [visibilityStatus, setVisibilityStatus] = useState({});
29
+ const handleOnVisibilityChange = (visible, i) => {
30
+ if (i !== undefined && visibilityStatus[i] !== visible)
31
+ setVisibilityStatus((prev) => (Object.assign(Object.assign({}, prev), { [i]: visible })));
30
32
  };
33
+ const visibleIndexes = Object.entries(visibilityStatus)
34
+ // eslint-disable-next-line
35
+ .filter(([_, isVisible]) => isVisible)
36
+ .map(([index]) => parseInt(index));
37
+ const visibleCount = Object.values(visibilityStatus).filter(Boolean).length;
38
+ const lowestVisibleItemIndex = visibleIndexes.length
39
+ ? Math.min(...visibleIndexes)
40
+ : 0;
41
+ const highestVisibleItemIndex = visibleIndexes.length
42
+ ? Math.max(...visibleIndexes)
43
+ : 0;
44
+ const lowestLoadedItemIndex = loadedItems[0].props.index;
45
+ const highestLoadedItemIndex = loadedItems[loadedItems.length - 1].props.index;
31
46
  useEffect(() => {
32
- if (maxLoadedItem < maxVisibledItem + 5) {
33
- const prevIndex = maxLoadedItem;
34
- setMaxLoadedItem(prevIndex + 1);
47
+ if (highestLoadedItemIndex < loadingLimit &&
48
+ highestLoadedItemIndex < highestVisibleItemIndex + extraLoading) {
35
49
  setLoadedItems([
36
50
  ...loadedItems,
37
51
  React.cloneElement(children, {
38
- index: prevIndex + 1,
52
+ index: highestLoadedItemIndex + 1,
39
53
  }),
40
- ].slice(loadedItems.length >= loadingLimit ? 1 : 0));
54
+ ].slice(
55
+ // Slice from start
56
+ lowestVisibleItemIndex - lowestLoadedItemIndex >
57
+ extraLoading
58
+ ? 1
59
+ : 0));
60
+ console.log(">>>>>>>>>>>>>>>>>>>>>>>> ++++ Item ", highestLoadedItemIndex + 1, " Added to end");
41
61
  }
42
- }, [
43
- children,
44
- loadingLimit,
45
- loadedItems,
46
- maxLoadedItem,
47
- maxVisibledItem,
48
- ]);
49
- console.log("loadedItems.length", loadedItems.length, "maxLoadedItem", maxLoadedItem, "maxVisibledItem", maxVisibledItem);
62
+ if (lowestLoadedItemIndex > 0 &&
63
+ lowestLoadedItemIndex > lowestVisibleItemIndex - extraLoading) {
64
+ setLoadedItems([
65
+ React.cloneElement(children, {
66
+ index: lowestLoadedItemIndex - 1,
67
+ }),
68
+ ...loadedItems,
69
+ ].slice(
70
+ // Slice from end
71
+ 0, highestLoadedItemIndex - highestVisibleItemIndex >
72
+ extraLoading
73
+ ? -1
74
+ : undefined));
75
+ console.log(">>>>>>>>>>>> ---- Item ", lowestLoadedItemIndex - 1, " Added to start");
76
+ }
77
+ if (visibleCount > maxTotalVisibledItems) {
78
+ setMaxTotalVisibledItems(visibleCount);
79
+ }
80
+ // eslint-disable-next-line
81
+ }, [visibilityStatus]);
82
+ console.log("###### ", "Total Loaded:", loadedItems.length, "visibleCount:", visibleCount, "extraLoading:", extraLoading, " ##### ", "L:", lowestLoadedItemIndex, "V:", lowestVisibleItemIndex, "D:", -(lowestLoadedItemIndex - lowestVisibleItemIndex), "|", "D:", highestLoadedItemIndex - highestVisibleItemIndex, "V:", highestVisibleItemIndex, "L:", highestLoadedItemIndex);
83
+ // console.log("visibilityStatus", visibilityStatus);
84
+ // console.log(
85
+ // "loadedItems",
86
+ // loadedItems.map((item) => item.props.index)
87
+ // );
88
+ // console.log(
89
+ // "visibilityStatus.length",
90
+ // Object.keys(visibilityStatus).length
91
+ // );
50
92
  const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, className);
51
- return (_jsx("div", Object.assign({ ref: ref, className: joinedClassNames }, restProps, { children: loadedItems.map((item) => (_jsxs(DisplayOnVisible, { onVisible: () => handleOnVisible(item.props.index), children: [_jsx("h1", { children: item.props.index }), item] }, item.props.index))) })));
93
+ return (_jsx("div", Object.assign({ ref: ref, className: joinedClassNames }, restProps, { children: loadedItems.map((item) => (_jsxs(DisplayOnVisible, { onVisibilityChange: (visible) => handleOnVisibilityChange(visible, item.props.index), children: [_jsx("h1", { children: item.props.index }), item] }, item.props.index))) })));
52
94
  });
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ export interface RenderOnVisibleProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ align?: "start" | "space" | "center" | "end";
4
+ fullWidth?: boolean;
5
+ onVisibilityChange?: (visible: boolean) => void;
6
+ onVisible?: () => void;
7
+ onHidden?: () => void;
8
+ children?: React.ReactNode;
9
+ }
10
+ export declare const RenderOnVisible: import("react").ForwardRefExoticComponent<RenderOnVisibleProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,40 @@
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 } from "react/jsx-runtime";
14
+ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
15
+ import classNames from "classnames";
16
+ import boxingStyles from "../boxing.module.css";
17
+ import { WithInteractions } from "..";
18
+ export const RenderOnVisible = forwardRef(function RenderOnVisible(_a, forwardedRef) {
19
+ var { align, fullWidth = true, onVisibilityChange, onVisible, onHidden, className, style, children } = _a, restProps = __rest(_a, ["align", "fullWidth", "onVisibilityChange", "onVisible", "onHidden", "className", "style", "children"]);
20
+ const localRef = useRef(null);
21
+ // Let the parent access our DOM node
22
+ useImperativeHandle(forwardedRef, () => localRef.current);
23
+ const [boxHeight, setBoxHeight] = useState(0);
24
+ const isVisible = boxHeight === 0;
25
+ const handleOnVisible = () => {
26
+ setBoxHeight(0);
27
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(true);
28
+ onVisible === null || onVisible === void 0 ? void 0 : onVisible();
29
+ };
30
+ const handleOnHidden = () => {
31
+ if (localRef.current) {
32
+ const boxRect = localRef.current.getBoundingClientRect();
33
+ setBoxHeight(boxRect.height);
34
+ }
35
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(false);
36
+ onHidden === null || onHidden === void 0 ? void 0 : onHidden();
37
+ };
38
+ const joinedClassNames = classNames(boxingStyles.flexColumnBox, { [boxingStyles[align]]: align }, { fullWidth: fullWidth }, className);
39
+ return (_jsx(WithInteractions, { onVisible: handleOnVisible, onHidden: handleOnHidden, children: _jsx("div", Object.assign({ ref: localRef }, restProps, { className: joinedClassNames, style: Object.assign({ height: boxHeight || "auto" }, style), children: isVisible && children })) }));
40
+ });
@@ -1,7 +1,7 @@
1
1
  import { RefObject } from "react";
2
2
  import { Dropdown, DropdownProps, Popup, PopupProps } from "..";
3
3
  export interface OverlayProps {
4
- triggerRef?: RefObject<HTMLElement | null>;
4
+ triggerref?: RefObject<HTMLElement | null>;
5
5
  onClose?: () => void;
6
6
  }
7
7
  type AllowedOverlays = React.ReactElement<PopupProps, typeof Popup> | React.ReactElement<DropdownProps, typeof Dropdown>;
@@ -27,7 +27,7 @@ export function WithOverlay({ trigger = "onClick", overlay, children, }) {
27
27
  }) }), showOverlay &&
28
28
  overlay &&
29
29
  cloneElement(overlay, {
30
- triggerRef: triggerRef,
30
+ triggerref: triggerRef,
31
31
  onClose: () => {
32
32
  var _a, _b;
33
33
  (_b = (_a = overlay.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
package/dist/index.d.ts CHANGED
@@ -28,9 +28,10 @@ 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 "./DisplayOnVisible/DisplayOnVisible";
32
31
  export * from "./WithInteractions/WithInteractions";
33
32
  export * from "./WithOverlay/WithOverlay";
34
33
  export * from "./Dropdown/Dropdown";
35
34
  export * from "./Popup/Popup";
36
35
  export * from "./LoadingControl/LoadingControl";
36
+ export * from "./DisplayOnVisible/DisplayOnVisible";
37
+ export * from "./RenderOnVisible/RenderOnVisible";
package/dist/index.js CHANGED
@@ -33,10 +33,12 @@ export * from "./RadioButton/RadioButton";
33
33
  export * from "./CodeBox/CodeBox";
34
34
  // Utilities
35
35
  export * from "./Display/Display";
36
- export * from "./DisplayOnVisible/DisplayOnVisible";
37
36
  export * from "./WithInteractions/WithInteractions";
38
37
  export * from "./WithOverlay/WithOverlay";
39
38
  // Overlays
40
39
  export * from "./Dropdown/Dropdown";
41
40
  export * from "./Popup/Popup";
41
+ // Loading Control
42
42
  export * from "./LoadingControl/LoadingControl";
43
+ export * from "./DisplayOnVisible/DisplayOnVisible";
44
+ export * from "./RenderOnVisible/RenderOnVisible";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yakad/ui",
3
- "version": "1.3.130",
3
+ "version": "1.3.132",
4
4
  "private": false,
5
5
  "author": "Natiq",
6
6
  "description": "UI components for NextJS/React",