@pautena/react-design-system 0.4.7 → 0.5.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/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/alerts/expandable-alert/expandable-alert.d.ts +11 -0
- package/dist/cjs/types/components/alerts/expandable-alert/index.d.ts +1 -0
- package/dist/cjs/types/components/alerts/index.d.ts +1 -0
- package/dist/cjs/types/components/data-display/board/board.d.ts +10 -0
- package/dist/cjs/types/components/data-display/board/index.d.ts +1 -0
- package/dist/cjs/types/components/data-display/index.d.ts +2 -0
- package/dist/cjs/types/components/data-display/markdown/index.d.ts +1 -0
- package/dist/cjs/types/components/data-display/markdown/markdown.d.ts +7 -0
- package/dist/cjs/types/components/dialogs/bootstrap-dialog/bootstrap-dialog.d.ts +2 -0
- package/dist/cjs/types/components/dialogs/bootstrap-dialog/index.d.ts +1 -0
- package/dist/cjs/types/components/dialogs/confirm-dialog/confirm-dialog.d.ts +10 -0
- package/dist/cjs/types/components/dialogs/confirm-dialog/index.d.ts +1 -0
- package/dist/cjs/types/components/dialogs/dialog-hooks/index.d.ts +1 -0
- package/dist/cjs/types/components/dialogs/dialog-hooks/use-dialog.d.ts +7 -0
- package/dist/cjs/types/components/dialogs/dialog.types.d.ts +26 -0
- package/dist/cjs/types/components/dialogs/form-dialog/form-dialog.d.ts +10 -0
- package/dist/cjs/types/components/dialogs/form-dialog/index.d.ts +1 -0
- package/dist/cjs/types/components/dialogs/index.d.ts +5 -0
- package/dist/cjs/types/components/index.d.ts +2 -0
- package/dist/cjs/types/components/inputs/enhanced-autocomplete/enhanced-autocomplete.d.ts +10 -0
- package/dist/cjs/types/components/inputs/enhanced-autocomplete/index.d.ts +1 -0
- package/dist/cjs/types/components/inputs/enhanced-text-field/enhanced-text-field.d.ts +7 -0
- package/dist/cjs/types/components/inputs/enhanced-text-field/index.d.ts +1 -0
- package/dist/cjs/types/components/inputs/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/index.d.ts +2 -1
- package/dist/cjs/types/components/value-displays/value-base/index.d.ts +2 -0
- package/dist/cjs/types/components/value-displays/{value-displays.types.d.ts → value-base/value-displays.types.d.ts} +10 -0
- package/dist/cjs/types/components/value-displays/value-base/value-edit.d.ts +19 -0
- package/dist/cjs/types/components/value-displays/value-boolean/value-boolean.d.ts +3 -3
- package/dist/cjs/types/components/value-displays/value-datetime/value-datetime.d.ts +8 -3
- package/dist/cjs/types/components/value-displays/value-image/value-image.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-rating/value-rating.d.ts +3 -3
- package/dist/cjs/types/components/value-displays/value-text/value-text.d.ts +3 -17
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/alerts/expandable-alert/expandable-alert.d.ts +11 -0
- package/dist/esm/types/components/alerts/expandable-alert/index.d.ts +1 -0
- package/dist/esm/types/components/alerts/index.d.ts +1 -0
- package/dist/esm/types/components/data-display/board/board.d.ts +10 -0
- package/dist/esm/types/components/data-display/board/index.d.ts +1 -0
- package/dist/esm/types/components/data-display/index.d.ts +2 -0
- package/dist/esm/types/components/data-display/markdown/index.d.ts +1 -0
- package/dist/esm/types/components/data-display/markdown/markdown.d.ts +7 -0
- package/dist/esm/types/components/dialogs/bootstrap-dialog/bootstrap-dialog.d.ts +2 -0
- package/dist/esm/types/components/dialogs/bootstrap-dialog/index.d.ts +1 -0
- package/dist/esm/types/components/dialogs/confirm-dialog/confirm-dialog.d.ts +10 -0
- package/dist/esm/types/components/dialogs/confirm-dialog/index.d.ts +1 -0
- package/dist/esm/types/components/dialogs/dialog-hooks/index.d.ts +1 -0
- package/dist/esm/types/components/dialogs/dialog-hooks/use-dialog.d.ts +7 -0
- package/dist/esm/types/components/dialogs/dialog.types.d.ts +26 -0
- package/dist/esm/types/components/dialogs/form-dialog/form-dialog.d.ts +10 -0
- package/dist/esm/types/components/dialogs/form-dialog/index.d.ts +1 -0
- package/dist/esm/types/components/dialogs/index.d.ts +5 -0
- package/dist/esm/types/components/index.d.ts +2 -0
- package/dist/esm/types/components/inputs/enhanced-autocomplete/enhanced-autocomplete.d.ts +10 -0
- package/dist/esm/types/components/inputs/enhanced-autocomplete/index.d.ts +1 -0
- package/dist/esm/types/components/inputs/enhanced-text-field/enhanced-text-field.d.ts +7 -0
- package/dist/esm/types/components/inputs/enhanced-text-field/index.d.ts +1 -0
- package/dist/esm/types/components/inputs/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/index.d.ts +2 -1
- package/dist/esm/types/components/value-displays/value-base/index.d.ts +2 -0
- package/dist/esm/types/components/value-displays/{value-displays.types.d.ts → value-base/value-displays.types.d.ts} +10 -0
- package/dist/esm/types/components/value-displays/value-base/value-edit.d.ts +19 -0
- package/dist/esm/types/components/value-displays/value-boolean/value-boolean.d.ts +3 -3
- package/dist/esm/types/components/value-displays/value-datetime/value-datetime.d.ts +8 -3
- package/dist/esm/types/components/value-displays/value-image/value-image.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-rating/value-rating.d.ts +3 -3
- package/dist/esm/types/components/value-displays/value-text/value-text.d.ts +3 -17
- package/dist/index.d.ts +130 -22
- package/package.json +34 -32
- package/src/components/alerts/alerts.stories.mdx +10 -0
- package/src/components/alerts/expandable-alert/expandable-alert.stories.tsx +48 -0
- package/src/components/alerts/expandable-alert/expandable-alert.test.tsx +114 -0
- package/src/components/alerts/expandable-alert/expandable-alert.tsx +71 -0
- package/src/components/alerts/expandable-alert/index.ts +1 -0
- package/src/components/alerts/index.ts +1 -0
- package/src/components/components.stories.mdx +2 -0
- package/src/components/data-display/board/board.stories.tsx +54 -0
- package/src/components/data-display/board/board.test.tsx +100 -0
- package/src/components/data-display/board/board.tsx +63 -0
- package/src/components/data-display/board/index.ts +1 -0
- package/src/components/data-display/data-display.stories.mdx +2 -0
- package/src/components/data-display/index.ts +2 -0
- package/src/components/data-display/markdown/index.ts +1 -0
- package/src/components/data-display/markdown/markdown.stories.tsx +25 -0
- package/src/components/data-display/markdown/markdown.test.tsx +64 -0
- package/src/components/data-display/markdown/markdown.tsx +38 -0
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.stories.tsx +81 -0
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.test.tsx +233 -0
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.tsx +95 -0
- package/src/components/dialogs/bootstrap-dialog/index.ts +1 -0
- package/src/components/dialogs/confirm-dialog/confirm-dialog.stories.tsx +43 -0
- package/src/components/dialogs/confirm-dialog/confirm-dialog.test.tsx +150 -0
- package/src/components/dialogs/confirm-dialog/confirm-dialog.tsx +51 -0
- package/src/components/dialogs/confirm-dialog/index.ts +1 -0
- package/src/components/dialogs/dialog-hooks/index.ts +1 -0
- package/src/components/dialogs/dialog-hooks/use-dialog.ts +10 -0
- package/src/components/dialogs/dialog.types.ts +27 -0
- package/src/components/dialogs/dialogs.stories.mdx +12 -0
- package/src/components/dialogs/form-dialog/form-dialog.stories.tsx +52 -0
- package/src/components/dialogs/form-dialog/form-dialog.test.tsx +164 -0
- package/src/components/dialogs/form-dialog/form-dialog.tsx +69 -0
- package/src/components/dialogs/form-dialog/index.ts +1 -0
- package/src/components/dialogs/index.ts +5 -0
- package/src/components/drawers/drawer-collapsable-item/drawer-collapsable-item.tsx +1 -3
- package/src/components/index.ts +2 -0
- package/src/components/inputs/enhanced-autocomplete/enhanced-autocomplete.stories.tsx +109 -0
- package/src/components/inputs/enhanced-autocomplete/enhanced-autocomplete.test.tsx +74 -0
- package/src/components/inputs/enhanced-autocomplete/enhanced-autocomplete.tsx +64 -0
- package/src/components/inputs/enhanced-autocomplete/index.ts +1 -0
- package/src/components/inputs/enhanced-text-field/enhanced-text-field.stories.tsx +120 -0
- package/src/components/inputs/enhanced-text-field/enhanced-text-field.test.tsx +63 -0
- package/src/components/inputs/enhanced-text-field/enhanced-text-field.tsx +101 -0
- package/src/components/inputs/enhanced-text-field/index.ts +1 -0
- package/src/components/inputs/index.ts +1 -0
- package/src/components/inputs/inputs.stories.mdx +2 -0
- package/src/components/value-displays/index.ts +2 -1
- package/src/components/value-displays/value-base/index.ts +2 -0
- package/src/components/value-displays/{value-displays.types.ts → value-base/value-displays.types.ts} +12 -2
- package/src/components/value-displays/value-base/value-edit.tsx +59 -0
- package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +7 -0
- package/src/components/value-displays/value-boolean/value-boolean.test.tsx +81 -2
- package/src/components/value-displays/value-boolean/value-boolean.tsx +33 -8
- package/src/components/value-displays/value-datetime/value-datetime.stories.tsx +29 -2
- package/src/components/value-displays/value-datetime/value-datetime.test.tsx +103 -5
- package/src/components/value-displays/value-datetime/value-datetime.tsx +67 -6
- package/src/components/value-displays/value-image/value-image.tsx +1 -1
- package/src/components/value-displays/value-rating/value-rating.stories.tsx +8 -0
- package/src/components/value-displays/value-rating/value-rating.test.tsx +71 -2
- package/src/components/value-displays/value-rating/value-rating.tsx +29 -5
- package/src/components/value-displays/value-text/value-text.test.tsx +5 -8
- package/src/components/value-displays/value-text/value-text.tsx +16 -60
- package/src/generators/generators.mock.ts +3 -14
- package/src/generators/model-form/model-form.tsx +3 -6
- package/src/storybook.tsx +34 -2
- package/src/tests/actions.ts +3 -2
- package/src/tests/assertions.ts +17 -5
- package/src/tests/datatable-placeholder/datatable-placeholder.tsx +2 -4
- package/src/tests/mocks/markdown.mock.ts +25 -0
- package/src/types/index.d.ts +6 -0
- package/dist/cjs/types/generators/generators.model.test.d.ts +0 -1
- package/dist/cjs/types/utils/arrays.test.d.ts +0 -1
- package/dist/esm/types/generators/generators.model.test.d.ts +0 -1
- package/dist/esm/types/utils/arrays.test.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pautena/react-design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "My custom design system on top of MUI",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -32,32 +32,33 @@
|
|
|
32
32
|
"@emotion/react": "^11.10.6",
|
|
33
33
|
"@emotion/styled": "^11.10.6",
|
|
34
34
|
"@emotion/utils": "^1.2.0",
|
|
35
|
-
"@mui/icons-material": "^5.11.
|
|
36
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
37
|
-
"@mui/material": "^5.11.
|
|
38
|
-
"@mui/x-data-grid": "^
|
|
39
|
-
"@mui/x-date-pickers": "^
|
|
35
|
+
"@mui/icons-material": "^5.11.11",
|
|
36
|
+
"@mui/lab": "^5.0.0-alpha.124",
|
|
37
|
+
"@mui/material": "^5.11.15",
|
|
38
|
+
"@mui/x-data-grid": "^6.0.4",
|
|
39
|
+
"@mui/x-date-pickers": "^6.0.4",
|
|
40
40
|
"date-fns": "^2.29.3",
|
|
41
41
|
"lorem-ipsum": "^2.0.8",
|
|
42
|
+
"markdown-to-jsx": "^7.2.0",
|
|
42
43
|
"react": "^18.2.0",
|
|
43
44
|
"react-dom": "^18.2.0",
|
|
44
|
-
"react-router-dom": "^6.
|
|
45
|
+
"react-router-dom": "^6.10.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@babel/core": "^7.
|
|
48
|
-
"@babel/preset-env": "^7.
|
|
48
|
+
"@babel/core": "^7.21.4",
|
|
49
|
+
"@babel/preset-env": "^7.21.4",
|
|
49
50
|
"@babel/preset-react": "^7.18.6",
|
|
50
|
-
"@babel/preset-typescript": "^7.21.
|
|
51
|
-
"@date-io/date-fns": "^2.
|
|
52
|
-
"@faker-js/faker": "^7.
|
|
53
|
-
"@mui/x-data-grid-generator": "^
|
|
51
|
+
"@babel/preset-typescript": "^7.21.4",
|
|
52
|
+
"@date-io/date-fns": "^2.16.0",
|
|
53
|
+
"@faker-js/faker": "^7.6.0",
|
|
54
|
+
"@mui/x-data-grid-generator": "^6.0.4",
|
|
54
55
|
"@rollup/plugin-alias": "^3.1.9",
|
|
55
|
-
"@rollup/plugin-commonjs": "^22.0.
|
|
56
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
56
57
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
57
58
|
"@rollup/plugin-typescript": "8.3.3",
|
|
58
|
-
"@storybook/addon-actions": "^6.5.
|
|
59
|
-
"@storybook/addon-essentials": "^6.5.
|
|
60
|
-
"@storybook/addon-interactions": "^6.5.
|
|
59
|
+
"@storybook/addon-actions": "^6.5.16",
|
|
60
|
+
"@storybook/addon-essentials": "^6.5.16",
|
|
61
|
+
"@storybook/addon-interactions": "^6.5.16",
|
|
61
62
|
"@storybook/addon-knobs": "^6.4.0",
|
|
62
63
|
"@storybook/addon-links": "^6.5.16",
|
|
63
64
|
"@storybook/builder-webpack4": "^6.5.16",
|
|
@@ -67,29 +68,29 @@
|
|
|
67
68
|
"@storybook/testing-react": "^1.3.0",
|
|
68
69
|
"@testing-library/jest-dom": "^5.16.5",
|
|
69
70
|
"@testing-library/react": "^14.0.0",
|
|
70
|
-
"@types/jest": "^29.
|
|
71
|
+
"@types/jest": "^29.5.0",
|
|
71
72
|
"@types/ramda": "^0.28.23",
|
|
72
|
-
"@types/react": "^18.0.
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
74
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
-
"babel-jest": "^29.
|
|
73
|
+
"@types/react": "^18.0.31",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
75
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
76
|
+
"babel-jest": "^29.5.0",
|
|
76
77
|
"babel-loader": "^9.1.2",
|
|
77
78
|
"babel-plugin-module-resolver": "^5.0.0",
|
|
78
|
-
"eslint": "^8.
|
|
79
|
-
"eslint-config-prettier": "^8.
|
|
79
|
+
"eslint": "^8.37.0",
|
|
80
|
+
"eslint-config-prettier": "^8.8.0",
|
|
80
81
|
"eslint-plugin-prettier": "^4.2.1",
|
|
81
82
|
"eslint-plugin-react": "^7.32.2",
|
|
82
83
|
"gh-pages": "^5.0.0",
|
|
83
84
|
"history": "^5.3.0",
|
|
84
85
|
"husky": "^8.0.3",
|
|
85
|
-
"jest": "^29.
|
|
86
|
-
"jest-environment-jsdom": "^29.
|
|
86
|
+
"jest": "^29.5.0",
|
|
87
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
87
88
|
"npm-run-all": "^4.1.5",
|
|
88
|
-
"prettier": "^2.8.
|
|
89
|
+
"prettier": "^2.8.7",
|
|
89
90
|
"ramda": "^0.28.0",
|
|
90
91
|
"react-test-renderer": "^18.2.0",
|
|
91
|
-
"rollup": "^2.
|
|
92
|
-
"rollup-plugin-dts": "^4.2.
|
|
92
|
+
"rollup": "^2.79.1",
|
|
93
|
+
"rollup-plugin-dts": "^4.2.3",
|
|
93
94
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
94
95
|
"rollup-plugin-terser": "^7.0.2",
|
|
95
96
|
"tslib": "^2.5.0",
|
|
@@ -102,14 +103,15 @@
|
|
|
102
103
|
"@mui/icons-material": "^5.11.0",
|
|
103
104
|
"@mui/lab": "^5.0.0",
|
|
104
105
|
"@mui/material": "^5.11.0",
|
|
105
|
-
"@mui/x-data-grid": "^
|
|
106
|
-
"@mui/x-date-pickers": "^
|
|
106
|
+
"@mui/x-data-grid": "^6.0.0",
|
|
107
|
+
"@mui/x-date-pickers": "^6.0.0",
|
|
107
108
|
"@types/react": "^17.0.0 || ^18.0.0",
|
|
108
109
|
"date-fns": "^2.0.0",
|
|
109
110
|
"lorem-ipsum": "^2.0.0",
|
|
110
111
|
"react": "^17.0.0 || ^18.0.0",
|
|
111
112
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
112
|
-
"react-router-dom": "^6.0.0"
|
|
113
|
+
"react-router-dom": "^6.0.0",
|
|
114
|
+
"markdown-to-jsx": "^7.0.0"
|
|
113
115
|
},
|
|
114
116
|
"repository": {
|
|
115
117
|
"type": "git",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Meta } from '@storybook/addon-docs';
|
|
2
|
+
import LinkTo from '@storybook/addon-links/react';
|
|
3
|
+
|
|
4
|
+
<Meta title="Components/Alerts/Introduction" />
|
|
5
|
+
|
|
6
|
+
# Alerts
|
|
7
|
+
|
|
8
|
+
<ul>
|
|
9
|
+
<li><LinkTo kind="Components/Alerts/ExpandableAlert">ExpandableAlert</LinkTo></li>
|
|
10
|
+
</ul>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ExpandableAlert } from "./expandable-alert";
|
|
4
|
+
import { withContainer } from "~/storybook";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Components/Alerts/ExpandableAlert",
|
|
8
|
+
component: ExpandableAlert,
|
|
9
|
+
decorators: [withContainer({ width: 500 })],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
},
|
|
13
|
+
} as ComponentMeta<typeof ExpandableAlert>;
|
|
14
|
+
|
|
15
|
+
const Template: ComponentStory<typeof ExpandableAlert> = (args) => <ExpandableAlert {...args} />;
|
|
16
|
+
|
|
17
|
+
export const Info = Template.bind({});
|
|
18
|
+
Info.args = {
|
|
19
|
+
severity: "info",
|
|
20
|
+
title: "Lorem ipsum",
|
|
21
|
+
message: "Lorem ipsum dolor sit amet",
|
|
22
|
+
metadata: ["lorem: ipsum", "foo: bar", "header: this", "host: localhost"],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Success = Template.bind({});
|
|
26
|
+
Success.args = {
|
|
27
|
+
...Info.args,
|
|
28
|
+
severity: "success",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Error = Template.bind({});
|
|
32
|
+
Error.args = {
|
|
33
|
+
...Info.args,
|
|
34
|
+
severity: "error",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Warning = Template.bind({});
|
|
38
|
+
Warning.args = {
|
|
39
|
+
...Info.args,
|
|
40
|
+
severity: "warning",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const WihtoutMetadata = Template.bind({});
|
|
44
|
+
WihtoutMetadata.args = {
|
|
45
|
+
severity: "info",
|
|
46
|
+
title: "Lorem ipsum",
|
|
47
|
+
message: "Lorem ipsum dolor sit amet",
|
|
48
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, waitFor } from "~/tests/testing-library";
|
|
3
|
+
import { ExpandableAlert } from "./expandable-alert";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
const message = "Lorem ipsum dolor sit amet";
|
|
7
|
+
const metadata =
|
|
8
|
+
"Of recommend residence education be on difficult repulsive offending. Judge views had mirth table seems great him for her. Alone all happy asked begin fully stand own get. Excuse ye seeing result of we. See scale dried songs old may not. Promotion did disposing you household any instantly. Hills we do under times at first short an.";
|
|
9
|
+
const arrayMetadata = ["lorem: ipsum", "foo: bar", "header: this", "host: localhost"];
|
|
10
|
+
|
|
11
|
+
describe("ExpandableAlert", () => {
|
|
12
|
+
const renderComponent = ({
|
|
13
|
+
title,
|
|
14
|
+
metadata,
|
|
15
|
+
}: { title?: string; metadata?: string | string[] } = {}) => {
|
|
16
|
+
const onClose = jest.fn();
|
|
17
|
+
const copy = jest.fn();
|
|
18
|
+
Object.assign(navigator, {
|
|
19
|
+
clipboard: {
|
|
20
|
+
writeText: copy,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
render(
|
|
25
|
+
<ExpandableAlert
|
|
26
|
+
severity="info"
|
|
27
|
+
title={title}
|
|
28
|
+
message={message}
|
|
29
|
+
metadata={metadata}
|
|
30
|
+
onClose={onClose}
|
|
31
|
+
/>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return { onClose, copy };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
it("should render a title if is set", () => {
|
|
38
|
+
const title = "This is the title";
|
|
39
|
+
renderComponent({ title });
|
|
40
|
+
|
|
41
|
+
expect(screen.getByText(title)).toBeVisible();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should render a message", () => {
|
|
45
|
+
renderComponent();
|
|
46
|
+
|
|
47
|
+
expect(screen.getByText(message)).toBeVisible();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should call onClose if the close button is clicked", async () => {
|
|
51
|
+
const { onClose } = renderComponent();
|
|
52
|
+
|
|
53
|
+
await userEvent.click(screen.getByTestId("CloseIcon"));
|
|
54
|
+
|
|
55
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should show a button to expand info if it has metadata", () => {
|
|
59
|
+
renderComponent({ metadata });
|
|
60
|
+
|
|
61
|
+
expect(screen.getByTestId("ExpandMoreIcon")).toBeVisible();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("shouldn't show a button to expand info if it doesn't have metadata", () => {
|
|
65
|
+
renderComponent({ metadata: undefined });
|
|
66
|
+
|
|
67
|
+
expect(screen.queryByTestId("ExpandMoreIcon")).not.toBeInTheDocument();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should show the metadata if the expand button is clicked", async () => {
|
|
71
|
+
renderComponent({ metadata });
|
|
72
|
+
|
|
73
|
+
await userEvent.click(screen.getByTestId("ExpandMoreIcon"));
|
|
74
|
+
|
|
75
|
+
expect(screen.getByText(metadata)).toBeVisible();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should show the array metadata if the expand button is clicked", async () => {
|
|
79
|
+
renderComponent({ metadata: arrayMetadata });
|
|
80
|
+
|
|
81
|
+
await userEvent.click(screen.getByTestId("ExpandMoreIcon"));
|
|
82
|
+
|
|
83
|
+
expect(screen.getByText(arrayMetadata[0])).toBeVisible();
|
|
84
|
+
expect(screen.getByText(arrayMetadata[1])).toBeVisible();
|
|
85
|
+
expect(screen.getByText(arrayMetadata[2])).toBeVisible();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should render a button to hide info if the expand button is clicked", async () => {
|
|
89
|
+
renderComponent({ metadata: arrayMetadata });
|
|
90
|
+
|
|
91
|
+
await userEvent.click(screen.getByTestId("ExpandMoreIcon"));
|
|
92
|
+
|
|
93
|
+
expect(screen.getByTestId("ExpandLessIcon")).toBeVisible();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should hide the metadata if the hide button is clicked", async () => {
|
|
97
|
+
renderComponent({ metadata });
|
|
98
|
+
|
|
99
|
+
await userEvent.click(screen.getByTestId("ExpandMoreIcon"));
|
|
100
|
+
await userEvent.click(screen.getByTestId("ExpandLessIcon"));
|
|
101
|
+
|
|
102
|
+
await waitFor(() => expect(screen.getByText(metadata)).not.toBeVisible());
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should copy the content if the copy button is clicked", async () => {
|
|
106
|
+
const { copy } = renderComponent({ metadata });
|
|
107
|
+
|
|
108
|
+
await userEvent.click(screen.getByTestId("ExpandMoreIcon"));
|
|
109
|
+
await userEvent.click(screen.getByRole("button", { name: /copy/i }));
|
|
110
|
+
|
|
111
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(copy).toHaveBeenCalledWith(metadata);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Alert,
|
|
3
|
+
alertClasses,
|
|
4
|
+
AlertColor,
|
|
5
|
+
AlertTitle,
|
|
6
|
+
Box,
|
|
7
|
+
Collapse,
|
|
8
|
+
IconButton,
|
|
9
|
+
} from "@mui/material";
|
|
10
|
+
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|
11
|
+
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
|
|
12
|
+
import CloseIcon from "@mui/icons-material/Close";
|
|
13
|
+
import { useState } from "react";
|
|
14
|
+
import React from "react";
|
|
15
|
+
import { Board } from "~/components/data-display";
|
|
16
|
+
|
|
17
|
+
export interface ExpandableAlertProps {
|
|
18
|
+
severity: AlertColor;
|
|
19
|
+
iconMapping?: Partial<Record<AlertColor, React.ReactNode>>;
|
|
20
|
+
title?: string;
|
|
21
|
+
message: string;
|
|
22
|
+
metadata?: string | string[];
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const alertSx = {
|
|
27
|
+
[`& .${alertClasses.message}`]: {
|
|
28
|
+
width: 1,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const ExpandableAlert = ({
|
|
33
|
+
severity,
|
|
34
|
+
iconMapping,
|
|
35
|
+
title,
|
|
36
|
+
message,
|
|
37
|
+
metadata,
|
|
38
|
+
onClose,
|
|
39
|
+
}: ExpandableAlertProps) => {
|
|
40
|
+
const [expanded, setExpanded] = useState(false);
|
|
41
|
+
return (
|
|
42
|
+
<Alert
|
|
43
|
+
severity={severity}
|
|
44
|
+
iconMapping={iconMapping}
|
|
45
|
+
onClose={onClose}
|
|
46
|
+
action={
|
|
47
|
+
<Box display="flex" flexDirection="column">
|
|
48
|
+
<IconButton color="inherit" onClick={onClose}>
|
|
49
|
+
<CloseIcon fontSize="small" />
|
|
50
|
+
</IconButton>
|
|
51
|
+
{metadata && (
|
|
52
|
+
<IconButton color="inherit" onClick={() => setExpanded((e) => !e)}>
|
|
53
|
+
{expanded ? <ExpandLessIcon fontSize="small" /> : <ExpandMoreIcon fontSize="small" />}
|
|
54
|
+
</IconButton>
|
|
55
|
+
)}
|
|
56
|
+
</Box>
|
|
57
|
+
}
|
|
58
|
+
sx={alertSx}
|
|
59
|
+
>
|
|
60
|
+
<Box sx={{ w: 1 }}>
|
|
61
|
+
{title && <AlertTitle>{title}</AlertTitle>}
|
|
62
|
+
{message}
|
|
63
|
+
{metadata && (
|
|
64
|
+
<Collapse in={expanded} sx={{ mt: 2 }}>
|
|
65
|
+
<Board content={metadata} />
|
|
66
|
+
</Collapse>
|
|
67
|
+
)}
|
|
68
|
+
</Box>
|
|
69
|
+
</Alert>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./expandable-alert";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./expandable-alert";
|
|
@@ -16,4 +16,6 @@ import LinkTo from '@storybook/addon-links/react';
|
|
|
16
16
|
<li><LinkTo kind="Components/Navigation/Introduction">Navigation</LinkTo></li>
|
|
17
17
|
<li><LinkTo kind="Components/Placeholders/Introduction">Placeholders</LinkTo></li>
|
|
18
18
|
<li><LinkTo kind="Components/Tables/Introduction">Tables</LinkTo></li>
|
|
19
|
+
<li><LinkTo kind="Components/Alerts/Introduction">Alerts</LinkTo></li>
|
|
20
|
+
<li><LinkTo kind="Components/Dialogs/Introduction">Dialogs</LinkTo></li>
|
|
19
21
|
</ul>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ComponentMeta } from "@storybook/react";
|
|
2
|
+
import { createTemplate, withContainer } from "../../../storybook";
|
|
3
|
+
import { Board } from "./board";
|
|
4
|
+
import demoMarkdownContent from "~/tests/mocks/markdown.mock.md";
|
|
5
|
+
import { Typography } from "@mui/material";
|
|
6
|
+
import React from "react";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "Components/Data Display/Board",
|
|
10
|
+
component: Board,
|
|
11
|
+
decorators: [withContainer({ width: 500 })],
|
|
12
|
+
parameters: {
|
|
13
|
+
layout: "centered",
|
|
14
|
+
},
|
|
15
|
+
} as ComponentMeta<typeof Board>;
|
|
16
|
+
|
|
17
|
+
const Template = createTemplate(Board);
|
|
18
|
+
|
|
19
|
+
export const Text = Template.bind({});
|
|
20
|
+
Text.args = {
|
|
21
|
+
content:
|
|
22
|
+
"Of recommend residence education be on difficult repulsive offending. Judge views had mirth table seems great him for her. Alone all happy asked begin fully stand own get. Excuse ye seeing result of we. See scale dried songs old may not. Promotion did disposing you household any instantly. Hills we do under times at first short an.",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const ArrayParagraph = Template.bind({});
|
|
26
|
+
ArrayParagraph.args = {
|
|
27
|
+
content: [
|
|
28
|
+
"Of recommend residence education be on difficult repulsive offending. Judge views had mirth table seems great him for her. Alone all happy asked begin fully stand own get. Excuse ye seeing result of we. See scale dried songs old may not. Promotion did disposing you household any instantly. Hills we do under times at first short an.",
|
|
29
|
+
"His having within saw become ask passed misery giving. Recommend questions get too fulfilled. He fact in we case miss sake. Entrance be throwing he do blessing up. Hearts warmth in genius do garden advice mr it garret. Collected preserved are middleton dependent residence but him how. Handsome weddings yet mrs you has carriage packages. Preferred joy agreement put continual elsewhere delivered now. Mrs exercise felicity had men speaking met. Rich deal mrs part led pure will but.",
|
|
30
|
+
"Boy desirous families prepared gay reserved add ecstatic say. Replied joy age visitor nothing cottage. Mrs door paid led loud sure easy read. Hastily at perhaps as neither or ye fertile tedious visitor. Use fine bed none call busy dull when. Quiet ought match my right by table means. Principles up do in me favourable affronting. Twenty mother denied effect we to do on.",
|
|
31
|
+
],
|
|
32
|
+
spacing: 1,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const ArrayList = Template.bind({});
|
|
36
|
+
ArrayList.args = {
|
|
37
|
+
content: ["lorem: ipsum", "foo: bar", "header: this", "host: localhost"],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Markdown = Template.bind({});
|
|
41
|
+
Markdown.args = {
|
|
42
|
+
markdown: demoMarkdownContent,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Children = Template.bind({});
|
|
46
|
+
Children.args = {
|
|
47
|
+
children: (
|
|
48
|
+
<>
|
|
49
|
+
<Typography variant="h2">First line</Typography>
|
|
50
|
+
<Typography variant="subtitle1">Second line</Typography>
|
|
51
|
+
<Typography variant="h6">Third line</Typography>
|
|
52
|
+
</>
|
|
53
|
+
),
|
|
54
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, waitFor } from "~/tests/testing-library";
|
|
3
|
+
import { Board } from "./board";
|
|
4
|
+
import { mockMarkdownContent } from "~/tests/mocks/markdown.mock";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
|
+
|
|
7
|
+
const content = "This is the content";
|
|
8
|
+
|
|
9
|
+
const content1 = "This is the content 1";
|
|
10
|
+
const content2 = "This is the content 2";
|
|
11
|
+
const content3 = "This is the content 3";
|
|
12
|
+
const arrayContent = [content1, content2, content3];
|
|
13
|
+
|
|
14
|
+
describe("Board", () => {
|
|
15
|
+
const renderComponent = ({
|
|
16
|
+
markdown,
|
|
17
|
+
content,
|
|
18
|
+
}: {
|
|
19
|
+
markdown?: string;
|
|
20
|
+
content?: string | string[];
|
|
21
|
+
}) => {
|
|
22
|
+
const copy = jest.fn();
|
|
23
|
+
Object.assign(navigator, {
|
|
24
|
+
clipboard: {
|
|
25
|
+
writeText: copy,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
render(<Board markdown={markdown} content={content} timeoutCopyText={100} />);
|
|
29
|
+
|
|
30
|
+
return { copy };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
it("should render a string content", () => {
|
|
34
|
+
renderComponent({ content });
|
|
35
|
+
|
|
36
|
+
expect(screen.getByText(content)).toBeVisible();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should render a array of string content", () => {
|
|
40
|
+
renderComponent({ content: arrayContent });
|
|
41
|
+
|
|
42
|
+
expect(screen.getByText(content1)).toBeVisible();
|
|
43
|
+
expect(screen.getByText(content2)).toBeVisible();
|
|
44
|
+
expect(screen.getByText(content3)).toBeVisible();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should render a markdown content", () => {
|
|
48
|
+
renderComponent({ markdown: mockMarkdownContent });
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
screen.getByRole("heading", { name: "Diu in illa Lavini atque de quoque", level: 5 }),
|
|
52
|
+
).toBeVisible();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should copy the string content to the clipboard if the copy button is clicked", async () => {
|
|
56
|
+
const { copy } = renderComponent({ content });
|
|
57
|
+
|
|
58
|
+
await userEvent.click(screen.getByRole("button"));
|
|
59
|
+
|
|
60
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
61
|
+
expect(copy).toHaveBeenCalledWith(content);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should copy the string array content to the clipboard if the copy button is clicked", async () => {
|
|
65
|
+
const expectedCopy = arrayContent.join("\n");
|
|
66
|
+
const { copy } = renderComponent({ content: arrayContent });
|
|
67
|
+
|
|
68
|
+
await userEvent.click(screen.getByRole("button"));
|
|
69
|
+
|
|
70
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(copy).toHaveBeenCalledWith(expectedCopy);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should copy the markdown content to the clipboard if the copy button is clicked", async () => {
|
|
75
|
+
const { copy } = renderComponent({ markdown: mockMarkdownContent });
|
|
76
|
+
|
|
77
|
+
await userEvent.click(screen.getByRole("button"));
|
|
78
|
+
|
|
79
|
+
expect(copy).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(copy).toHaveBeenCalledWith(mockMarkdownContent);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should change the copy button text when is clicked", async () => {
|
|
84
|
+
renderComponent({ content });
|
|
85
|
+
|
|
86
|
+
await userEvent.click(screen.getByRole("button"));
|
|
87
|
+
|
|
88
|
+
expect(screen.getByRole("button", { name: /copied/i })).toBeVisible();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should return to the original button text after a delay", async () => {
|
|
92
|
+
renderComponent({ content });
|
|
93
|
+
|
|
94
|
+
await userEvent.click(screen.getByRole("button"));
|
|
95
|
+
|
|
96
|
+
expect(screen.getByRole("button", { name: /copied/i })).toBeVisible();
|
|
97
|
+
|
|
98
|
+
await waitFor(() => expect(screen.getByRole("button", { name: /copy/i })).toBeVisible());
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Box, Button, Paper, SxProps, Theme, Typography } from "@mui/material";
|
|
2
|
+
import { blueGrey } from "@mui/material/colors";
|
|
3
|
+
import React, { PropsWithChildren, ReactNode, useState } from "react";
|
|
4
|
+
import { Markdown } from "../markdown";
|
|
5
|
+
|
|
6
|
+
export type BoardProps = PropsWithChildren<{
|
|
7
|
+
markdown?: string;
|
|
8
|
+
content?: string | string[];
|
|
9
|
+
spacing?: 0 | 1 | 2 | 3 | 4 | 5;
|
|
10
|
+
timeoutCopyText?: number;
|
|
11
|
+
sx?: SxProps<Theme>;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export const Board = ({
|
|
15
|
+
markdown: markdownProps,
|
|
16
|
+
content: contentProp,
|
|
17
|
+
spacing = 0,
|
|
18
|
+
timeoutCopyText = 2000,
|
|
19
|
+
children,
|
|
20
|
+
sx,
|
|
21
|
+
}: BoardProps) => {
|
|
22
|
+
const [copyText, setCopyText] = useState("Copy");
|
|
23
|
+
let copyContent: string;
|
|
24
|
+
let content: ReactNode;
|
|
25
|
+
|
|
26
|
+
if (markdownProps) {
|
|
27
|
+
copyContent = markdownProps || "";
|
|
28
|
+
} else if (Array.isArray(contentProp)) {
|
|
29
|
+
content = contentProp.map((line, i) => (
|
|
30
|
+
<Typography key={i} sx={{ pb: spacing }}>
|
|
31
|
+
{line}
|
|
32
|
+
</Typography>
|
|
33
|
+
));
|
|
34
|
+
copyContent = contentProp.join("\n");
|
|
35
|
+
} else {
|
|
36
|
+
content = <Typography>{contentProp}</Typography>;
|
|
37
|
+
copyContent = contentProp || "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const markdown = markdownProps && <Markdown content={markdownProps} />;
|
|
41
|
+
|
|
42
|
+
const handleCopy = () => {
|
|
43
|
+
navigator.clipboard.writeText(copyContent);
|
|
44
|
+
setCopyText("Copied!");
|
|
45
|
+
|
|
46
|
+
setTimeout(() => setCopyText("Copy"), timeoutCopyText);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Paper sx={{ p: 2, backgroundColor: blueGrey[800], color: "white", ...sx }}>
|
|
51
|
+
<Box display="flex" flexDirection="row">
|
|
52
|
+
<Box width={1}>{children || markdown || content}</Box>
|
|
53
|
+
<Box width={100} sx={{ ml: 1 }}>
|
|
54
|
+
{copyContent && (
|
|
55
|
+
<Button fullWidth color="inherit" size="small" variant="outlined" onClick={handleCopy}>
|
|
56
|
+
{copyText}
|
|
57
|
+
</Button>
|
|
58
|
+
)}
|
|
59
|
+
</Box>
|
|
60
|
+
</Box>
|
|
61
|
+
</Paper>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./board";
|
|
@@ -9,4 +9,6 @@ import LinkTo from '@storybook/addon-links/react';
|
|
|
9
9
|
<li><LinkTo kind="Components/Data Display/Bullet">Bullet</LinkTo></li>
|
|
10
10
|
<li><LinkTo kind="Components/Data Display/Label">Label</LinkTo></li>
|
|
11
11
|
<li><LinkTo kind="Components/Data Display/Header">Header</LinkTo></li>
|
|
12
|
+
<li><LinkTo kind="Components/Data Display/Board">Board</LinkTo></li>
|
|
13
|
+
<li><LinkTo kind="Components/Data Display/Markdown">Markdown</LinkTo></li>
|
|
12
14
|
</ul>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./markdown";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
2
|
+
import { Markdown } from "./markdown";
|
|
3
|
+
import mockMarkdownContentFile from "~/tests/mocks/markdown.mock.md";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { mockMarkdownContent } from "~/tests/mocks/markdown.mock";
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: "Components/Data Display/Markdown",
|
|
9
|
+
component: Markdown,
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
},
|
|
13
|
+
} as ComponentMeta<typeof Markdown>;
|
|
14
|
+
|
|
15
|
+
const Template: ComponentStory<typeof Markdown> = (args) => <Markdown {...args} />;
|
|
16
|
+
|
|
17
|
+
export const File = Template.bind({});
|
|
18
|
+
File.args = {
|
|
19
|
+
content: mockMarkdownContentFile,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const StringVariable = Template.bind({});
|
|
23
|
+
StringVariable.args = {
|
|
24
|
+
content: mockMarkdownContent,
|
|
25
|
+
};
|