@react-fabric/data 1.0.0-beta.9 → 1.0.2
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/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/css/styles.css +24 -0
- package/dist/cjs/checklist/CheckList.js +59 -33
- package/dist/cjs/histogram/Histogram.js +41 -26
- package/dist/cjs/hooks/useFilteredList.js +100 -17
- package/dist/cjs/hooks/usePagination.js +29 -8
- package/dist/cjs/hooks/useSelectableList.js +30 -5
- package/dist/cjs/i18n/{ar.json.js → ar/data.json.js} +8 -1
- package/dist/cjs/i18n/{en.json.js → en/data.json.js} +8 -1
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/json/JsonViewer.js +80 -43
- package/dist/cjs/pagination/Pagination.js +24 -15
- package/dist/cjs/table/AddColumn.js +5 -5
- package/dist/cjs/table/BodyCell.js +20 -13
- package/dist/cjs/table/BodyRow.js +41 -28
- package/dist/cjs/table/CheckboxCell.js +10 -9
- package/dist/cjs/table/ColumnFilters.js +100 -0
- package/dist/cjs/table/EmptyCell.js +4 -4
- package/dist/cjs/table/HeaderCell.js +79 -53
- package/dist/cjs/table/HtmlTable.js +84 -0
- package/dist/cjs/table/{Context.js → Provider.js} +8 -10
- package/dist/cjs/table/Table.js +99 -33
- package/dist/cjs/{tree/types.js → table/context.js} +9 -5
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +10 -10
- package/dist/cjs/table/useTableColumns.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +129 -22
- package/dist/cjs/tree/TreeNode.js +66 -46
- package/dist/cjs/tree/TreePanel.js +60 -24
- package/dist/cjs/tree/useTree.js +212 -47
- package/dist/cjs/tree/utils.js +63 -34
- package/dist/cjs/utils/getColor.js +58 -0
- package/dist/cjs/virtual/Gallery.js +119 -61
- package/dist/cjs/virtual/List.js +116 -55
- package/dist/cjs/virtual/Scroller.js +16 -8
- package/dist/esm/checklist/CheckList.js +61 -35
- package/dist/esm/histogram/Histogram.js +43 -28
- package/dist/esm/hooks/useFilteredList.js +101 -18
- package/dist/esm/hooks/usePagination.js +29 -8
- package/dist/esm/hooks/useSelectableList.js +30 -5
- package/dist/esm/i18n/{ar.json.js → ar/data.json.js} +8 -2
- package/dist/esm/i18n/{en.json.js → en/data.json.js} +8 -2
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +31 -0
- package/dist/esm/json/JsonViewer.js +82 -45
- package/dist/esm/pagination/Pagination.js +25 -16
- package/dist/esm/table/AddColumn.js +6 -6
- package/dist/esm/table/BodyCell.js +21 -14
- package/dist/esm/table/BodyRow.js +41 -28
- package/dist/esm/table/CheckboxCell.js +11 -10
- package/dist/esm/table/ColumnFilters.js +100 -0
- package/dist/esm/table/EmptyCell.js +4 -4
- package/dist/esm/table/HeaderCell.js +80 -54
- package/dist/esm/table/HtmlTable.js +84 -0
- package/dist/esm/table/{Context.js → Provider.js} +11 -12
- package/dist/esm/table/Table.js +100 -34
- package/dist/esm/{tree/types.js → table/context.js} +8 -4
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +10 -10
- package/dist/esm/table/useTableColumns.js +4 -4
- package/dist/esm/table/useVirtualTable.js +131 -24
- package/dist/esm/tree/TreeNode.js +69 -49
- package/dist/esm/tree/TreePanel.js +62 -26
- package/dist/esm/tree/useTree.js +215 -50
- package/dist/esm/tree/utils.js +64 -35
- package/dist/esm/utils/getColor.js +58 -0
- package/dist/esm/virtual/Gallery.js +121 -63
- package/dist/esm/virtual/List.js +118 -57
- package/dist/esm/virtual/Scroller.js +17 -9
- package/dist/types/checklist/CheckList.d.ts +25 -6
- package/dist/types/histogram/Histogram.d.ts +28 -6
- package/dist/types/hooks/useFilteredList.d.ts +62 -5
- package/dist/types/hooks/usePagination.d.ts +18 -2
- package/dist/types/hooks/useSelectableList.d.ts +24 -1
- package/dist/types/index.d.ts +27 -0
- package/dist/types/json/JsonViewer.d.ts +23 -3
- package/dist/types/pagination/Pagination.d.ts +8 -2
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +2 -2
- package/dist/types/table/BodyRow.d.ts +9 -9
- package/dist/types/table/CheckboxCell.d.ts +3 -3
- package/dist/types/table/ColumnFilters.d.ts +12 -0
- package/dist/types/table/EmptyCell.d.ts +1 -1
- package/dist/types/table/HeaderCell.d.ts +1 -1
- package/dist/types/table/HtmlTable.d.ts +21 -0
- package/dist/types/table/Provider.d.ts +2 -0
- package/dist/types/table/Table.d.ts +10 -1
- package/dist/types/table/context.d.ts +7 -0
- package/dist/types/table/types.d.ts +52 -10
- package/dist/types/table/useResizer.d.ts +1 -1
- package/dist/types/table/useTableColumns.d.ts +1 -1
- package/dist/types/table/useVirtualTable.d.ts +31 -12
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +36 -1
- package/dist/types/tree/types.d.ts +75 -28
- package/dist/types/tree/useTree.d.ts +8 -12
- package/dist/types/tree/utils.d.ts +15 -8
- package/dist/types/utils/getColor.d.ts +43 -0
- package/dist/types/virtual/Gallery.d.ts +37 -6
- package/dist/types/virtual/List.d.ts +38 -6
- package/dist/types/virtual/Scroller.d.ts +1 -1
- package/package.json +17 -19
- package/src/checklist/CheckList.tsx +68 -71
- package/src/histogram/Histogram.tsx +47 -48
- package/src/hooks/useFilteredList.tsx +111 -28
- package/src/hooks/usePagination.tsx +39 -39
- package/src/hooks/useSelectableList.ts +45 -33
- package/src/i18n/{ar.json → ar/data.json} +5 -0
- package/src/i18n/{en.json → en/data.json} +5 -0
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +23 -17
- package/src/json/JsonViewer.tsx +89 -120
- package/src/pagination/Pagination.tsx +104 -105
- package/src/table/AddColumn.tsx +6 -15
- package/src/table/BodyCell.tsx +27 -36
- package/src/table/BodyRow.tsx +36 -59
- package/src/table/CheckboxCell.tsx +12 -15
- package/src/table/ColumnFilters.tsx +93 -0
- package/src/table/EmptyCell.tsx +5 -18
- package/src/table/HeaderCell.tsx +72 -53
- package/src/table/HtmlTable.tsx +106 -0
- package/src/table/{Context.tsx → Provider.tsx} +11 -28
- package/src/table/Table.tsx +98 -83
- package/src/table/context.ts +33 -0
- package/src/table/types.ts +53 -27
- package/src/table/useResizer.ts +5 -9
- package/src/table/useTableColumns.ts +4 -6
- package/src/table/useVirtualTable.ts +136 -37
- package/src/tree/TreeNode.tsx +91 -86
- package/src/tree/TreePanel.tsx +87 -51
- package/src/tree/types.ts +85 -46
- package/src/tree/useTree.ts +210 -65
- package/src/tree/utils.ts +81 -62
- package/src/utils/getColor.ts +55 -0
- package/src/virtual/Gallery.tsx +129 -120
- package/src/virtual/List.tsx +124 -91
- package/src/virtual/Scroller.tsx +25 -9
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
- package/dist/types/table/Context.d.ts +0 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { ButtonGroup, Button
|
|
3
|
+
import { ButtonGroup, Button } from '@react-fabric/core';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -39,35 +39,43 @@ var Scroller = function Scroller(_ref) {
|
|
|
39
39
|
variant: "link",
|
|
40
40
|
className: "outline",
|
|
41
41
|
children: [/*#__PURE__*/jsx(Button, {
|
|
42
|
-
rtlFlip: true,
|
|
43
42
|
size: "sm",
|
|
44
43
|
variant: "link",
|
|
45
44
|
"aria-label": "scroll to top",
|
|
46
|
-
icon:
|
|
45
|
+
icon: {
|
|
46
|
+
icon: vertical ? "icon-[mdi--chevron-double-up]" : "icon-[mdi--chevron-double-left]",
|
|
47
|
+
rtlFlip: true
|
|
48
|
+
},
|
|
47
49
|
disabled: (scrollActive & 2) === 0,
|
|
48
50
|
onClick: onStart
|
|
49
51
|
}), /*#__PURE__*/jsx(Button, {
|
|
50
|
-
rtlFlip: true,
|
|
51
52
|
size: "sm",
|
|
52
53
|
variant: "link",
|
|
53
54
|
"aria-label": "scroll up",
|
|
54
|
-
icon:
|
|
55
|
+
icon: {
|
|
56
|
+
icon: vertical ? "icon-[mdi--chevron-up]" : "icon-[mdi--chevron-left]",
|
|
57
|
+
rtlFlip: true
|
|
58
|
+
},
|
|
55
59
|
disabled: (scrollActive & 2) === 0,
|
|
56
60
|
onClick: onPrevious
|
|
57
61
|
}), /*#__PURE__*/jsx(Button, {
|
|
58
|
-
rtlFlip: true,
|
|
59
62
|
size: "sm",
|
|
60
63
|
variant: "link",
|
|
61
64
|
"aria-label": "scroll down",
|
|
62
|
-
icon:
|
|
65
|
+
icon: {
|
|
66
|
+
icon: vertical ? "icon-[mdi--chevron-down]" : "icon-[mdi--chevron-right]",
|
|
67
|
+
rtlFlip: true
|
|
68
|
+
},
|
|
63
69
|
disabled: scrollActive % 2 === 0,
|
|
64
70
|
onClick: onNext
|
|
65
71
|
}), /*#__PURE__*/jsx(Button, {
|
|
66
|
-
rtlFlip: true,
|
|
67
72
|
size: "sm",
|
|
68
73
|
variant: "link",
|
|
69
74
|
"aria-label": "scroll to bottom",
|
|
70
|
-
icon:
|
|
75
|
+
icon: {
|
|
76
|
+
icon: vertical ? "icon-[mdi--chevron-double-down]" : "icon-[mdi--chevron-double-right]",
|
|
77
|
+
rtlFlip: true
|
|
78
|
+
},
|
|
71
79
|
disabled: scrollActive % 2 === 0,
|
|
72
80
|
onClick: onEnd
|
|
73
81
|
})]
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
1
|
+
import type { BadgeType } from "@react-fabric/core/dist/types/components/badge/Badge";
|
|
2
|
+
import { type TestProps } from "@react-fabric/core/dist/types/types";
|
|
3
3
|
import { type SelectableProps } from "../hooks/useSelectableList";
|
|
4
|
-
export interface CheckListItem
|
|
4
|
+
export interface CheckListItem {
|
|
5
5
|
id: string;
|
|
6
6
|
label: string;
|
|
7
|
-
icon?: string;
|
|
7
|
+
icon?: string | React.ReactElement;
|
|
8
8
|
badge?: BadgeType;
|
|
9
|
-
|
|
9
|
+
disabled?: boolean;
|
|
10
10
|
}
|
|
11
11
|
export interface CheckListProps extends SelectableProps, TestProps {
|
|
12
12
|
/**
|
|
@@ -27,4 +27,23 @@ export interface CheckListProps extends SelectableProps, TestProps {
|
|
|
27
27
|
emptyMessage?: string;
|
|
28
28
|
sortItems?: boolean;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* CheckList component to display a list of selectable items with checkboxes.
|
|
32
|
+
* It supports selection, deselection, and allows for negative selections.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```jsx
|
|
36
|
+
* <CheckList
|
|
37
|
+
* items={[
|
|
38
|
+
* { id: "1", label: "Item 1", icon: "icon1" },
|
|
39
|
+
* { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
|
|
40
|
+
* ]}
|
|
41
|
+
* maxCount={5}
|
|
42
|
+
* allowNegative={true}
|
|
43
|
+
* emptyMessage="No items available"
|
|
44
|
+
* onChange={(selectedItems) => console.log(selectedItems)}
|
|
45
|
+
* onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
|
|
46
|
+
* />
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function CheckList({ items, maxCount, allowNegative, emptyMessage, sortItems, selected, nonselected, onChange, onClick, ...aria }: CheckListProps): import("react").JSX.Element;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { type ColorType, type PaletteType, type TestProps } from "@react-fabric/core/dist/types/types";
|
|
1
|
+
import type { CustomColors, TestProps } from "@react-fabric/core/dist/types/types";
|
|
3
2
|
interface HistogramItem {
|
|
4
3
|
id: string;
|
|
5
4
|
label: string;
|
|
@@ -19,7 +18,7 @@ export interface HistogramProps extends TestProps {
|
|
|
19
18
|
/**
|
|
20
19
|
* histogram bar color
|
|
21
20
|
*/
|
|
22
|
-
color?:
|
|
21
|
+
color?: CustomColors;
|
|
23
22
|
/**
|
|
24
23
|
* sorted list
|
|
25
24
|
*/
|
|
@@ -27,15 +26,38 @@ export interface HistogramProps extends TestProps {
|
|
|
27
26
|
/**
|
|
28
27
|
* title when histo list is empty
|
|
29
28
|
*/
|
|
30
|
-
emptyTitle?: string |
|
|
29
|
+
emptyTitle?: string | React.ReactElement;
|
|
31
30
|
/**
|
|
32
31
|
* message when histo list is empty
|
|
33
32
|
*/
|
|
34
|
-
emptyMessage?: string |
|
|
33
|
+
emptyMessage?: string | React.ReactElement;
|
|
35
34
|
/**
|
|
36
35
|
* handle histo click
|
|
37
36
|
*/
|
|
38
37
|
onClick?: (id: string, negative?: true) => void;
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Histogram component displays a bar chart of items with counts.
|
|
41
|
+
* It allows users to visualize the distribution of counts across different items.
|
|
42
|
+
* The component supports sorting, custom colors, and click handling for each item.
|
|
43
|
+
* It also provides an empty state when there are no items to display.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```jsx
|
|
47
|
+
* <Histogram
|
|
48
|
+
* items={[
|
|
49
|
+
* { id: "1", label: "Item 1", count: 10 },
|
|
50
|
+
* { id: "2", label: "Item 2", count: 20 },
|
|
51
|
+
* { id: "3", label: "Item 3", count: 5, disabled: true },
|
|
52
|
+
* ]}
|
|
53
|
+
* total={30}
|
|
54
|
+
* color="primary-500"
|
|
55
|
+
* sortBy="count"
|
|
56
|
+
* emptyTitle="No Data Available"
|
|
57
|
+
* emptyMessage="Please check back later."
|
|
58
|
+
* onClick={(id, negative) => console.log(`Clicked on ${id}`, negative ? "Negative" : "Positive")}
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function Histogram({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, }: HistogramProps): import("react").JSX.Element;
|
|
41
63
|
export {};
|
|
@@ -1,7 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
query: Q | undefined;
|
|
1
|
+
interface RetType<T, Q> {
|
|
2
|
+
onSearch: (query?: Q) => void;
|
|
3
|
+
query: Q;
|
|
5
4
|
filteredList: T[];
|
|
6
5
|
isSearching: boolean;
|
|
7
|
-
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Custom hook to filter a list of items based on a query.
|
|
9
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
10
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
11
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
12
|
+
*
|
|
13
|
+
* @param items - The list of items to filter.
|
|
14
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
15
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```jsx
|
|
19
|
+
* useFilteredList(items, (item, query) => {
|
|
20
|
+
* return item.name.includes(query);
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
|
|
25
|
+
*/
|
|
26
|
+
export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matchAll?: boolean): RetType<T, Q>;
|
|
27
|
+
/**
|
|
28
|
+
* Custom hook to filter a list of items based on a query.
|
|
29
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
30
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
31
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
32
|
+
*
|
|
33
|
+
* @param items - The list of items to filter.
|
|
34
|
+
* @param matcher - An optional function to match items against the query.
|
|
35
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```jsx
|
|
39
|
+
* useFilteredList(items, (item, query) => {
|
|
40
|
+
* return item.name.includes(query);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matcher?: (item: T, query: Q) => boolean): RetType<T, Q>;
|
|
45
|
+
/**
|
|
46
|
+
* Custom hook to filter a list of items based on a query.
|
|
47
|
+
* It provides a way to search through the items and returns the filtered list.
|
|
48
|
+
* The hook uses a deferred value to optimize performance during transitions.
|
|
49
|
+
* It also allows for a custom matcher function to define how items should be matched against the query.
|
|
50
|
+
*
|
|
51
|
+
* @param items - The list of items to filter.
|
|
52
|
+
* @param matchAll - Match all phrases in the query list against the items.
|
|
53
|
+
* @param matcher - An optional function to match items against the query.
|
|
54
|
+
* @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```jsx
|
|
58
|
+
* useFilteredList(items, (item, query) => {
|
|
59
|
+
* return item.name.includes(query);
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function useFilteredList<T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matchAll?: boolean, matcher?: (item: T, query: Q) => boolean): RetType<T, Q>;
|
|
64
|
+
export {};
|
|
@@ -16,10 +16,26 @@ export interface PaginationOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
onChange?: (page: number) => void;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to manage pagination state and logic.
|
|
21
|
+
* It calculates the total number of pages, generates page ranges,
|
|
22
|
+
* and provides a way to change the current page.
|
|
23
|
+
* It also handles the transition of page changes to optimize performance.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```jsx
|
|
27
|
+
* const { page, totalPages, headLabel, ranges, onPageChange } = usePagination({
|
|
28
|
+
* totalRecords: 100,
|
|
29
|
+
* currentPage: 0,
|
|
30
|
+
* perPage: 10,
|
|
31
|
+
* onChange: (newPage) => console.log("Page changed to:", newPage),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function usePagination({ totalRecords, currentPage, perPage, onChange }: PaginationOptions): {
|
|
20
36
|
page: number;
|
|
21
37
|
totalPages: number;
|
|
22
|
-
headLabel: import("react
|
|
38
|
+
headLabel: import("react").JSX.Element;
|
|
23
39
|
ranges: number[][];
|
|
24
40
|
onPageChange: (page: number) => void;
|
|
25
41
|
};
|
|
@@ -4,6 +4,7 @@ export interface SelectableProps {
|
|
|
4
4
|
*/
|
|
5
5
|
items: Array<{
|
|
6
6
|
label: string;
|
|
7
|
+
id: string;
|
|
7
8
|
} & KeyValue>;
|
|
8
9
|
/**
|
|
9
10
|
* selected item ids
|
|
@@ -22,7 +23,29 @@ export interface SelectableProps {
|
|
|
22
23
|
*/
|
|
23
24
|
onClick?: (id: string, isNegative: boolean) => void;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to manage selection of items in a list.
|
|
28
|
+
* It allows toggling selection state of items, handling both selected and non-selected states.
|
|
29
|
+
* The hook maintains a selection state and provides a function to toggle the selection of items.
|
|
30
|
+
* It also supports callbacks for when the selection changes or when an item is clicked.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* const { selection, toggleSelection } = useSelectableList({
|
|
35
|
+
* items: [{ id: '1', label: 'Item 1' }, { id: '2', label: 'Item 2' }],
|
|
36
|
+
* selected: ['1'],
|
|
37
|
+
* nonselected: ['2'],
|
|
38
|
+
* onChange: (selectedIds, nonSelectedIds) => {
|
|
39
|
+
* console.log('Selected:', selectedIds);
|
|
40
|
+
* console.log('Non-selected:', nonSelectedIds);
|
|
41
|
+
* },
|
|
42
|
+
* onClick: (id, isNegative) => {
|
|
43
|
+
* console.log(`Item ${id} clicked, isNegative: ${isNegative}`);
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function useSelectableList({ items, selected, nonselected, onChange, onClick }: SelectableProps): {
|
|
26
49
|
selection: KeyValue<number>;
|
|
27
50
|
toggleSelection: (id: string, isNegative?: boolean) => void;
|
|
28
51
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DATA_PACKAGE = "@react-fabric/data";
|
|
26
|
+
export declare const DATA_VERSION = "1.0.0";
|
|
1
27
|
import "./i18n";
|
|
2
28
|
export { CheckList } from "./checklist/CheckList";
|
|
3
29
|
export { Histogram } from "./histogram/Histogram";
|
|
4
30
|
export { JsonViewer } from "./json/JsonViewer";
|
|
5
31
|
export { Pagination } from "./pagination/Pagination";
|
|
32
|
+
export { HtmlTable } from "./table/HtmlTable";
|
|
6
33
|
export { Table } from "./table/Table";
|
|
7
34
|
export { type TableColumn, type TableRef } from "./table/types";
|
|
8
35
|
export { TreePanel } from "./tree/TreePanel";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type CssProp } from "@react-fabric/core/dist/types/types";
|
|
3
2
|
export interface JsonViewProps<T> extends CssProp {
|
|
4
3
|
/**
|
|
@@ -54,6 +53,27 @@ export interface JsonViewProps<T> extends CssProp {
|
|
|
54
53
|
/**
|
|
55
54
|
* render function for custom value display
|
|
56
55
|
*/
|
|
57
|
-
formatter?: (path?: string, value?: AnyObject) => string |
|
|
56
|
+
formatter?: (path?: string, value?: AnyObject) => string | React.ReactElement | undefined;
|
|
58
57
|
}
|
|
59
|
-
|
|
58
|
+
/**
|
|
59
|
+
* JsonViewer component to display JSON data in a structured format.
|
|
60
|
+
* It supports inline display, property filtering, and custom formatting.
|
|
61
|
+
* The component can handle nested objects and arrays, displaying them in a tree-like structure.
|
|
62
|
+
* It also provides options for copying values and filtering properties.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```jsx
|
|
66
|
+
* <JsonViewer
|
|
67
|
+
* json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
|
|
68
|
+
* copy={true}
|
|
69
|
+
* filters={true}
|
|
70
|
+
* propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
|
|
71
|
+
* inline={true}
|
|
72
|
+
* labelWidth="25%"
|
|
73
|
+
* formatter={(path, value) => (path === "age" ? `${value} years` : value)}
|
|
74
|
+
* labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
|
|
75
|
+
* onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
|
|
76
|
+
* />
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function JsonViewer<T extends KeyValue = KeyValue>({ className, json, copy, propertyScheme, filters, inline, labelWidth, formatter, labeler, onFilter, emptyMessage, showPropertyTree, ...rest }: JsonViewProps<T>): import("react").JSX.Element;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export interface PaginationProps {
|
|
3
2
|
/**
|
|
4
3
|
* currrent page number
|
|
@@ -21,4 +20,11 @@ export interface PaginationProps {
|
|
|
21
20
|
*/
|
|
22
21
|
onPageChange: (page: number) => void;
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Pagination component to navigate through pages of data.
|
|
25
|
+
* It displays buttons for navigating to the first, previous, next, and last pages,
|
|
26
|
+
* as well as buttons for specific page numbers based on the provided ranges.
|
|
27
|
+
* The component supports a minimal view that shows the current page and total pages.
|
|
28
|
+
* It uses memoization to optimize rendering performance.
|
|
29
|
+
*/
|
|
30
|
+
export declare const Pagination: import("react").MemoExoticComponent<({ page, ranges, totalPages, minimal, onPageChange }: PaginationProps) => import("react").JSX.Element>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TableColumn } from "./types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function AddColumn({ columns, onClick }: {
|
|
3
3
|
columns: TableColumn[];
|
|
4
4
|
onClick: (id: string) => void;
|
|
5
|
-
})
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TableColumn } from "./types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function BodyCell({ column, item, index }: {
|
|
3
3
|
column: TableColumn;
|
|
4
4
|
item: KeyValue;
|
|
5
5
|
index: number;
|
|
6
|
-
})
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { type TableColumn } from "./types";
|
|
2
|
-
export declare
|
|
3
|
-
rowKey:
|
|
2
|
+
export declare function BodyRow<T extends KeyValue = KeyValue>({ rowKey, index, data, keyProperty, measureElement, state, hideableColumns, wrapperStart, wrapperEnd, onRowClick, checkableRows, checked, toggleChecked, canExpand, expanded, toggleExpand, expandRow, }: {
|
|
3
|
+
rowKey: keyof T;
|
|
4
4
|
index: number;
|
|
5
|
-
data:
|
|
6
|
-
keyProperty?:
|
|
7
|
-
measureElement: AnyObject;
|
|
5
|
+
data: T;
|
|
6
|
+
keyProperty?: keyof T;
|
|
8
7
|
state: KeyValue<TableColumn[]>;
|
|
9
8
|
hideableColumns?: boolean;
|
|
10
9
|
wrapperStart: string;
|
|
11
10
|
wrapperEnd: string;
|
|
12
11
|
checkableRows?: boolean;
|
|
13
12
|
checked: 0 | 1;
|
|
14
|
-
onRowClick?: AnyObject;
|
|
15
|
-
canExpand?: AnyObject;
|
|
16
|
-
expandRow?: AnyObject;
|
|
17
13
|
expanded: boolean;
|
|
14
|
+
measureElement: (el: HTMLDivElement) => void;
|
|
15
|
+
expandRow?: (data: T) => React.ReactElement<unknown>;
|
|
16
|
+
canExpand?: (data: T) => boolean;
|
|
17
|
+
onRowClick?: (data: T) => void;
|
|
18
18
|
toggleExpand: (key: Key) => void;
|
|
19
19
|
toggleChecked: (key: Key) => void;
|
|
20
|
-
})
|
|
20
|
+
}): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
state:
|
|
1
|
+
export declare function CheckboxCell({ state, onClick }: {
|
|
2
|
+
state: number;
|
|
3
3
|
onClick?: () => void;
|
|
4
|
-
})
|
|
4
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TableColumn } from "./types";
|
|
2
|
+
interface FilterProps {
|
|
3
|
+
type: TableColumn["dataType"];
|
|
4
|
+
onFilter: (value: AnyObject) => void;
|
|
5
|
+
list?: Array<string | {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}>;
|
|
9
|
+
filter?: string | string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function ColumnFilters({ type, list, filter, onFilter }: FilterProps): import("react").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type TableColumn } from "./types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function EmptyCell({ id, width: _width, maxWidth, minWidth }: TableColumn): import("react").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type TableColumn, type TableProps } from "./types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function HeaderCell({ id, field, dataType, label, icon, actions, filter, filterable, filterOptions, tooltip, sortable, resizable, width: _width, maxWidth, minWidth, sort, onSort, onFilter, }: TableColumn & Pick<TableProps, "sort" | "onSort" | "onFilter">): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Props<T = KeyValue> {
|
|
2
|
+
data: T[];
|
|
3
|
+
columns: Array<{
|
|
4
|
+
id: keyof T;
|
|
5
|
+
label?: string;
|
|
6
|
+
width?: number | string;
|
|
7
|
+
maxWidth?: number | string;
|
|
8
|
+
align?: "start" | "center" | "end";
|
|
9
|
+
className?: string;
|
|
10
|
+
headRenderer?: React.ReactNode;
|
|
11
|
+
renderer?: (value: AnyObject, row: T, index: number) => React.ReactNode;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Number of pagination buttons to show, default is 25
|
|
15
|
+
* If set to 0, pagination will be hidden
|
|
16
|
+
*/
|
|
17
|
+
paginationSize?: number;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function HtmlTable<T extends KeyValue = KeyValue>({ data, columns, paginationSize, className }: Props<T>): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { type TableProps } from "./types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Table component for displaying data in a tabular format with features like sorting, filtering, and virtual scrolling.
|
|
4
|
+
* It supports expandable rows, checkable rows, and customizable columns.
|
|
5
|
+
* The component is designed to handle large datasets efficiently by rendering only the visible rows.
|
|
6
|
+
* It also provides a way to manage column visibility and allows for custom rendering of group headers.
|
|
7
|
+
* Uses TanStack's `useVirtual` for virtualization and React's `useMemo` for performance optimization.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://tanstack.com/table/v8/docs/api/virtual}
|
|
10
|
+
*/
|
|
11
|
+
export declare function Table<T extends KeyValue = KeyValue>({ ref, data, columns, keyProperty, groupProperty, checkableRows, initialScroll, hideableColumns, sort, loading, checked, emptyDisplay, groupRenderer, canExpand, children, onSort, onFilter, onScroll, onRowClick, onCheckedChanged, total, onLoadMore, }: TableProps<T>): import("react").JSX.Element;
|
|
@@ -1,28 +1,64 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type IconProps } from "@react-fabric/core/dist/types/components/icon/Icon";
|
|
2
|
+
import { type CssProp, type NestedKeys, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
|
|
2
3
|
import { type ReactElement } from "react";
|
|
3
4
|
export declare const COL_MIN_WIDTH = "3rem";
|
|
4
5
|
export declare const COL_MAX_WIDTH = "64rem";
|
|
5
6
|
export declare const COL_DEFAULT_WIDTH = "12rem";
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* TableColumn interface defines the structure of a column in a table.
|
|
9
|
+
* It includes properties for column identification, display options, alignment,
|
|
10
|
+
* visibility, resizing, sorting, filtering, and rendering.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type of data the column will represent, defaulting to KeyValue.
|
|
13
|
+
* @property {keyof T | string} id - Unique identifier for the column.
|
|
14
|
+
* @property {"string" | "number" | "boolean" | "datetime" | "date" | "time" | "unknown"} [dataType] - Data type of the column values.
|
|
15
|
+
* @property {string} [label] - Display label for the column header.
|
|
16
|
+
* @property {string} [tooltip] - Tooltip text for the column header.
|
|
17
|
+
* @property {string} [format] - Format string for displaying the column values.
|
|
18
|
+
* @property {"start" | "center" | "end"} [align] - Text alignment within the column.
|
|
19
|
+
* @property {"start" | "end"} [locked] - Indicates if the column is locked at the start or end.
|
|
20
|
+
* @property {boolean} [hidden] - Whether the column is hidden.
|
|
21
|
+
* @property {boolean} [truncate] - Whether to truncate the text in the column.
|
|
22
|
+
* @property {boolean} [hideable] - Whether the column can be hidden by the user.
|
|
23
|
+
* @property {boolean} [resizable] - Whether the column can be resized by the user.
|
|
24
|
+
* @property {boolean} [sortable] - Whether the column can be sorted.
|
|
25
|
+
* @property {boolean} [filterable] - Whether the column can be filtered.
|
|
26
|
+
* @property {AnyObject} [filter] - Filter criteria for the column.
|
|
27
|
+
* @property {ReactElement[]} [actions] - Array of action elements to be displayed in the column.
|
|
28
|
+
* @property {AnyObject[]} [filterOptions] - Options for filtering the column.
|
|
29
|
+
* @property {string | number} [width] - Width of the column.
|
|
30
|
+
* @property {string | number} [minWidth] - Minimum width of the column.
|
|
31
|
+
* @property {string | number} [maxWidth] - Maximum width of the column.
|
|
32
|
+
* @property {KeyValue} [valueMap] - Mapping of values for the column.
|
|
33
|
+
* @property {(value: AnyObject, data: T, index: number) => Elements<AnyObject>} [renderer] - Custom renderer function for the column values.
|
|
34
|
+
*/
|
|
35
|
+
export interface TableColumn<T = KeyValue> extends CssProp, TestProps {
|
|
36
|
+
id: NestedKeys<T>;
|
|
37
|
+
field?: string;
|
|
8
38
|
label?: string;
|
|
9
39
|
tooltip?: string;
|
|
10
|
-
|
|
40
|
+
icon?: IconProps;
|
|
41
|
+
actions?: ReactElement[];
|
|
11
42
|
align?: "start" | "center" | "end";
|
|
12
43
|
locked?: "start" | "end";
|
|
13
44
|
hidden?: boolean;
|
|
45
|
+
truncate?: boolean;
|
|
14
46
|
hideable?: boolean;
|
|
15
47
|
resizable?: boolean;
|
|
16
48
|
sortable?: boolean;
|
|
17
49
|
filterable?: boolean;
|
|
18
|
-
|
|
50
|
+
filter?: string | string[];
|
|
51
|
+
filterOptions?: Array<string | {
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
}>;
|
|
19
55
|
width?: string | number;
|
|
20
56
|
minWidth?: string | number;
|
|
21
57
|
maxWidth?: string | number;
|
|
22
58
|
dataType?: "string" | "number" | "boolean" | "datetime" | "date" | "time" | "unknown";
|
|
23
59
|
format?: string;
|
|
24
|
-
valueMap?: KeyValue
|
|
25
|
-
renderer?: (value: AnyObject, data: T, index: number) =>
|
|
60
|
+
valueMap?: KeyValue<string>;
|
|
61
|
+
renderer?: (value: AnyObject, data: T, index: number) => React.ReactElement<unknown>;
|
|
26
62
|
}
|
|
27
63
|
export interface TableRef {
|
|
28
64
|
hilight: (row: number) => void;
|
|
@@ -32,13 +68,16 @@ export interface TableRef {
|
|
|
32
68
|
export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
|
|
33
69
|
columns: Array<TableColumn<T>>;
|
|
34
70
|
data: T[];
|
|
35
|
-
keyProperty?:
|
|
71
|
+
keyProperty?: NestedKeys<T>;
|
|
72
|
+
groupProperty?: NestedKeys<T>;
|
|
73
|
+
groupRenderer?: (key: AnyObject) => ReactElement;
|
|
36
74
|
emptyDisplay?: ReactElement;
|
|
37
75
|
/**
|
|
38
76
|
* checkable rows
|
|
39
77
|
*/
|
|
78
|
+
checked?: AnyObject[];
|
|
40
79
|
checkableRows?: boolean;
|
|
41
|
-
onCheckedChanged?: (rows:
|
|
80
|
+
onCheckedChanged?: (rows: AnyObject[]) => void;
|
|
42
81
|
/**
|
|
43
82
|
* sorting
|
|
44
83
|
*/
|
|
@@ -56,5 +95,8 @@ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
|
|
|
56
95
|
initialScroll?: number;
|
|
57
96
|
onScroll?: (firstItem: number) => void;
|
|
58
97
|
canExpand?: (record: T) => boolean;
|
|
59
|
-
children?: (record: T) =>
|
|
98
|
+
children?: (record: T) => React.ReactElement<unknown>;
|
|
99
|
+
onFilter?: (id: NestedKeys<T> | string, value?: AnyObject) => void;
|
|
100
|
+
total?: number;
|
|
101
|
+
onLoadMore?: (lastIndex?: number) => void;
|
|
60
102
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare function startResizer(colEl: HTMLElement, ghostEl: HTMLElement, callback: (width: number) => void): void;
|