ar-design 0.4.44 → 0.4.45

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.
@@ -7,6 +7,7 @@ export type Config<T extends object> = {
7
7
  bottom?: number;
8
8
  left?: number;
9
9
  };
10
+ perPage?: number;
10
11
  filter?: {
11
12
  search?: (item: T, value: string) => boolean;
12
13
  keys: (item: T) => {
@@ -20,6 +21,7 @@ interface IProps<T extends object, TColumnProperties> {
20
21
  trackBy: (item: T) => string;
21
22
  columns: KanbanBoardColumnType<T, TColumnProperties>[];
22
23
  onChange?: (item: T, columnKey: string, columnProperties: TColumnProperties, hoverIndex: number) => void;
24
+ onLazy?: (perPage: number) => void;
23
25
  config?: Config<T>;
24
26
  }
25
27
  export default IProps;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import IProps from "./IProps";
3
3
  import "../../../assets/css/components/data-display/kanban-board/styles.css";
4
- declare const KanbanBoard: <T extends object, TColumnProperties>({ trackBy, columns, onChange, config, }: IProps<T, TColumnProperties>) => React.JSX.Element;
4
+ declare const KanbanBoard: <T extends object, TColumnProperties>({ trackBy, columns, onChange, onLazy, config, }: IProps<T, TColumnProperties>) => React.JSX.Element;
5
5
  export default KanbanBoard;
@@ -1,19 +1,21 @@
1
1
  "use client";
2
- import React, { useEffect, useRef, useState } from "react";
2
+ import React, { useEffect, useMemo, useRef, useState } from "react";
3
3
  import "../../../assets/css/components/data-display/kanban-board/styles.css";
4
4
  import DnD from "../dnd";
5
5
  import { ARIcon } from "../../icons";
6
6
  import Filter from "./filter";
7
- const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
7
+ const KanbanBoard = function ({ trackBy, columns, onChange, onLazy, config, }) {
8
8
  // refs
9
9
  const _kanbanWrapper = useRef(null);
10
10
  const _kanbanItems = useRef({});
11
11
  const _hoverItemIndex = useRef(null);
12
12
  const _scrollInterval = useRef(null);
13
13
  const _scrollAnimationFrame = useRef(null);
14
- const _scrollSpeedRef = useRef(0); // px/frame
14
+ const _scrollSpeedRef = useRef(0);
15
+ const _lastScrollTop = useRef(0);
15
16
  // states
16
17
  const [data, setData] = useState([]);
18
+ const [perPage, setPerPage] = useState(config?.perPage ?? 10);
17
19
  // states -> Filters
18
20
  const [search, setSearch] = useState("");
19
21
  const [selectFilters, setSelectFilters] = useState({});
@@ -104,6 +106,20 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
104
106
  if (item.classList.contains("dragging"))
105
107
  item.classList.remove("dragging");
106
108
  };
109
+ const handleLazyScroll = useMemo(() => {
110
+ return (event) => {
111
+ const target = event.currentTarget;
112
+ const { scrollTop, scrollHeight, clientHeight } = target;
113
+ const isVerticalScroll = scrollTop !== _lastScrollTop.current;
114
+ _lastScrollTop.current = scrollTop;
115
+ if (!isVerticalScroll)
116
+ return;
117
+ const isBottom = scrollHeight - scrollTop <= clientHeight;
118
+ if (isBottom) {
119
+ setPerPage((prev) => prev + Number(config?.perPage ?? 10));
120
+ }
121
+ };
122
+ }, [config?.perPage]);
107
123
  const handleStartScroll = (direction) => {
108
124
  const el = _kanbanWrapper.current;
109
125
  if (!el)
@@ -237,10 +253,14 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
237
253
  });
238
254
  }
239
255
  }
240
- else if (!search?.trim() && _kanbanWrapper.current) {
241
- _kanbanWrapper.current.scrollTo({ top: 0, left: 0, behavior: "smooth" });
242
- }
256
+ // else if (!search?.trim() && _kanbanWrapper.current) {
257
+ // _kanbanWrapper.current.scrollTo({ top: 0, left: 0, behavior: "smooth" });
258
+ // }
243
259
  }, [columns, search, selectedFilters, dateFilters]);
260
+ useEffect(() => {
261
+ if (onLazy)
262
+ onLazy(perPage);
263
+ }, [perPage, onLazy]);
244
264
  return (React.createElement(React.Fragment, null,
245
265
  config?.filter && (React.createElement(Filter, { states: {
246
266
  search: {
@@ -262,7 +282,7 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
262
282
  }, config: config })),
263
283
  React.createElement("div", { ref: _kanbanWrapper, className: "ar-kanban-board", style: {
264
284
  height: `calc(100dvh - (${_kanbanWrapper.current?.getBoundingClientRect().top}px + ${config?.safeAreaOffset?.bottom ?? 0}px))`,
265
- }, onDragOver: handleBoardDragOver, onDragEnd: stopScrolling, onDrop: stopScrolling },
285
+ }, onScroll: handleLazyScroll, onDragOver: handleBoardDragOver, onDragEnd: stopScrolling, onDrop: stopScrolling },
266
286
  React.createElement("div", { className: "buttons" },
267
287
  React.createElement("div", { className: "button left", onMouseDown: () => handleStartScroll("left"), onMouseUp: handleStopScroll, onMouseLeave: handleStopScroll },
268
288
  React.createElement(ARIcon, { icon: "ArrowLeft" })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.4.44",
3
+ "version": "0.4.45",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",