@coveord/plasma-mantine 47.9.3 → 48.1.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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-test.log +8 -8
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/__tests__/Utils.js.map +1 -1
- package/dist/cjs/components/blank-slate/BlankSlate.js.map +1 -1
- package/dist/cjs/components/collection/Collection.js +9 -4
- package/dist/cjs/components/collection/Collection.js.map +1 -1
- package/dist/cjs/components/collection/CollectionItem.js.map +1 -1
- package/dist/cjs/components/header/Header.js.map +1 -1
- package/dist/cjs/components/inline-confirm/InlineConfirm.js.map +1 -1
- package/dist/cjs/components/modal-wizard/ModalWizardStep.js.map +1 -1
- package/dist/cjs/components/prompt/PromptFooter.js.map +1 -1
- package/dist/cjs/components/sticky-footer/StickyFooter.js.map +1 -1
- package/dist/cjs/components/table/Table.js +45 -39
- package/dist/cjs/components/table/Table.js.map +1 -1
- package/dist/cjs/components/table/TableFooter.js.map +1 -1
- package/dist/cjs/components/table/TableHeader.js.map +1 -1
- package/dist/cjs/theme/Plasmantine.js.map +1 -1
- package/dist/definitions/__tests__/Utils.d.ts.map +1 -1
- package/dist/definitions/components/blank-slate/BlankSlate.d.ts +2 -2
- package/dist/definitions/components/blank-slate/BlankSlate.d.ts.map +1 -1
- package/dist/definitions/components/collection/Collection.d.ts +1 -0
- package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
- package/dist/definitions/components/collection/CollectionItem.d.ts +2 -2
- package/dist/definitions/components/collection/CollectionItem.d.ts.map +1 -1
- package/dist/definitions/components/header/Header.d.ts +2 -2
- package/dist/definitions/components/header/Header.d.ts.map +1 -1
- package/dist/definitions/components/inline-confirm/InlineConfirm.d.ts +2 -2
- package/dist/definitions/components/inline-confirm/InlineConfirm.d.ts.map +1 -1
- package/dist/definitions/components/modal-wizard/ModalWizardStep.d.ts +2 -2
- package/dist/definitions/components/modal-wizard/ModalWizardStep.d.ts.map +1 -1
- package/dist/definitions/components/prompt/PromptFooter.d.ts +2 -2
- package/dist/definitions/components/prompt/PromptFooter.d.ts.map +1 -1
- package/dist/definitions/components/sticky-footer/StickyFooter.d.ts +2 -2
- package/dist/definitions/components/sticky-footer/StickyFooter.d.ts.map +1 -1
- package/dist/definitions/components/table/Table.d.ts.map +1 -1
- package/dist/definitions/components/table/TableFooter.d.ts +2 -2
- package/dist/definitions/components/table/TableFooter.d.ts.map +1 -1
- package/dist/definitions/components/table/TableHeader.d.ts +2 -2
- package/dist/definitions/components/table/TableHeader.d.ts.map +1 -1
- package/dist/definitions/theme/Plasmantine.d.ts +2 -2
- package/dist/definitions/theme/Plasmantine.d.ts.map +1 -1
- package/dist/esm/__tests__/Utils.js.map +1 -1
- package/dist/esm/components/blank-slate/BlankSlate.js.map +1 -1
- package/dist/esm/components/collection/Collection.js +9 -4
- package/dist/esm/components/collection/Collection.js.map +1 -1
- package/dist/esm/components/collection/CollectionItem.js.map +1 -1
- package/dist/esm/components/header/Header.js.map +1 -1
- package/dist/esm/components/inline-confirm/InlineConfirm.js.map +1 -1
- package/dist/esm/components/modal-wizard/ModalWizardStep.js.map +1 -1
- package/dist/esm/components/prompt/PromptFooter.js.map +1 -1
- package/dist/esm/components/sticky-footer/StickyFooter.js.map +1 -1
- package/dist/esm/components/table/Table.js +47 -41
- package/dist/esm/components/table/Table.js.map +1 -1
- package/dist/esm/components/table/TableFooter.js.map +1 -1
- package/dist/esm/components/table/TableHeader.js.map +1 -1
- package/dist/esm/theme/Plasmantine.js.map +1 -1
- package/package.json +19 -20
- package/src/__tests__/Utils.tsx +2 -2
- package/src/components/blank-slate/BlankSlate.tsx +2 -2
- package/src/components/collection/Collection.tsx +8 -1
- package/src/components/collection/CollectionItem.tsx +9 -5
- package/src/components/collection/__tests__/Collection.spec.tsx +27 -0
- package/src/components/header/Header.tsx +2 -2
- package/src/components/inline-confirm/InlineConfirm.tsx +2 -2
- package/src/components/modal-wizard/ModalWizardStep.tsx +4 -2
- package/src/components/modal-wizard/__tests__/ModalWizard.spec.tsx +1 -1
- package/src/components/prompt/PromptFooter.tsx +2 -2
- package/src/components/sticky-footer/StickyFooter.tsx +6 -2
- package/src/components/table/Table.tsx +42 -36
- package/src/components/table/TableFooter.tsx +2 -2
- package/src/components/table/TableHeader.tsx +2 -2
- package/src/components/table/__tests__/Table.spec.tsx +27 -0
- package/src/components/table/__tests__/Th.spec.tsx +2 -1
- package/src/hooks/__tests__/useControlledList.spec.tsx +1 -1
- package/src/theme/Plasmantine.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coveord/plasma-mantine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "48.1.0",
|
|
4
4
|
"description": "A Plasma flavoured Mantine theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plasma",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"module": "dist/esm/index.js",
|
|
22
22
|
"types": "./dist/definitions/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@coveord/plasma-react-icons": "
|
|
24
|
+
"@coveord/plasma-react-icons": "48.0.0",
|
|
25
25
|
"@coveord/plasma-tokens": "47.3.7",
|
|
26
26
|
"@monaco-editor/react": "4.4.5",
|
|
27
27
|
"@swc/helpers": "0.4.11",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dayjs": "1.11.3",
|
|
31
31
|
"lodash.defaultsdeep": "4.6.1",
|
|
32
32
|
"monaco-editor": "0.34.0",
|
|
33
|
-
"react-beautiful-dnd": "13.1.
|
|
33
|
+
"react-beautiful-dnd": "13.1.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@emotion/react": "11.10.0",
|
|
@@ -42,31 +42,30 @@
|
|
|
42
42
|
"@mantine/modals": "5.6.2",
|
|
43
43
|
"@swc/cli": "0.1.57",
|
|
44
44
|
"@swc/core": "1.3.3",
|
|
45
|
-
"@swc/jest": "0.2.
|
|
46
|
-
"@testing-library/dom": "8.
|
|
45
|
+
"@swc/jest": "0.2.23",
|
|
46
|
+
"@testing-library/dom": "8.18.1",
|
|
47
47
|
"@testing-library/jest-dom": "5.16.5",
|
|
48
|
-
"@testing-library/react": "
|
|
49
|
-
"@testing-library/react-hooks": "8.0.1",
|
|
48
|
+
"@testing-library/react": "13.4.0",
|
|
50
49
|
"@testing-library/user-event": "12.8.3",
|
|
51
|
-
"@types/jest": "
|
|
50
|
+
"@types/jest": "29.1.2",
|
|
52
51
|
"@types/lodash.defaultsdeep": "4.6.7",
|
|
53
|
-
"@types/react": "
|
|
52
|
+
"@types/react": "18.0.21",
|
|
54
53
|
"@types/react-beautiful-dnd": "13.1.2",
|
|
55
|
-
"@types/react-dom": "
|
|
54
|
+
"@types/react-dom": "18.0.6",
|
|
56
55
|
"@types/testing-library__jest-dom": "5.14.5",
|
|
57
56
|
"embla-carousel-react": "7.0.4",
|
|
58
|
-
"eslint-plugin-jest": "
|
|
59
|
-
"eslint-plugin-testing-library": "5.
|
|
57
|
+
"eslint-plugin-jest": "27.1.1",
|
|
58
|
+
"eslint-plugin-testing-library": "5.7.2",
|
|
60
59
|
"identity-obj-proxy": "3.0.0",
|
|
61
|
-
"jest": "
|
|
62
|
-
"jest-environment-jsdom": "
|
|
60
|
+
"jest": "29.2.1",
|
|
61
|
+
"jest-environment-jsdom": "29.1.2",
|
|
63
62
|
"jest-junit": "13.2.0",
|
|
64
63
|
"npm-run-all": "4.1.5",
|
|
65
|
-
"react": "
|
|
66
|
-
"react-dom": "
|
|
64
|
+
"react": "18.2.0",
|
|
65
|
+
"react-dom": "18.2.0",
|
|
67
66
|
"rimraf": "3.0.2",
|
|
68
|
-
"tslib": "2.
|
|
69
|
-
"typescript": "4.
|
|
67
|
+
"tslib": "2.4.0",
|
|
68
|
+
"typescript": "4.7.4"
|
|
70
69
|
},
|
|
71
70
|
"peerDependencies": {
|
|
72
71
|
"@emotion/react": "^11.10.0",
|
|
@@ -77,8 +76,8 @@
|
|
|
77
76
|
"@mantine/hooks": "^5.6.2",
|
|
78
77
|
"@mantine/modals": "^5.6.2",
|
|
79
78
|
"embla-carousel-react": "7.0.4",
|
|
80
|
-
"react": ">=
|
|
81
|
-
"react-dom": ">=
|
|
79
|
+
"react": ">= 18.0.0",
|
|
80
|
+
"react-dom": ">= 18.0.0"
|
|
82
81
|
},
|
|
83
82
|
"scripts": {
|
|
84
83
|
"build": "node ../../scripts/build",
|
package/src/__tests__/Utils.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {render, RenderOptions, RenderResult} from '@testing-library/react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import {FunctionComponent, ReactElement} from 'react';
|
|
3
|
+
import {FunctionComponent, PropsWithChildren, ReactElement} from 'react';
|
|
4
4
|
|
|
5
5
|
import {Plasmantine} from '../theme';
|
|
6
6
|
|
|
7
7
|
const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'queries'>): RenderResult => {
|
|
8
|
-
const TestWrapper: FunctionComponent = ({children}) => <Plasmantine>{children}</Plasmantine>;
|
|
8
|
+
const TestWrapper: FunctionComponent<PropsWithChildren> = ({children}) => <Plasmantine>{children}</Plasmantine>;
|
|
9
9
|
|
|
10
10
|
return render(ui, {wrapper: TestWrapper, ...options});
|
|
11
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Paper, Stack} from '@mantine/core';
|
|
2
|
-
import {FunctionComponent} from 'react';
|
|
2
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
3
3
|
|
|
4
4
|
interface BlankSlateProps {
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ interface BlankSlateProps {
|
|
|
10
10
|
withBorder?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const BlankSlate: FunctionComponent<BlankSlateProps
|
|
13
|
+
export const BlankSlate: FunctionComponent<PropsWithChildren<BlankSlateProps>> = ({children, withBorder = true}) => (
|
|
14
14
|
<Paper shadow={withBorder && 'xs'} p="xl" withBorder={withBorder}>
|
|
15
15
|
<Stack align="center">{children}</Stack>
|
|
16
16
|
</Paper>
|
|
@@ -25,6 +25,7 @@ interface CollectionProps<T> extends DefaultProps<Selectors<typeof useStyles>> {
|
|
|
25
25
|
value?: T[];
|
|
26
26
|
onFocus?: () => void;
|
|
27
27
|
onChange?: (value: T[]) => void;
|
|
28
|
+
onRemoveItem?: (itemIndex: number) => void;
|
|
28
29
|
draggable?: boolean;
|
|
29
30
|
disabled?: boolean;
|
|
30
31
|
allowAdd?: (values: T[]) => boolean;
|
|
@@ -48,6 +49,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
|
|
|
48
49
|
value,
|
|
49
50
|
defaultValue,
|
|
50
51
|
onChange,
|
|
52
|
+
onRemoveItem,
|
|
51
53
|
disabled,
|
|
52
54
|
draggable,
|
|
53
55
|
children,
|
|
@@ -71,13 +73,18 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
|
|
|
71
73
|
|
|
72
74
|
const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});
|
|
73
75
|
const hasOnlyOneItem = values.length === 1;
|
|
76
|
+
const removeItem = (index: number) => () => {
|
|
77
|
+
remove(index);
|
|
78
|
+
onRemoveItem?.(index);
|
|
79
|
+
};
|
|
80
|
+
|
|
74
81
|
const items = values.map((item, index) => (
|
|
75
82
|
<CollectionItem
|
|
76
83
|
key={index}
|
|
77
84
|
disabled={disabled}
|
|
78
85
|
draggable={draggable}
|
|
79
86
|
index={index}
|
|
80
|
-
onRemove={(
|
|
87
|
+
onRemove={removeItem(index)}
|
|
81
88
|
styles={styles}
|
|
82
89
|
removable={!(required && hasOnlyOneItem)}
|
|
83
90
|
>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {DragAndDropSize16Px, RemoveSize16Px} from '@coveord/plasma-react-icons';
|
|
2
2
|
import {ActionIcon, DefaultProps, Group, Selectors} from '@mantine/core';
|
|
3
|
-
import {FunctionComponent} from 'react';
|
|
3
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
4
4
|
import {Draggable} from 'react-beautiful-dnd';
|
|
5
5
|
|
|
6
6
|
import useStyles from './Colllection.styles';
|
|
@@ -26,7 +26,7 @@ const RemoveButton: FunctionComponent<{
|
|
|
26
26
|
|
|
27
27
|
const RemoveButtonPlaceholder = () => <div style={{width: 28}} />;
|
|
28
28
|
|
|
29
|
-
const StaticCollectionItem: FunctionComponent<CollectionItemSharedProps
|
|
29
|
+
const StaticCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({
|
|
30
30
|
onRemove,
|
|
31
31
|
removable = true,
|
|
32
32
|
styles,
|
|
@@ -43,12 +43,12 @@ const StaticCollectionItem: FunctionComponent<CollectionItemSharedProps> = ({
|
|
|
43
43
|
);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const DisabledCollectionItem: FunctionComponent<CollectionItemSharedProps
|
|
46
|
+
const DisabledCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({children}) => {
|
|
47
47
|
const {classes, cx} = useStyles();
|
|
48
48
|
return <Group className={cx(classes.item)}>{children}</Group>;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const DraggableCollectionItem: FunctionComponent<CollectionItemSharedProps
|
|
51
|
+
const DraggableCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({
|
|
52
52
|
index,
|
|
53
53
|
onRemove,
|
|
54
54
|
removable = true,
|
|
@@ -77,7 +77,11 @@ const DraggableCollectionItem: FunctionComponent<CollectionItemSharedProps> = ({
|
|
|
77
77
|
);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
export const CollectionItem: FunctionComponent<CollectionItemProps
|
|
80
|
+
export const CollectionItem: FunctionComponent<PropsWithChildren<CollectionItemProps>> = ({
|
|
81
|
+
draggable,
|
|
82
|
+
disabled,
|
|
83
|
+
...otherProps
|
|
84
|
+
}) => {
|
|
81
85
|
if (disabled) {
|
|
82
86
|
return <DisabledCollectionItem {...otherProps} />;
|
|
83
87
|
}
|
|
@@ -51,6 +51,33 @@ describe('Collection', () => {
|
|
|
51
51
|
expect(screen.getByTestId('form-state')).toHaveTextContent('{"fruits":["orange"]}');
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
it('calls the onRemoveItem function when clicking on a remove button', async () => {
|
|
55
|
+
const onRemoveItemSpy = jest.fn();
|
|
56
|
+
const Fixture = () => {
|
|
57
|
+
const form = useForm({initialValues: {fruits: ['banana', 'orange']}});
|
|
58
|
+
return (
|
|
59
|
+
<Collection newItem="" {...form.getInputProps('fruits')} onRemoveItem={onRemoveItemSpy}>
|
|
60
|
+
{(name) => <span data-testid="item">{name}</span>}
|
|
61
|
+
</Collection>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
render(<Fixture />);
|
|
66
|
+
let items = screen.getAllByTestId('item');
|
|
67
|
+
expect(items).toHaveLength(2);
|
|
68
|
+
/* eslint-disable-next-line testing-library/no-node-access */
|
|
69
|
+
const removeOrange = await within(items[1].parentElement).findByRole('button', {name: /remove/i});
|
|
70
|
+
userEvent.click(removeOrange);
|
|
71
|
+
|
|
72
|
+
expect(onRemoveItemSpy).toHaveBeenCalledWith(1);
|
|
73
|
+
|
|
74
|
+
items = screen.getAllByTestId('item');
|
|
75
|
+
const removeBanana = await within(items[0].parentElement).findByRole('button', {name: /remove/i});
|
|
76
|
+
userEvent.click(removeBanana);
|
|
77
|
+
|
|
78
|
+
expect(onRemoveItemSpy).toHaveBeenCalledWith(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
54
81
|
it('does not render the remove button when disabled', async () => {
|
|
55
82
|
const Fixture = () => {
|
|
56
83
|
const [disabled, setDisabled] = useState(false);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {QuestionSize24Px} from '@coveord/plasma-react-icons';
|
|
2
2
|
import {Anchor, Breadcrumbs, DefaultProps, Divider, Group, Stack, Text, Title, Tooltip} from '@mantine/core';
|
|
3
|
-
import {FunctionComponent, ReactNode} from 'react';
|
|
3
|
+
import {FunctionComponent, PropsWithChildren, ReactNode} from 'react';
|
|
4
4
|
|
|
5
5
|
interface HeaderProps extends DefaultProps {
|
|
6
6
|
description?: ReactNode;
|
|
@@ -10,7 +10,7 @@ interface HeaderProps extends DefaultProps {
|
|
|
10
10
|
docLinkTooltipLabel?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const Header: FunctionComponent<HeaderProps
|
|
13
|
+
export const Header: FunctionComponent<PropsWithChildren<HeaderProps>> = ({
|
|
14
14
|
description,
|
|
15
15
|
actions,
|
|
16
16
|
borderBottom,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {Children, FunctionComponent, ReactElement, useState} from 'react';
|
|
1
|
+
import {Children, FunctionComponent, PropsWithChildren, ReactElement, useState} from 'react';
|
|
2
2
|
|
|
3
3
|
import {InlineConfirmButton} from './InlineConfirmButton';
|
|
4
4
|
import {InlineConfirmContext} from './InlineConfirmContext';
|
|
5
5
|
import {InlineConfirmPrompt} from './InlineConfirmPrompt';
|
|
6
6
|
|
|
7
|
-
type InlineConfirmType = FunctionComponent & {
|
|
7
|
+
type InlineConfirmType = FunctionComponent<PropsWithChildren> & {
|
|
8
8
|
Prompt: typeof InlineConfirmPrompt;
|
|
9
9
|
Button: typeof InlineConfirmButton;
|
|
10
10
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {FunctionComponent, ReactElement} from 'react';
|
|
1
|
+
import {FunctionComponent, PropsWithChildren, ReactElement} from 'react';
|
|
2
2
|
|
|
3
3
|
type DependsOnStep<T> = (currentStep: number, numberOfSteps: number) => T;
|
|
4
4
|
|
|
@@ -43,7 +43,9 @@ export interface ModalWizardStepProps {
|
|
|
43
43
|
countsAsProgress?: boolean;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const ModalWizardStep: FunctionComponent<ModalWizardStepProps
|
|
46
|
+
const ModalWizardStep: FunctionComponent<PropsWithChildren<ModalWizardStepProps>> = ({children}) => (
|
|
47
|
+
<div>{children}</div>
|
|
48
|
+
);
|
|
47
49
|
|
|
48
50
|
ModalWizardStep.defaultProps = {
|
|
49
51
|
showProgressBar: true,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {FunctionComponent} from 'react';
|
|
1
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
2
2
|
import {StickyFooter, StickyFooterProps} from '../sticky-footer';
|
|
3
3
|
|
|
4
4
|
export interface PromptFooterProps extends StickyFooterProps {}
|
|
5
5
|
|
|
6
|
-
export const PromptFooter: FunctionComponent<PromptFooterProps
|
|
6
|
+
export const PromptFooter: FunctionComponent<PropsWithChildren<PromptFooterProps>> = ({children, ...otherProps}) => (
|
|
7
7
|
<StickyFooter {...otherProps}>{children}</StickyFooter>
|
|
8
8
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {createStyles, DefaultProps, Divider, Group, Paper} from '@mantine/core';
|
|
2
|
-
import {FunctionComponent} from 'react';
|
|
2
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
3
3
|
|
|
4
4
|
export interface StickyFooterProps extends DefaultProps {
|
|
5
5
|
/**
|
|
@@ -17,7 +17,11 @@ const useStyles = createStyles(() => ({
|
|
|
17
17
|
},
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
|
-
export const StickyFooter: FunctionComponent<StickyFooterProps
|
|
20
|
+
export const StickyFooter: FunctionComponent<PropsWithChildren<StickyFooterProps>> = ({
|
|
21
|
+
borderTop,
|
|
22
|
+
children,
|
|
23
|
+
...others
|
|
24
|
+
}) => {
|
|
21
25
|
const {classes} = useStyles();
|
|
22
26
|
|
|
23
27
|
return (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {Center, Collapse, createStyles, Loader, Skeleton, Table as MantineTable} from '@mantine/core';
|
|
1
|
+
import {Box, Center, Collapse, createStyles, Loader, Skeleton, Table as MantineTable} from '@mantine/core';
|
|
2
2
|
import {useForm} from '@mantine/form';
|
|
3
|
-
import {useDidUpdate} from '@mantine/hooks';
|
|
3
|
+
import {useClickOutside, useDidUpdate} from '@mantine/hooks';
|
|
4
4
|
import {
|
|
5
5
|
ColumnDef,
|
|
6
6
|
defaultColumnSizing,
|
|
@@ -175,6 +175,10 @@ export const Table: TableType = <T,>({
|
|
|
175
175
|
onMount?.({...state, ...form.values});
|
|
176
176
|
}, []);
|
|
177
177
|
|
|
178
|
+
const outsideClickRef = useClickOutside(() => {
|
|
179
|
+
table.resetRowSelection(true);
|
|
180
|
+
});
|
|
181
|
+
|
|
178
182
|
useDidUpdate(() => {
|
|
179
183
|
triggerChange();
|
|
180
184
|
clearSelection();
|
|
@@ -244,40 +248,42 @@ export const Table: TableType = <T,>({
|
|
|
244
248
|
});
|
|
245
249
|
|
|
246
250
|
return (
|
|
247
|
-
<
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<
|
|
261
|
-
{
|
|
262
|
-
|
|
263
|
-
{headerGroup.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
rows
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
<
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
251
|
+
<Box ref={outsideClickRef}>
|
|
252
|
+
<TableContext.Provider
|
|
253
|
+
value={{
|
|
254
|
+
onChange: triggerChange,
|
|
255
|
+
state,
|
|
256
|
+
setState,
|
|
257
|
+
clearFilters,
|
|
258
|
+
getSelectedRow,
|
|
259
|
+
clearSelection,
|
|
260
|
+
form,
|
|
261
|
+
}}
|
|
262
|
+
>
|
|
263
|
+
{header}
|
|
264
|
+
<MantineTable className={classes.table} horizontalSpacing="sm" verticalSpacing="xs" pb="sm">
|
|
265
|
+
<thead className={classes.header}>
|
|
266
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
267
|
+
<tr key={headerGroup.id}>
|
|
268
|
+
{headerGroup.headers.map((columnHeader) => (
|
|
269
|
+
<Th key={columnHeader.id} header={columnHeader} />
|
|
270
|
+
))}
|
|
271
|
+
</tr>
|
|
272
|
+
))}
|
|
273
|
+
</thead>
|
|
274
|
+
<tbody>
|
|
275
|
+
{rows.length ? (
|
|
276
|
+
rows
|
|
277
|
+
) : (
|
|
278
|
+
<tr>
|
|
279
|
+
<td colSpan={columns.length}>{noDataChildren}</td>
|
|
280
|
+
</tr>
|
|
281
|
+
)}
|
|
282
|
+
</tbody>
|
|
283
|
+
</MantineTable>
|
|
284
|
+
{footer}
|
|
285
|
+
</TableContext.Provider>
|
|
286
|
+
</Box>
|
|
281
287
|
);
|
|
282
288
|
};
|
|
283
289
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Group} from '@mantine/core';
|
|
2
|
-
import {FunctionComponent} from 'react';
|
|
2
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
3
3
|
|
|
4
|
-
export const TableFooter: FunctionComponent = ({children}) => (
|
|
4
|
+
export const TableFooter: FunctionComponent<PropsWithChildren> = ({children}) => (
|
|
5
5
|
<Group position="apart" px="md" py="sm">
|
|
6
6
|
{children}
|
|
7
7
|
</Group>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {createStyles, Group} from '@mantine/core';
|
|
2
|
-
import {FunctionComponent} from 'react';
|
|
2
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
3
3
|
|
|
4
4
|
const useStyles = createStyles((theme) => ({
|
|
5
5
|
header: {
|
|
@@ -11,7 +11,7 @@ const useStyles = createStyles((theme) => ({
|
|
|
11
11
|
},
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
-
export const TableHeader: FunctionComponent = ({children}) => {
|
|
14
|
+
export const TableHeader: FunctionComponent<PropsWithChildren> = ({children}) => {
|
|
15
15
|
const {classes} = useStyles();
|
|
16
16
|
return (
|
|
17
17
|
<Group position="right" spacing="lg" className={classes.header} px="md" py="sm">
|
|
@@ -125,4 +125,31 @@ describe('Table', () => {
|
|
|
125
125
|
const allRows = screen.getAllByRole('button', {name: 'arrowHeadDown'});
|
|
126
126
|
expect(allRows).toHaveLength(2);
|
|
127
127
|
});
|
|
128
|
+
|
|
129
|
+
it('reset row selection when user click outside the table', () => {
|
|
130
|
+
render(
|
|
131
|
+
<div>
|
|
132
|
+
<div>I'm a header</div>
|
|
133
|
+
<Table
|
|
134
|
+
data={[
|
|
135
|
+
{firstName: 'first', lastName: 'last'},
|
|
136
|
+
{firstName: 'patate', lastName: 'king'},
|
|
137
|
+
]}
|
|
138
|
+
columns={columns}
|
|
139
|
+
/>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const row = screen.getByRole('row', {name: 'patate king'});
|
|
144
|
+
|
|
145
|
+
expect(row).not.toHaveClass('__mantine-ref-rowSelected');
|
|
146
|
+
|
|
147
|
+
userEvent.click(row);
|
|
148
|
+
|
|
149
|
+
expect(row).toHaveClass('__mantine-ref-rowSelected');
|
|
150
|
+
|
|
151
|
+
userEvent.click(screen.getByText(/i'm a header/i));
|
|
152
|
+
|
|
153
|
+
expect(row).not.toHaveClass('__mantine-ref-rowSelected');
|
|
154
|
+
});
|
|
128
155
|
});
|
|
@@ -45,7 +45,7 @@ describe('Th', () => {
|
|
|
45
45
|
await screen.findAllByRole('img', {name: 'arrowHeadDown'});
|
|
46
46
|
await screen.findAllByRole('img', {name: 'arrowHeadUp'});
|
|
47
47
|
|
|
48
|
-
userEvent.click(screen.getByRole('button', {name:
|
|
48
|
+
userEvent.click(screen.getByRole('button', {name: /name arrowheaddown/i}));
|
|
49
49
|
await waitFor(() => {
|
|
50
50
|
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({sorting: [{id: 'name', desc: false}]}));
|
|
51
51
|
});
|
|
@@ -55,6 +55,7 @@ describe('Th', () => {
|
|
|
55
55
|
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({sorting: [{id: 'name', desc: true}]}));
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
await waitFor(() => expect(screen.queryByRole('button', {name: 'name arrowHeadUp'})).toBeVisible());
|
|
58
59
|
userEvent.click(screen.getByRole('button', {name: 'name arrowHeadUp'}));
|
|
59
60
|
await waitFor(() => {
|
|
60
61
|
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({sorting: [{id: 'name', desc: false}]}));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {MantineProvider} from '@mantine/core';
|
|
2
|
-
import {FunctionComponent} from 'react';
|
|
2
|
+
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
3
3
|
|
|
4
4
|
import {plasmaTheme} from './Theme';
|
|
5
5
|
|
|
6
|
-
export const Plasmantine: FunctionComponent = ({children}) => (
|
|
6
|
+
export const Plasmantine: FunctionComponent<PropsWithChildren> = ({children}) => (
|
|
7
7
|
<MantineProvider withGlobalStyles withNormalizeCSS theme={plasmaTheme}>
|
|
8
8
|
{children}
|
|
9
9
|
</MantineProvider>
|