@pautena/react-design-system 0.1.2 → 0.2.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 (191) hide show
  1. package/README.md +4 -0
  2. package/dist/cjs/index.js +4 -259
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/generators/model-router/screens/add-screen.d.ts +1 -1
  5. package/dist/cjs/types/generators/model-router/screens/list-screen.d.ts +1 -1
  6. package/dist/cjs/types/generators/model-router/screens/screens.types.d.ts +20 -0
  7. package/dist/cjs/types/generators/model-router/screens/update-screen.d.ts +1 -1
  8. package/dist/cjs/types/index.d.ts +1 -0
  9. package/dist/esm/index.js +4 -259
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/types/generators/model-router/screens/add-screen.d.ts +1 -1
  12. package/dist/esm/types/generators/model-router/screens/list-screen.d.ts +1 -1
  13. package/dist/esm/types/generators/model-router/screens/screens.types.d.ts +20 -0
  14. package/dist/esm/types/generators/model-router/screens/update-screen.d.ts +1 -1
  15. package/dist/esm/types/index.d.ts +1 -0
  16. package/dist/index.d.ts +52 -3
  17. package/package.json +13 -2
  18. package/src/components/app-bar/app-bar.stories.tsx +54 -0
  19. package/src/components/app-bar/app-bar.test.tsx +142 -0
  20. package/src/components/app-bar/app-bar.tsx +150 -0
  21. package/src/components/app-bar/app-bar.types.ts +17 -0
  22. package/src/components/app-bar/index.ts +3 -0
  23. package/src/components/app-bar/mini-app-bar/index.ts +1 -0
  24. package/src/components/app-bar/mini-app-bar/mini-app-bar.tsx +31 -0
  25. package/src/components/bullet/bullet.stories.tsx +43 -0
  26. package/src/components/bullet/bullet.test.tsx +24 -0
  27. package/src/components/bullet/bullet.tsx +30 -0
  28. package/src/components/bullet/index.ts +1 -0
  29. package/src/components/center-container/center-container.stories.tsx +50 -0
  30. package/src/components/center-container/center-container.test.tsx +16 -0
  31. package/src/components/center-container/center-container.tsx +32 -0
  32. package/src/components/center-container/index.ts +1 -0
  33. package/src/components/content/content.stories.tsx +23 -0
  34. package/src/components/content/content.test.tsx +26 -0
  35. package/src/components/content/content.tsx +11 -0
  36. package/src/components/content/content.types.ts +5 -0
  37. package/src/components/content/index.ts +2 -0
  38. package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +20 -0
  39. package/src/components/drawer/drawer.context.ts +20 -0
  40. package/src/components/drawer/drawer.mixins.ts +24 -0
  41. package/src/components/drawer/drawer.mock.tsx +100 -0
  42. package/src/components/drawer/drawer.provider.tsx +23 -0
  43. package/src/components/drawer/drawer.test.tsx +97 -0
  44. package/src/components/drawer/drawer.tsx +30 -0
  45. package/src/components/drawer/drawer.types.ts +53 -0
  46. package/src/components/drawer/index.ts +5 -0
  47. package/src/components/drawer/mini-drawer/index.ts +1 -0
  48. package/src/components/drawer/mini-drawer/mini-drawer.stories.tsx +34 -0
  49. package/src/components/drawer/mini-drawer/mini-drawer.tsx +67 -0
  50. package/src/components/drawer-content/drawer-content.stories.tsx +29 -0
  51. package/src/components/drawer-content/drawer-content.test.tsx +34 -0
  52. package/src/components/drawer-content/drawer-content.tsx +18 -0
  53. package/src/components/drawer-content/index.ts +1 -0
  54. package/src/components/drawer-item/drawer-item.stories.tsx +62 -0
  55. package/src/components/drawer-item/drawer-item.test.tsx +119 -0
  56. package/src/components/drawer-item/drawer-item.tsx +71 -0
  57. package/src/components/drawer-item/index.ts +1 -0
  58. package/src/components/drawer-section/drawer-section.mock.tsx +39 -0
  59. package/src/components/drawer-section/drawer-section.stories.tsx +28 -0
  60. package/src/components/drawer-section/drawer-section.test.tsx +44 -0
  61. package/src/components/drawer-section/drawer-section.tsx +40 -0
  62. package/src/components/drawer-section/index.ts +1 -0
  63. package/src/components/header/header.dummy.ts +55 -0
  64. package/src/components/header/header.stories.tsx +116 -0
  65. package/src/components/header/header.test.tsx +159 -0
  66. package/src/components/header/header.tsx +121 -0
  67. package/src/components/header/header.types.ts +61 -0
  68. package/src/components/header/index.ts +2 -0
  69. package/src/components/index.ts +18 -0
  70. package/src/components/label/index.ts +1 -0
  71. package/src/components/label/label.stories.tsx +49 -0
  72. package/src/components/label/label.test.tsx +30 -0
  73. package/src/components/label/label.tsx +60 -0
  74. package/src/components/link/index.ts +1 -0
  75. package/src/components/link/link.tsx +17 -0
  76. package/src/components/loading-area/index.ts +1 -0
  77. package/src/components/loading-area/loading-area.stories.tsx +17 -0
  78. package/src/components/loading-area/loading-area.test.tsx +11 -0
  79. package/src/components/loading-area/loading-area.tsx +13 -0
  80. package/src/components/placeholder/index.ts +1 -0
  81. package/src/components/placeholder/placeholder.mock.ts +15 -0
  82. package/src/components/placeholder/placeholder.stories.tsx +44 -0
  83. package/src/components/placeholder/placeholder.test.tsx +76 -0
  84. package/src/components/placeholder/placeholder.tsx +75 -0
  85. package/src/components/query-container/index.ts +1 -0
  86. package/src/components/query-container/query-container.stories.tsx +68 -0
  87. package/src/components/query-container/query-container.test.tsx +95 -0
  88. package/src/components/query-container/query-container.tsx +71 -0
  89. package/src/components/sign-in/index.ts +1 -0
  90. package/src/components/sign-in/sign-in.stories.tsx +36 -0
  91. package/src/components/sign-in/sign-in.test.tsx +95 -0
  92. package/src/components/sign-in/sign-in.tsx +97 -0
  93. package/src/components/tab/index.ts +2 -0
  94. package/src/components/tab/tab-card/index.ts +1 -0
  95. package/src/components/tab/tab-card/tab-card.dummy.tsx +30 -0
  96. package/src/components/tab/tab-card/tab-card.stories.tsx +22 -0
  97. package/src/components/tab/tab-card/tab-card.test.tsx +53 -0
  98. package/src/components/tab/tab-card/tab-card.tsx +27 -0
  99. package/src/components/tab/tab-panel/index.ts +1 -0
  100. package/src/components/tab/tab-panel/tab-panel.test.tsx +26 -0
  101. package/src/components/tab/tab-panel/tab-panel.tsx +27 -0
  102. package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +27 -0
  103. package/src/components/table/enhanced-remote-table/enhanced-remote-table.stories.tsx +24 -0
  104. package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +77 -0
  105. package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +74 -0
  106. package/src/components/table/enhanced-remote-table/index.ts +1 -0
  107. package/src/components/table/enhanced-table/enhanced-table-head.tsx +58 -0
  108. package/src/components/table/enhanced-table/enhanced-table.mock.tsx +93 -0
  109. package/src/components/table/enhanced-table/enhanced-table.stories.tsx +21 -0
  110. package/src/components/table/enhanced-table/enhanced-table.test.tsx +107 -0
  111. package/src/components/table/enhanced-table/enhanced-table.tsx +136 -0
  112. package/src/components/table/enhanced-table/index.ts +2 -0
  113. package/src/components/table/index.ts +2 -0
  114. package/src/components/table-list/index.ts +1 -0
  115. package/src/components/table-list/table-list.stories.tsx +75 -0
  116. package/src/components/table-list/table-list.test.tsx +291 -0
  117. package/src/components/table-list/table-list.tsx +127 -0
  118. package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +35 -0
  119. package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +26 -0
  120. package/src/components/value-displays/group-value-card/group-value-card.test.tsx +58 -0
  121. package/src/components/value-displays/group-value-card/group-value-card.tsx +63 -0
  122. package/src/components/value-displays/group-value-card/index.ts +1 -0
  123. package/src/components/value-displays/index.ts +4 -0
  124. package/src/components/value-displays/value-boolean/index.ts +1 -0
  125. package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +25 -0
  126. package/src/components/value-displays/value-boolean/value-boolean.test.tsx +27 -0
  127. package/src/components/value-displays/value-boolean/value-boolean.tsx +33 -0
  128. package/src/components/value-displays/value-card/index.ts +1 -0
  129. package/src/components/value-displays/value-card/value-card.stories.tsx +22 -0
  130. package/src/components/value-displays/value-card/value-card.test.tsx +18 -0
  131. package/src/components/value-displays/value-card/value-card.tsx +12 -0
  132. package/src/components/value-displays/value-text/index.ts +1 -0
  133. package/src/components/value-displays/value-text/value-test.test.tsx +21 -0
  134. package/src/components/value-displays/value-text/value-text.stories.tsx +26 -0
  135. package/src/components/value-displays/value-text/value-text.tsx +32 -0
  136. package/src/generators/generators.mock.ts +238 -0
  137. package/src/generators/generators.model.ts +46 -0
  138. package/src/generators/index.ts +4 -0
  139. package/src/generators/model-form/index.ts +1 -0
  140. package/src/generators/model-form/model-form.stories.tsx +30 -0
  141. package/src/generators/model-form/model-form.test.tsx +100 -0
  142. package/src/generators/model-form/model-form.tsx +97 -0
  143. package/src/generators/model-router/index.ts +1 -0
  144. package/src/generators/model-router/model-router.test.tsx +831 -0
  145. package/src/generators/model-router/model-router.tsx +30 -0
  146. package/src/generators/model-router/model-router.types.ts +14 -0
  147. package/src/generators/model-router/screens/add-screen.tsx +70 -0
  148. package/src/generators/model-router/screens/details-screen.tsx +62 -0
  149. package/src/generators/model-router/screens/index.ts +4 -0
  150. package/src/generators/model-router/screens/list-screen.tsx +125 -0
  151. package/src/generators/model-router/screens/screens.types.ts +38 -0
  152. package/src/generators/model-router/screens/update-screen.tsx +97 -0
  153. package/src/generators/model-router/stories/details-screen.stories.tsx +38 -0
  154. package/src/generators/model-router/stories/list-screen.stories.tsx +96 -0
  155. package/src/generators/model-router/stories/model-router.stories.tsx +176 -0
  156. package/src/generators/model-router/stories/templates.tsx +39 -0
  157. package/src/generators/object-details/index.ts +1 -0
  158. package/src/generators/object-details/object-details.stories.tsx +20 -0
  159. package/src/generators/object-details/object-details.test.tsx +21 -0
  160. package/src/generators/object-details/object-details.tsx +76 -0
  161. package/src/index.ts +5 -0
  162. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +28 -0
  163. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +30 -0
  164. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.tsx +37 -0
  165. package/src/layouts/app-bar-with-drawer-layout/index.ts +1 -0
  166. package/src/layouts/header-layout/header-layout.stories.tsx +204 -0
  167. package/src/layouts/header-layout/header-layout.test.tsx +37 -0
  168. package/src/layouts/header-layout/header-layout.tsx +23 -0
  169. package/src/layouts/header-layout/index.ts +1 -0
  170. package/src/layouts/index.ts +2 -0
  171. package/src/providers/index.ts +2 -0
  172. package/src/providers/notification-center/index.ts +2 -0
  173. package/src/providers/notification-center/notification-center.context.ts +37 -0
  174. package/src/providers/notification-center/notification-center.provider.tsx +51 -0
  175. package/src/providers/notification-center/notification-center.stories.tsx +52 -0
  176. package/src/providers/notification-center/notification-center.test.tsx +112 -0
  177. package/src/providers/tab-provider/index.ts +2 -0
  178. package/src/providers/tab-provider/tab-provider.context.ts +8 -0
  179. package/src/providers/tab-provider/tab-provider.provider.tsx +13 -0
  180. package/src/storybook.tsx +90 -0
  181. package/src/tests/assertions.ts +76 -0
  182. package/src/tests/components.tsx +60 -0
  183. package/src/tests/content-placeholder.stories.tsx +16 -0
  184. package/src/tests/index.ts +3 -0
  185. package/src/tests/skeleton-card.stories.tsx +18 -0
  186. package/src/tests/testing-library.tsx +65 -0
  187. package/src/utils/arrays.test.ts +9 -0
  188. package/src/utils/arrays.ts +7 -0
  189. package/src/utils/index.ts +2 -0
  190. package/src/utils/theme.ts +11 -0
  191. package/.prettierrc.js +0 -5
@@ -0,0 +1,58 @@
1
+ import { render, screen } from "../../../tests";
2
+ import React from "react";
3
+ import { GroupValueCardDummy } from "./group-value-card.mock";
4
+
5
+ describe("GroupValueCard", () => {
6
+ const renderComponent = ({
7
+ title = "Hello world",
8
+ subtitle = undefined,
9
+ }: { title?: string; subtitle?: string } = {}) => {
10
+ return render(<GroupValueCardDummy title={title} subtitle={subtitle} />);
11
+ };
12
+ it("would render a title", () => {
13
+ renderComponent({ title: "Hello world" });
14
+
15
+ expect(screen.getByRole("heading", { level: 1 })).toBeInTheDocument();
16
+ });
17
+
18
+ describe("subtitle", () => {
19
+ it("would not render a subtitle if it's not provided", () => {
20
+ renderComponent({ subtitle: undefined });
21
+
22
+ expect(screen.queryByRole("heading", { level: 2 })).not.toBeInTheDocument();
23
+ });
24
+
25
+ it("would render a subtitle if it's provided", () => {
26
+ renderComponent({ subtitle: "Hi. I am batman" });
27
+
28
+ expect(
29
+ screen.getByRole("heading", { level: 2, name: /hi. i am batman/i }),
30
+ ).toBeInTheDocument();
31
+ });
32
+ });
33
+
34
+ it("would render all values", () => {
35
+ renderComponent();
36
+
37
+ expect(screen.getByRole("label", { name: /hello world/i })).toBeInTheDocument();
38
+ expect(screen.getByText(/lorem ipsum sit amet/i)).toBeInTheDocument();
39
+
40
+ expect(screen.getByRole("label", { name: /enabled/i })).toBeInTheDocument();
41
+ expect(screen.getByTestId("CheckIcon")).toBeInTheDocument();
42
+
43
+ expect(screen.getByRole("label", { name: /quantity/i })).toBeInTheDocument();
44
+ expect(screen.getByText(/1200/i)).toBeInTheDocument();
45
+
46
+ expect(screen.getByRole("label", { name: /currency/i })).toBeInTheDocument();
47
+ expect(screen.getByText(/eur/i)).toBeInTheDocument();
48
+
49
+ expect(screen.getByRole("label", { name: /i am batman/i })).toBeInTheDocument();
50
+ expect(screen.getByText(/does it come in black/i)).toBeInTheDocument();
51
+
52
+ expect(screen.getByRole("label", { name: /status/i })).toBeInTheDocument();
53
+ expect(screen.getByText(/open/i)).toBeInTheDocument();
54
+
55
+ expect(screen.getByRole("label", { name: /level/i })).toBeInTheDocument();
56
+ expect(screen.getByText(/2144/i)).toBeInTheDocument();
57
+ });
58
+ });
@@ -0,0 +1,63 @@
1
+ import { Grid, Paper, GridProps, Box, Typography } from "@mui/material";
2
+ import React, { FunctionComponent, PropsWithChildren, ReactElement } from "react";
3
+ import { useGetDefaultThemeColor } from "../../../utils/theme";
4
+
5
+ export type GroupValueItemProps = PropsWithChildren<Omit<GridProps, "item" | "container">>;
6
+ export type GroupValueItemComponent = FunctionComponent<GroupValueItemProps>;
7
+ export type GroupValueItemElement = ReactElement<GroupValueItemProps, GroupValueItemComponent>;
8
+
9
+ export const groupValueItemClasses = {
10
+ root: "RdsGroupValueItem-root",
11
+ };
12
+
13
+ export const GroupValueItem: GroupValueItemComponent = ({
14
+ children,
15
+ ...rest
16
+ }: GroupValueItemProps) => {
17
+ const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
18
+
19
+ return (
20
+ <Grid item className={groupValueItemClasses.root} {...rest}>
21
+ <Box
22
+ px={1}
23
+ sx={{
24
+ borderLeft: `solid ${defaultColor} 1px`,
25
+ }}
26
+ >
27
+ {children}
28
+ </Box>
29
+ </Grid>
30
+ );
31
+ };
32
+
33
+ export interface GroupValueCardProps {
34
+ title: string;
35
+ subtitle?: string;
36
+ children: GroupValueItemElement | GroupValueItemElement[];
37
+ }
38
+
39
+ export const GroupValueCard = ({ title, subtitle, children }: GroupValueCardProps) => {
40
+ const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
41
+
42
+ return (
43
+ <Paper
44
+ sx={{
45
+ paddingBottom: 1,
46
+ }}
47
+ >
48
+ <Box bgcolor={defaultColor} px={2} py={1}>
49
+ <Typography variant="h6" role="heading" aria-level={1}>
50
+ {title}
51
+ </Typography>
52
+ {subtitle && (
53
+ <Typography variant="body2" role="heading" aria-level={2}>
54
+ {subtitle}
55
+ </Typography>
56
+ )}
57
+ </Box>
58
+ <Grid container margin={2} rowSpacing={2}>
59
+ {children}
60
+ </Grid>
61
+ </Paper>
62
+ );
63
+ };
@@ -0,0 +1 @@
1
+ export * from "./group-value-card";
@@ -0,0 +1,4 @@
1
+ export * from "./value-text";
2
+ export * from "./value-card";
3
+ export * from "./value-boolean";
4
+ export * from "./group-value-card";
@@ -0,0 +1 @@
1
+ export * from "./value-boolean";
@@ -0,0 +1,25 @@
1
+ import { ComponentMeta } from "@storybook/react";
2
+ import { ValueBoolean } from "./value-boolean";
3
+ import { createTemplate } from "../../../storybook";
4
+
5
+ export default {
6
+ title: "Value displays/ValueBoolean",
7
+ component: ValueBoolean,
8
+ parameters: {
9
+ layout: "centered",
10
+ },
11
+ } as ComponentMeta<typeof ValueBoolean>;
12
+
13
+ const Template = createTemplate(ValueBoolean);
14
+
15
+ export const True = Template.bind({});
16
+ True.args = {
17
+ label: "Lorem ipsum",
18
+ value: true,
19
+ };
20
+
21
+ export const False = Template.bind({});
22
+ False.args = {
23
+ label: "Lorem ipsum",
24
+ value: false,
25
+ };
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import { ValueBoolean } from "./value-boolean";
3
+ import { render, screen } from "../../../tests";
4
+
5
+ describe("ValueBoolean", () => {
6
+ const renderComponent = ({ value }: { value: boolean }) => {
7
+ return render(<ValueBoolean label="Hello world" value={value} />);
8
+ };
9
+
10
+ it("would render the label", () => {
11
+ renderComponent({ value: true });
12
+
13
+ expect(screen.getByRole("label", { name: /hello world/i })).toBeInTheDocument();
14
+ });
15
+
16
+ it("would render a check if value is true", () => {
17
+ renderComponent({ value: true });
18
+
19
+ expect(screen.getByTestId("CheckIcon")).toBeInTheDocument();
20
+ });
21
+
22
+ it("would render a cross if value is false", () => {
23
+ renderComponent({ value: false });
24
+
25
+ expect(screen.getByTestId("CloseIcon")).toBeInTheDocument();
26
+ });
27
+ });
@@ -0,0 +1,33 @@
1
+ import { Box, Typography, useTheme } from "@mui/material";
2
+ import React from "react";
3
+ import CheckIcon from "@mui/icons-material/Check";
4
+ import CloseIcon from "@mui/icons-material/Close";
5
+
6
+ export interface ValueBooleanProps {
7
+ /**
8
+ * Name of the displayed value
9
+ */
10
+ label: string;
11
+ /**
12
+ * Value displayed
13
+ */
14
+ value: boolean;
15
+ }
16
+
17
+ /**
18
+ * Displays a boolean value with a label
19
+ */
20
+ export const ValueBoolean = ({ label, value }: ValueBooleanProps) => {
21
+ const { typography } = useTheme();
22
+
23
+ const iconSx = { fontSize: typography.h5.fontSize };
24
+
25
+ return (
26
+ <Box>
27
+ <Typography variant="subtitle2" role="label">
28
+ {label}
29
+ </Typography>
30
+ {value ? <CheckIcon color="success" sx={iconSx} /> : <CloseIcon color="error" sx={iconSx} />}
31
+ </Box>
32
+ );
33
+ };
@@ -0,0 +1 @@
1
+ export * from "./value-card";
@@ -0,0 +1,22 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { ComponentMeta } from "@storybook/react";
3
+ import { ValueCard } from "./value-card";
4
+ import { createTemplate } from "../../../storybook";
5
+ import { ValueText } from "../value-text";
6
+
7
+ export default {
8
+ title: "Value displays/ValueCard",
9
+ component: ValueCard,
10
+ parameters: {
11
+ layout: "centered",
12
+ },
13
+ } as ComponentMeta<typeof ValueCard>;
14
+
15
+ const Template = createTemplate(({ children }: PropsWithChildren) => {
16
+ return <ValueCard>{children}</ValueCard>;
17
+ });
18
+
19
+ export const ValueCardText = Template.bind({});
20
+ ValueCardText.args = {
21
+ children: <ValueText label="Hello world" value="Lorem ipsum sit amet" />,
22
+ };
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { ValueCard } from "./value-card";
3
+ import { render, screen } from "../../../tests";
4
+ import { ReactElement } from "react";
5
+ import { ValueText } from "../value-text";
6
+
7
+ describe("ValueCard", () => {
8
+ const renderComponent = ({ children }: { children: ReactElement }) => {
9
+ return render(<ValueCard>{children}</ValueCard>);
10
+ };
11
+
12
+ it("would render with a ValueText inside", () => {
13
+ renderComponent({ children: <ValueText label="Hello world" value="Lorem ipsum sit amet" /> });
14
+
15
+ expect(screen.getByRole("label", { name: /hello world/i })).toBeInTheDocument();
16
+ expect(screen.getByText(/lorem ipsum sit amet/i)).toBeInTheDocument();
17
+ });
18
+ });
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { Paper } from "@mui/material";
3
+ import { PropsWithChildren } from "react";
4
+
5
+ export type ValueCardProps = PropsWithChildren;
6
+
7
+ /**
8
+ * Container to show a labeled value
9
+ */
10
+ export const ValueCard = ({ children }: ValueCardProps) => {
11
+ return <Paper sx={{ p: 2 }}>{children}</Paper>;
12
+ };
@@ -0,0 +1 @@
1
+ export * from "./value-text";
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { render, screen } from "../../../tests";
3
+ import { ValueText } from "./value-text";
4
+
5
+ describe("ValueText", () => {
6
+ const renderComponent = () => {
7
+ return render(<ValueText label="Hello world" value="Lorem ipsum sit amet" />);
8
+ };
9
+
10
+ it("would render the label", () => {
11
+ renderComponent();
12
+
13
+ expect(screen.getByRole("label", { name: /hello world/i })).toBeInTheDocument();
14
+ });
15
+
16
+ it("would render the value", () => {
17
+ renderComponent();
18
+
19
+ expect(screen.getByText(/lorem ipsum sit amet/i)).toBeInTheDocument();
20
+ });
21
+ });
@@ -0,0 +1,26 @@
1
+ import { ComponentMeta } from "@storybook/react";
2
+ import { ValueText } from "./value-text";
3
+ import { createTemplate, withContainer } from "../../../storybook";
4
+
5
+ export default {
6
+ title: "Value displays/ValueText",
7
+ component: ValueText,
8
+ decorators: [withContainer({ width: 200 })],
9
+ parameters: {
10
+ layout: "centered",
11
+ },
12
+ } as ComponentMeta<typeof ValueText>;
13
+
14
+ const Template = createTemplate(ValueText);
15
+
16
+ export const Default = Template.bind({});
17
+ Default.args = {
18
+ label: "Lorem",
19
+ value: "ipsum sit",
20
+ };
21
+
22
+ export const TruncatedText = Template.bind({});
23
+ TruncatedText.args = {
24
+ label: "Lorem",
25
+ value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
26
+ };
@@ -0,0 +1,32 @@
1
+ import { Box, Tooltip, Typography } from "@mui/material";
2
+ import React from "react";
3
+
4
+ export interface ValueTextProps {
5
+ /**
6
+ * Name of the displayed value
7
+ */
8
+ label: string;
9
+ /**
10
+ * Value displayed
11
+ */
12
+ value: string;
13
+ }
14
+
15
+ /**
16
+ * Displays a string value with a label
17
+ */
18
+ export const ValueText = ({ label, value }: ValueTextProps) => {
19
+ const id = `label-${label.replace(/ /g, "-")}`;
20
+ return (
21
+ <Box>
22
+ <Typography variant="subtitle2" role="label" id={id}>
23
+ {label}
24
+ </Typography>
25
+ <Tooltip title={value} placement="top" enterDelay={2000}>
26
+ <Typography variant="h5" noWrap aria-labelledby={id}>
27
+ {value}
28
+ </Typography>
29
+ </Tooltip>
30
+ </Box>
31
+ );
32
+ };
@@ -0,0 +1,238 @@
1
+ import { Model, ModelField } from "./generators.model";
2
+ import { faker } from "@faker-js/faker";
3
+ import { BasicData } from "../components";
4
+
5
+ export const mockModel: Model = {
6
+ fields: [
7
+ {
8
+ id: "id",
9
+ type: "string",
10
+ description: "User identifier",
11
+ name: "Id",
12
+ xs: 12,
13
+ sm: 6,
14
+ md: 4,
15
+ listable: false,
16
+ },
17
+ {
18
+ id: "firstName",
19
+ type: "string",
20
+ description: "User first name",
21
+ name: "First name",
22
+ xs: 12,
23
+ sm: 6,
24
+ md: 4,
25
+ listable: true,
26
+ },
27
+ {
28
+ id: "middleName",
29
+ type: "string",
30
+ description: "User middle name",
31
+ name: "Middle name",
32
+ xs: 12,
33
+ sm: 6,
34
+ md: 4,
35
+ listable: true,
36
+ },
37
+ {
38
+ id: "lastName",
39
+ type: "string",
40
+ description: "User last name",
41
+ name: "Last name",
42
+ xs: 12,
43
+ sm: 6,
44
+ md: 4,
45
+ listable: true,
46
+ },
47
+ {
48
+ id: "gender",
49
+ type: "string",
50
+ description: "User gender",
51
+ name: "Gender",
52
+ xs: 12,
53
+ sm: 6,
54
+ md: 3,
55
+ },
56
+ {
57
+ id: "age",
58
+ type: "number",
59
+ description: "User age",
60
+ name: "Age",
61
+ xs: 12,
62
+ sm: 6,
63
+ md: 3,
64
+ listable: true,
65
+ },
66
+ {
67
+ id: "birthDate",
68
+ type: "string",
69
+ description: "When he was born",
70
+ name: "Birth Date",
71
+ xs: 12,
72
+ sm: 6,
73
+ md: 6,
74
+ listable: true,
75
+ },
76
+ {
77
+ id: "car",
78
+ type: "group",
79
+ description: "Information about the user car",
80
+ name: "User car",
81
+ value: [
82
+ {
83
+ id: "model",
84
+ type: "string",
85
+ description: "Lorem ipsum",
86
+ name: "Model",
87
+ xs: 12,
88
+ sm: 5,
89
+ },
90
+ {
91
+ id: "manufacturer",
92
+ type: "string",
93
+ description: "Lorem ipsum",
94
+ name: "Manufacturer",
95
+ xs: 12,
96
+ sm: 5,
97
+ },
98
+ {
99
+ id: "color",
100
+ type: "string",
101
+ description: "Lorem ipsum",
102
+ name: "Color",
103
+ xs: 12,
104
+ sm: 2,
105
+ },
106
+ {
107
+ id: "type",
108
+ type: "string",
109
+ description: "Lorem ipsum",
110
+ name: "Type",
111
+ xs: 12,
112
+ sm: 3,
113
+ },
114
+ {
115
+ id: "vin",
116
+ type: "string",
117
+ description: "Lorem ipsum",
118
+ name: "VIN",
119
+ xs: 12,
120
+ sm: 5,
121
+ },
122
+ {
123
+ id: "vrm",
124
+ type: "string",
125
+ description: "Lorem ipsum",
126
+ name: "VRM",
127
+ xs: 12,
128
+ sm: 4,
129
+ },
130
+ ],
131
+ },
132
+ {
133
+ id: "quantity",
134
+ type: "number",
135
+ description: "Lorem ipsum",
136
+ name: "Q",
137
+ xs: 12,
138
+ sm: 2,
139
+ md: 1,
140
+ },
141
+ {
142
+ id: "available",
143
+ type: "boolean",
144
+ description: "Lorem ipsum",
145
+ name: "Available",
146
+ xs: 12,
147
+ sm: 2,
148
+ },
149
+ {
150
+ id: "currency",
151
+ type: "string",
152
+ description: "Lorem ipsum",
153
+ name: "Unit Price Currency",
154
+ xs: 12,
155
+ sm: 3,
156
+ },
157
+ {
158
+ id: "tradeDate",
159
+ type: "string",
160
+ description: "Lorem ipsum",
161
+ name: "Trade date",
162
+ xs: 12,
163
+ sm: 3,
164
+ },
165
+ ],
166
+ };
167
+
168
+ export interface MockInstance {
169
+ id: string;
170
+ firstName: string;
171
+ middleName: string;
172
+ lastName: string;
173
+ gender: string;
174
+ age: number;
175
+ birthDate: string;
176
+ car: {
177
+ model: string;
178
+ manufacturer: string;
179
+ color: string;
180
+ type: string;
181
+ vin: string;
182
+ vrm: string;
183
+ };
184
+ quantity: number;
185
+ available: boolean;
186
+ currency: string;
187
+ tradeDate: string;
188
+ }
189
+
190
+ const mockFieldValue = {
191
+ id: () => faker.datatype.number({ min: 1000, max: 100000 }).toString(),
192
+ firstName: faker.name.firstName,
193
+ middleName: faker.name.middleName,
194
+ lastName: faker.name.lastName,
195
+ gender: faker.name.gender,
196
+ age: () => faker.datatype.number({ min: 20, max: 60 }),
197
+ birthDate: () => faker.datatype.datetime().toString(),
198
+ model: faker.vehicle.model,
199
+ manufacturer: faker.vehicle.manufacturer,
200
+ color: faker.vehicle.color,
201
+ type: faker.vehicle.type,
202
+ vin: faker.vehicle.vin,
203
+ vrm: faker.vehicle.vrm,
204
+ quantity: () => faker.datatype.number({ min: 1, max: 9 }),
205
+ available: faker.datatype.boolean,
206
+ currency: () => "MXN",
207
+ tradeDate: () => "Thu Jul 21 2022 22:44:10 GMT+0200 (Central European Summer Time)",
208
+ };
209
+
210
+ export const createModelInstance = <T extends BasicData>(model: Model, seed = 100): T => {
211
+ faker.seed(seed);
212
+ const obj = {};
213
+
214
+ model.fields.forEach((field) => {
215
+ let value;
216
+ if (field.type === "group") {
217
+ value = {};
218
+ field.value.forEach((groupField) => {
219
+ value[groupField.id] = getModelFieldValue(groupField);
220
+ });
221
+ } else {
222
+ value = getModelFieldValue(field);
223
+ }
224
+
225
+ obj[field.id] = value;
226
+ });
227
+
228
+ return obj as T;
229
+ };
230
+
231
+ const getModelFieldValue = ({ id, type }: ModelField) => {
232
+ const fieldGenerator = mockFieldValue[id];
233
+ if (!fieldGenerator) {
234
+ const generator = faker.datatype[type];
235
+ return generator ? generator() : faker.datatype.string();
236
+ }
237
+ return fieldGenerator();
238
+ };
@@ -0,0 +1,46 @@
1
+ type Base = {
2
+ id: string;
3
+ description: string;
4
+ name: string;
5
+ listable?: boolean;
6
+ };
7
+
8
+ type Breakpoints = {
9
+ xs?: number;
10
+ sm?: number;
11
+ md?: number;
12
+ lg?: number;
13
+ xl?: number;
14
+ };
15
+
16
+ type StringField = {
17
+ type: "string";
18
+ };
19
+
20
+ type NumberField = {
21
+ type: "number";
22
+ };
23
+
24
+ type BooleanField = {
25
+ type: "boolean";
26
+ };
27
+
28
+ type SingleFields = StringField | NumberField | BooleanField;
29
+
30
+ export type GroupField = {
31
+ type: "group";
32
+ value: (Base & Breakpoints & SingleFields)[];
33
+ } & Base;
34
+
35
+ type Fields = SingleFields | GroupField;
36
+
37
+ export type ModelField = Base & Breakpoints & Fields;
38
+
39
+ export type Model = {
40
+ fields: ModelField[];
41
+ };
42
+
43
+ export interface BasicModelInstance {
44
+ id: string;
45
+ [key: string]: any;
46
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./object-details";
2
+ export * from "./model-router";
3
+ export * from "./generators.model";
4
+ export * from "./model-form";
@@ -0,0 +1 @@
1
+ export * from "./model-form";
@@ -0,0 +1,30 @@
1
+ import { ComponentMeta } from "@storybook/react";
2
+ import { ModelForm } from "./model-form";
3
+ import { createTemplate, withPadding } from "../../storybook";
4
+ import { createModelInstance, mockModel } from "../generators.mock";
5
+
6
+ const initialValues = createModelInstance(mockModel);
7
+
8
+ export default {
9
+ title: "Generators/ModelForm",
10
+ component: ModelForm,
11
+ decorators: [withPadding(2)],
12
+ parameters: {
13
+ layout: "fullscreen",
14
+ },
15
+ } as ComponentMeta<typeof ModelForm>;
16
+
17
+ const Template = createTemplate(ModelForm);
18
+
19
+ export const AddForm = Template.bind({});
20
+ AddForm.args = {
21
+ model: mockModel,
22
+ saveButtonText: "add",
23
+ };
24
+
25
+ export const UpdateForm = Template.bind({});
26
+ UpdateForm.args = {
27
+ model: mockModel,
28
+ initialValues,
29
+ saveButtonText: "update",
30
+ };