@pautena/react-design-system 0.1.1 → 0.1.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/package.json +1 -1
- package/.eslintrc.js +0 -26
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/deploy-storybook.yaml +0 -23
- package/.github/workflows/publish.yml +0 -31
- package/.husky/pre-commit +0 -5
- package/.prettierignore +0 -5
- package/.storybook/main.js +0 -10
- package/.storybook/preview.js +0 -36
- package/babel.config.js +0 -13
- package/jest.config.js +0 -17
- package/jest.setup.ts +0 -5
- package/rollup.config.js +0 -52
- package/src/components/app-bar/app-bar.stories.tsx +0 -54
- package/src/components/app-bar/app-bar.test.tsx +0 -142
- package/src/components/app-bar/app-bar.tsx +0 -150
- package/src/components/app-bar/app-bar.types.ts +0 -17
- package/src/components/app-bar/index.ts +0 -3
- package/src/components/app-bar/mini-app-bar/index.ts +0 -1
- package/src/components/app-bar/mini-app-bar/mini-app-bar.tsx +0 -31
- package/src/components/bullet/bullet.stories.tsx +0 -43
- package/src/components/bullet/bullet.test.tsx +0 -24
- package/src/components/bullet/bullet.tsx +0 -30
- package/src/components/bullet/index.ts +0 -1
- package/src/components/center-container/center-container.stories.tsx +0 -50
- package/src/components/center-container/center-container.test.tsx +0 -16
- package/src/components/center-container/center-container.tsx +0 -32
- package/src/components/center-container/index.ts +0 -1
- package/src/components/content/content.stories.tsx +0 -23
- package/src/components/content/content.test.tsx +0 -26
- package/src/components/content/content.tsx +0 -11
- package/src/components/content/content.types.ts +0 -5
- package/src/components/content/index.ts +0 -2
- package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +0 -20
- package/src/components/drawer/drawer.context.ts +0 -20
- package/src/components/drawer/drawer.mixins.ts +0 -24
- package/src/components/drawer/drawer.mock.tsx +0 -100
- package/src/components/drawer/drawer.provider.tsx +0 -23
- package/src/components/drawer/drawer.test.tsx +0 -97
- package/src/components/drawer/drawer.tsx +0 -30
- package/src/components/drawer/drawer.types.ts +0 -53
- package/src/components/drawer/index.ts +0 -5
- package/src/components/drawer/mini-drawer/index.ts +0 -1
- package/src/components/drawer/mini-drawer/mini-drawer.stories.tsx +0 -34
- package/src/components/drawer/mini-drawer/mini-drawer.tsx +0 -67
- package/src/components/drawer-content/drawer-content.stories.tsx +0 -29
- package/src/components/drawer-content/drawer-content.test.tsx +0 -34
- package/src/components/drawer-content/drawer-content.tsx +0 -18
- package/src/components/drawer-content/index.ts +0 -1
- package/src/components/drawer-item/drawer-item.stories.tsx +0 -62
- package/src/components/drawer-item/drawer-item.test.tsx +0 -119
- package/src/components/drawer-item/drawer-item.tsx +0 -71
- package/src/components/drawer-item/index.ts +0 -1
- package/src/components/drawer-section/drawer-section.mock.tsx +0 -39
- package/src/components/drawer-section/drawer-section.stories.tsx +0 -28
- package/src/components/drawer-section/drawer-section.test.tsx +0 -44
- package/src/components/drawer-section/drawer-section.tsx +0 -40
- package/src/components/drawer-section/index.ts +0 -1
- package/src/components/header/header.dummy.ts +0 -55
- package/src/components/header/header.stories.tsx +0 -116
- package/src/components/header/header.test.tsx +0 -169
- package/src/components/header/header.tsx +0 -121
- package/src/components/header/header.types.ts +0 -61
- package/src/components/header/index.ts +0 -2
- package/src/components/index.ts +0 -18
- package/src/components/label/index.ts +0 -1
- package/src/components/label/label.stories.tsx +0 -49
- package/src/components/label/label.test.tsx +0 -30
- package/src/components/label/label.tsx +0 -60
- package/src/components/link/index.ts +0 -1
- package/src/components/link/link.tsx +0 -17
- package/src/components/loading-area/index.ts +0 -1
- package/src/components/loading-area/loading-area.stories.tsx +0 -17
- package/src/components/loading-area/loading-area.test.tsx +0 -11
- package/src/components/loading-area/loading-area.tsx +0 -13
- package/src/components/placeholder/index.ts +0 -1
- package/src/components/placeholder/placeholder.mock.ts +0 -15
- package/src/components/placeholder/placeholder.stories.tsx +0 -44
- package/src/components/placeholder/placeholder.test.tsx +0 -76
- package/src/components/placeholder/placeholder.tsx +0 -75
- package/src/components/query-container/index.ts +0 -1
- package/src/components/query-container/query-container.stories.tsx +0 -68
- package/src/components/query-container/query-container.test.tsx +0 -95
- package/src/components/query-container/query-container.tsx +0 -71
- package/src/components/sign-in/index.ts +0 -1
- package/src/components/sign-in/sign-in.stories.tsx +0 -36
- package/src/components/sign-in/sign-in.test.tsx +0 -95
- package/src/components/sign-in/sign-in.tsx +0 -97
- package/src/components/tab/index.ts +0 -2
- package/src/components/tab/tab-card/index.ts +0 -1
- package/src/components/tab/tab-card/tab-card.dummy.tsx +0 -30
- package/src/components/tab/tab-card/tab-card.stories.tsx +0 -22
- package/src/components/tab/tab-card/tab-card.test.tsx +0 -53
- package/src/components/tab/tab-card/tab-card.tsx +0 -27
- package/src/components/tab/tab-panel/index.ts +0 -1
- package/src/components/tab/tab-panel/tab-panel.test.tsx +0 -26
- package/src/components/tab/tab-panel/tab-panel.tsx +0 -27
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +0 -27
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.stories.tsx +0 -24
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +0 -77
- package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +0 -74
- package/src/components/table/enhanced-remote-table/index.ts +0 -1
- package/src/components/table/enhanced-table/enhanced-table-head.tsx +0 -58
- package/src/components/table/enhanced-table/enhanced-table.mock.tsx +0 -93
- package/src/components/table/enhanced-table/enhanced-table.stories.tsx +0 -21
- package/src/components/table/enhanced-table/enhanced-table.test.tsx +0 -107
- package/src/components/table/enhanced-table/enhanced-table.tsx +0 -136
- package/src/components/table/enhanced-table/index.ts +0 -2
- package/src/components/table/index.ts +0 -2
- package/src/components/table-list/index.ts +0 -1
- package/src/components/table-list/table-list.stories.tsx +0 -75
- package/src/components/table-list/table-list.test.tsx +0 -284
- package/src/components/table-list/table-list.tsx +0 -127
- package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +0 -35
- package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +0 -26
- package/src/components/value-displays/group-value-card/group-value-card.test.tsx +0 -58
- package/src/components/value-displays/group-value-card/group-value-card.tsx +0 -63
- package/src/components/value-displays/group-value-card/index.ts +0 -1
- package/src/components/value-displays/index.ts +0 -4
- package/src/components/value-displays/value-boolean/index.ts +0 -1
- package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +0 -25
- package/src/components/value-displays/value-boolean/value-boolean.test.tsx +0 -27
- package/src/components/value-displays/value-boolean/value-boolean.tsx +0 -33
- package/src/components/value-displays/value-card/index.ts +0 -1
- package/src/components/value-displays/value-card/value-card.stories.tsx +0 -22
- package/src/components/value-displays/value-card/value-card.test.tsx +0 -18
- package/src/components/value-displays/value-card/value-card.tsx +0 -12
- package/src/components/value-displays/value-text/index.ts +0 -1
- package/src/components/value-displays/value-text/value-test.test.tsx +0 -21
- package/src/components/value-displays/value-text/value-text.stories.tsx +0 -26
- package/src/components/value-displays/value-text/value-text.tsx +0 -32
- package/src/generators/generators.mock.ts +0 -238
- package/src/generators/generators.model.ts +0 -46
- package/src/generators/index.ts +0 -4
- package/src/generators/model-form/index.ts +0 -1
- package/src/generators/model-form/model-form.stories.tsx +0 -30
- package/src/generators/model-form/model-form.test.tsx +0 -100
- package/src/generators/model-form/model-form.tsx +0 -97
- package/src/generators/model-router/index.ts +0 -1
- package/src/generators/model-router/model-router.test.tsx +0 -666
- package/src/generators/model-router/model-router.tsx +0 -29
- package/src/generators/model-router/model-router.types.ts +0 -14
- package/src/generators/model-router/screens/add-screen.tsx +0 -69
- package/src/generators/model-router/screens/details-screen.tsx +0 -62
- package/src/generators/model-router/screens/index.ts +0 -4
- package/src/generators/model-router/screens/list-screen.tsx +0 -110
- package/src/generators/model-router/screens/screens.types.ts +0 -13
- package/src/generators/model-router/screens/update-screen.tsx +0 -96
- package/src/generators/model-router/stories/details-screen.stories.tsx +0 -38
- package/src/generators/model-router/stories/list-screen.stories.tsx +0 -45
- package/src/generators/model-router/stories/model-router.stories.tsx +0 -164
- package/src/generators/model-router/stories/templates.tsx +0 -39
- package/src/generators/object-details/index.ts +0 -1
- package/src/generators/object-details/object-details.stories.tsx +0 -20
- package/src/generators/object-details/object-details.test.tsx +0 -21
- package/src/generators/object-details/object-details.tsx +0 -76
- package/src/index.ts +0 -4
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +0 -28
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +0 -30
- package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.tsx +0 -37
- package/src/layouts/app-bar-with-drawer-layout/index.ts +0 -1
- package/src/layouts/header-layout/header-layout.stories.tsx +0 -204
- package/src/layouts/header-layout/header-layout.test.tsx +0 -37
- package/src/layouts/header-layout/header-layout.tsx +0 -23
- package/src/layouts/header-layout/index.ts +0 -1
- package/src/layouts/index.ts +0 -2
- package/src/providers/index.ts +0 -2
- package/src/providers/notification-center/index.ts +0 -2
- package/src/providers/notification-center/notification-center.context.ts +0 -37
- package/src/providers/notification-center/notification-center.provider.tsx +0 -51
- package/src/providers/notification-center/notification-center.stories.tsx +0 -52
- package/src/providers/notification-center/notification-center.test.tsx +0 -112
- package/src/providers/tab-provider/index.ts +0 -2
- package/src/providers/tab-provider/tab-provider.context.ts +0 -8
- package/src/providers/tab-provider/tab-provider.provider.tsx +0 -13
- package/src/storybook.tsx +0 -90
- package/src/tests/assertions.ts +0 -76
- package/src/tests/components.tsx +0 -60
- package/src/tests/content-placeholder.stories.tsx +0 -16
- package/src/tests/index.ts +0 -3
- package/src/tests/skeleton-card.stories.tsx +0 -18
- package/src/tests/testing-library.tsx +0 -65
- package/src/utils/arrays.test.ts +0 -9
- package/src/utils/arrays.ts +0 -7
- package/src/utils/index.ts +0 -2
- package/src/utils/theme.ts +0 -11
- package/tsconfig.json +0 -25
- package/tsconfig.rollup.json +0 -28
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React, { FormEvent, useState } from "react";
|
|
2
|
-
import { Stack, Box, TextField, Typography, Alert } from "@mui/material";
|
|
3
|
-
import { LoadingButton } from "@mui/lab";
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
title: string;
|
|
7
|
-
subtitle: string;
|
|
8
|
-
error?: Error;
|
|
9
|
-
loading?: boolean;
|
|
10
|
-
onSubmitSignIn: (email: string, password: string) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function SignIn({ title, subtitle, loading, error, onSubmitSignIn }: Props) {
|
|
14
|
-
const [emailError, setEmailError] = useState("");
|
|
15
|
-
const [passwordError, setPasswordError] = useState("");
|
|
16
|
-
|
|
17
|
-
function handleSubmit(e: FormEvent<HTMLFormElement>) {
|
|
18
|
-
e.preventDefault();
|
|
19
|
-
setEmailError("");
|
|
20
|
-
setPasswordError("");
|
|
21
|
-
|
|
22
|
-
const data = new FormData(e.currentTarget);
|
|
23
|
-
const email = data.get("email")?.toString();
|
|
24
|
-
const password = data.get("password")?.toString();
|
|
25
|
-
|
|
26
|
-
if (!email) {
|
|
27
|
-
setEmailError("Please fill out this field");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!password) {
|
|
31
|
-
setPasswordError("Please fill out this field");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (email && password) {
|
|
35
|
-
onSubmitSignIn(email, password);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<>
|
|
41
|
-
<Box marginBottom={2}>
|
|
42
|
-
<Typography component="h1" variant="h4">
|
|
43
|
-
{title}
|
|
44
|
-
</Typography>
|
|
45
|
-
<Typography variant="body1">{subtitle}</Typography>
|
|
46
|
-
</Box>
|
|
47
|
-
<Box component="form" onSubmit={handleSubmit}>
|
|
48
|
-
{error && (
|
|
49
|
-
<Stack width="100%" marginTop={1}>
|
|
50
|
-
<Alert variant="filled" severity="error">
|
|
51
|
-
{error.message}
|
|
52
|
-
</Alert>
|
|
53
|
-
</Stack>
|
|
54
|
-
)}
|
|
55
|
-
<TextField
|
|
56
|
-
margin="normal"
|
|
57
|
-
fullWidth
|
|
58
|
-
id="email"
|
|
59
|
-
label="Email Address"
|
|
60
|
-
name="email"
|
|
61
|
-
autoComplete="email"
|
|
62
|
-
autoFocus
|
|
63
|
-
disabled={loading}
|
|
64
|
-
type="email"
|
|
65
|
-
inputProps={{ role: "input" }}
|
|
66
|
-
error={!!emailError}
|
|
67
|
-
helperText={emailError}
|
|
68
|
-
/>
|
|
69
|
-
<TextField
|
|
70
|
-
margin="normal"
|
|
71
|
-
fullWidth
|
|
72
|
-
role="input"
|
|
73
|
-
name="password"
|
|
74
|
-
label="Password"
|
|
75
|
-
type="password"
|
|
76
|
-
id="password"
|
|
77
|
-
disabled={loading}
|
|
78
|
-
autoComplete="current-password"
|
|
79
|
-
inputProps={{ role: "input" }}
|
|
80
|
-
error={!!passwordError}
|
|
81
|
-
helperText={passwordError}
|
|
82
|
-
/>
|
|
83
|
-
<LoadingButton
|
|
84
|
-
type="submit"
|
|
85
|
-
fullWidth
|
|
86
|
-
variant="contained"
|
|
87
|
-
loading={loading}
|
|
88
|
-
disabled={loading}
|
|
89
|
-
role="button"
|
|
90
|
-
sx={{ mt: 2 }}
|
|
91
|
-
>
|
|
92
|
-
Sign In
|
|
93
|
-
</LoadingButton>
|
|
94
|
-
</Box>
|
|
95
|
-
</>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./tab-card";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { TabCard } from "./tab-card";
|
|
3
|
-
import { TabPanel } from "../tab-panel";
|
|
4
|
-
import { Typography } from "@mui/material";
|
|
5
|
-
import { TabProvider } from "../../../providers";
|
|
6
|
-
|
|
7
|
-
export const DummyTabs = ["tab 1", "tab 2.1", "tab 2.2", "tab 3"];
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
tabs: string[];
|
|
11
|
-
initialTab: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function TabCardDummy({ tabs, initialTab }: Props) {
|
|
15
|
-
return (
|
|
16
|
-
<TabProvider initialValue={initialTab}>
|
|
17
|
-
<TabCard tabs={tabs}>
|
|
18
|
-
<TabPanel index={0}>
|
|
19
|
-
<Typography>Panel 1</Typography>
|
|
20
|
-
</TabPanel>
|
|
21
|
-
<TabPanel index={[1, 2]}>
|
|
22
|
-
<Typography>Panel 2</Typography>
|
|
23
|
-
</TabPanel>
|
|
24
|
-
<TabPanel index={3}>
|
|
25
|
-
<Typography>Panel 3</Typography>
|
|
26
|
-
</TabPanel>
|
|
27
|
-
</TabCard>
|
|
28
|
-
</TabProvider>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ComponentMeta } from "@storybook/react";
|
|
3
|
-
import { TabCard } from "./tab-card";
|
|
4
|
-
import { createTemplate } from "../../../storybook";
|
|
5
|
-
import { DummyTabs, TabCardDummy } from "./tab-card.dummy";
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: "Cards/Tab card",
|
|
9
|
-
component: TabCard,
|
|
10
|
-
parameters: {
|
|
11
|
-
layout: "fullscreen",
|
|
12
|
-
},
|
|
13
|
-
} as ComponentMeta<typeof TabCard>;
|
|
14
|
-
|
|
15
|
-
const Template = createTemplate((props) => {
|
|
16
|
-
return <TabCardDummy {...props} />;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const Default = Template.bind({});
|
|
20
|
-
Default.args = {
|
|
21
|
-
tabs: DummyTabs,
|
|
22
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { DummyTabs, TabCardDummy } from "./tab-card.dummy";
|
|
3
|
-
import { screen, render } from "../../../tests";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
describe("TabCard", () => {
|
|
7
|
-
function renderInstance(initialValue = 0) {
|
|
8
|
-
return render(<TabCardDummy tabs={DummyTabs} initialTab={initialValue} />);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
it('initialTab is not set the "panel 1" is displayed', () => {
|
|
12
|
-
renderInstance();
|
|
13
|
-
|
|
14
|
-
expect(screen.getByText(/panel 1/i)).toBeInTheDocument();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('initialTab is set to 3 the "panel 3" is displayed', () => {
|
|
18
|
-
renderInstance(3);
|
|
19
|
-
|
|
20
|
-
expect(screen.getByText(/panel 3/i)).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it.each([
|
|
24
|
-
[/tab 1/i, /panel 1/i],
|
|
25
|
-
[/tab 2.1/i, /panel 2/i],
|
|
26
|
-
[/tab 2.2/i, /panel 2/i],
|
|
27
|
-
[/tab 3/i, /panel 3/i],
|
|
28
|
-
])(
|
|
29
|
-
'click the tab "%s" the "%s" panel is displayed',
|
|
30
|
-
async (tabName: RegExp, expectedText: RegExp) => {
|
|
31
|
-
renderInstance();
|
|
32
|
-
|
|
33
|
-
const tab = screen.getByRole("tab", { name: tabName });
|
|
34
|
-
await userEvent.click(tab);
|
|
35
|
-
|
|
36
|
-
expect(screen.getByText(expectedText)).toBeInTheDocument();
|
|
37
|
-
expect(tab).toHaveAttribute("aria-selected", "true");
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
it('click the tab "tab 2" and click again the tab "tab 1" the "panel 1" is displayed', async () => {
|
|
42
|
-
renderInstance();
|
|
43
|
-
|
|
44
|
-
const tab1 = screen.getByRole("tab", { name: /tab 1/i });
|
|
45
|
-
const tab2 = screen.getByRole("tab", { name: /tab 2.1/i });
|
|
46
|
-
await userEvent.click(tab2);
|
|
47
|
-
await userEvent.click(tab1);
|
|
48
|
-
|
|
49
|
-
expect(screen.getByText(/panel 1/i)).toBeInTheDocument();
|
|
50
|
-
expect(tab1).toHaveAttribute("aria-selected", "true");
|
|
51
|
-
expect(tab2).toHaveAttribute("aria-selected", "false");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Paper, Tabs, Tab, styled, tabsClasses } from "@mui/material";
|
|
2
|
-
import React, { PropsWithChildren, useState } from "react";
|
|
3
|
-
import { TabProvider, useTab } from "~/providers";
|
|
4
|
-
|
|
5
|
-
const StyledTabs = styled(Tabs)(({ theme }) => ({
|
|
6
|
-
[`&.${tabsClasses.root}`]: {
|
|
7
|
-
backgroundColor: theme.palette.grey[100],
|
|
8
|
-
},
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
tabs: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const TabCard = ({ children, tabs }: PropsWithChildren<Props>) => {
|
|
16
|
-
const [tab, setTab] = useTab();
|
|
17
|
-
return (
|
|
18
|
-
<Paper>
|
|
19
|
-
<StyledTabs value={tab} onChange={(_, index: number) => setTab(index)}>
|
|
20
|
-
{tabs.map((tab) => (
|
|
21
|
-
<Tab key={tab} label={tab} />
|
|
22
|
-
))}
|
|
23
|
-
</StyledTabs>
|
|
24
|
-
{children}
|
|
25
|
-
</Paper>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./tab-panel";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, screen } from "@testing-library/react";
|
|
3
|
-
import { TabPanel } from "./tab-panel";
|
|
4
|
-
import { TabProvider } from "../../../providers";
|
|
5
|
-
|
|
6
|
-
describe("TabPanel", () => {
|
|
7
|
-
function renderInstance(initialValue: number) {
|
|
8
|
-
render(
|
|
9
|
-
<TabProvider initialValue={initialValue}>
|
|
10
|
-
<TabPanel index={0}>Panel content</TabPanel>
|
|
11
|
-
</TabProvider>,
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
it("if the provider value is the index the content is displayed", () => {
|
|
16
|
-
renderInstance(0);
|
|
17
|
-
|
|
18
|
-
expect(screen.getByText(/panel content/i)).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("if the provider value is not the index the content is not displayed", () => {
|
|
22
|
-
renderInstance(1);
|
|
23
|
-
|
|
24
|
-
expect(screen.queryByText(/panel content/i)).not.toBeInTheDocument();
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Box } from "@mui/material";
|
|
3
|
-
import { useTab } from "~/providers";
|
|
4
|
-
|
|
5
|
-
interface TabPanelProps {
|
|
6
|
-
children?: React.ReactNode;
|
|
7
|
-
index: number | number[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function TabPanel({ children, index }: TabPanelProps) {
|
|
11
|
-
const [value] = useTab();
|
|
12
|
-
let isTab = value === index;
|
|
13
|
-
if (Array.isArray(index)) {
|
|
14
|
-
isTab = index.includes(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<div
|
|
19
|
-
role="tabpanel"
|
|
20
|
-
hidden={!isTab}
|
|
21
|
-
id={`simple-tabpanel-${index}`}
|
|
22
|
-
aria-labelledby={`simple-tab-${index}`}
|
|
23
|
-
>
|
|
24
|
-
{isTab && <Box sx={{ p: 3 }}>{children}</Box>}
|
|
25
|
-
</div>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { TableCell, TableRow } from "@mui/material";
|
|
3
|
-
import { EnhancedRemoteTable } from "./enhanced-remote-table";
|
|
4
|
-
import { HeadCell, Order } from "../enhanced-table/enhanced-table-head";
|
|
5
|
-
|
|
6
|
-
interface DummyProps<T> {
|
|
7
|
-
data: T[];
|
|
8
|
-
loading: boolean;
|
|
9
|
-
defaultSort: string;
|
|
10
|
-
defaultOrder?: Order;
|
|
11
|
-
columns: HeadCell[];
|
|
12
|
-
onRequestSort: (col: string, orderBy: Order) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function EnhancedRemoteDummyTable<T>(props: DummyProps<T>) {
|
|
16
|
-
return (
|
|
17
|
-
<EnhancedRemoteTable {...props}>
|
|
18
|
-
{(d: unknown) => (
|
|
19
|
-
<TableRow key={d.id}>
|
|
20
|
-
<TableCell>{d.name}</TableCell>
|
|
21
|
-
<TableCell>{d.id}</TableCell>
|
|
22
|
-
<TableCell>{d.startDate}</TableCell>
|
|
23
|
-
</TableRow>
|
|
24
|
-
)}
|
|
25
|
-
</EnhancedRemoteTable>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ComponentMeta } from "@storybook/react";
|
|
2
|
-
import { createTemplate } from "../../../storybook";
|
|
3
|
-
import { EnhancedRemoteTable } from "./enhanced-remote-table";
|
|
4
|
-
import { columns, data } from "../enhanced-table/enhanced-table.mock";
|
|
5
|
-
import { EnhancedRemoteDummyTable } from "./enhanced-remote-table.mock";
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: "Tables/Enhanced remote table",
|
|
9
|
-
component: EnhancedRemoteTable,
|
|
10
|
-
parameters: {
|
|
11
|
-
layout: "fullscreen",
|
|
12
|
-
},
|
|
13
|
-
} as ComponentMeta<typeof EnhancedRemoteTable>;
|
|
14
|
-
|
|
15
|
-
const Template = createTemplate(EnhancedRemoteDummyTable);
|
|
16
|
-
|
|
17
|
-
export const Default = Template.bind({});
|
|
18
|
-
Default.args = {
|
|
19
|
-
columns,
|
|
20
|
-
data,
|
|
21
|
-
loading: false,
|
|
22
|
-
defaultSort: "startDate",
|
|
23
|
-
defaultOrder: "asc",
|
|
24
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { screen, render } from "@testing-library/react";
|
|
3
|
-
import { EnhancedRemoteDummyTable } from "./enhanced-remote-table.mock";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { columns, data } from "../enhanced-table/enhanced-table.mock";
|
|
6
|
-
import { expectProgressIndicator } from "../../../tests";
|
|
7
|
-
|
|
8
|
-
function renderInstance({
|
|
9
|
-
defaultSort = "startDate",
|
|
10
|
-
loading = false,
|
|
11
|
-
}: { defaultSort?: string; loading?: boolean } = {}) {
|
|
12
|
-
const onRequestSort = jest.fn();
|
|
13
|
-
render(
|
|
14
|
-
<EnhancedRemoteDummyTable
|
|
15
|
-
data={data}
|
|
16
|
-
columns={columns}
|
|
17
|
-
defaultSort={defaultSort}
|
|
18
|
-
defaultOrder="asc"
|
|
19
|
-
loading={loading}
|
|
20
|
-
onRequestSort={onRequestSort}
|
|
21
|
-
/>,
|
|
22
|
-
);
|
|
23
|
-
return { onRequestSort };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe("Table", () => {
|
|
27
|
-
it("all items are rendered in the correct", async () => {
|
|
28
|
-
renderInstance();
|
|
29
|
-
|
|
30
|
-
expect(screen.getByText("Tabata")).toBeInTheDocument();
|
|
31
|
-
expect(screen.getByText("AMRAPx2")).toBeInTheDocument();
|
|
32
|
-
expect(screen.getByText("HIIT")).toBeInTheDocument();
|
|
33
|
-
expect(screen.getByText("on/off x 1")).toBeInTheDocument();
|
|
34
|
-
expect(screen.getByText("EMOM 30'")).toBeInTheDocument();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("loading is true a loading indicator is displayed", () => {
|
|
38
|
-
renderInstance({ loading: true });
|
|
39
|
-
|
|
40
|
-
expectProgressIndicator();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("the defaultSort is indicated", () => {
|
|
44
|
-
renderInstance();
|
|
45
|
-
|
|
46
|
-
expect(screen.getByText(/date/i)).toHaveTextContent(/datesorted ascending/i);
|
|
47
|
-
expect(screen.getByText(/name/i)).toHaveTextContent(/name/i);
|
|
48
|
-
expect(screen.getByText(/garmin/i)).toHaveTextContent(/garmin/i);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("clicks 'Name'", () => {
|
|
52
|
-
it("once onRequestSort will be called to sort by name in ascendent order", async () => {
|
|
53
|
-
const { onRequestSort } = renderInstance();
|
|
54
|
-
|
|
55
|
-
await userEvent.click(screen.getByText(/name/i));
|
|
56
|
-
|
|
57
|
-
expect(screen.getByText(/date/i)).toHaveTextContent(/date/i);
|
|
58
|
-
expect(screen.getByText(/name/i)).toHaveTextContent(/namesorted ascending/i);
|
|
59
|
-
expect(screen.getByText(/garmin/i)).toHaveTextContent(/garmin/i);
|
|
60
|
-
expect(onRequestSort).toHaveBeenCalledWith("name", "asc");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("twice onRequestSort will be called twice to sort by name in ascendent and descendent order", async () => {
|
|
64
|
-
const { onRequestSort } = renderInstance();
|
|
65
|
-
|
|
66
|
-
await userEvent.click(screen.getByText(/name/i));
|
|
67
|
-
await userEvent.click(screen.getByText(/name/i));
|
|
68
|
-
|
|
69
|
-
expect(screen.getByText(/date/i)).toHaveTextContent(/date/i);
|
|
70
|
-
expect(screen.getByText(/name/i)).toHaveTextContent(/namesorted descending/i);
|
|
71
|
-
expect(screen.getByText(/garmin/i)).toHaveTextContent(/garmin/i);
|
|
72
|
-
expect(onRequestSort).toHaveBeenCalledTimes(2);
|
|
73
|
-
expect(onRequestSort).toHaveBeenCalledWith("name", "asc");
|
|
74
|
-
expect(onRequestSort).toHaveBeenCalledWith("name", "desc");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ReactNode, useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
TableContainer,
|
|
5
|
-
TableBody,
|
|
6
|
-
Table,
|
|
7
|
-
TableRow,
|
|
8
|
-
CircularProgress,
|
|
9
|
-
TableCell,
|
|
10
|
-
} from "@mui/material";
|
|
11
|
-
import { EnhancedTableHead, HeadCell, Order } from "../enhanced-table";
|
|
12
|
-
|
|
13
|
-
interface Props<T> {
|
|
14
|
-
data: T[];
|
|
15
|
-
loading: boolean;
|
|
16
|
-
defaultSort: string;
|
|
17
|
-
defaultOrder?: Order;
|
|
18
|
-
columns: HeadCell[];
|
|
19
|
-
children: (data: T, index: number) => ReactNode;
|
|
20
|
-
onRequestSort: (col: string, orderBy: "asc" | "desc") => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const EnhancedRemoteTable = <T,>({
|
|
24
|
-
children,
|
|
25
|
-
data,
|
|
26
|
-
loading,
|
|
27
|
-
columns,
|
|
28
|
-
defaultSort,
|
|
29
|
-
defaultOrder,
|
|
30
|
-
onRequestSort,
|
|
31
|
-
}: Props<T>) => {
|
|
32
|
-
const [order, setOrder] = useState({
|
|
33
|
-
orderBy: defaultSort,
|
|
34
|
-
order: defaultOrder || "asc",
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const handleRequestSort = (property: string) => {
|
|
38
|
-
setOrder((prevState) => {
|
|
39
|
-
const newOrder = prevState.orderBy === property && prevState.order === "asc" ? "desc" : "asc";
|
|
40
|
-
onRequestSort(property, newOrder);
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
orderBy: property,
|
|
44
|
-
order: newOrder,
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<>
|
|
51
|
-
<TableContainer>
|
|
52
|
-
<Table>
|
|
53
|
-
<EnhancedTableHead
|
|
54
|
-
order={order.order}
|
|
55
|
-
orderBy={order.orderBy}
|
|
56
|
-
headCells={columns}
|
|
57
|
-
onRequestSort={handleRequestSort}
|
|
58
|
-
/>
|
|
59
|
-
<TableBody>
|
|
60
|
-
{loading ? (
|
|
61
|
-
<TableRow>
|
|
62
|
-
<TableCell colSpan={columns.length} sx={{ textAlign: "center" }}>
|
|
63
|
-
<CircularProgress />
|
|
64
|
-
</TableCell>
|
|
65
|
-
</TableRow>
|
|
66
|
-
) : (
|
|
67
|
-
data.map((d, i) => children(d, i))
|
|
68
|
-
)}
|
|
69
|
-
</TableBody>
|
|
70
|
-
</Table>
|
|
71
|
-
</TableContainer>
|
|
72
|
-
</>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./enhanced-remote-table";
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { TableSortLabel, TableRow, Box, TableCell, TableHead } from "@mui/material";
|
|
3
|
-
import { visuallyHidden } from "@mui/utils";
|
|
4
|
-
|
|
5
|
-
export type Order = "asc" | "desc";
|
|
6
|
-
export interface HeadCell {
|
|
7
|
-
disablePadding: boolean;
|
|
8
|
-
id: string;
|
|
9
|
-
label: string;
|
|
10
|
-
numeric: boolean;
|
|
11
|
-
sort: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface Props {
|
|
15
|
-
onRequestSort: (property: string) => void;
|
|
16
|
-
order: Order;
|
|
17
|
-
orderBy: string;
|
|
18
|
-
headCells: HeadCell[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function EnhancedTableHead({ order, orderBy, headCells, onRequestSort }: Props) {
|
|
22
|
-
const createSortHandler = (property: string) => () => {
|
|
23
|
-
onRequestSort(property);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<TableHead>
|
|
28
|
-
<TableRow>
|
|
29
|
-
{headCells.map((headCell) => (
|
|
30
|
-
<TableCell
|
|
31
|
-
variant="head"
|
|
32
|
-
key={String(headCell.id)}
|
|
33
|
-
padding={headCell.disablePadding ? "none" : "normal"}
|
|
34
|
-
sortDirection={orderBy === headCell.id ? order : false}
|
|
35
|
-
sx={{ fontWeight: "bold" }}
|
|
36
|
-
>
|
|
37
|
-
{headCell.sort ? (
|
|
38
|
-
<TableSortLabel
|
|
39
|
-
active={orderBy === headCell.id}
|
|
40
|
-
direction={orderBy === headCell.id ? order : "asc"}
|
|
41
|
-
onClick={createSortHandler(headCell.id)}
|
|
42
|
-
>
|
|
43
|
-
{headCell.label}
|
|
44
|
-
{orderBy === headCell.id ? (
|
|
45
|
-
<Box component="span" sx={visuallyHidden}>
|
|
46
|
-
{order === "desc" ? "sorted descending" : "sorted ascending"}
|
|
47
|
-
</Box>
|
|
48
|
-
) : null}
|
|
49
|
-
</TableSortLabel>
|
|
50
|
-
) : (
|
|
51
|
-
headCell.label
|
|
52
|
-
)}
|
|
53
|
-
</TableCell>
|
|
54
|
-
))}
|
|
55
|
-
</TableRow>
|
|
56
|
-
</TableHead>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { EnhancedTable } from ".";
|
|
3
|
-
import { TableCell, TableRow } from "@mui/material";
|
|
4
|
-
import { HeadCell, Order } from "./enhanced-table-head";
|
|
5
|
-
|
|
6
|
-
export const columns: HeadCell[] = [
|
|
7
|
-
{
|
|
8
|
-
id: "name",
|
|
9
|
-
numeric: false,
|
|
10
|
-
disablePadding: false,
|
|
11
|
-
label: "Name",
|
|
12
|
-
sort: true,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: "id",
|
|
16
|
-
numeric: true,
|
|
17
|
-
disablePadding: false,
|
|
18
|
-
label: "Garmin ID",
|
|
19
|
-
sort: true,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
id: "startDate",
|
|
23
|
-
numeric: false,
|
|
24
|
-
disablePadding: false,
|
|
25
|
-
label: "Date",
|
|
26
|
-
sort: true,
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
interface Data {
|
|
31
|
-
id: number;
|
|
32
|
-
name: string;
|
|
33
|
-
startDate: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const data: Data[] = [
|
|
37
|
-
{
|
|
38
|
-
id: 2,
|
|
39
|
-
name: "HIIT",
|
|
40
|
-
startDate: "11/04/2022",
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: 1,
|
|
44
|
-
name: "on/off x 1",
|
|
45
|
-
startDate: "05/04/2022",
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: 3,
|
|
49
|
-
name: "EMOM 30'",
|
|
50
|
-
startDate: "07/04/2022",
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: 4,
|
|
54
|
-
name: "Tabata",
|
|
55
|
-
startDate: "09/04/2022",
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: 5,
|
|
59
|
-
name: "AMRAPx2",
|
|
60
|
-
startDate: "10/04/2022",
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
interface Props {
|
|
65
|
-
data: Data[];
|
|
66
|
-
columns: HeadCell[];
|
|
67
|
-
defaultSort: string;
|
|
68
|
-
defaultOrder: Order;
|
|
69
|
-
loading: boolean;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const TestTable = ({ data, columns, defaultOrder, defaultSort, loading }: Props) => {
|
|
73
|
-
return (
|
|
74
|
-
<EnhancedTable
|
|
75
|
-
search
|
|
76
|
-
data={data}
|
|
77
|
-
columns={columns}
|
|
78
|
-
defaultSort={defaultSort}
|
|
79
|
-
defaultOrder={defaultOrder}
|
|
80
|
-
loading={loading}
|
|
81
|
-
>
|
|
82
|
-
{(data) =>
|
|
83
|
-
data.map((d) => (
|
|
84
|
-
<TableRow key={d.id}>
|
|
85
|
-
<TableCell>{d.name}</TableCell>
|
|
86
|
-
<TableCell>{d.id}</TableCell>
|
|
87
|
-
<TableCell>{d.startDate}</TableCell>
|
|
88
|
-
</TableRow>
|
|
89
|
-
))
|
|
90
|
-
}
|
|
91
|
-
</EnhancedTable>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentMeta } from "@storybook/react";
|
|
2
|
-
import { createTemplate } from "../../../storybook";
|
|
3
|
-
import { TestTable, columns, data } from "./enhanced-table.mock";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: "Tables/Table",
|
|
7
|
-
component: TestTable,
|
|
8
|
-
parameters: {
|
|
9
|
-
layout: "fullscreen",
|
|
10
|
-
},
|
|
11
|
-
} as ComponentMeta<typeof TestTable>;
|
|
12
|
-
|
|
13
|
-
const Template = createTemplate(TestTable);
|
|
14
|
-
|
|
15
|
-
export const Default = Template.bind({});
|
|
16
|
-
Default.args = {
|
|
17
|
-
columns,
|
|
18
|
-
data,
|
|
19
|
-
defaultSort: "startDate",
|
|
20
|
-
defaultOrder: "asc",
|
|
21
|
-
};
|