ehscan-react-table 0.0.12 → 0.0.13
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/Components.d.ts +3 -2
- package/dist/Components.js +3 -2
- package/dist/cells/TableCellDueDate.d.ts +13 -0
- package/dist/cells/TableCellDueDate.js +12 -0
- package/dist/cells/TableCellSelect.d.ts +11 -0
- package/dist/cells/TableCellSelect.js +9 -0
- package/dist/cells/TableDefCell.d.ts +13 -0
- package/dist/cells/TableDefCell.js +4 -0
- package/dist/elements/Table.js +1 -1
- package/dist/elements/table.module.css +59 -2
- package/dist/tools/dateFunction.d.ts +2 -0
- package/dist/tools/dateFunction.js +47 -0
- package/package.json +1 -1
package/dist/Components.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { Table } from './elements/Table';
|
|
2
2
|
export { Pagination } from './elements/Pagination';
|
|
3
|
-
export { TableCellSelect } from './
|
|
4
|
-
export { TableDefCell } from './
|
|
3
|
+
export { TableCellSelect } from './cells/TableCellSelect';
|
|
4
|
+
export { TableDefCell } from './cells/TableDefCell';
|
|
5
|
+
export { TableCellDueDate } from './cells/TableCellDueDate';
|
|
5
6
|
export { useSortOrder } from './elements/SortOrderUtils';
|
|
6
7
|
export { sortRows } from './elements/SortOrderUtils';
|
|
7
8
|
export type { SortOrder } from './elements/SortOrderUtils';
|
package/dist/Components.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// ehscan-react-table entry
|
|
2
2
|
export { Table } from './elements/Table';
|
|
3
3
|
export { Pagination } from './elements/Pagination';
|
|
4
|
-
export { TableCellSelect } from './
|
|
5
|
-
export { TableDefCell } from './
|
|
4
|
+
export { TableCellSelect } from './cells/TableCellSelect';
|
|
5
|
+
export { TableDefCell } from './cells/TableDefCell';
|
|
6
|
+
export { TableCellDueDate } from './cells/TableCellDueDate';
|
|
6
7
|
export { useSortOrder } from './elements/SortOrderUtils';
|
|
7
8
|
export { sortRows } from './elements/SortOrderUtils';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type Props = {
|
|
3
|
+
content: string;
|
|
4
|
+
id: string | number;
|
|
5
|
+
col: string | number;
|
|
6
|
+
clickRow: (args: {
|
|
7
|
+
id: string | number;
|
|
8
|
+
col: string | number;
|
|
9
|
+
type: 'default';
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const TableCellDueDate: React.FC<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { calcDateDiff, formatToDDMMYYYY } from '../tools/dateFunction';
|
|
3
|
+
import styles from './table.module.css';
|
|
4
|
+
export const TableCellDueDate = ({ content, id, col, clickRow }) => {
|
|
5
|
+
const DateContent = ({ value }) => {
|
|
6
|
+
const valDate = value;
|
|
7
|
+
return valDate === '-' || !valDate
|
|
8
|
+
? '-'
|
|
9
|
+
: _jsx("span", { className: `${styles.dateTag} ${calcDateDiff(valDate)}`, children: formatToDDMMYYYY(valDate) });
|
|
10
|
+
};
|
|
11
|
+
return (_jsx("div", { onClick: () => clickRow({ id, col, type: 'default' }), children: _jsx(DateContent, { value: content }) }));
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type SelectProps = {
|
|
2
|
+
rowIndex: number;
|
|
3
|
+
checked?: boolean;
|
|
4
|
+
};
|
|
5
|
+
type Props = {
|
|
6
|
+
rowIndex: number;
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
selectRow: (args: SelectProps, shift: boolean) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const TableCellSelect: React.FC<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import TableChecklistItem from "../elements/TableChecklistItem";
|
|
3
|
+
export const TableCellSelect = ({ rowIndex, checked, selectRow }) => {
|
|
4
|
+
const checkClick = (event) => {
|
|
5
|
+
const shift = event.shiftKey;
|
|
6
|
+
selectRow({ rowIndex, checked: !checked }, shift);
|
|
7
|
+
};
|
|
8
|
+
return (_jsx(_Fragment, { children: _jsx("div", { onClick: (e) => { e.stopPropagation(); checkClick(e); }, children: _jsx(TableChecklistItem, { checked: checked !== null && checked !== void 0 ? checked : false }) }) }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
type TableDefCellProps = {
|
|
3
|
+
content: ReactNode;
|
|
4
|
+
id: string | number;
|
|
5
|
+
col: string | number;
|
|
6
|
+
clickRow: (args: {
|
|
7
|
+
id: string | number;
|
|
8
|
+
col: string | number;
|
|
9
|
+
type: 'default';
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const TableDefCell: React.FC<TableDefCellProps>;
|
|
13
|
+
export {};
|
package/dist/elements/Table.js
CHANGED
|
@@ -100,7 +100,7 @@ export const Table = ({ columns, rows, sortOrder, setSortOrder, cellComponents,
|
|
|
100
100
|
};
|
|
101
101
|
const HeadColMain = ({ col }) => {
|
|
102
102
|
const { tag, search, title } = col;
|
|
103
|
-
const colTitle = title
|
|
103
|
+
const colTitle = title !== undefined ? title : tag;
|
|
104
104
|
return (_jsx("th", { children: _jsxs("div", { className: styles.headcolcell, children: [_jsx(HeadColSort, { tag: tag }), _jsx("div", { className: styles.headcolcellmain, children: search ? _jsx(HeadSearchBar, { content: colTitle, tag: tag }) : _jsx("div", { children: colTitle }) })] }) }));
|
|
105
105
|
};
|
|
106
106
|
const HeadCols = () => {
|
|
@@ -274,10 +274,9 @@ input.headsearch:focus {
|
|
|
274
274
|
.deftabletr > td, .trstickyhead > th {
|
|
275
275
|
padding: 0;
|
|
276
276
|
text-align: left;
|
|
277
|
-
color: #374151;
|
|
278
277
|
box-sizing: border-box;
|
|
279
278
|
font-size: 80%;
|
|
280
|
-
padding: 5px;
|
|
279
|
+
padding: 5px 5px 5px 0;
|
|
281
280
|
width: var(--custom-width) !important;
|
|
282
281
|
min-width: 30px;
|
|
283
282
|
}
|
|
@@ -491,4 +490,62 @@ RIPPLE
|
|
|
491
490
|
transform: scale(4);
|
|
492
491
|
opacity: 0;
|
|
493
492
|
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
.dateTag {
|
|
496
|
+
position: relative;
|
|
497
|
+
color: var(--ext-table-date-tag-clr, black);
|
|
498
|
+
padding: 3px 6px;
|
|
499
|
+
border-radius: 12px;
|
|
500
|
+
font-size: 0.65rem;
|
|
501
|
+
font-weight: 600;
|
|
502
|
+
display: inline-block;
|
|
503
|
+
text-align: center;
|
|
504
|
+
text-overflow: ellipsis;
|
|
505
|
+
white-space: nowrap;
|
|
506
|
+
width: -webkit-fill-available;
|
|
507
|
+
z-index: 0;
|
|
508
|
+
}
|
|
509
|
+
.dateTag::before {
|
|
510
|
+
content: "";
|
|
511
|
+
position: absolute;
|
|
512
|
+
inset: 0;
|
|
513
|
+
background-color: var(--ext-table-date-tag-bck-clr, darkgrey);
|
|
514
|
+
opacity: 0.7;
|
|
515
|
+
/* dim background */
|
|
516
|
+
border-radius: 12px;
|
|
517
|
+
z-index: -1;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.dateTagUnknown {
|
|
521
|
+
--ext-table-date-tag-bck-clr: darkgray;
|
|
522
|
+
}
|
|
523
|
+
.upcomingDueDate {
|
|
524
|
+
--ext-table-date-tag-clr: white;
|
|
525
|
+
--ext-table-date-tag-bck-clr: lightslategray;
|
|
526
|
+
}
|
|
527
|
+
/* Due Today */
|
|
528
|
+
.dueToday {
|
|
529
|
+
--ext-table-date-tag-clr: white;
|
|
530
|
+
--ext-table-date-tag-bck-clr: lightslategray;
|
|
531
|
+
}
|
|
532
|
+
/* Overdue (1–3 days late) */
|
|
533
|
+
.overdueDueDate {
|
|
534
|
+
--ext-table-date-tag-clr: white;
|
|
535
|
+
--ext-table-date-tag-bck-clr: lightcoral;
|
|
536
|
+
}
|
|
537
|
+
/* Long Overdue (4–14 days late) */
|
|
538
|
+
.longOverdue {
|
|
539
|
+
--ext-table-date-tag-clr: white;
|
|
540
|
+
--ext-table-date-tag-bck-clr: firebrick;
|
|
541
|
+
}
|
|
542
|
+
/* Critically Overdue (25+ days late) */
|
|
543
|
+
.criticallyOverdue {
|
|
544
|
+
--ext-table-date-tag-clr: white;
|
|
545
|
+
--ext-table-date-tag-bck-clr: #8B00FF;
|
|
546
|
+
}
|
|
547
|
+
/* Future (Beyond 7 days) */
|
|
548
|
+
.futureDueDate {
|
|
549
|
+
--ext-table-date-tag-clr: white;
|
|
550
|
+
--ext-table-date-tag-bck-clr: #008000;
|
|
494
551
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const calcDateDiff = (date) => {
|
|
2
|
+
const targetDate = new Date(date);
|
|
3
|
+
const currentDate = new Date();
|
|
4
|
+
targetDate.setHours(0, 0, 0, 0);
|
|
5
|
+
currentDate.setHours(0, 0, 0, 0);
|
|
6
|
+
const msInDay = 24 * 60 * 60 * 1000;
|
|
7
|
+
const daysDiff = Math.floor((targetDate.getTime() - currentDate.getTime()) / msInDay);
|
|
8
|
+
const daysLate = Math.abs(daysDiff);
|
|
9
|
+
let dueDateType;
|
|
10
|
+
switch (true) {
|
|
11
|
+
case daysDiff === 0:
|
|
12
|
+
dueDateType = 'dueToday';
|
|
13
|
+
break;
|
|
14
|
+
case daysDiff > 0 && daysDiff <= 7:
|
|
15
|
+
dueDateType = 'upcomingDueDate';
|
|
16
|
+
break;
|
|
17
|
+
case daysDiff > 7:
|
|
18
|
+
dueDateType = 'futureDueDate';
|
|
19
|
+
break;
|
|
20
|
+
case daysDiff < 0 && daysLate <= 3:
|
|
21
|
+
dueDateType = 'overdueDueDate';
|
|
22
|
+
break;
|
|
23
|
+
case daysDiff < 0 && daysLate <= 25:
|
|
24
|
+
dueDateType = 'longOverdue';
|
|
25
|
+
break;
|
|
26
|
+
case daysDiff < 0 && daysLate > 25:
|
|
27
|
+
dueDateType = 'criticallyOverdue';
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
dueDateType = 'dateTagUnknown';
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
return dueDateType;
|
|
34
|
+
};
|
|
35
|
+
export const formatToDDMMYYYY = (input, short = false) => {
|
|
36
|
+
const date = new Date(input);
|
|
37
|
+
if (isNaN(date.getTime()))
|
|
38
|
+
return undefined;
|
|
39
|
+
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
40
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
41
|
+
const year = date.getUTCFullYear();
|
|
42
|
+
const currentYear = new Date().getUTCFullYear();
|
|
43
|
+
if (short && year === currentYear) {
|
|
44
|
+
return `${day}.${month}.`; // omit year if short and current year
|
|
45
|
+
}
|
|
46
|
+
return `${day}.${month}.${year}`;
|
|
47
|
+
};
|