qbs-react-grid 1.2.0 → 1.2.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/dist/css/qbs-react-grid.css +1 -1095
- package/dist/css/qbs-react-grid.min.css +1 -1
- package/dist/css/qbs-react-grid.min.css.map +1 -1
- package/es/Pagination.js +3 -1
- package/es/Table.js +19 -19
- package/es/less/index.less +3 -0
- package/es/qbsTable/QbsTable.js +34 -7
- package/es/qbsTable/TableCardList.d.ts +5 -0
- package/es/qbsTable/TableCardList.js +564 -0
- package/es/qbsTable/Toolbar.js +16 -2
- package/es/qbsTable/commontypes.d.ts +9 -0
- package/es/qbsTable/utilities/CardComponent.d.ts +12 -0
- package/es/qbsTable/utilities/CardComponent.js +64 -0
- package/es/qbsTable/utilities/CardMenuDropdown.d.ts +13 -0
- package/es/qbsTable/utilities/CardMenuDropdown.js +89 -0
- package/es/qbsTable/utilities/SwitchCardColumns.d.ts +2 -0
- package/es/qbsTable/utilities/SwitchCardColumns.js +24 -0
- package/es/qbsTable/utilities/icons.d.ts +3 -0
- package/es/qbsTable/utilities/icons.js +45 -0
- package/es/utils/getTotalByColumns.js +1 -1
- package/es/utils/mergeCells.js +1 -1
- package/es/utils/useCellDescriptor.js +11 -11
- package/es/utils/useClassNames.js +2 -0
- package/lib/Pagination.js +2 -2
- package/lib/Table.js +19 -19
- package/lib/less/index.less +3 -0
- package/lib/qbsTable/QbsTable.js +34 -7
- package/lib/qbsTable/TableCardList.d.ts +5 -0
- package/lib/qbsTable/TableCardList.js +571 -0
- package/lib/qbsTable/Toolbar.js +16 -2
- package/lib/qbsTable/commontypes.d.ts +9 -0
- package/lib/qbsTable/utilities/CardComponent.d.ts +12 -0
- package/lib/qbsTable/utilities/CardComponent.js +72 -0
- package/lib/qbsTable/utilities/CardMenuDropdown.d.ts +13 -0
- package/lib/qbsTable/utilities/CardMenuDropdown.js +95 -0
- package/lib/qbsTable/utilities/SwitchCardColumns.d.ts +2 -0
- package/lib/qbsTable/utilities/SwitchCardColumns.js +30 -0
- package/lib/qbsTable/utilities/icons.d.ts +3 -0
- package/lib/qbsTable/utilities/icons.js +50 -2
- package/lib/utils/getTotalByColumns.js +1 -1
- package/lib/utils/mergeCells.js +1 -1
- package/lib/utils/useCellDescriptor.js +11 -11
- package/lib/utils/useClassNames.js +2 -0
- package/package.json +11 -6
- package/src/Pagination.tsx +4 -1
- package/src/less/index.less +3 -0
- package/src/qbsTable/QbsTable.tsx +201 -173
- package/src/qbsTable/TableCardList.tsx +629 -0
- package/src/qbsTable/Toolbar.tsx +22 -2
- package/src/qbsTable/commontypes.ts +9 -0
- package/src/qbsTable/utilities/CardComponent.tsx +102 -0
- package/src/qbsTable/utilities/CardMenuDropdown.tsx +118 -0
- package/src/qbsTable/utilities/SwitchCardColumns.tsx +29 -0
- package/src/qbsTable/utilities/icons.tsx +51 -0
- /package/es/{CustomSelect.d.ts → customSelect.d.ts} +0 -0
- /package/lib/{CustomSelect.d.ts → customSelect.d.ts} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { QbsColumnProps } from '../commontypes';
|
|
3
|
+
import CardMenuDropdown from './CardMenuDropdown';
|
|
4
|
+
import { CustomTableCell } from './SwitchCardColumns';
|
|
5
|
+
import { handleCellFormat } from './handleFormatCell';
|
|
6
|
+
import { ArrowUpIcon } from './icons';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
columns: QbsColumnProps[];
|
|
10
|
+
data: any;
|
|
11
|
+
tableBodyRef: any;
|
|
12
|
+
actionProps?: any;
|
|
13
|
+
index?: number;
|
|
14
|
+
handleMenuActions?: () => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const CardComponent: React.FC<Props> = ({
|
|
18
|
+
columns,
|
|
19
|
+
data,
|
|
20
|
+
tableBodyRef,
|
|
21
|
+
actionProps,
|
|
22
|
+
index,
|
|
23
|
+
handleMenuActions
|
|
24
|
+
}) => {
|
|
25
|
+
const [viewMore, setViewMore] = useState(false);
|
|
26
|
+
const initialDisplayCount = 5;
|
|
27
|
+
|
|
28
|
+
const toggleViewMore = () => {
|
|
29
|
+
setViewMore(!viewMore);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const displayedColumns = viewMore ? columns : columns.slice(0, initialDisplayCount);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className="grid grid-cols-5 p-3 gap-3 border-2 border-grey shadow-sm rounded-lg relative qbs-card-container">
|
|
36
|
+
{displayedColumns.map((col: QbsColumnProps, index: number) => (
|
|
37
|
+
<div key={index} className="grid col-span-1 place-content-start text-sm qbs-card-column">
|
|
38
|
+
<p className=" text-grey ">{col.title}</p>
|
|
39
|
+
{col.customCell || col.link ? (
|
|
40
|
+
<span
|
|
41
|
+
className={`qbs-card-column-content mt-1 font-semibold ${
|
|
42
|
+
!viewMore ? 'line-clamp-1' : ''
|
|
43
|
+
}`}
|
|
44
|
+
>
|
|
45
|
+
<CustomTableCell
|
|
46
|
+
dataKey={col.field}
|
|
47
|
+
rowData={data}
|
|
48
|
+
type={col.type}
|
|
49
|
+
path={col.getPath}
|
|
50
|
+
link={col.link}
|
|
51
|
+
viewMore={viewMore}
|
|
52
|
+
rowClick={col.rowClick}
|
|
53
|
+
renderCell={col.renderCell}
|
|
54
|
+
/>
|
|
55
|
+
</span>
|
|
56
|
+
) : (
|
|
57
|
+
<p
|
|
58
|
+
className={`mt-1 font-semibold qbs-card-column-content ${
|
|
59
|
+
!viewMore ? 'line-clamp-1' : ''
|
|
60
|
+
}`}
|
|
61
|
+
key={index}
|
|
62
|
+
>
|
|
63
|
+
{handleCellFormat(data[col.field], col.type as string)}
|
|
64
|
+
</p>
|
|
65
|
+
)}
|
|
66
|
+
</div>
|
|
67
|
+
))}
|
|
68
|
+
<div
|
|
69
|
+
className={`qbs-card-column-action absolute text-blue-500 mt-2 right-2 ${
|
|
70
|
+
columns.length > initialDisplayCount ? 'top-2' : 'top-4'
|
|
71
|
+
} text-xs`}
|
|
72
|
+
>
|
|
73
|
+
<div
|
|
74
|
+
className={`flex qbs-card-column-action-container
|
|
75
|
+
flex-col items-center gap-y-2
|
|
76
|
+
`}
|
|
77
|
+
>
|
|
78
|
+
<div className=" text-blue-500 qbs-card-column-action-menu ">
|
|
79
|
+
<CardMenuDropdown
|
|
80
|
+
tableBodyRef={tableBodyRef}
|
|
81
|
+
actionDropDown={actionProps}
|
|
82
|
+
rowData={data}
|
|
83
|
+
iconName="more"
|
|
84
|
+
rowIndex={index}
|
|
85
|
+
handleMenuActions={handleMenuActions}
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
{columns.length > initialDisplayCount && (
|
|
89
|
+
<button
|
|
90
|
+
onClick={toggleViewMore}
|
|
91
|
+
className=" qbs-card-column-action-menu-view-more justify-end text-blue-500 text-xs"
|
|
92
|
+
>
|
|
93
|
+
<ArrowUpIcon className={`${viewMore ? 'rotate-180' : ''} `} />
|
|
94
|
+
</button>
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default CardComponent;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { ActionProps } from '../commontypes';
|
|
5
|
+
import { ThreeDotIcon } from './icons';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
iconName: string;
|
|
9
|
+
actionDropDown: ActionProps[];
|
|
10
|
+
handleMenuActions?: (slug: ActionProps, rowData?: any) => void;
|
|
11
|
+
rowData?: any;
|
|
12
|
+
dataTheme?: string;
|
|
13
|
+
tableBodyRef: React.RefObject<HTMLDivElement>;
|
|
14
|
+
rowIndex?: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const CardMenuDropdown: React.FC<Props> = ({ actionDropDown, handleMenuActions, rowData }) => {
|
|
18
|
+
const [openMenu, setOpenMenu] = useState(false);
|
|
19
|
+
const [menuPositionStyles, setMenuPositionStyles] = useState<{
|
|
20
|
+
top?: string;
|
|
21
|
+
bottom?: string;
|
|
22
|
+
right?: string;
|
|
23
|
+
}>({});
|
|
24
|
+
const menuButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
25
|
+
const menuRef = useRef<HTMLDivElement | null>(null);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
29
|
+
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
|
30
|
+
setOpenMenu(false);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
document.addEventListener('click', handleClickOutside);
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
document.removeEventListener('click', handleClickOutside);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const toggleMenu = () => {
|
|
42
|
+
setOpenMenu(prevState => {
|
|
43
|
+
if (!prevState && menuButtonRef.current) {
|
|
44
|
+
const buttonRect = menuButtonRef.current.getBoundingClientRect();
|
|
45
|
+
const dropdownHeight = 200; // Adjust this if your dropdown height varies
|
|
46
|
+
const spaceBelow = window.innerHeight - buttonRect.bottom;
|
|
47
|
+
const spaceAbove = buttonRect.top;
|
|
48
|
+
console.log(spaceAbove, spaceBelow, dropdownHeight);
|
|
49
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
50
|
+
setMenuPositionStyles({
|
|
51
|
+
bottom: '30px',
|
|
52
|
+
right: '10px'
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
setMenuPositionStyles({
|
|
56
|
+
top: `${buttonRect.height}px`,
|
|
57
|
+
right: '10px'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return !prevState;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleClose = () => {
|
|
66
|
+
setOpenMenu(false);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const handleMenuItemClick = (item: ActionProps) => {
|
|
70
|
+
item.action?.(item);
|
|
71
|
+
handleMenuActions?.(item, rowData);
|
|
72
|
+
handleClose();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
console.log(menuPositionStyles);
|
|
76
|
+
return (
|
|
77
|
+
<div className="dropdown text-black dark:text-white dark:bg-[#424242] bg-white" ref={menuRef}>
|
|
78
|
+
<button className="dropdown-toggle" onClick={toggleMenu} ref={menuButtonRef}>
|
|
79
|
+
<ThreeDotIcon />
|
|
80
|
+
</button>
|
|
81
|
+
{openMenu && (
|
|
82
|
+
<div
|
|
83
|
+
className=" qbs-card-dropdown rounded absolute right-0 mt-2 w-56 z-10 shadow-modalShadow bg-white dark:bg-[#424242] dark:text-white"
|
|
84
|
+
style={menuPositionStyles}
|
|
85
|
+
>
|
|
86
|
+
<div className="qbs-card-dropdown-menu px-2 bg-white rounded w-full border border-grey-border shadow-menudropdown dark:bg-[#424242] dark:text-white">
|
|
87
|
+
{actionDropDown?.map(
|
|
88
|
+
item =>
|
|
89
|
+
!item.hidden && (
|
|
90
|
+
<a
|
|
91
|
+
key={item.title}
|
|
92
|
+
href="#/"
|
|
93
|
+
className={'px-2 hover:bg-background '}
|
|
94
|
+
onClick={e => {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
e.stopPropagation();
|
|
97
|
+
handleMenuItemClick(item);
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<div
|
|
101
|
+
className={` qbs-card-dropdown-menu-item ${
|
|
102
|
+
item.isWarning ? 'text-error-light' : 'text-black dark:text-white'
|
|
103
|
+
} text-xxs flex items-center w-full tracking-[0.24px] font-medium `}
|
|
104
|
+
>
|
|
105
|
+
{item?.icon && <>{item.icon}</>}
|
|
106
|
+
<span className="pl-1.5">{item.title}</span>
|
|
107
|
+
</div>
|
|
108
|
+
</a>
|
|
109
|
+
)
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default CardMenuDropdown;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
import { handleCellFormat } from './handleFormatCell';
|
|
4
|
+
|
|
5
|
+
export const CustomTableCell: React.FC<any> = React.memo(
|
|
6
|
+
({ rowData, renderCell, hideLink, dataKey, rowClick, type, path, link, viewMore }) => {
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
{link && !path && !hideLink?.(rowData) ? (
|
|
10
|
+
<a
|
|
11
|
+
onClick={() => rowClick?.(rowData)}
|
|
12
|
+
className={`qbs-table-row-link ${!viewMore ? 'line-clamp-1' : ''}`}
|
|
13
|
+
>
|
|
14
|
+
{renderCell ? renderCell(rowData)?.cell : handleCellFormat(rowData[dataKey], type)}
|
|
15
|
+
</a>
|
|
16
|
+
) : path && !hideLink?.(rowData) ? (
|
|
17
|
+
<Link
|
|
18
|
+
to={path?.(rowData) ?? ''}
|
|
19
|
+
className={`qbs-table-row-link ${!viewMore ? 'line-clamp-1' : ''}`}
|
|
20
|
+
>
|
|
21
|
+
{renderCell ? renderCell(rowData)?.cell : handleCellFormat(rowData[dataKey], type)}
|
|
22
|
+
</Link>
|
|
23
|
+
) : (
|
|
24
|
+
<>{renderCell ? renderCell(rowData)?.cell : handleCellFormat(rowData[dataKey], type)}</>
|
|
25
|
+
)}
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
@@ -36,3 +36,54 @@ export const SettingsIcon: React.FC<any> = () => {
|
|
|
36
36
|
</svg>
|
|
37
37
|
);
|
|
38
38
|
};
|
|
39
|
+
|
|
40
|
+
export const ArrowUpIcon: React.FC<any> = ({ className }) => {
|
|
41
|
+
return (
|
|
42
|
+
<svg
|
|
43
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
44
|
+
fill="none"
|
|
45
|
+
viewBox="0 0 24 24"
|
|
46
|
+
strokeWidth="3"
|
|
47
|
+
stroke="currentColor"
|
|
48
|
+
className={`${className} w-4 h-4`}
|
|
49
|
+
>
|
|
50
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
|
|
51
|
+
</svg>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
export const TableIcon: React.FC<any> = ({ className }: any) => {
|
|
55
|
+
return (
|
|
56
|
+
<svg
|
|
57
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
58
|
+
fill="none"
|
|
59
|
+
viewBox="0 0 24 24"
|
|
60
|
+
strokeWidth="1.5"
|
|
61
|
+
stroke="currentColor"
|
|
62
|
+
className={`${className} w-6 h-6`}
|
|
63
|
+
>
|
|
64
|
+
<path
|
|
65
|
+
strokeLinecap="round"
|
|
66
|
+
strokeLinejoin="round"
|
|
67
|
+
d="M2.25 8.25h19.5M2.25 9h19.5m-16.5 5.25h6m-6 2.25h3m-3.75 3h15a2.25 2.25 0 0 0 2.25-2.25V6.75A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25v10.5A2.25 2.25 0 0 0 4.5 19.5Z"
|
|
68
|
+
/>
|
|
69
|
+
</svg>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
export const CardIcon: React.FC<any> = ({ className }: any) => {
|
|
73
|
+
return (
|
|
74
|
+
<svg
|
|
75
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
76
|
+
fill="none"
|
|
77
|
+
viewBox="0 0 24 24"
|
|
78
|
+
strokeWidth="1.5"
|
|
79
|
+
stroke="currentColor"
|
|
80
|
+
className={`${className} w-6 h-6`}
|
|
81
|
+
>
|
|
82
|
+
<path
|
|
83
|
+
strokeLinecap="round"
|
|
84
|
+
strokeLinejoin="round"
|
|
85
|
+
d="M3.375 19.5h17.25m-17.25 0a1.125 1.125 0 0 1-1.125-1.125M3.375 19.5h7.5c.621 0 1.125-.504 1.125-1.125m-9.75 0V5.625m0 12.75v-1.5c0-.621.504-1.125 1.125-1.125m18.375 2.625V5.625m0 12.75c0 .621-.504 1.125-1.125 1.125m1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125m0 3.75h-7.5A1.125 1.125 0 0 1 12 18.375m9.75-12.75c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125m19.5 0v1.5c0 .621-.504 1.125-1.125 1.125M2.25 5.625v1.5c0 .621.504 1.125 1.125 1.125m0 0h17.25m-17.25 0h7.5c.621 0 1.125.504 1.125 1.125M3.375 8.25c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125m17.25-3.75h-7.5c-.621 0-1.125.504-1.125 1.125m8.625-1.125c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125M12 10.875v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 10.875c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125M13.125 12h7.5m-7.5 0c-.621 0-1.125.504-1.125 1.125M20.625 12c.621 0 1.125.504 1.125 1.125v1.5c0 .621-.504 1.125-1.125 1.125m-17.25 0h7.5M12 14.625v-1.5m0 1.5c0 .621-.504 1.125-1.125 1.125M12 14.625c0 .621.504 1.125 1.125 1.125m-2.25 0c.621 0 1.125.504 1.125 1.125m0 1.5v-1.5m0 0c0-.621.504-1.125 1.125-1.125m0 0h7.5"
|
|
86
|
+
/>
|
|
87
|
+
</svg>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
File without changes
|
|
File without changes
|