@xqmsg/ui-core 0.15.2 → 0.15.4
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/table/empty/index.d.ts +5 -0
- package/dist/components/table/index.d.ts +1 -1
- package/dist/hooks/useOnOutsideClick.d.ts +2 -0
- package/dist/ui-core.cjs.development.js +86 -18
- package/dist/ui-core.cjs.development.js.map +1 -1
- package/dist/ui-core.cjs.production.min.js +1 -1
- package/dist/ui-core.cjs.production.min.js.map +1 -1
- package/dist/ui-core.esm.js +87 -19
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/input/StackedMultiSelect/index.tsx +3 -12
- package/src/components/input/StackedSelect/StackedSelect.tsx +2 -2
- package/src/components/input/components/dropdown/index.tsx +1 -1
- package/src/components/table/empty/index.tsx +47 -0
- package/src/components/table/index.tsx +30 -29
- package/src/hooks/useOnOutsideClick.tsx +31 -0
package/package.json
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Flex,
|
|
5
|
-
Text,
|
|
6
|
-
Image,
|
|
7
|
-
useOutsideClick,
|
|
8
|
-
Input,
|
|
9
|
-
} from '@chakra-ui/react';
|
|
2
|
+
import { Box, Flex, Text, Image, Input } from '@chakra-ui/react';
|
|
10
3
|
import {
|
|
11
4
|
FieldOption,
|
|
12
5
|
FieldOptions,
|
|
@@ -24,6 +17,7 @@ import {
|
|
|
24
17
|
import SubtractIcon from '../StackedSelect/assets/svg/subtract.svg';
|
|
25
18
|
import { Dropdown } from '../components/dropdown';
|
|
26
19
|
import Token from '../components/token';
|
|
20
|
+
import { useOnClickOutside } from '../../../hooks/useOnOutsideClick';
|
|
27
21
|
|
|
28
22
|
export interface StackedMultiSelectProps extends ReactSelectFieldProps {
|
|
29
23
|
options: FieldOptions;
|
|
@@ -62,10 +56,7 @@ const StackedMultiSelect = React.forwardRef<
|
|
|
62
56
|
}
|
|
63
57
|
}, [boundingClientRect]);
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
ref: dropdownRef,
|
|
67
|
-
handler: () => setIsFocussed(false),
|
|
68
|
-
});
|
|
59
|
+
useOnClickOutside(dropdownRef, () => setIsFocussed(false));
|
|
69
60
|
|
|
70
61
|
// gets latest watched form value (common delimited) from RHF state and creates a list
|
|
71
62
|
useEffect(() => {
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
Input,
|
|
6
6
|
InputGroup,
|
|
7
7
|
InputRightElement,
|
|
8
|
-
useOutsideClick,
|
|
9
8
|
} from '@chakra-ui/react';
|
|
10
9
|
import { FieldOptions } from '../InputTypes';
|
|
11
10
|
import { StackedInputProps } from '../StackedInput/StackedInput';
|
|
@@ -14,6 +13,7 @@ import { UseFormSetValue, FieldValues, Control } from 'react-hook-form';
|
|
|
14
13
|
import SubtractIcon from './assets/svg/subtract.svg';
|
|
15
14
|
import { Dropdown } from '../components/dropdown';
|
|
16
15
|
import useDidMountEffect from '../../../hooks/useDidMountEffect';
|
|
16
|
+
import { useOnClickOutside } from '../../../hooks/useOnOutsideClick';
|
|
17
17
|
|
|
18
18
|
export interface StackedSelectProps extends StackedInputProps {
|
|
19
19
|
options: FieldOptions;
|
|
@@ -57,7 +57,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
|
|
|
57
57
|
);
|
|
58
58
|
}, [value]);
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
useOnClickOutside(dropdownRef, () => setIsFocussed(false));
|
|
61
61
|
|
|
62
62
|
const handleOnSelectItem = (option: {
|
|
63
63
|
label: string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Table as ChakraTable, Tbody, Td, Tr } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A React component utilized to render the `EmptyTable` component
|
|
6
|
+
*/
|
|
7
|
+
export const EmptyTable: React.FC = () => {
|
|
8
|
+
const getOpacity = (index: number) => {
|
|
9
|
+
switch (index) {
|
|
10
|
+
case 1:
|
|
11
|
+
return 0.7;
|
|
12
|
+
case 3:
|
|
13
|
+
return 0.6;
|
|
14
|
+
case 5:
|
|
15
|
+
return 0.5;
|
|
16
|
+
case 7:
|
|
17
|
+
return 0.4;
|
|
18
|
+
case 9:
|
|
19
|
+
return 0.3;
|
|
20
|
+
case 11:
|
|
21
|
+
return 0.2;
|
|
22
|
+
case 13:
|
|
23
|
+
return 0.1;
|
|
24
|
+
default:
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<ChakraTable
|
|
31
|
+
variant="unstyled"
|
|
32
|
+
width="100%"
|
|
33
|
+
style={{
|
|
34
|
+
borderCollapse: 'separate',
|
|
35
|
+
borderSpacing: '0px',
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<Tbody>
|
|
39
|
+
{Array.from({ length: 14 }, (_, i) => i + 1).map(i => (
|
|
40
|
+
<Tr>
|
|
41
|
+
<Td height="23px" opacity={getOpacity(i)}></Td>
|
|
42
|
+
</Tr>
|
|
43
|
+
))}
|
|
44
|
+
</Tbody>
|
|
45
|
+
</ChakraTable>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -9,7 +9,6 @@ import { generateTableColumnsAsConst } from './utils/generateTableColumns';
|
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
Table as ChakraTable,
|
|
12
|
-
TableCaption,
|
|
13
12
|
TableContainer,
|
|
14
13
|
Tbody,
|
|
15
14
|
Td,
|
|
@@ -19,6 +18,7 @@ import {
|
|
|
19
18
|
} from '@chakra-ui/react';
|
|
20
19
|
import { TableLoadingRows } from './components/loading';
|
|
21
20
|
import colors from '../../theme/foundations/colors';
|
|
21
|
+
import { EmptyTable } from './empty';
|
|
22
22
|
|
|
23
23
|
export interface TableProps<T extends ReadonlyTableColumns> {
|
|
24
24
|
columns: TableColumns;
|
|
@@ -36,46 +36,47 @@ export function Table<T extends ReadonlyTableColumns>({
|
|
|
36
36
|
columns,
|
|
37
37
|
headers,
|
|
38
38
|
body,
|
|
39
|
-
placeholder = 'There is currently no available data',
|
|
40
39
|
loading,
|
|
41
|
-
|
|
42
40
|
loadMore,
|
|
43
41
|
}: TableProps<T>) {
|
|
44
42
|
const columnsAsConst = generateTableColumnsAsConst(columns);
|
|
45
43
|
|
|
46
44
|
return (
|
|
47
45
|
<TableContainer border="none" overflowX="auto" bg="white" width="100%">
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<
|
|
58
|
-
{
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
<Th>{headers[column]}</Th>
|
|
61
|
-
))}
|
|
62
|
-
</Tr>
|
|
63
|
-
</Thead>
|
|
64
|
-
<Tbody>
|
|
65
|
-
{body.map(row => (
|
|
66
|
-
<Tr>
|
|
46
|
+
{body.length ? (
|
|
47
|
+
<ChakraTable
|
|
48
|
+
variant="unstyled"
|
|
49
|
+
width="100%"
|
|
50
|
+
style={{
|
|
51
|
+
borderCollapse: 'separate',
|
|
52
|
+
borderSpacing: '0px',
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<Thead>
|
|
56
|
+
<Tr _odd={{ bg: colors.label.primary.dark }}>
|
|
67
57
|
{columnsAsConst.map(column => (
|
|
68
58
|
// @ts-ignore
|
|
69
|
-
<
|
|
59
|
+
<Th>{headers[column]}</Th>
|
|
70
60
|
))}
|
|
71
61
|
</Tr>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
</Thead>
|
|
63
|
+
<Tbody>
|
|
64
|
+
{body.map(row => (
|
|
65
|
+
<Tr>
|
|
66
|
+
{columnsAsConst.map(column => (
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
<Td>{row[column]}</Td>
|
|
69
|
+
))}
|
|
70
|
+
</Tr>
|
|
71
|
+
))}
|
|
72
|
+
</Tbody>
|
|
73
|
+
</ChakraTable>
|
|
74
|
+
) : (
|
|
75
|
+
<EmptyTable />
|
|
78
76
|
)}
|
|
77
|
+
{loadMore && loading !== undefined && body.length ? (
|
|
78
|
+
<TableLoadingRows isLoading={loading} onLoadMore={loadMore} />
|
|
79
|
+
) : null}
|
|
79
80
|
</TableContainer>
|
|
80
81
|
);
|
|
81
82
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RefObject, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useOnClickOutside(ref: RefObject<any>, handler: () => void) {
|
|
4
|
+
useEffect(
|
|
5
|
+
() => {
|
|
6
|
+
const listener: EventListener = event => {
|
|
7
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
8
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
handler();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
document.addEventListener('mousedown', listener);
|
|
16
|
+
document.addEventListener('touchstart', listener);
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
document.removeEventListener('mousedown', listener);
|
|
20
|
+
document.removeEventListener('touchstart', listener);
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
// Add ref and handler to effect dependencies
|
|
24
|
+
// It's worth noting that because passed in handler is a new ...
|
|
25
|
+
// ... function on every render that will cause this effect ...
|
|
26
|
+
// ... callback/cleanup to run every render. It's not a big deal ...
|
|
27
|
+
// ... but to optimize you can wrap handler in useCallback before ...
|
|
28
|
+
// ... passing it into this hook.
|
|
29
|
+
[ref, handler]
|
|
30
|
+
);
|
|
31
|
+
}
|