@digigov/ui 0.32.2 → 0.33.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/CHANGELOG.md +12 -1
- package/admin/Drawer/__stories__/Default.js +3 -0
- package/admin/Dropdown/index.d.ts +1 -1
- package/admin/Dropdown/index.js +14 -3
- package/core/CaretContainer/index.d.ts +3 -0
- package/core/CaretContainer/index.js +30 -0
- package/core/Table/Table.stories.d.ts +1 -0
- package/core/Table/Table.stories.js +14 -0
- package/core/Table/Table.stories.playwright.json +16 -0
- package/core/Table/__stories__/WithSortFilters.d.ts +2 -0
- package/core/Table/__stories__/WithSortFilters.js +141 -0
- package/core/Table/index.d.ts +22 -1
- package/core/Table/index.js +210 -24
- package/core/index.d.ts +1 -0
- package/core/index.js +13 -0
- package/es/admin/Drawer/__stories__/Default.js +3 -0
- package/es/admin/Dropdown/index.js +14 -3
- package/es/core/CaretContainer/index.js +3 -0
- package/es/core/Table/Table.stories.js +1 -0
- package/es/core/Table/Table.stories.playwright.json +16 -0
- package/es/core/Table/__stories__/WithSortFilters.js +126 -0
- package/es/core/Table/index.js +170 -1
- package/es/core/index.js +1 -0
- package/es/registry.js +2 -0
- package/esm/admin/Drawer/__stories__/Default.js +3 -0
- package/esm/admin/Dropdown/index.js +14 -3
- package/esm/core/CaretContainer/index.js +3 -0
- package/esm/core/Table/Table.stories.js +1 -0
- package/esm/core/Table/Table.stories.playwright.json +16 -0
- package/esm/core/Table/__stories__/WithSortFilters.js +126 -0
- package/esm/core/Table/index.js +170 -1
- package/esm/core/index.js +1 -0
- package/esm/index.js +1 -1
- package/esm/registry.js +2 -0
- package/package.json +3 -3
- package/registry.d.ts +1 -0
- package/registry.js +3 -0
- package/src/admin/Drawer/__stories__/Default.tsx +3 -1
- package/src/admin/Dropdown/index.tsx +16 -7
- package/src/core/CaretContainer/index.tsx +3 -0
- package/src/core/Table/Table.stories.js +1 -0
- package/src/core/Table/Table.stories.playwright.json +16 -0
- package/src/core/Table/__stories__/WithSortFilters.tsx +189 -0
- package/src/core/Table/index.tsx +195 -2
- package/src/core/index.ts +1 -0
- package/src/registry.js +2 -0
package/registry.js
CHANGED
|
@@ -153,6 +153,8 @@ var _digigov_ui_core_Button_ThemeToggleButton = _interopRequireWildcard(require(
|
|
|
153
153
|
|
|
154
154
|
var _digigov_ui_core_Card = _interopRequireWildcard(require("@digigov/ui/core/Card"));
|
|
155
155
|
|
|
156
|
+
var _digigov_ui_core_CaretContainer = _interopRequireWildcard(require("@digigov/ui/core/CaretContainer"));
|
|
157
|
+
|
|
156
158
|
var _digigov_ui_core_Checkbox = _interopRequireWildcard(require("@digigov/ui/core/Checkbox"));
|
|
157
159
|
|
|
158
160
|
var _digigov_ui_core_DateInputContainer = _interopRequireWildcard(require("@digigov/ui/core/DateInputContainer"));
|
|
@@ -597,6 +599,7 @@ var _default = {
|
|
|
597
599
|
'@digigov/ui/core/Button': lazyImport(_digigov_ui_core_Button),
|
|
598
600
|
'@digigov/ui/core/Button/ThemeToggleButton': lazyImport(_digigov_ui_core_Button_ThemeToggleButton),
|
|
599
601
|
'@digigov/ui/core/Card': lazyImport(_digigov_ui_core_Card),
|
|
602
|
+
'@digigov/ui/core/CaretContainer': lazyImport(_digigov_ui_core_CaretContainer),
|
|
600
603
|
'@digigov/ui/core/Checkbox': lazyImport(_digigov_ui_core_Checkbox),
|
|
601
604
|
'@digigov/ui/core/DateInputContainer': lazyImport(_digigov_ui_core_DateInputContainer),
|
|
602
605
|
'@digigov/ui/core/Details': lazyImport(_digigov_ui_core_Details),
|
|
@@ -69,9 +69,10 @@ export const Default = () => {
|
|
|
69
69
|
|
|
70
70
|
const layout = 'vertical';
|
|
71
71
|
const border = false;
|
|
72
|
+
const fixed = false;
|
|
72
73
|
|
|
73
74
|
return (
|
|
74
|
-
<Drawer direction="left" open={open}>
|
|
75
|
+
<Drawer upRelative="m" direction="left" open={open}>
|
|
75
76
|
<DrawerHeading onClick={() => toggleDrawer()}>
|
|
76
77
|
<Title size="md">Menu</Title>
|
|
77
78
|
</DrawerHeading>
|
|
@@ -79,6 +80,7 @@ export const Default = () => {
|
|
|
79
80
|
layout={layout}
|
|
80
81
|
links={links}
|
|
81
82
|
border={border}
|
|
83
|
+
fixed={fixed}
|
|
82
84
|
aria-label="Nav list"
|
|
83
85
|
>
|
|
84
86
|
{links.map((item, key) => (
|
|
@@ -21,22 +21,30 @@ export interface DropdownProps extends DropdownBaseProps {
|
|
|
21
21
|
/**
|
|
22
22
|
* Dropdown component is used for showing more options with a button.
|
|
23
23
|
*/
|
|
24
|
-
export const Dropdown = ({
|
|
25
|
-
closeBehaviour = 'clickOutside',
|
|
26
|
-
float = false,
|
|
27
|
-
...props
|
|
28
|
-
}: DropdownProps): React.ReactElement => {
|
|
29
|
-
const innerRef = useRef() as React.MutableRefObject<HTMLDetailsElement>;
|
|
30
24
|
|
|
25
|
+
export const Dropdown = React.forwardRef(function Dropdown(
|
|
26
|
+
{ closeBehaviour = 'clickOutside', float = false, ...props }: DropdownProps,
|
|
27
|
+
ref: React.MutableRefObject<HTMLDetailsElement>
|
|
28
|
+
): React.ReactElement {
|
|
29
|
+
const innerRef =
|
|
30
|
+
ref || (useRef() as React.MutableRefObject<HTMLDetailsElement>);
|
|
31
31
|
useEffect(() => {
|
|
32
|
+
const keyDownHandler = (event) => {
|
|
33
|
+
if (event.key === 'Escape') {
|
|
34
|
+
innerRef.current.open = false;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
32
38
|
const handleClickOutside = (event) => {
|
|
33
39
|
if (innerRef.current && !innerRef.current.contains(event.target)) {
|
|
34
40
|
innerRef.current.open = false;
|
|
35
41
|
}
|
|
36
42
|
};
|
|
43
|
+
|
|
37
44
|
if (closeBehaviour === 'clickOutside') {
|
|
38
45
|
document.addEventListener('click', handleClickOutside, true);
|
|
39
46
|
}
|
|
47
|
+
document.addEventListener('keydown', keyDownHandler);
|
|
40
48
|
const toggleFloat = () => {
|
|
41
49
|
const tbody = innerRef.current.closest('tbody') as HTMLElement;
|
|
42
50
|
const parentElement = innerRef.current?.parentElement as HTMLElement;
|
|
@@ -76,12 +84,13 @@ export const Dropdown = ({
|
|
|
76
84
|
if (float) {
|
|
77
85
|
innerRef.current.removeEventListener('toggle', toggleFloat);
|
|
78
86
|
}
|
|
87
|
+
document.removeEventListener('keydown', keyDownHandler);
|
|
79
88
|
};
|
|
80
89
|
}, []);
|
|
81
90
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
82
91
|
// @ts-ignore
|
|
83
92
|
return <DropdownBase ref={innerRef} {...props} />;
|
|
84
|
-
};
|
|
93
|
+
});
|
|
85
94
|
|
|
86
95
|
export { DropdownBase };
|
|
87
96
|
export default Dropdown;
|
|
@@ -22,5 +22,6 @@ export * from './__stories__/WithLoader';
|
|
|
22
22
|
export * from './__stories__/DefinedWidth';
|
|
23
23
|
export * from './__stories__/Densed';
|
|
24
24
|
export * from './__stories__/MultipleProps';
|
|
25
|
+
export * from './__stories__/WithSortFilters';
|
|
25
26
|
export * from './__stories__/WithFloatingScroll';
|
|
26
27
|
export * from './__stories__/Full';
|
|
@@ -16,6 +16,22 @@
|
|
|
16
16
|
"title": "Toggle Loading"
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
|
+
},
|
|
20
|
+
"digigov-ui-core-table--with-sort-filters": {
|
|
21
|
+
"actionSets": [
|
|
22
|
+
{
|
|
23
|
+
"actions": [
|
|
24
|
+
{
|
|
25
|
+
"name": "click",
|
|
26
|
+
"args": {
|
|
27
|
+
"selector": "html>body>div:nth-child(5)>div>div>table>thead>tr>th:nth-child(2)>details>summary"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"id": "Gdm_Fpollj7d",
|
|
32
|
+
"title": "Table with filter action"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
19
35
|
}
|
|
20
36
|
}
|
|
21
37
|
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TableContainer,
|
|
5
|
+
Table,
|
|
6
|
+
TableCaption,
|
|
7
|
+
TableHead,
|
|
8
|
+
TableRow,
|
|
9
|
+
TableBody,
|
|
10
|
+
TableHeadCellSort,
|
|
11
|
+
TableDataCell,
|
|
12
|
+
TableNoDataRow,
|
|
13
|
+
useSortableData,
|
|
14
|
+
} from '@digigov/ui/core/Table';
|
|
15
|
+
|
|
16
|
+
const headerItems = [
|
|
17
|
+
{
|
|
18
|
+
name: 'product',
|
|
19
|
+
label: 'Προϊόν',
|
|
20
|
+
sortLabels: [
|
|
21
|
+
{
|
|
22
|
+
label: 'Αλφαβητική σειρά (Α -> Ω)',
|
|
23
|
+
direction: 'asc',
|
|
24
|
+
value: 1,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Αλφαβητική σειρά (Ω -> Α)',
|
|
28
|
+
direction: 'desc',
|
|
29
|
+
value: -1,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'price',
|
|
35
|
+
label: 'Τιμή',
|
|
36
|
+
sortLabels: [
|
|
37
|
+
{
|
|
38
|
+
label: 'Αύξουσα σειρά',
|
|
39
|
+
direction: 'ascending',
|
|
40
|
+
value: 1,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'Φθίνουσα σειρά',
|
|
44
|
+
direction: 'descending',
|
|
45
|
+
value: -1,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'stock',
|
|
51
|
+
label: 'Στοκ',
|
|
52
|
+
sortLabels: [
|
|
53
|
+
{
|
|
54
|
+
label: 'Αύξουσα σειρά',
|
|
55
|
+
direction: 'ascending',
|
|
56
|
+
value: 1,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
label: 'Φθίνουσα σειρά',
|
|
60
|
+
direction: 'descending',
|
|
61
|
+
value: -1,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'date',
|
|
67
|
+
label: 'Ημερομηνία',
|
|
68
|
+
sortLabels: [
|
|
69
|
+
{
|
|
70
|
+
label: 'Αύξουσα σειρά',
|
|
71
|
+
direction: 'ascending',
|
|
72
|
+
value: 1,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
label: 'Φθίνουσα σειρά',
|
|
76
|
+
direction: 'descending',
|
|
77
|
+
value: -1,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const data = [
|
|
84
|
+
{
|
|
85
|
+
id: 1,
|
|
86
|
+
product: 'Τυρί',
|
|
87
|
+
price: '4.9€',
|
|
88
|
+
stock: 20,
|
|
89
|
+
date: '2013-04-01',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 2,
|
|
93
|
+
product: 'Γάλα',
|
|
94
|
+
price: '1.9€',
|
|
95
|
+
stock: 32,
|
|
96
|
+
date: '2013-01-01',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 3,
|
|
100
|
+
product: 'Γιαούρτι',
|
|
101
|
+
price: '2.4€',
|
|
102
|
+
stock: 12,
|
|
103
|
+
date: '2002-04-12',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 4,
|
|
107
|
+
product: 'Κρέμα',
|
|
108
|
+
price: '3.9€',
|
|
109
|
+
stock: 8,
|
|
110
|
+
date: '2011-12-12',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 5,
|
|
114
|
+
product: 'Βούτυρο',
|
|
115
|
+
price: '0.9€',
|
|
116
|
+
stock: 99,
|
|
117
|
+
date: '2019-06-01',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 6,
|
|
121
|
+
product: 'Καφές',
|
|
122
|
+
price: '2.9€',
|
|
123
|
+
stock: 86,
|
|
124
|
+
date: '2023-02-11',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 7,
|
|
128
|
+
product: 'Ψωμί',
|
|
129
|
+
price: '99€',
|
|
130
|
+
stock: 12,
|
|
131
|
+
date: '2000-12-12',
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
export const WithSortFilters = () => {
|
|
136
|
+
const { sortedData, sortedProps } = useSortableData(data);
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<div className="example">
|
|
140
|
+
<TableContainer
|
|
141
|
+
/* Possible style solution in order to display dropdown properly when we have only one table row
|
|
142
|
+
* style={{
|
|
143
|
+
* overflow: 'inherit',
|
|
144
|
+
* }}
|
|
145
|
+
*/
|
|
146
|
+
>
|
|
147
|
+
<Table>
|
|
148
|
+
<TableCaption>Table of products</TableCaption>
|
|
149
|
+
<TableHead>
|
|
150
|
+
<TableRow>
|
|
151
|
+
{headerItems &&
|
|
152
|
+
headerItems.length > 0 &&
|
|
153
|
+
headerItems.map((header, index) => {
|
|
154
|
+
return (
|
|
155
|
+
<TableHeadCellSort
|
|
156
|
+
key={index}
|
|
157
|
+
{...sortedProps}
|
|
158
|
+
headerItems={header}
|
|
159
|
+
>
|
|
160
|
+
{header.label}
|
|
161
|
+
</TableHeadCellSort>
|
|
162
|
+
);
|
|
163
|
+
})}
|
|
164
|
+
</TableRow>
|
|
165
|
+
</TableHead>
|
|
166
|
+
<TableBody>
|
|
167
|
+
{sortedData && sortedData.length > 0 ? (
|
|
168
|
+
sortedData.map((d, index) => {
|
|
169
|
+
return (
|
|
170
|
+
<TableRow key={index}>
|
|
171
|
+
<TableDataCell>{d.product}</TableDataCell>
|
|
172
|
+
<TableDataCell>{d.price}</TableDataCell>
|
|
173
|
+
<TableDataCell>{d.stock}</TableDataCell>
|
|
174
|
+
<TableDataCell>
|
|
175
|
+
{new Date(d.date).toLocaleDateString('en-GB')}
|
|
176
|
+
</TableDataCell>
|
|
177
|
+
</TableRow>
|
|
178
|
+
);
|
|
179
|
+
})
|
|
180
|
+
) : (
|
|
181
|
+
<TableNoDataRow>No data</TableNoDataRow>
|
|
182
|
+
)}
|
|
183
|
+
</TableBody>
|
|
184
|
+
</Table>
|
|
185
|
+
</TableContainer>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
export default WithSortFilters;
|
package/src/core/Table/index.tsx
CHANGED
|
@@ -1,3 +1,197 @@
|
|
|
1
|
+
import React, { useCallback, useState, useRef } from 'react';
|
|
2
|
+
import Table from '@digigov/react-core/Table';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Dropdown,
|
|
6
|
+
DropdownButton,
|
|
7
|
+
DropdownContent,
|
|
8
|
+
} from '@digigov/ui/admin/Dropdown';
|
|
9
|
+
import { NavVertical } from '@digigov/ui/core/NavList/NavVertical';
|
|
10
|
+
import { NavVerticalItem } from '@digigov/ui/core/NavList/NavVerticalItem';
|
|
11
|
+
import { CaretIcon } from '@digigov/ui/core/SvgIcon';
|
|
12
|
+
import TableHeadCellBase, {
|
|
13
|
+
TableHeadCellProps as TableHeadCellSortProps,
|
|
14
|
+
} from '@digigov/react-core/TableHeadCell';
|
|
15
|
+
import CaretContainer from '@digigov/ui/core/CaretContainer';
|
|
16
|
+
|
|
17
|
+
export interface sortedProps extends TableHeadCellSortProps {
|
|
18
|
+
sortedAscDesc?: (x: any, y: number) => void;
|
|
19
|
+
sortedField?: string;
|
|
20
|
+
sortedDirectionValue?: number;
|
|
21
|
+
headerItems?: any;
|
|
22
|
+
sortedData?: any[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const useSortableData = (items) => {
|
|
26
|
+
const [field, setField] = useState('');
|
|
27
|
+
const [directionValue, setDirectionValue] = useState(0);
|
|
28
|
+
const sortedItems = useMemo(() => {
|
|
29
|
+
const sortableItems = [...items];
|
|
30
|
+
if (sortableItems.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (field) {
|
|
34
|
+
sortableItems.sort((a, b) => {
|
|
35
|
+
if (a[field] === null) return 1;
|
|
36
|
+
if (b[field] === null) return -1;
|
|
37
|
+
if (a[field] === null && b[field] === null) return 0;
|
|
38
|
+
return (
|
|
39
|
+
a[field].toString().localeCompare(b[field].toString(), undefined, {
|
|
40
|
+
numeric: true,
|
|
41
|
+
}) * (directionValue > 0 ? 1 : -1)
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return sortableItems;
|
|
46
|
+
}, [items, directionValue, field]);
|
|
47
|
+
|
|
48
|
+
const sortAscDesc = (item, value) => {
|
|
49
|
+
setDirectionValue(value);
|
|
50
|
+
setField(item);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
sortedData: sortedItems,
|
|
55
|
+
sortedProps: {
|
|
56
|
+
sortedData: sortedItems,
|
|
57
|
+
sortedDirectionValue: directionValue,
|
|
58
|
+
sortedField: field,
|
|
59
|
+
sortedAscDesc: sortAscDesc,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const TableHeadCellSort = React.forwardRef<HTMLTableCellElement, sortedProps>(
|
|
64
|
+
function TableHeadCellSort({ ...props }, ref) {
|
|
65
|
+
return <TableHeadCellSortBase ref={ref} {...props} />;
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
export const TableHeadCellSortBase = React.forwardRef<
|
|
70
|
+
HTMLTableCellElement,
|
|
71
|
+
sortedProps
|
|
72
|
+
>(function TableHeadCellSortBase(
|
|
73
|
+
{
|
|
74
|
+
sortedAscDesc,
|
|
75
|
+
sortedField,
|
|
76
|
+
sortedDirectionValue,
|
|
77
|
+
headerItems,
|
|
78
|
+
sortedData,
|
|
79
|
+
children,
|
|
80
|
+
...props
|
|
81
|
+
},
|
|
82
|
+
ref
|
|
83
|
+
) {
|
|
84
|
+
const innerRef = useRef() as React.MutableRefObject<HTMLDetailsElement>;
|
|
85
|
+
const { name, sortLabels } = headerItems || {};
|
|
86
|
+
const [sortDirection, setSortDirection] = useState(0);
|
|
87
|
+
const setSortAscDesc = useCallback(
|
|
88
|
+
(name, value) => {
|
|
89
|
+
if (sortedAscDesc) {
|
|
90
|
+
if (sortedField !== name) {
|
|
91
|
+
sortedAscDesc('', 0);
|
|
92
|
+
|
|
93
|
+
setSortDirection(value);
|
|
94
|
+
sortedAscDesc(name, value);
|
|
95
|
+
} else {
|
|
96
|
+
if (value !== sortDirection) {
|
|
97
|
+
setSortDirection(value);
|
|
98
|
+
sortedAscDesc(name, value);
|
|
99
|
+
} else {
|
|
100
|
+
setSortDirection(0);
|
|
101
|
+
sortedAscDesc('', 0);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[sortedField, sortedDirectionValue, sortDirection]
|
|
107
|
+
);
|
|
108
|
+
const onKeyDown = useCallback(
|
|
109
|
+
(e, name, value) => {
|
|
110
|
+
if (e.key === 'Enter' && innerRef.current.contains(e.target)) {
|
|
111
|
+
if (innerRef.current.open) {
|
|
112
|
+
setSortAscDesc(name, value);
|
|
113
|
+
innerRef.current.open = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
[name, sortDirection]
|
|
118
|
+
);
|
|
119
|
+
const setDisabled = useCallback(
|
|
120
|
+
(sortedData) => {
|
|
121
|
+
return sortedData === undefined || sortedData.length === 0 ? true : false;
|
|
122
|
+
},
|
|
123
|
+
[sortedData]
|
|
124
|
+
);
|
|
125
|
+
const setCaretColor = useCallback(
|
|
126
|
+
(value: number) => {
|
|
127
|
+
if (sortedField === name) {
|
|
128
|
+
return sortedDirectionValue === value ? 'dark' : 'gray';
|
|
129
|
+
} else {
|
|
130
|
+
return 'gray';
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
[sortedDirectionValue, sortedField]
|
|
134
|
+
);
|
|
135
|
+
return (
|
|
136
|
+
<TableHeadCellBase {...props} ref={ref}>
|
|
137
|
+
<Dropdown tabIndex={0} disabled={setDisabled(sortedData)} ref={innerRef}>
|
|
138
|
+
<DropdownButton
|
|
139
|
+
variant="link"
|
|
140
|
+
underline={sortedField === name ? true : false}
|
|
141
|
+
>
|
|
142
|
+
{children}
|
|
143
|
+
<CaretContainer marginLeft={1}>
|
|
144
|
+
{sortLabels &&
|
|
145
|
+
sortLabels.length > 0 &&
|
|
146
|
+
sortLabels.map((obj, index) => {
|
|
147
|
+
return (
|
|
148
|
+
<CaretIcon
|
|
149
|
+
key={index}
|
|
150
|
+
direction={obj.value == 1 ? 'up' : 'down'}
|
|
151
|
+
size="m"
|
|
152
|
+
variant={setCaretColor(obj.value)}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
</CaretContainer>
|
|
157
|
+
</DropdownButton>
|
|
158
|
+
<DropdownContent>
|
|
159
|
+
{sortLabels &&
|
|
160
|
+
sortLabels.length > 0 &&
|
|
161
|
+
sortLabels.map((obj, index) => {
|
|
162
|
+
return (
|
|
163
|
+
<NavVertical key={index}>
|
|
164
|
+
<NavVerticalItem
|
|
165
|
+
{...(sortedField === name &&
|
|
166
|
+
sortedDirectionValue === obj.value && { active: true })}
|
|
167
|
+
tabIndex={0}
|
|
168
|
+
onClick={() => {
|
|
169
|
+
if (setSortAscDesc) {
|
|
170
|
+
setSortAscDesc(name, obj.value);
|
|
171
|
+
innerRef.current.open = false;
|
|
172
|
+
}
|
|
173
|
+
}}
|
|
174
|
+
onKeyDown={(e) => {
|
|
175
|
+
onKeyDown(e, name, obj.value);
|
|
176
|
+
}}
|
|
177
|
+
>
|
|
178
|
+
<CaretIcon
|
|
179
|
+
direction={obj.value == 1 ? 'up' : 'down'}
|
|
180
|
+
marginRight={1}
|
|
181
|
+
marginTop={1}
|
|
182
|
+
size="m"
|
|
183
|
+
/>
|
|
184
|
+
{obj.label}
|
|
185
|
+
</NavVerticalItem>
|
|
186
|
+
</NavVertical>
|
|
187
|
+
);
|
|
188
|
+
})}
|
|
189
|
+
</DropdownContent>
|
|
190
|
+
</Dropdown>
|
|
191
|
+
</TableHeadCellBase>
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
1
195
|
export * from '@digigov/react-core/TableContainer';
|
|
2
196
|
export * from '@digigov/react-core/Table';
|
|
3
197
|
export * from '@digigov/react-core/TableBody';
|
|
@@ -8,6 +202,5 @@ export * from '@digigov/react-core/TableHeadCell';
|
|
|
8
202
|
export * from '@digigov/react-core/TableRow';
|
|
9
203
|
export * from '@digigov/react-core/TableNoDataRow';
|
|
10
204
|
export * from '@digigov/ui/core/Table/TableFloatingScroll';
|
|
11
|
-
|
|
12
|
-
import Table from '@digigov/react-core/Table';
|
|
205
|
+
export { TableHeadCellSort, useSortableData };
|
|
13
206
|
export default Table;
|
package/src/core/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from '@digigov/ui/core/Accordion';
|
|
|
6
6
|
export * from '@digigov/ui/core/Blockquote';
|
|
7
7
|
export * from '@digigov/ui/core/Breadcrumbs';
|
|
8
8
|
export * from '@digigov/ui/core/Card';
|
|
9
|
+
export * from '@digigov/ui/core/CaretContainer';
|
|
9
10
|
export * from '@digigov/ui/core/Checkbox';
|
|
10
11
|
export * from '@digigov/ui/core/DateInputContainer';
|
|
11
12
|
export * from '@digigov/ui/core/Details';
|
package/src/registry.js
CHANGED
|
@@ -72,6 +72,7 @@ import * as _digigov_ui_core_Button_Icon from '@digigov/ui/core/Button/Icon';
|
|
|
72
72
|
import * as _digigov_ui_core_Button from '@digigov/ui/core/Button';
|
|
73
73
|
import * as _digigov_ui_core_Button_ThemeToggleButton from '@digigov/ui/core/Button/ThemeToggleButton';
|
|
74
74
|
import * as _digigov_ui_core_Card from '@digigov/ui/core/Card';
|
|
75
|
+
import * as _digigov_ui_core_CaretContainer from '@digigov/ui/core/CaretContainer';
|
|
75
76
|
import * as _digigov_ui_core_Checkbox from '@digigov/ui/core/Checkbox';
|
|
76
77
|
import * as _digigov_ui_core_DateInputContainer from '@digigov/ui/core/DateInputContainer';
|
|
77
78
|
import * as _digigov_ui_core_Details from '@digigov/ui/core/Details';
|
|
@@ -287,6 +288,7 @@ export default {
|
|
|
287
288
|
'@digigov/ui/core/Button': lazyImport(_digigov_ui_core_Button),
|
|
288
289
|
'@digigov/ui/core/Button/ThemeToggleButton': lazyImport(_digigov_ui_core_Button_ThemeToggleButton),
|
|
289
290
|
'@digigov/ui/core/Card': lazyImport(_digigov_ui_core_Card),
|
|
291
|
+
'@digigov/ui/core/CaretContainer': lazyImport(_digigov_ui_core_CaretContainer),
|
|
290
292
|
'@digigov/ui/core/Checkbox': lazyImport(_digigov_ui_core_Checkbox),
|
|
291
293
|
'@digigov/ui/core/DateInputContainer': lazyImport(_digigov_ui_core_DateInputContainer),
|
|
292
294
|
'@digigov/ui/core/Details': lazyImport(_digigov_ui_core_Details),
|