@react-fabric/data 1.0.0-beta.1 → 1.0.0-beta.12

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.
Files changed (63) hide show
  1. package/dist/cjs/checklist/CheckList.js +143 -0
  2. package/dist/cjs/histogram/Histogram.js +14 -5
  3. package/dist/cjs/hooks/useSelectableList.js +54 -0
  4. package/dist/cjs/index.js +2 -0
  5. package/dist/cjs/table/BodyCell.js +35 -3
  6. package/dist/cjs/table/BodyRow.js +107 -0
  7. package/dist/cjs/table/HeaderCell.js +4 -3
  8. package/dist/cjs/table/Table.js +84 -49
  9. package/dist/cjs/table/useVirtualTable.js +16 -2
  10. package/dist/cjs/tree/TreePanel.js +14 -2
  11. package/dist/cjs/tree/useTree.js +7 -0
  12. package/dist/cjs/virtual/Gallery.js +11 -4
  13. package/dist/cjs/virtual/List.js +11 -4
  14. package/dist/esm/checklist/CheckList.js +143 -0
  15. package/dist/esm/histogram/Histogram.js +14 -5
  16. package/dist/esm/hooks/useSelectableList.js +54 -0
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/table/BodyCell.js +35 -3
  19. package/dist/esm/table/BodyRow.js +107 -0
  20. package/dist/esm/table/HeaderCell.js +4 -3
  21. package/dist/esm/table/Table.js +85 -50
  22. package/dist/esm/table/useVirtualTable.js +16 -2
  23. package/dist/esm/tree/TreePanel.js +15 -3
  24. package/dist/esm/tree/useTree.js +7 -0
  25. package/dist/esm/virtual/Gallery.js +11 -4
  26. package/dist/esm/virtual/List.js +11 -4
  27. package/dist/types/checklist/CheckList.d.ts +30 -0
  28. package/dist/types/histogram/Histogram.d.ts +3 -3
  29. package/dist/types/hooks/useSelectableList.d.ts +28 -0
  30. package/dist/types/index.d.ts +3 -0
  31. package/dist/types/table/AddColumn.d.ts +2 -2
  32. package/dist/types/table/BodyCell.d.ts +4 -3
  33. package/dist/types/table/BodyRow.d.ts +20 -0
  34. package/dist/types/table/EmptyCell.d.ts +2 -2
  35. package/dist/types/table/HeaderCell.d.ts +2 -2
  36. package/dist/types/table/Table.d.ts +1 -1
  37. package/dist/types/table/types.d.ts +19 -7
  38. package/dist/types/table/useTableColumns.d.ts +6 -6
  39. package/dist/types/table/useVirtualTable.d.ts +5 -1
  40. package/dist/types/tree/TreePanel.d.ts +1 -1
  41. package/dist/types/tree/types.d.ts +6 -2
  42. package/dist/types/tree/useTree.d.ts +1 -0
  43. package/dist/types/virtual/Gallery.d.ts +3 -2
  44. package/dist/types/virtual/List.d.ts +3 -2
  45. package/package.json +6 -5
  46. package/src/checklist/CheckList.tsx +222 -0
  47. package/src/histogram/Histogram.tsx +7 -2
  48. package/src/hooks/useSelectableList.ts +94 -0
  49. package/src/index.ts +3 -0
  50. package/src/table/AddColumn.tsx +2 -2
  51. package/src/table/BodyCell.tsx +30 -3
  52. package/src/table/BodyRow.tsx +142 -0
  53. package/src/table/EmptyCell.tsx +2 -2
  54. package/src/table/HeaderCell.tsx +4 -3
  55. package/src/table/Table.tsx +103 -56
  56. package/src/table/types.ts +23 -6
  57. package/src/table/useTableColumns.ts +7 -7
  58. package/src/table/useVirtualTable.ts +19 -5
  59. package/src/tree/TreePanel.tsx +12 -1
  60. package/src/tree/types.ts +8 -1
  61. package/src/tree/useTree.ts +5 -0
  62. package/src/virtual/Gallery.tsx +4 -1
  63. package/src/virtual/List.tsx +4 -1
@@ -1,6 +1,8 @@
1
1
  'use client';
2
2
 
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
6
  import { useDebounce, Skeleton } from '@react-fabric/core';
5
7
  import { debounce } from '@react-fabric/utilities';
6
8
  import { useVirtualizer } from '@tanstack/react-virtual';
@@ -10,6 +12,9 @@ import { useDeferredValue, useMemo, useRef, useEffect, useCallback, useState, us
10
12
  import { Scroller } from './Scroller.js';
11
13
  import { jsx, jsxs } from 'react/jsx-runtime';
12
14
 
15
+ var _excluded = ["items", "children", "fullWidth", "padding", "orientation", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "listRef"];
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
18
  var createItemList = memoizeOne(function (items) {
14
19
  return items;
15
20
  });
@@ -31,7 +36,8 @@ var _VirtualList = function _VirtualList(_ref) {
31
36
  loading = _ref.loading,
32
37
  onLoadMore = _ref.onLoadMore,
33
38
  onScroll = _ref.onScroll,
34
- listRef = _ref.listRef;
39
+ listRef = _ref.listRef,
40
+ aria = _objectWithoutProperties(_ref, _excluded);
35
41
  var count = useDeferredValue(items.length);
36
42
  var extraSize = useMemo(function () {
37
43
  return onLoadMore ? 64 : 0;
@@ -154,10 +160,11 @@ var _VirtualList = function _VirtualList(_ref) {
154
160
  }
155
161
  };
156
162
  }, [virtualizer]);
157
- return /*#__PURE__*/jsx("div", {
163
+ return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
158
164
  ref: scrollerRef,
159
165
  onScroll: handleScroll,
160
- className: classNames("area-content bg-base overflow-auto contain-strict"),
166
+ className: classNames("area-content bg-base overflow-auto contain-strict")
167
+ }, aria), {}, {
161
168
  children: /*#__PURE__*/jsxs("div", {
162
169
  className: classNames("inline-flex flex-nowrap gap-2 justify-center min-h-full min-w-full", orientation === "horizontal" && "flex-col"),
163
170
  children: [/*#__PURE__*/jsxs("div", {
@@ -209,7 +216,7 @@ var _VirtualList = function _VirtualList(_ref) {
209
216
  })
210
217
  })]
211
218
  })
212
- });
219
+ }));
213
220
  };
214
221
  _VirtualList.displayName = "VirtualList";
215
222
  var GenericMemo = memo;
@@ -0,0 +1,30 @@
1
+ import { type BadgeType, type TestProps } from "@react-fabric/core/dist/types/types";
2
+ import { type FC } from "react";
3
+ import { type SelectableProps } from "../hooks/useSelectableList";
4
+ export interface CheckListItem extends KeyValue {
5
+ id: string;
6
+ label: string;
7
+ icon?: string;
8
+ badge?: BadgeType;
9
+ isDisabled?: boolean;
10
+ }
11
+ export interface CheckListProps extends SelectableProps, TestProps {
12
+ /**
13
+ * list items
14
+ */
15
+ items: CheckListItem[];
16
+ /**
17
+ * allow negative selections
18
+ */
19
+ allowNegative?: boolean;
20
+ /**
21
+ * max list items
22
+ */
23
+ maxCount?: number;
24
+ /**
25
+ * message for empty list
26
+ */
27
+ emptyMessage?: string;
28
+ sortItems?: boolean;
29
+ }
30
+ export declare const CheckList: FC<CheckListProps>;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type ColorType, type PaletteType } from "@react-fabric/core/dist/types/types";
2
+ import { type ColorType, type PaletteType, type TestProps } from "@react-fabric/core/dist/types/types";
3
3
  interface HistogramItem {
4
4
  id: string;
5
5
  label: string;
@@ -7,7 +7,7 @@ interface HistogramItem {
7
7
  total?: number;
8
8
  disabled?: boolean;
9
9
  }
10
- export interface HistogramProps {
10
+ export interface HistogramProps extends TestProps {
11
11
  /**
12
12
  * histogram items list
13
13
  */
@@ -37,5 +37,5 @@ export interface HistogramProps {
37
37
  */
38
38
  onClick?: (id: string, negative?: true) => void;
39
39
  }
40
- export declare const Histogram: ({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, }: HistogramProps) => import("react/jsx-runtime").JSX.Element;
40
+ export declare const Histogram: ({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, ...aria }: HistogramProps) => import("react/jsx-runtime").JSX.Element;
41
41
  export {};
@@ -0,0 +1,28 @@
1
+ export interface SelectableProps {
2
+ /**
3
+ * list items
4
+ */
5
+ items: Array<{
6
+ label: string;
7
+ } & KeyValue>;
8
+ /**
9
+ * selected item ids
10
+ */
11
+ selected?: string[];
12
+ /**
13
+ * selected negative item ids
14
+ */
15
+ nonselected?: string[];
16
+ /**
17
+ * change callback
18
+ */
19
+ onChange?: (ids: string[], nonIds?: string[]) => void;
20
+ /**
21
+ * item click callback
22
+ */
23
+ onClick?: (id: string, isNegative: boolean) => void;
24
+ }
25
+ export declare const useSelectableList: ({ items, selected, nonselected, onChange, onClick, }: SelectableProps) => {
26
+ selection: KeyValue<number>;
27
+ toggleSelection: (id: string, isNegative?: boolean) => void;
28
+ };
@@ -1,9 +1,12 @@
1
1
  import "./i18n";
2
+ export { CheckList } from "./checklist/CheckList";
2
3
  export { Histogram } from "./histogram/Histogram";
3
4
  export { JsonViewer } from "./json/JsonViewer";
4
5
  export { Pagination } from "./pagination/Pagination";
5
6
  export { Table } from "./table/Table";
7
+ export { type TableColumn, type TableRef } from "./table/types";
6
8
  export { TreePanel } from "./tree/TreePanel";
9
+ export { type TreeNodeType as TreeNode } from "./tree/types";
7
10
  export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
8
11
  export { VirtualList, type VirtualListRef } from "./virtual/List";
9
12
  export * from "./hooks/useFilteredList";
@@ -1,5 +1,5 @@
1
- import { type ColumnType } from "./types";
1
+ import { type TableColumn } from "./types";
2
2
  export declare const AddColumn: ({ columns, onClick, }: {
3
- columns: ColumnType[];
3
+ columns: TableColumn[];
4
4
  onClick: (id: string) => void;
5
5
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
- import { type ColumnType } from "./types";
2
- export declare const BodyCell: ({ column, item, }: {
3
- column: ColumnType;
1
+ import { type TableColumn } from "./types";
2
+ export declare const BodyCell: ({ column, item, index, }: {
3
+ column: TableColumn;
4
4
  item: KeyValue;
5
+ index: number;
5
6
  }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { type TableColumn } from "./types";
2
+ export declare const BodyRow: ({ rowKey, index, data, keyProperty, measureElement, state, hideableColumns, wrapperStart, wrapperEnd, onRowClick, checkableRows, checked, toggleChecked, canExpand, expanded, toggleExpand, expandRow, }: {
3
+ rowKey: Key;
4
+ index: number;
5
+ data: KeyValue;
6
+ keyProperty?: Key;
7
+ measureElement: AnyObject;
8
+ state: KeyValue<TableColumn[]>;
9
+ hideableColumns?: boolean;
10
+ wrapperStart: string;
11
+ wrapperEnd: string;
12
+ checkableRows?: boolean;
13
+ checked: 0 | 1;
14
+ onRowClick?: AnyObject;
15
+ canExpand?: AnyObject;
16
+ expandRow?: AnyObject;
17
+ expanded: boolean;
18
+ toggleExpand: (key: Key) => void;
19
+ toggleChecked: (key: Key) => void;
20
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
- import { type ColumnType } from "./types";
2
- export declare const EmptyCell: ({ id, width: _width, maxWidth, minWidth, }: ColumnType) => import("react/jsx-runtime").JSX.Element;
1
+ import { type TableColumn } from "./types";
2
+ export declare const EmptyCell: ({ id, width: _width, maxWidth, minWidth, }: TableColumn) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
- import { type ColumnType, type TableProps } from "./types";
2
- export declare const HeaderCell: ({ id, label, icon, iconBg, iconColor, rtlFlip, actions, locked, sortable, resizable, width: _width, maxWidth, minWidth, sort, onSort, }: ColumnType & Pick<TableProps, "sort" | "onSort">) => import("react/jsx-runtime").JSX.Element;
1
+ import { type TableColumn, type TableProps } from "./types";
2
+ export declare const HeaderCell: ({ id, label, icon, iconBg, iconColor, rtlFlip, actions, locked, tooltip, sortable, resizable, width: _width, maxWidth, minWidth, sort, onSort, }: TableColumn & Pick<TableProps, "sort" | "onSort">) => import("react/jsx-runtime").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { type TableProps } from "./types";
2
- export declare const Table: <T extends KeyValue<any> = KeyValue<any>>({ data, columns, keyProperty, checkableRows, hideableColumns, sort, loading, onSort, onRowClick, onCheckedChanged, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const Table: <T extends KeyValue<any> = KeyValue<any>>({ ref, data, columns, keyProperty, checkableRows, initialScroll, hideableColumns, sort, loading, emptyDisplay, canExpand, children, onSort, onScroll, onRowClick, onCheckedChanged, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,12 @@
1
- import { type CssProp, type IconProps, type TestProps } from "@react-fabric/core/dist/types/types";
1
+ import { type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
2
2
  import { type ReactElement } from "react";
3
3
  export declare const COL_MIN_WIDTH = "3rem";
4
4
  export declare const COL_MAX_WIDTH = "64rem";
5
5
  export declare const COL_DEFAULT_WIDTH = "12rem";
6
- export interface ColumnType<T = KeyValue> extends CssProp, IconProps, TestProps {
7
- id: keyof T;
6
+ export interface TableColumn<T = KeyValue> extends CssProp, IconProps, TestProps {
7
+ id: keyof T | string;
8
8
  label?: string;
9
+ tooltip?: string;
9
10
  actions?: ReactElement;
10
11
  align?: "start" | "center" | "end";
11
12
  locked?: "start" | "end";
@@ -20,12 +21,19 @@ export interface ColumnType<T = KeyValue> extends CssProp, IconProps, TestProps
20
21
  maxWidth?: string | number;
21
22
  dataType?: "string" | "number" | "boolean" | "datetime" | "date" | "time" | "unknown";
22
23
  format?: string;
23
- renderer?: (value: AnyObject, data: T) => void;
24
+ valueMap?: KeyValue;
25
+ renderer?: (value: AnyObject, data: T, index: number) => Elements<AnyObject>;
24
26
  }
25
- export interface TableProps<T = KeyValue> {
26
- columns: Array<ColumnType<T>>;
27
+ export interface TableRef {
28
+ hilight: (row: number) => void;
29
+ unhilight: () => void;
30
+ scrollTo: (row: number) => void;
31
+ }
32
+ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
33
+ columns: Array<TableColumn<T>>;
27
34
  data: T[];
28
- keyProperty: keyof T;
35
+ keyProperty?: keyof T;
36
+ emptyDisplay?: ReactElement;
29
37
  /**
30
38
  * checkable rows
31
39
  */
@@ -45,4 +53,8 @@ export interface TableProps<T = KeyValue> {
45
53
  loading?: boolean;
46
54
  hideableColumns?: boolean;
47
55
  onRowClick?: (data: T) => void;
56
+ initialScroll?: number;
57
+ onScroll?: (firstItem: number) => void;
58
+ canExpand?: (record: T) => boolean;
59
+ children?: (record: T) => Elements<AnyObject>;
48
60
  }
@@ -1,10 +1,10 @@
1
- import { type ColumnType } from "./types";
2
- export declare const useTableColumns: (columns: ColumnType[]) => {
1
+ import { type TableColumn } from "./types";
2
+ export declare const useTableColumns: (columns: TableColumn[]) => {
3
3
  state: {
4
- start: ColumnType<KeyValue<any>>[];
5
- end: ColumnType<KeyValue<any>>[];
6
- cols: ColumnType<KeyValue<any>>[];
7
- columns: ColumnType[];
4
+ start: TableColumn<KeyValue<any>>[];
5
+ end: TableColumn<KeyValue<any>>[];
6
+ cols: TableColumn<KeyValue<any>>[];
7
+ columns: TableColumn[];
8
8
  };
9
9
  onHide: (id: string) => void;
10
10
  };
@@ -1,15 +1,19 @@
1
1
  /// <reference types="react" />
2
2
  interface DataState {
3
+ expanded: Key[];
3
4
  checked: Key[];
4
5
  allChecked: 0 | 1 | 2;
5
6
  }
6
- export declare const useVirtualTable: (data: KeyValue[], keyProperty: Key, onCheckChanged: (checked: Key[]) => void) => {
7
+ export declare const useVirtualTable: (data: KeyValue[], keyProperty?: Key, onCheckChanged?: (checked: Key[]) => void) => {
7
8
  scrollerRef: import("react").RefObject<HTMLDivElement>;
8
9
  items: import("@tanstack/virtual-core").VirtualItem<Element>[];
9
10
  checkState: DataState;
10
11
  getData: (index: number) => KeyValue<any>;
12
+ virtualizer: import("@tanstack/virtual-core").Virtualizer<HTMLDivElement, Element>;
13
+ top: number | undefined;
11
14
  totalSize: () => number;
12
15
  measureElement: (node: Element | null | undefined) => void;
16
+ toggleExpand: (key: Key) => void;
13
17
  toggleChecked: (key: Key) => void;
14
18
  toggleAllChecked: () => void;
15
19
  };
@@ -1,2 +1,2 @@
1
1
  import { type TreePanelProps } from "./types";
2
- export declare const TreePanel: <T extends KeyValue<any>>({ items, selected, checked, checkable, noLines, renderer, searchable, selectable, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onSelect, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const TreePanel: <T extends KeyValue<any>>({ ref, items, selected, checked, checkable, noLines, renderer, searchable, selectable, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onSelect, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type TestProps } from "@react-fabric/core/dist/types/types";
2
+ import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
3
3
  interface TreeBaseNode<T> extends IconProps, CssProp, TestProps {
4
4
  id: string;
5
5
  /**
@@ -70,7 +70,11 @@ export interface TreeNodeProps extends ChildProp {
70
70
  onSelect: (id: string) => void;
71
71
  onChecked: (id: string) => void;
72
72
  }
73
- export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps {
73
+ export interface TreeRef {
74
+ select: (id: string) => void;
75
+ open: (id: string) => void;
76
+ }
77
+ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
74
78
  items?: Array<TreeNodeType<T>>;
75
79
  /**
76
80
  * make tree searchable
@@ -13,6 +13,7 @@ export declare const useTree: <T extends KeyValue<any>>({ items, checked, select
13
13
  collapseAll: () => void;
14
14
  toggleCheck: (id: string) => void;
15
15
  select: (id: string) => void;
16
+ expand: (id: string) => void;
16
17
  onFilter: {
17
18
  (...args: any): void;
18
19
  cancel(): void;
@@ -1,10 +1,11 @@
1
+ import { type TestProps } from "@react-fabric/core/dist/types/types";
1
2
  import { type ReactElement, type Ref } from "react";
2
3
  export interface VirtualGalleryRef {
3
4
  scrollToItem: (index: number) => void;
4
5
  hilight: (index: number) => void;
5
6
  unhilight: () => void;
6
7
  }
7
- export interface VirtualGalleryProps<T> {
8
+ export interface VirtualGalleryProps<T> extends TestProps {
8
9
  children: (props: {
9
10
  data: T;
10
11
  index: number;
@@ -50,6 +51,6 @@ export interface VirtualGalleryProps<T> {
50
51
  onScroll?: (top: number) => void;
51
52
  }
52
53
  export declare const VirtualGallery: {
53
- <T extends KeyValue<any>>({ items, children, columns, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
54
+ <T extends KeyValue<any>>({ items, children, columns, padding, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, galleryRef, ...aria }: VirtualGalleryProps<T>): import("react/jsx-runtime").JSX.Element;
54
55
  displayName: string;
55
56
  };
@@ -1,10 +1,11 @@
1
+ import { type TestProps } from "@react-fabric/core/dist/types/types";
1
2
  import { type ReactElement, type Ref } from "react";
2
3
  export interface VirtualListRef {
3
4
  scrollToItem: (index: number) => void;
4
5
  hilight: (index: number) => void;
5
6
  unhilight: () => void;
6
7
  }
7
- export interface VirtualListProps<T> {
8
+ export interface VirtualListProps<T> extends TestProps {
8
9
  children: (props: {
9
10
  data: T;
10
11
  index: number;
@@ -54,6 +55,6 @@ export interface VirtualListProps<T> {
54
55
  onScroll?: (top: number) => void;
55
56
  }
56
57
  export declare const VirtualList: {
57
- <T extends KeyValue<any>>({ items, children, fullWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
58
+ <T extends KeyValue<any>>({ items, children, fullWidth, padding, orientation, defaultHeight: height, defaultWidth: width, hideScroller, initialScroll, loading, onLoadMore, onScroll, listRef, ...aria }: VirtualListProps<T>): import("react/jsx-runtime").JSX.Element;
58
59
  displayName: string;
59
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -33,9 +33,10 @@
33
33
  "watch": "npm-run-all -p watch:rollup watch:dts"
34
34
  },
35
35
  "dependencies": {
36
- "@react-fabric/core": "^1.0.0-beta.1",
37
- "@react-fabric/form": "^1.0.0-beta.1",
38
- "@react-fabric/utilities": "^1.0.0-beta.1",
36
+ "@react-fabric/core": "^1.0.0-beta.12",
37
+ "@react-fabric/date": "^1.0.0-beta.12",
38
+ "@react-fabric/form": "^1.0.0-beta.12",
39
+ "@react-fabric/utilities": "^1.0.0-beta.12",
39
40
  "@tanstack/react-virtual": "^3.8.6",
40
41
  "classnames": "^2.5.1",
41
42
  "color": "^4.2.3",
@@ -51,5 +52,5 @@
51
52
  "node": ">=18.12.0",
52
53
  "npm": ">=8.19.0"
53
54
  },
54
- "gitHead": "e0712d7ea2c945de876bef813b5d2dcec1218ed7"
55
+ "gitHead": "7f5a400622fb0266331b527b2078d4dc6886c95e"
55
56
  }
@@ -0,0 +1,222 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { Badge, CoreIcons, EmptyContent, Icon } from "@react-fabric/core";
25
+ import {
26
+ type BadgeType,
27
+ type TestProps,
28
+ } from "@react-fabric/core/dist/types/types";
29
+ import { isString } from "@react-fabric/utilities";
30
+ import {
31
+ Fragment,
32
+ isValidElement,
33
+ useEffect,
34
+ useMemo,
35
+ useState,
36
+ type FC,
37
+ } from "react";
38
+ import { useTranslation } from "react-i18next";
39
+ import {
40
+ useSelectableList,
41
+ type SelectableProps,
42
+ } from "../hooks/useSelectableList";
43
+
44
+ export interface CheckListItem extends KeyValue {
45
+ id: string;
46
+ label: string;
47
+ icon?: string;
48
+ badge?: BadgeType;
49
+ isDisabled?: boolean;
50
+ }
51
+
52
+ export interface CheckListProps extends SelectableProps, TestProps {
53
+ /**
54
+ * list items
55
+ */
56
+ items: CheckListItem[];
57
+ /**
58
+ * allow negative selections
59
+ */
60
+ allowNegative?: boolean;
61
+ /**
62
+ * max list items
63
+ */
64
+ maxCount?: number;
65
+ /**
66
+ * message for empty list
67
+ */
68
+ emptyMessage?: string;
69
+
70
+ sortItems?: boolean;
71
+ }
72
+
73
+ const CheckItem: FC<
74
+ Omit<CheckListItem, "selected"> & {
75
+ selected?: number;
76
+ allowNegative?: boolean;
77
+ }
78
+ > = ({
79
+ id,
80
+ allowNegative,
81
+ selected,
82
+ icon,
83
+ label,
84
+ isDisabled,
85
+ onClick,
86
+ badge,
87
+ ...aria
88
+ }: Omit<CheckListItem, "selected"> & {
89
+ selected?: number;
90
+ allowNegative?: boolean;
91
+ }) => {
92
+ return (
93
+ <div
94
+ role="none"
95
+ className="ax-checkList__item"
96
+ data-disabled={isDisabled}
97
+ onClick={() => onClick(id, false)}
98
+ onContextMenu={(e) => [
99
+ allowNegative && onClick(id, true),
100
+ e.preventDefault(),
101
+ ]}
102
+ {...aria}
103
+ >
104
+ {!allowNegative && (
105
+ <Icon
106
+ data-type="checkbox"
107
+ className="ax-checkList__checkbox"
108
+ data-selected={selected === 1}
109
+ icon={selected ? CoreIcons.checkboxInt : CoreIcons.checkboxOff}
110
+ />
111
+ )}
112
+ {allowNegative && (
113
+ <Fragment>
114
+ <Icon
115
+ data-type="multiple"
116
+ className="ax-checkList__checkbox"
117
+ icon={
118
+ selected === 1
119
+ ? CoreIcons.expand
120
+ : selected === -1
121
+ ? CoreIcons.collapse
122
+ : CoreIcons.checkboxOff
123
+ }
124
+ data-selected={selected}
125
+ />
126
+ <div className="ax-checkList__checkbox">
127
+ <Icon
128
+ data-type="positive"
129
+ onClick={(e) => [(onClick(id, false), e.stopPropagation())]}
130
+ icon={selected === 1 ? CoreIcons.expandActive : CoreIcons.expand}
131
+ data-selected={selected === 1}
132
+ />
133
+ <Icon
134
+ data-type="negative"
135
+ onClick={(e) => [(onClick(id, true), e.stopPropagation())]}
136
+ icon={
137
+ selected === -1 ? CoreIcons.collapseActive : CoreIcons.collapse
138
+ }
139
+ data-selected={selected === -1}
140
+ />
141
+ </div>
142
+ </Fragment>
143
+ )}
144
+ {isValidElement(icon) && icon}
145
+ {isString(icon) && <Icon icon={icon} />}
146
+ <label>{label}</label>
147
+ <Badge {...badge} />
148
+ </div>
149
+ );
150
+ };
151
+
152
+ export const CheckList: FC<CheckListProps> = ({
153
+ items = [],
154
+ maxCount = 0,
155
+ allowNegative,
156
+ emptyMessage,
157
+ sortItems = true,
158
+ selected,
159
+ nonselected,
160
+ onChange,
161
+ onClick,
162
+ ...aria
163
+ }: CheckListProps) => {
164
+ const { t } = useTranslation("data");
165
+ const { selection, toggleSelection } = useSelectableList({
166
+ items,
167
+ selected,
168
+ nonselected,
169
+ onChange,
170
+ onClick,
171
+ });
172
+ const [showMore, setShowMore] = useState(false);
173
+
174
+ useEffect(() => {
175
+ setShowMore(false);
176
+ }, [items]);
177
+
178
+ const listItems = useMemo(() => {
179
+ return [...items]
180
+ .sort((a, b) => {
181
+ if (sortItems && selection[a.id] !== selection[b.id]) {
182
+ if (selection[a.id] === 1) return -1;
183
+ if (selection[b.id] === 1) return 1;
184
+ if (selection[a.id] === -1) return -1;
185
+ if (selection[b.id] === -1) return 1;
186
+ }
187
+ return 0;
188
+ })
189
+ .slice(0, !showMore && maxCount > 0 ? maxCount : undefined);
190
+ }, [items, selection, maxCount, showMore, sortItems]);
191
+
192
+ return (
193
+ <div {...aria}>
194
+ {listItems.map((item, index) => (
195
+ <CheckItem
196
+ {...item}
197
+ key={index}
198
+ onClick={toggleSelection}
199
+ allowNegative={allowNegative}
200
+ selected={selection[item.id]}
201
+ />
202
+ ))}
203
+ {maxCount > 0 && items.length > maxCount && (
204
+ <div className="ax-moreLink">
205
+ <span
206
+ role="none"
207
+ className="link"
208
+ onClick={() => setShowMore(!showMore)}
209
+ >
210
+ ...{t(`core:action.${showMore ? "less" : "more"}`)}
211
+ </span>
212
+ </div>
213
+ )}
214
+ {listItems.length === 0 && (
215
+ <EmptyContent
216
+ className="text-sm"
217
+ message={emptyMessage ?? t("checkList.empty")}
218
+ />
219
+ )}
220
+ </div>
221
+ );
222
+ };