@react-fabric/data 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/histogram/Histogram.js +89 -0
- package/dist/cjs/histogram/Histogram.module.css +1 -0
- package/dist/cjs/hooks/useFilteredList.js +56 -0
- package/dist/cjs/hooks/usePagination.js +85 -0
- package/dist/cjs/i18n/ar.json.js +56 -0
- package/dist/cjs/i18n/en.json.js +56 -0
- package/dist/cjs/i18n/index.js +33 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/json/JsonViewer.js +246 -0
- package/dist/cjs/pagination/Pagination.js +100 -0
- package/dist/cjs/table/BodyCell.js +47 -0
- package/dist/cjs/table/HeaderCell.js +79 -0
- package/dist/cjs/table/Table.js +133 -0
- package/dist/cjs/table/useTableColumns.js +26 -0
- package/dist/cjs/table/useVirtualTable.js +56 -0
- package/dist/cjs/tree/TreeNode.js +107 -0
- package/dist/cjs/tree/TreePanel.js +136 -0
- package/dist/cjs/tree/types.js +30 -0
- package/dist/cjs/tree/useTree.js +181 -0
- package/dist/cjs/tree/utils.js +145 -0
- package/dist/cjs/virtual/Gallery.js +229 -0
- package/dist/cjs/virtual/List.js +218 -0
- package/dist/cjs/virtual/Scroller.js +77 -0
- package/dist/esm/histogram/Histogram.js +89 -0
- package/dist/esm/histogram/Histogram.module.css +1 -0
- package/dist/esm/hooks/useFilteredList.js +56 -0
- package/dist/esm/hooks/usePagination.js +85 -0
- package/dist/esm/i18n/ar.json.js +47 -0
- package/dist/esm/i18n/en.json.js +47 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/json/JsonViewer.js +246 -0
- package/dist/esm/pagination/Pagination.js +100 -0
- package/dist/esm/table/BodyCell.js +47 -0
- package/dist/esm/table/HeaderCell.js +79 -0
- package/dist/esm/table/Table.js +133 -0
- package/dist/esm/table/useTableColumns.js +26 -0
- package/dist/esm/table/useVirtualTable.js +56 -0
- package/dist/esm/tree/TreeNode.js +107 -0
- package/dist/esm/tree/TreePanel.js +136 -0
- package/dist/esm/tree/types.js +29 -0
- package/dist/esm/tree/useTree.js +181 -0
- package/dist/esm/tree/utils.js +140 -0
- package/dist/esm/virtual/Gallery.js +229 -0
- package/dist/esm/virtual/List.js +218 -0
- package/dist/esm/virtual/Scroller.js +77 -0
- package/dist/types/histogram/Histogram.d.ts +41 -0
- package/dist/types/hooks/useFilteredList.d.ts +7 -0
- package/dist/types/hooks/usePagination.d.ts +25 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/json/JsonViewer.d.ts +59 -0
- package/dist/types/pagination/Pagination.d.ts +24 -0
- package/dist/types/table/BodyCell.d.ts +5 -0
- package/dist/types/table/HeaderCell.d.ts +2 -0
- package/dist/types/table/Table.d.ts +2 -0
- package/dist/types/table/types.d.ts +26 -0
- package/dist/types/table/useTableColumns.d.ts +8 -0
- package/dist/types/table/useVirtualTable.d.ts +8 -0
- package/dist/types/tree/TreeNode.d.ts +2 -0
- package/dist/types/tree/TreePanel.d.ts +2 -0
- package/dist/types/tree/types.d.ts +138 -0
- package/dist/types/tree/useTree.d.ts +20 -0
- package/dist/types/tree/utils.d.ts +10 -0
- package/dist/types/virtual/Gallery.d.ts +55 -0
- package/dist/types/virtual/List.d.ts +59 -0
- package/dist/types/virtual/Scroller.d.ts +8 -0
- package/package.json +55 -0
- package/src/histogram/Histogram.module.css +57 -0
- package/src/histogram/Histogram.tsx +176 -0
- package/src/hooks/useFilteredList.tsx +78 -0
- package/src/hooks/usePagination.tsx +135 -0
- package/src/i18n/ar.json +36 -0
- package/src/i18n/en.json +36 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +35 -0
- package/src/json/JsonViewer.tsx +381 -0
- package/src/pagination/Pagination.tsx +157 -0
- package/src/table/BodyCell.tsx +54 -0
- package/src/table/HeaderCell.tsx +70 -0
- package/src/table/Table.tsx +143 -0
- package/src/table/types.ts +65 -0
- package/src/table/useTableColumns.ts +52 -0
- package/src/table/useVirtualTable.ts +54 -0
- package/src/tree/TreeNode.tsx +163 -0
- package/src/tree/TreePanel.tsx +157 -0
- package/src/tree/types.ts +181 -0
- package/src/tree/useTree.ts +227 -0
- package/src/tree/utils.ts +185 -0
- package/src/virtual/Gallery.tsx +349 -0
- package/src/virtual/List.tsx +351 -0
- package/src/virtual/Scroller.tsx +81 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type InternalNode, type TreeNodeType } from "./types";
|
|
2
|
+
export declare const useTree: <T extends KeyValue<any>>({ items, checked, selected, matcher, onSelect, onChecked, }: {
|
|
3
|
+
items?: Array<TreeNodeType<T>>;
|
|
4
|
+
selected?: string;
|
|
5
|
+
checked?: string[];
|
|
6
|
+
onSelect?: (id: string) => void;
|
|
7
|
+
onChecked?: (leafs: string[], nodes: string[]) => void;
|
|
8
|
+
matcher?: (data: T, query: string) => boolean;
|
|
9
|
+
}) => {
|
|
10
|
+
tree: InternalNode[];
|
|
11
|
+
toggleExpand: (id: string) => void;
|
|
12
|
+
expandAll: () => void;
|
|
13
|
+
collapseAll: () => void;
|
|
14
|
+
toggleCheck: (id: string) => void;
|
|
15
|
+
select: (id: string) => void;
|
|
16
|
+
onFilter: {
|
|
17
|
+
(...args: any): void;
|
|
18
|
+
cancel(): void;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type InternalNode, type TreeNodeType } from "./types";
|
|
2
|
+
export declare const refactorTree: (nodes: TreeNodeType[], options?: {
|
|
3
|
+
level: number;
|
|
4
|
+
parent?: string;
|
|
5
|
+
}) => InternalNode[];
|
|
6
|
+
export declare const makeTreeMap: (nodes: InternalNode[], map?: Map<any, any>) => Map<any, any>;
|
|
7
|
+
export declare const flattenTree: (nodes: InternalNode[], lines?: Array<0 | 1 | 2 | 3>) => InternalNode[];
|
|
8
|
+
export declare const updateSelection: (nodes: Map<string, InternalNode>, id: string, selected?: true) => void;
|
|
9
|
+
export declare const updateChecked: (list: Map<string, AnyObject>, id: string) => void;
|
|
10
|
+
export declare const filterTree: (nodes: Map<string, InternalNode>, query?: string, matcher?: AnyObject) => void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ReactElement, type Ref } from "react";
|
|
2
|
+
export interface VirtualGalleryRef {
|
|
3
|
+
scrollToItem: (index: number) => void;
|
|
4
|
+
hilight: (index: number) => void;
|
|
5
|
+
unhilight: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface VirtualGalleryProps<T> {
|
|
8
|
+
children: (props: {
|
|
9
|
+
data: T;
|
|
10
|
+
index: number;
|
|
11
|
+
isLast: boolean;
|
|
12
|
+
}) => ReactElement;
|
|
13
|
+
galleryRef?: Ref<VirtualGalleryRef | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* fixed columns
|
|
16
|
+
*/
|
|
17
|
+
columns?: number;
|
|
18
|
+
/**
|
|
19
|
+
* default item height
|
|
20
|
+
*/
|
|
21
|
+
defaultHeight?: number;
|
|
22
|
+
/**
|
|
23
|
+
* default item width
|
|
24
|
+
*/
|
|
25
|
+
defaultWidth?: number;
|
|
26
|
+
/**
|
|
27
|
+
* padding
|
|
28
|
+
*/
|
|
29
|
+
padding?: "sm" | "md" | "lg" | "none";
|
|
30
|
+
/**
|
|
31
|
+
* data list
|
|
32
|
+
*/
|
|
33
|
+
items: T[];
|
|
34
|
+
/**
|
|
35
|
+
* loading state
|
|
36
|
+
*/
|
|
37
|
+
loading?: boolean;
|
|
38
|
+
initialScroll?: number;
|
|
39
|
+
/**
|
|
40
|
+
* hide scroll buttons
|
|
41
|
+
*/
|
|
42
|
+
hideScroller?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* load more callback
|
|
45
|
+
*/
|
|
46
|
+
onLoadMore?: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* scroll handler
|
|
49
|
+
*/
|
|
50
|
+
onScroll?: (top: number) => void;
|
|
51
|
+
}
|
|
52
|
+
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
|
+
displayName: string;
|
|
55
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ReactElement, type Ref } from "react";
|
|
2
|
+
export interface VirtualListRef {
|
|
3
|
+
scrollToItem: (index: number) => void;
|
|
4
|
+
hilight: (index: number) => void;
|
|
5
|
+
unhilight: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface VirtualListProps<T> {
|
|
8
|
+
children: (props: {
|
|
9
|
+
data: T;
|
|
10
|
+
index: number;
|
|
11
|
+
isLast: boolean;
|
|
12
|
+
}) => ReactElement;
|
|
13
|
+
listRef?: Ref<VirtualListRef | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* default item height
|
|
16
|
+
*/
|
|
17
|
+
defaultHeight?: number;
|
|
18
|
+
/**
|
|
19
|
+
* default item width
|
|
20
|
+
*/
|
|
21
|
+
defaultWidth?: number;
|
|
22
|
+
/**
|
|
23
|
+
* full width list
|
|
24
|
+
*/
|
|
25
|
+
fullWidth?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* padding
|
|
28
|
+
*/
|
|
29
|
+
padding?: "sm" | "md" | "lg" | "none";
|
|
30
|
+
/**
|
|
31
|
+
* list orientation
|
|
32
|
+
*/
|
|
33
|
+
orientation?: "vertical" | "horizontal";
|
|
34
|
+
/**
|
|
35
|
+
* data list
|
|
36
|
+
*/
|
|
37
|
+
items: T[];
|
|
38
|
+
initialScroll?: number;
|
|
39
|
+
/**
|
|
40
|
+
* loading state
|
|
41
|
+
*/
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* hide scroll buttons
|
|
45
|
+
*/
|
|
46
|
+
hideScroller?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* load more callback
|
|
49
|
+
*/
|
|
50
|
+
onLoadMore?: (page?: number) => void;
|
|
51
|
+
/**
|
|
52
|
+
* scroll handler
|
|
53
|
+
*/
|
|
54
|
+
onScroll?: (top: number) => void;
|
|
55
|
+
}
|
|
56
|
+
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
|
+
displayName: string;
|
|
59
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const Scroller: ({ vertical, scrollActive, onStart, onEnd, onPrevious, onNext, }: {
|
|
2
|
+
scrollActive: number;
|
|
3
|
+
vertical: boolean;
|
|
4
|
+
onStart: () => void;
|
|
5
|
+
onEnd: () => void;
|
|
6
|
+
onPrevious: () => void;
|
|
7
|
+
onNext: () => void;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-fabric/data",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "RUF: Data package",
|
|
5
|
+
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "https://github.com/adarshpastakia/react-ui-framework/tree/main/packages/data",
|
|
8
|
+
"source": "src/index.ts",
|
|
9
|
+
"main": "dist/cjs/index.js",
|
|
10
|
+
"module": "dist/esm/index.js",
|
|
11
|
+
"types": "dist/types/index.d.ts",
|
|
12
|
+
"directories": {
|
|
13
|
+
"src": "src",
|
|
14
|
+
"test": "tests"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"makelink": "yarn link",
|
|
26
|
+
"removelink": "yarn unlink",
|
|
27
|
+
"prebuild": "rm -rf ./dist",
|
|
28
|
+
"build:dts": "tsc -p ./tsconfig.build.json",
|
|
29
|
+
"build:rollup": "rollup -c ../../rollup.config.mjs",
|
|
30
|
+
"build": "npm-run-all -p build:rollup build:dts",
|
|
31
|
+
"watch:dts": "tsc -w -p ./tsconfig.build.json",
|
|
32
|
+
"watch:rollup": "rollup -w -c ../../rollup.config.mjs",
|
|
33
|
+
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@react-fabric/core": "^1.0.0-beta.0",
|
|
37
|
+
"@react-fabric/form": "^1.0.0-beta.0",
|
|
38
|
+
"@react-fabric/utilities": "^1.0.0-beta.0",
|
|
39
|
+
"@tanstack/react-virtual": "^3.8.6",
|
|
40
|
+
"classnames": "^2.5.1",
|
|
41
|
+
"color": "^4.2.3",
|
|
42
|
+
"memoize-one": "^6.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"i18next": "^23.15.1",
|
|
46
|
+
"react": ">=18.0.0 <20.0.0",
|
|
47
|
+
"react-dom": ">=18.0.0 <20.0.0",
|
|
48
|
+
"react-i18next": "^15.0.2"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18.12.0",
|
|
52
|
+
"npm": ">=8.19.0"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "83fa79064b1d57e71149005432192d506810bbda"
|
|
55
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
@layer comp {
|
|
25
|
+
.histogram {
|
|
26
|
+
.histoLabel {
|
|
27
|
+
--tw-gradient-from: var(--color) var(--tw-gradient-from-position);
|
|
28
|
+
--tw-gradient-to: color-mix(in lab, var(--color) 20%, var(--fabric-bg))
|
|
29
|
+
var(--tw-gradient-to-position);
|
|
30
|
+
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
|
|
31
|
+
|
|
32
|
+
background-color: color(from var(--color) srgb r g b / 5%);
|
|
33
|
+
|
|
34
|
+
&:hover {
|
|
35
|
+
background-color: color(from var(--color) srgb r g b / 15%);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&[data-disabled="true"] {
|
|
39
|
+
--color: theme(colors.tint.300);
|
|
40
|
+
|
|
41
|
+
color: theme(colors.tint.600);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.histoBar {
|
|
46
|
+
box-shadow: -2px 0 0 var(--color) inset;
|
|
47
|
+
|
|
48
|
+
:global([dir="rtl"]) & {
|
|
49
|
+
box-shadow: 2px 0 0 var(--color) inset;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.histoBadge {
|
|
54
|
+
background-color: color(from var(--color) srgb r g b / 15%);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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 {
|
|
25
|
+
ActionLabel,
|
|
26
|
+
Button,
|
|
27
|
+
CoreIcons,
|
|
28
|
+
EmptyContent,
|
|
29
|
+
Icon,
|
|
30
|
+
} from "@react-fabric/core";
|
|
31
|
+
import {
|
|
32
|
+
type ColorType,
|
|
33
|
+
type PaletteType,
|
|
34
|
+
} from "@react-fabric/core/dist/types/types";
|
|
35
|
+
import { compareValues, Format } from "@react-fabric/utilities";
|
|
36
|
+
import classNames from "classnames";
|
|
37
|
+
import { useMemo } from "react";
|
|
38
|
+
import { useTranslation } from "react-i18next";
|
|
39
|
+
import classes from "./Histogram.module.css";
|
|
40
|
+
|
|
41
|
+
const emptyIcon =
|
|
42
|
+
"M20.84 22.73L11.11 13H3V11H9.11L6.11 8H3V6H4.11L1.11 3L2.39 1.73L22.11 21.46L20.84 22.73M15 11H14.2L15 11.8V11M21 8V6H9.2L11.2 8H21M3 18H9V16H3V18Z";
|
|
43
|
+
|
|
44
|
+
interface HistogramItem {
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
count: number;
|
|
48
|
+
total?: number;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface HistogramProps {
|
|
53
|
+
/**
|
|
54
|
+
* histogram items list
|
|
55
|
+
*/
|
|
56
|
+
items: HistogramItem[];
|
|
57
|
+
/**
|
|
58
|
+
* total count
|
|
59
|
+
*/
|
|
60
|
+
total?: number;
|
|
61
|
+
/**
|
|
62
|
+
* histogram bar color
|
|
63
|
+
*/
|
|
64
|
+
color?: ColorType | PaletteType;
|
|
65
|
+
/**
|
|
66
|
+
* sorted list
|
|
67
|
+
*/
|
|
68
|
+
sortBy?: "label" | "count";
|
|
69
|
+
/**
|
|
70
|
+
* title when histo list is empty
|
|
71
|
+
*/
|
|
72
|
+
emptyTitle?: string | JSX.Element;
|
|
73
|
+
/**
|
|
74
|
+
* message when histo list is empty
|
|
75
|
+
*/
|
|
76
|
+
emptyMessage?: string | JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* handle histo click
|
|
79
|
+
*/
|
|
80
|
+
onClick?: (id: string, negative?: true) => void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const Histogram = ({
|
|
84
|
+
items = [],
|
|
85
|
+
total,
|
|
86
|
+
color = "primary",
|
|
87
|
+
sortBy = "count",
|
|
88
|
+
emptyTitle,
|
|
89
|
+
emptyMessage,
|
|
90
|
+
onClick,
|
|
91
|
+
}: HistogramProps) => {
|
|
92
|
+
const { t } = useTranslation("data");
|
|
93
|
+
const maxTotal = useMemo(() => {
|
|
94
|
+
if (total) return total;
|
|
95
|
+
return Math.max(...items.map((item) => item.count));
|
|
96
|
+
}, [total, items]);
|
|
97
|
+
|
|
98
|
+
const sorted = useMemo(() => {
|
|
99
|
+
return items.sort(
|
|
100
|
+
compareValues(sortBy === "label" ? "asc" : "desc", sortBy),
|
|
101
|
+
);
|
|
102
|
+
}, [items, sortBy]);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
className={classes.histogram}
|
|
107
|
+
style={
|
|
108
|
+
{
|
|
109
|
+
"--color": `var(--${color})`,
|
|
110
|
+
} as AnyObject
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
{sorted.length === 0 && (
|
|
114
|
+
<EmptyContent
|
|
115
|
+
icon={<Icon icon={emptyIcon} size="2.5rem" />}
|
|
116
|
+
title={emptyTitle}
|
|
117
|
+
message={emptyMessage ?? t("histogram.empty")}
|
|
118
|
+
/>
|
|
119
|
+
)}
|
|
120
|
+
{sorted?.map((item) => (
|
|
121
|
+
<div
|
|
122
|
+
role="none"
|
|
123
|
+
key={item.id}
|
|
124
|
+
data-disabled={item.count === 0 || item.disabled}
|
|
125
|
+
className={classNames(
|
|
126
|
+
"relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px",
|
|
127
|
+
classes.histoLabel,
|
|
128
|
+
(item.count === 0 || item.disabled) && "pointer-events-none",
|
|
129
|
+
)}
|
|
130
|
+
onClick={(e) => [onClick?.(item.id), e.stopPropagation()]}
|
|
131
|
+
>
|
|
132
|
+
<div
|
|
133
|
+
className={classNames(
|
|
134
|
+
"absolute z-0 inset-0 opacity-50 min-w-2 ltr:bg-gradient-to-r rtl:bg-gradient-to-l from-0% to-100%",
|
|
135
|
+
classes.histoBar,
|
|
136
|
+
)}
|
|
137
|
+
style={{
|
|
138
|
+
width: `${Math.min(item.count / maxTotal, 1) * 100}%`,
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
<ActionLabel
|
|
142
|
+
className="flex-1 truncate z-1 text-sm cursor-pointer font-medium"
|
|
143
|
+
actions={[
|
|
144
|
+
<Button
|
|
145
|
+
key="negative"
|
|
146
|
+
color="danger"
|
|
147
|
+
size="sm"
|
|
148
|
+
icon={CoreIcons.funnelMinus}
|
|
149
|
+
aria-label="Filter Negative"
|
|
150
|
+
onClick={() => onClick?.(item.id, true)}
|
|
151
|
+
/>,
|
|
152
|
+
<Button
|
|
153
|
+
key="positive"
|
|
154
|
+
color="primary"
|
|
155
|
+
size="sm"
|
|
156
|
+
icon={CoreIcons.funnelPlus}
|
|
157
|
+
aria-label="Filter"
|
|
158
|
+
onClick={() => onClick?.(item.id)}
|
|
159
|
+
/>,
|
|
160
|
+
]}
|
|
161
|
+
>
|
|
162
|
+
{item.label}
|
|
163
|
+
</ActionLabel>
|
|
164
|
+
<span
|
|
165
|
+
className={classNames(
|
|
166
|
+
"z-1 rounded-full text-xs font-medium px-2 py-1 leading-none",
|
|
167
|
+
classes.histoBadge,
|
|
168
|
+
)}
|
|
169
|
+
>
|
|
170
|
+
{Format.number(item.count)}
|
|
171
|
+
</span>
|
|
172
|
+
</div>
|
|
173
|
+
))}
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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 { isString, matchString } from "@react-fabric/utilities";
|
|
25
|
+
import {
|
|
26
|
+
useCallback,
|
|
27
|
+
useDeferredValue,
|
|
28
|
+
useEffect,
|
|
29
|
+
useState,
|
|
30
|
+
useTransition,
|
|
31
|
+
} from "react";
|
|
32
|
+
|
|
33
|
+
const filterList = (
|
|
34
|
+
items: AnyObject[],
|
|
35
|
+
query: AnyObject = "",
|
|
36
|
+
matcher?: AnyObject,
|
|
37
|
+
) => {
|
|
38
|
+
const newList: AnyObject[] = [];
|
|
39
|
+
items.forEach((item) => {
|
|
40
|
+
if (matcher) {
|
|
41
|
+
return matcher?.(item, query) && newList.push(item);
|
|
42
|
+
}
|
|
43
|
+
if (query && isString(query)) {
|
|
44
|
+
if (matchString(item.label ?? item.toString(), query)) {
|
|
45
|
+
return newList.push(item);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
return newList.push(item);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return newList;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const useFilteredList = <
|
|
55
|
+
T extends AnyObject = KeyValue,
|
|
56
|
+
Q extends AnyObject = string,
|
|
57
|
+
>(
|
|
58
|
+
items: T[],
|
|
59
|
+
matcher?: (item: T, query: Q) => boolean,
|
|
60
|
+
) => {
|
|
61
|
+
const [query, setQuery] = useState<Q>();
|
|
62
|
+
const _items = useDeferredValue(items ?? []);
|
|
63
|
+
const [filteredList, setFilteredList] = useState<T[]>([]);
|
|
64
|
+
const [isSearching, startTransition] = useTransition();
|
|
65
|
+
|
|
66
|
+
const filterItems = useCallback(
|
|
67
|
+
(items: T[], query?: Q) =>
|
|
68
|
+
startTransition(() => setFilteredList(filterList(items, query, matcher))),
|
|
69
|
+
[],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (query) filterItems(_items, query);
|
|
74
|
+
else setFilteredList(items);
|
|
75
|
+
}, [query, _items]);
|
|
76
|
+
|
|
77
|
+
return { onSearch: setQuery, query, filteredList, isSearching };
|
|
78
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
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 {
|
|
25
|
+
useCallback,
|
|
26
|
+
useEffect,
|
|
27
|
+
useMemo,
|
|
28
|
+
useState,
|
|
29
|
+
useTransition,
|
|
30
|
+
} from "react";
|
|
31
|
+
|
|
32
|
+
export interface PaginationOptions {
|
|
33
|
+
/**
|
|
34
|
+
* total record count
|
|
35
|
+
*/
|
|
36
|
+
totalRecords: number;
|
|
37
|
+
/**
|
|
38
|
+
* current page (default 0)
|
|
39
|
+
*/
|
|
40
|
+
currentPage?: number;
|
|
41
|
+
/**
|
|
42
|
+
* records per page
|
|
43
|
+
*/
|
|
44
|
+
perPage?: number;
|
|
45
|
+
/**
|
|
46
|
+
* pagination change handler
|
|
47
|
+
*/
|
|
48
|
+
onChange?: (page: number) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const TOTAL_PILLS = 12;
|
|
52
|
+
const TOTAL_SIBLINGS = 2;
|
|
53
|
+
const TOTAL_MID_SIBLINGS = 3;
|
|
54
|
+
|
|
55
|
+
const makeRange = (start: number, end: number) => {
|
|
56
|
+
const length = end - start;
|
|
57
|
+
return Array.from({ length }, (_: AnyObject, idx: number) => idx + start);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const usePagination = ({
|
|
61
|
+
totalRecords,
|
|
62
|
+
currentPage = 0,
|
|
63
|
+
perPage = 25,
|
|
64
|
+
onChange,
|
|
65
|
+
}: PaginationOptions) => {
|
|
66
|
+
const [page, setPage] = useState(0);
|
|
67
|
+
const [, startTransition] = useTransition();
|
|
68
|
+
|
|
69
|
+
/** ***************** calculate total pages *******************/
|
|
70
|
+
const totalPages = useMemo(
|
|
71
|
+
() => Math.max(1, Math.ceil(totalRecords / perPage)),
|
|
72
|
+
[totalRecords, perPage],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
/** ***************** calculate ranges *******************/
|
|
76
|
+
const ranges = useMemo(() => {
|
|
77
|
+
if (totalPages <= TOTAL_PILLS) {
|
|
78
|
+
return [makeRange(0, totalPages)];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const leftSiblingIndex = Math.max(page - TOTAL_MID_SIBLINGS, 0);
|
|
82
|
+
const rightSiblingIndex = Math.min(
|
|
83
|
+
page + TOTAL_MID_SIBLINGS,
|
|
84
|
+
totalPages - 1,
|
|
85
|
+
);
|
|
86
|
+
const shouldShowLeftDots = leftSiblingIndex >= TOTAL_SIBLINGS;
|
|
87
|
+
const shouldShowRightDots = rightSiblingIndex < totalPages - TOTAL_SIBLINGS;
|
|
88
|
+
|
|
89
|
+
if (!shouldShowLeftDots && shouldShowRightDots) {
|
|
90
|
+
return [
|
|
91
|
+
makeRange(0, TOTAL_SIBLINGS * 3),
|
|
92
|
+
makeRange(totalPages - TOTAL_SIBLINGS, totalPages),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
if (shouldShowLeftDots && !shouldShowRightDots) {
|
|
96
|
+
return [
|
|
97
|
+
makeRange(0, TOTAL_SIBLINGS),
|
|
98
|
+
makeRange(totalPages - TOTAL_SIBLINGS * 3, totalPages),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
if (shouldShowLeftDots && shouldShowRightDots) {
|
|
102
|
+
return [
|
|
103
|
+
makeRange(0, TOTAL_SIBLINGS),
|
|
104
|
+
makeRange(leftSiblingIndex + 1, rightSiblingIndex),
|
|
105
|
+
makeRange(totalPages - TOTAL_SIBLINGS, totalPages),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return [];
|
|
110
|
+
}, [page, totalPages]);
|
|
111
|
+
|
|
112
|
+
/** ***************** set page *******************/
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
setPage(Math.min(currentPage, totalPages - 1));
|
|
115
|
+
onChange?.(Math.min(currentPage, totalPages - 1));
|
|
116
|
+
}, [currentPage, totalPages]);
|
|
117
|
+
|
|
118
|
+
const headLabel = useMemo(
|
|
119
|
+
() => (
|
|
120
|
+
<span className="text-muted">
|
|
121
|
+
{page * perPage + 1}
|
|
122
|
+
-
|
|
123
|
+
{Math.min(page * perPage + perPage, totalRecords)}
|
|
124
|
+
</span>
|
|
125
|
+
),
|
|
126
|
+
[page, perPage, totalRecords],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const onPageChange = useCallback((page: number) => {
|
|
130
|
+
setPage(page);
|
|
131
|
+
startTransition(() => onChange?.(page));
|
|
132
|
+
}, []);
|
|
133
|
+
|
|
134
|
+
return { page, totalPages, headLabel, ranges, onPageChange };
|
|
135
|
+
};
|
package/src/i18n/ar.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"label": {
|
|
3
|
+
"noRecords": "لا تسجيلات"
|
|
4
|
+
},
|
|
5
|
+
"tree": {
|
|
6
|
+
"noItems": "لا توجد عناصر",
|
|
7
|
+
"error": "خطأ في تحميل العناصر",
|
|
8
|
+
"loading": "تحميل العناصر…"
|
|
9
|
+
},
|
|
10
|
+
"datagrid": {
|
|
11
|
+
"empty": "لا توجد سجلات متاحة"
|
|
12
|
+
},
|
|
13
|
+
"json": {
|
|
14
|
+
"empty": "لا توجد خصائص بيانات",
|
|
15
|
+
"true": "نعم",
|
|
16
|
+
"false": "رقم"
|
|
17
|
+
},
|
|
18
|
+
"checkList": {
|
|
19
|
+
"empty": "لا توجد عناصر قائمة"
|
|
20
|
+
},
|
|
21
|
+
"histogram": {
|
|
22
|
+
"empty": "لا توجد رسوم بيانية"
|
|
23
|
+
},
|
|
24
|
+
"action": {
|
|
25
|
+
"find": "تجد…",
|
|
26
|
+
"copy": "قيمة النسخ",
|
|
27
|
+
"filter": "منقي…",
|
|
28
|
+
"showShortcuts": "اختصارات لوحة المفاتيح…",
|
|
29
|
+
"collapseAll": "انهيار جميع",
|
|
30
|
+
"expandAll": "توسيع الكل",
|
|
31
|
+
"checkAll": "تحقق من الكل",
|
|
32
|
+
"uncheckAll": "الغاءالكل",
|
|
33
|
+
"addFilter": "أضف عامل تصفية",
|
|
34
|
+
"addFilterNot": "إضافة لا تصفية"
|
|
35
|
+
}
|
|
36
|
+
}
|