@pautena/react-design-system 0.7.4 → 0.8.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.
Files changed (64) hide show
  1. package/dist/cjs/index.js +4 -4
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/components/data-display/label/label.d.ts +6 -2
  4. package/dist/cjs/types/components/dialogs/bootstrap-dialog/bootstrap-dialog.d.ts +1 -1
  5. package/dist/cjs/types/components/dialogs/confirm-dialog/confirm-dialog.d.ts +2 -1
  6. package/dist/cjs/types/components/dialogs/dialog.types.d.ts +2 -0
  7. package/dist/cjs/types/components/navigation/index.d.ts +2 -1
  8. package/dist/cjs/types/components/navigation/tab-card/tab-card-panel.d.ts +7 -0
  9. package/dist/cjs/types/components/navigation/tab-card/tab-card.context.d.ts +3 -0
  10. package/dist/cjs/types/components/navigation/tab-card/tab-card.d.ts +11 -0
  11. package/dist/cjs/types/components/navigation/tab-card/tab-card.dummy.d.ts +14 -0
  12. package/dist/esm/index.js +4 -4
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/types/components/data-display/label/label.d.ts +6 -2
  15. package/dist/esm/types/components/dialogs/bootstrap-dialog/bootstrap-dialog.d.ts +1 -1
  16. package/dist/esm/types/components/dialogs/confirm-dialog/confirm-dialog.d.ts +2 -1
  17. package/dist/esm/types/components/dialogs/dialog.types.d.ts +2 -0
  18. package/dist/esm/types/components/navigation/index.d.ts +2 -1
  19. package/dist/esm/types/components/navigation/tab-card/tab-card-panel.d.ts +7 -0
  20. package/dist/esm/types/components/navigation/tab-card/tab-card.context.d.ts +3 -0
  21. package/dist/esm/types/components/navigation/tab-card/tab-card.d.ts +11 -0
  22. package/dist/esm/types/components/navigation/tab-card/tab-card.dummy.d.ts +14 -0
  23. package/dist/index.d.ts +23 -10
  24. package/package.json +1 -1
  25. package/src/components/data-display/board/board.tsx +13 -3
  26. package/src/components/data-display/header/header.stories.tsx +1 -1
  27. package/src/components/data-display/label/label.test.tsx +3 -3
  28. package/src/components/data-display/label/label.tsx +45 -17
  29. package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.test.tsx +34 -0
  30. package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.tsx +4 -2
  31. package/src/components/dialogs/confirm-dialog/confirm-dialog.stories.tsx +13 -1
  32. package/src/components/dialogs/confirm-dialog/confirm-dialog.test.tsx +35 -0
  33. package/src/components/dialogs/confirm-dialog/confirm-dialog.tsx +17 -1
  34. package/src/components/dialogs/dialog.types.ts +2 -0
  35. package/src/components/drawers/drawer-item/drawer-item.test.tsx +1 -2
  36. package/src/components/navigation/index.ts +2 -1
  37. package/src/components/navigation/tab-card/tab-card-panel.tsx +19 -0
  38. package/src/components/navigation/tab-card/tab-card.context.tsx +7 -0
  39. package/src/components/navigation/tab-card/tab-card.dummy.tsx +34 -0
  40. package/src/components/navigation/{tab/tab-card → tab-card}/tab-card.stories.tsx +2 -2
  41. package/src/components/navigation/tab-card/tab-card.test.tsx +74 -0
  42. package/src/components/navigation/tab-card/tab-card.tsx +81 -0
  43. package/src/components/navigation/{tab/tab-panel → tab-panel}/tab-panel.test.tsx +1 -1
  44. package/src/components/value-displays/value-rating/value-rating.tsx +1 -2
  45. package/src/generators/object-details/object-details.tsx +0 -2
  46. package/dist/cjs/types/components/navigation/tab/index.d.ts +0 -2
  47. package/dist/cjs/types/components/navigation/tab/tab-card/tab-card.d.ts +0 -5
  48. package/dist/cjs/types/components/navigation/tab/tab-card/tab-card.dummy.d.ts +0 -6
  49. package/dist/esm/types/components/navigation/tab/index.d.ts +0 -2
  50. package/dist/esm/types/components/navigation/tab/tab-card/tab-card.d.ts +0 -5
  51. package/dist/esm/types/components/navigation/tab/tab-card/tab-card.dummy.d.ts +0 -6
  52. package/src/components/navigation/tab/index.ts +0 -2
  53. package/src/components/navigation/tab/tab-card/tab-card.dummy.tsx +0 -30
  54. package/src/components/navigation/tab/tab-card/tab-card.test.tsx +0 -53
  55. package/src/components/navigation/tab/tab-card/tab-card.tsx +0 -27
  56. /package/dist/cjs/types/components/navigation/{tab/tab-card → tab-card}/index.d.ts +0 -0
  57. /package/dist/cjs/types/components/navigation/{tab/tab-panel → tab-panel}/index.d.ts +0 -0
  58. /package/dist/cjs/types/components/navigation/{tab/tab-panel → tab-panel}/tab-panel.d.ts +0 -0
  59. /package/dist/esm/types/components/navigation/{tab/tab-card → tab-card}/index.d.ts +0 -0
  60. /package/dist/esm/types/components/navigation/{tab/tab-panel → tab-panel}/index.d.ts +0 -0
  61. /package/dist/esm/types/components/navigation/{tab/tab-panel → tab-panel}/tab-panel.d.ts +0 -0
  62. /package/src/components/navigation/{tab/tab-card → tab-card}/index.ts +0 -0
  63. /package/src/components/navigation/{tab/tab-panel → tab-panel}/index.ts +0 -0
  64. /package/src/components/navigation/{tab/tab-panel → tab-panel}/tab-panel.tsx +0 -0
@@ -0,0 +1,34 @@
1
+ import React from "react";
2
+ import { TabCard, TabData } from "./tab-card";
3
+ import { Typography } from "@mui/material";
4
+ import { TabCardPanel } from "./tab-card-panel";
5
+ import { Label } from "~/components/data-display";
6
+
7
+ export const DummyTabs = [
8
+ { text: "tab 1" },
9
+ { text: "tab 2.1", icon: <Label text="10" variant="success" sx={{ mr: 1 }} /> },
10
+ { text: "tab 2.2" },
11
+ { text: "tab 3", icon: <Label text="12" variant="error" sx={{ mr: 1 }} /> },
12
+ ];
13
+
14
+ export interface TabCardDummyProps {
15
+ tabs: TabData[];
16
+ initialTab: number;
17
+ onChangeTab: (tab: TabData, index: number) => void;
18
+ }
19
+
20
+ export function TabCardDummy({ tabs, initialTab, onChangeTab }: TabCardDummyProps) {
21
+ return (
22
+ <TabCard tabs={tabs} initialTab={initialTab} onChangeTab={onChangeTab}>
23
+ <TabCardPanel index={0} sx={{ p: 2 }}>
24
+ <Typography>Panel 1</Typography>
25
+ </TabCardPanel>
26
+ <TabCardPanel index={[1, 2]} sx={{ p: 2 }}>
27
+ <Typography>Panel 2</Typography>
28
+ </TabCardPanel>
29
+ <TabCardPanel index={3} sx={{ p: 2 }}>
30
+ <Typography>Panel 3</Typography>
31
+ </TabCardPanel>
32
+ </TabCard>
33
+ );
34
+ }
@@ -3,10 +3,10 @@ import { Meta, StoryObj } from "@storybook/react";
3
3
  import { DummyTabs, TabCardDummy, TabCardDummyProps } from "./tab-card.dummy";
4
4
 
5
5
  export default {
6
- title: "Components/Navigation/Tab card",
6
+ title: "Components/Navigation/TabCard",
7
7
  component: TabCardDummy,
8
8
  parameters: {
9
- layout: "fullscreen",
9
+ layout: "centered",
10
10
  },
11
11
  render: (props: TabCardDummyProps) => {
12
12
  return <TabCardDummy {...props} />;
@@ -0,0 +1,74 @@
1
+ import React from "react";
2
+ import { DummyTabs, TabCardDummy } from "./tab-card.dummy";
3
+ import { screen, render } from "~/tests/testing-library";
4
+ import userEvent from "@testing-library/user-event";
5
+ import { vi } from "vitest";
6
+
7
+ describe("TabCard", () => {
8
+ function renderComponent({ initialTab = 0 } = {}) {
9
+ const onChangeTab = vi.fn();
10
+ render(<TabCardDummy tabs={DummyTabs} initialTab={initialTab} onChangeTab={onChangeTab} />);
11
+ return { onChangeTab };
12
+ }
13
+
14
+ it('initialTab is not set the "panel 1" is displayed', () => {
15
+ renderComponent();
16
+
17
+ expect(screen.getByText(/panel 1/i)).toBeInTheDocument();
18
+ });
19
+
20
+ it('initialTab is set to 3 the "panel 3" is displayed', () => {
21
+ renderComponent({ initialTab: 3 });
22
+
23
+ expect(screen.getByText(/panel 3/i)).toBeInTheDocument();
24
+ });
25
+
26
+ it("should render the tab labels", () => {
27
+ renderComponent();
28
+
29
+ expect(screen.getByText(/10/i)).toBeVisible();
30
+ expect(screen.getByText(/12/i)).toBeVisible();
31
+ });
32
+
33
+ describe("click tab", () => {
34
+ it.each([
35
+ [/tab 1/i, /panel 1/i],
36
+ [/tab 2.1/i, /panel 2/i],
37
+ [/tab 2.2/i, /panel 2/i],
38
+ [/tab 3/i, /panel 3/i],
39
+ ])(
40
+ 'click the tab "%s" the "%s" panel is displayed',
41
+ async (tabName: RegExp, expectedText: RegExp) => {
42
+ renderComponent();
43
+
44
+ const tab = screen.getByRole("tab", { name: tabName });
45
+ await userEvent.click(tab);
46
+
47
+ expect(screen.getByText(expectedText)).toBeInTheDocument();
48
+ expect(tab).toHaveAttribute("aria-selected", "true");
49
+ },
50
+ );
51
+
52
+ it('click the tab "tab 2" and click again the tab "tab 1" the "panel 1" is displayed', async () => {
53
+ renderComponent();
54
+
55
+ const tab1 = screen.getByRole("tab", { name: /tab 1/i });
56
+ const tab2 = screen.getByRole("tab", { name: /tab 2.1/i });
57
+ await userEvent.click(tab2);
58
+ await userEvent.click(tab1);
59
+
60
+ expect(screen.getByText(/panel 1/i)).toBeInTheDocument();
61
+ expect(screen.getByRole("tab", { name: /tab 1/i, selected: true })).toBeVisible();
62
+ expect(screen.getByRole("tab", { name: /tab 2.1/i, selected: false })).toBeVisible();
63
+ });
64
+
65
+ it("should call onChangeTab", async () => {
66
+ const { onChangeTab } = renderComponent();
67
+
68
+ await userEvent.click(screen.getByRole("tab", { name: /tab 2.2/i }));
69
+
70
+ expect(onChangeTab).toHaveBeenCalledTimes(1);
71
+ expect(onChangeTab).toHaveBeenCalledWith({ text: "tab 2.2" }, 2);
72
+ });
73
+ });
74
+ });
@@ -0,0 +1,81 @@
1
+ import { Paper, Tabs, Tab, styled, Box } from "@mui/material";
2
+ import React, { PropsWithChildren, ReactElement, SyntheticEvent, useState } from "react";
3
+ import { TabCardContextProvider } from "./tab-card.context";
4
+ import { useGetDefaultThemeColor } from "~/utils";
5
+
6
+ export interface TabData {
7
+ text: string;
8
+ icon?: ReactElement;
9
+ }
10
+
11
+ interface StyledTabsProps {
12
+ children?: React.ReactNode;
13
+ value: number;
14
+ onChange: (event: React.SyntheticEvent, newValue: number) => void;
15
+ }
16
+
17
+ const StyledTabs = styled((props: StyledTabsProps) => (
18
+ <Tabs {...props} TabIndicatorProps={{ children: <span className="MuiTabs-indicatorSpan" /> }} />
19
+ ))(({ theme }) => ({
20
+ minHeight: theme.spacing(5),
21
+ "& .MuiTabs-indicator": {
22
+ display: "flex",
23
+ justifyContent: "center",
24
+ backgroundColor: "transparent",
25
+ },
26
+ "& .MuiTabs-indicatorSpan": {
27
+ maxWidth: 40,
28
+ width: "100%",
29
+ backgroundColor: theme.palette.primary.main,
30
+ },
31
+ }));
32
+
33
+ const StyledTab = styled(Tab)(({ theme }) => ({
34
+ textTransform: "none",
35
+ fontWeight: theme.typography.fontWeightRegular,
36
+ marginRight: theme.spacing(1),
37
+ color: theme.palette.text.secondary,
38
+ paddingTop: 0,
39
+ paddingBottom: 0,
40
+ minHeight: theme.spacing(5),
41
+ "&.Mui-selected": {
42
+ color: theme.palette.text.secondary,
43
+ fontWeight: theme.typography.fontWeightBold,
44
+ },
45
+ }));
46
+
47
+ export type TabCardProps = PropsWithChildren<{
48
+ tabs: TabData[];
49
+ initialTab?: number;
50
+ onChangeTab?: (tab: TabData, index: number) => void;
51
+ }>;
52
+
53
+ export const TabCard = ({
54
+ children,
55
+ tabs,
56
+ initialTab = 0,
57
+ onChangeTab = () => null,
58
+ }: TabCardProps) => {
59
+ const bgColor = useGetDefaultThemeColor();
60
+ const [selectedTab, setSelectedTab] = useState(initialTab);
61
+
62
+ const handleChangeTab = (_: SyntheticEvent<Element, Event>, index: number) => {
63
+ setSelectedTab(index);
64
+ onChangeTab(tabs[index], index);
65
+ };
66
+
67
+ return (
68
+ <TabCardContextProvider value={[selectedTab, setSelectedTab]}>
69
+ <Paper variant="outlined">
70
+ <Box bgcolor={bgColor}>
71
+ <StyledTabs value={selectedTab} onChange={handleChangeTab}>
72
+ {tabs.map(({ text, icon }) => (
73
+ <StyledTab iconPosition="start" disableRipple key={text} label={text} icon={icon} />
74
+ ))}
75
+ </StyledTabs>
76
+ </Box>
77
+ {children}
78
+ </Paper>
79
+ </TabCardContextProvider>
80
+ );
81
+ };
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { render, screen } from "@testing-library/react";
3
3
  import { TabPanel } from "./tab-panel";
4
- import { TabProvider } from "../../../../providers";
4
+ import { TabProvider } from "../../../providers";
5
5
 
6
6
  describe("TabPanel", () => {
7
7
  function renderInstance(initialValue: number) {
@@ -1,9 +1,8 @@
1
- import { Box, IconButton, Rating } from "@mui/material";
1
+ import { Box, Rating } from "@mui/material";
2
2
  import React from "react";
3
3
  import { useEditableValueDisplay, ValueEditButton, ValueEditButtons } from "../value-base";
4
4
  import { BaseValueProps, EditableValueProps } from "../value-base/value-displays.types";
5
5
  import { getValueContentLabelId, ValueContent } from "../value-content";
6
- import EditIcon from "@mui/icons-material/Edit";
7
6
 
8
7
  export type ValueRatingProps = BaseValueProps<number> & {
9
8
  maxRating?: number;
@@ -18,8 +18,6 @@ import {
18
18
  } from "../generators.model";
19
19
  import { newBreakpointsCounter } from "~/utils/breakpoints";
20
20
  import { DataGrid, GridColDef } from "@mui/x-data-grid";
21
- import { ValueContent } from "~/components/value-displays/value-content";
22
- import { ArrayFieldType } from "../generators.model";
23
21
 
24
22
  interface SingleDetailValueFactoryOptions {
25
23
  dense?: boolean;
@@ -1,2 +0,0 @@
1
- export * from "./tab-panel";
2
- export * from "./tab-card";
@@ -1,5 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- export type TabCardProps = PropsWithChildren<{
3
- tabs: string[];
4
- }>;
5
- export declare const TabCard: ({ children, tabs }: TabCardProps) => JSX.Element;
@@ -1,6 +0,0 @@
1
- export declare const DummyTabs: string[];
2
- export interface TabCardDummyProps {
3
- tabs: string[];
4
- initialTab: number;
5
- }
6
- export declare function TabCardDummy({ tabs, initialTab }: TabCardDummyProps): JSX.Element;
@@ -1,2 +0,0 @@
1
- export * from "./tab-panel";
2
- export * from "./tab-card";
@@ -1,5 +0,0 @@
1
- import { PropsWithChildren } from "react";
2
- export type TabCardProps = PropsWithChildren<{
3
- tabs: string[];
4
- }>;
5
- export declare const TabCard: ({ children, tabs }: TabCardProps) => JSX.Element;
@@ -1,6 +0,0 @@
1
- export declare const DummyTabs: string[];
2
- export interface TabCardDummyProps {
3
- tabs: string[];
4
- initialTab: number;
5
- }
6
- export declare function TabCardDummy({ tabs, initialTab }: TabCardDummyProps): JSX.Element;
@@ -1,2 +0,0 @@
1
- export * from "./tab-panel";
2
- 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
- export interface TabCardDummyProps {
10
- tabs: string[];
11
- initialTab: number;
12
- }
13
-
14
- export function TabCardDummy({ tabs, initialTab }: TabCardDummyProps) {
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,53 +0,0 @@
1
- import React from "react";
2
- import { DummyTabs, TabCardDummy } from "./tab-card.dummy";
3
- import { screen, render } from "~/tests/testing-library";
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 } from "react";
3
- import { useTab } from "~/providers";
4
-
5
- const StyledTabs = styled(Tabs)(({ theme }) => ({
6
- [`&.${tabsClasses.root}`]: {
7
- backgroundColor: theme.palette.grey[100],
8
- },
9
- }));
10
-
11
- export type TabCardProps = PropsWithChildren<{
12
- tabs: string[];
13
- }>;
14
-
15
- export const TabCard = ({ children, tabs }: TabCardProps) => {
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
- };