@centreon/ui 23.10.19 → 23.10.20-MON-18489-dashboard-list-view.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/package.json +13 -3
- package/src/@types/aria-attributes.d.ts +10 -0
- package/src/@types/data-attributes.d.ts +3 -0
- package/src/Dashboard/Dashboard.styles.ts +83 -0
- package/src/Dashboard/DashboardLayout.stories.tsx +104 -0
- package/src/Dashboard/Grid.tsx +71 -0
- package/src/Dashboard/Item.tsx +73 -0
- package/src/Dashboard/Layout.tsx +74 -0
- package/src/Dashboard/index.tsx +9 -0
- package/src/Dashboard/utils.ts +28 -0
- package/src/Form/{index.stories.tsx → Form.stories.tsx} +1 -2
- package/src/Form/Form.styles.ts +11 -0
- package/src/Form/{index.tsx → Form.tsx} +17 -10
- package/src/Form/FormButtons.tsx +1 -2
- package/src/Form/index.ts +1 -0
- package/src/Form/storiesData.tsx +1 -3
- package/src/InputField/Select/Autocomplete/index.stories.tsx +1 -10
- package/src/Typography/FluidTypography/index.stories.tsx +63 -0
- package/src/Typography/FluidTypography/index.tsx +51 -0
- package/src/Typography/FluidTypography/useFluidResizeObserver.ts +56 -0
- package/src/Typography/{index.stories.tsx → Typography.stories.tsx} +5 -5
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-dashboard-normal-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-dashboard-with-item-header-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-dashboard-with-many-panels-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-fluid-typography-basic-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-fluid-typography-with-20-px-height-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-fluid-typography-with-200-px-width-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-fluid-typography-with-heading-5-variant-1-snap.png +0 -0
- package/src/__image_snapshots__/storyshots-test-js-image-story-shots-fluid-typography-with-long-text-1-snap.png +0 -0
- package/src/api/useMutationQuery/index.ts +7 -3
- package/src/components/Button/Button.stories.tsx +34 -0
- package/src/components/Button/Button.styles.ts +30 -0
- package/src/components/Button/Button.tsx +69 -0
- package/src/components/Button/Icon/IconButton.stories.tsx +18 -0
- package/src/components/Button/Icon/IconButton.styles.ts +7 -0
- package/src/components/Button/Icon/IconButton.tsx +58 -0
- package/src/components/Button/Icon/index.tsx +1 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/DataTable/DataTable.stories.tsx +42 -0
- package/src/components/DataTable/DataTable.styles.ts +22 -0
- package/src/components/DataTable/DataTable.tsx +33 -0
- package/src/components/DataTable/EmptyState/DataTableEmptyState.stories.tsx +21 -0
- package/src/components/DataTable/EmptyState/DataTableEmptyState.styles.ts +28 -0
- package/src/components/DataTable/EmptyState/DataTableEmptyState.tsx +46 -0
- package/src/components/DataTable/Item/DataTableItem.stories.tsx +25 -0
- package/src/components/DataTable/Item/DataTableItem.styles.ts +36 -0
- package/src/components/DataTable/Item/DataTableItem.tsx +81 -0
- package/src/components/DataTable/Item/DataTableItemSkeleton.tsx +11 -0
- package/src/components/DataTable/index.ts +10 -0
- package/src/components/Form/Dashboard/Dashboard.resource.ts +4 -0
- package/src/components/Form/Dashboard/DashboardForm.stories.ts +39 -0
- package/src/components/Form/Dashboard/DashboardForm.styles.ts +19 -0
- package/src/components/Form/Dashboard/DashboardForm.tsx +112 -0
- package/src/components/Form/Dashboard/DashboardFormActions.tsx +56 -0
- package/src/components/Form/Dashboard/index.ts +2 -0
- package/src/components/Form/Dashboard/translatedLabels.ts +5 -0
- package/src/components/Form/Form.models.ts +1 -0
- package/src/components/Form/index.ts +2 -0
- package/src/components/Header/Header.stories.tsx +27 -0
- package/src/components/Header/Header.styles.ts +27 -0
- package/src/components/Header/Header.tsx +21 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/Icon/Icon.styles.ts +0 -0
- package/src/components/Icon/Icon.tsx +2 -0
- package/src/components/Icon/index.ts +0 -0
- package/src/components/Modal/Modal.stories.tsx +111 -0
- package/src/components/Modal/Modal.styles.ts +55 -0
- package/src/components/Modal/Modal.tsx +59 -0
- package/src/components/Modal/ModalActions.tsx +57 -0
- package/src/components/Modal/ModalBody.tsx +15 -0
- package/src/components/Modal/ModalHeader.tsx +21 -0
- package/src/components/Modal/index.ts +10 -0
- package/src/components/README.md +3 -0
- package/src/components/index.ts +5 -0
- package/src/index.ts +5 -1
- package/src/layout/TiledListingPage/TiledListingActions.tsx +15 -0
- package/src/layout/TiledListingPage/TiledListingContent.tsx +21 -0
- package/src/layout/TiledListingPage/TiledListingList.tsx +11 -0
- package/src/layout/TiledListingPage/TiledListingPage.styles.ts +16 -0
- package/src/layout/TiledListingPage/TiledListingPage.tsx +15 -0
- package/src/layout/TiledListingPage/index.ts +4 -0
- package/src/screens/dashboard/DashboardsOverview.stories.tsx +273 -0
- package/src/utils/useMemoComponent.ts +2 -0
- package/test/setupTests.js +86 -0
- package/test/testRenderer.tsx +56 -0
- /package/src/Typography/{index.tsx → story.utils.tsx} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centreon/ui",
|
|
3
|
-
"version": "23.10.
|
|
3
|
+
"version": "23.10.20-MON-18489-dashboard-list-view.0",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
|
@@ -31,10 +31,17 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/centreon/centreon#readme",
|
|
33
33
|
"main": "src/index.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./src/index.ts",
|
|
36
|
+
"./components": "./src/components/index.ts",
|
|
37
|
+
"./fonts/*": "./public/fonts/*",
|
|
38
|
+
"./test/testRenderer": "./test/testRenderer.tsx"
|
|
39
|
+
},
|
|
34
40
|
"files": [
|
|
35
41
|
"package.json",
|
|
36
42
|
"src/*",
|
|
37
|
-
"public/*"
|
|
43
|
+
"public/*",
|
|
44
|
+
"test/*"
|
|
38
45
|
],
|
|
39
46
|
"devDependencies": {
|
|
40
47
|
"@cypress/react": "^7.0.2",
|
|
@@ -89,7 +96,9 @@
|
|
|
89
96
|
"lexical": "0.8.0",
|
|
90
97
|
"notistack": "^2.0.8",
|
|
91
98
|
"react-transition-group": "^4.4.5",
|
|
92
|
-
"ulog": "^2.0.0-beta.19"
|
|
99
|
+
"ulog": "^2.0.0-beta.19",
|
|
100
|
+
"react-grid-layout": "^1.3.4",
|
|
101
|
+
"react-resizable": "^3.0.5"
|
|
93
102
|
},
|
|
94
103
|
"peerDependencies": {
|
|
95
104
|
"@centreon/ui-context": "file:../ui-context",
|
|
@@ -108,6 +117,7 @@
|
|
|
108
117
|
"ramda": "0.x",
|
|
109
118
|
"react-i18next": "12.x",
|
|
110
119
|
"react-router-dom": "6.x",
|
|
120
|
+
"react-scale-text": "1.x",
|
|
111
121
|
"resize-observer-polyfill": "1.x",
|
|
112
122
|
"ts.data.json": "2.x",
|
|
113
123
|
"tss-react": "4.x"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { makeStyles } from 'tss-react/mui';
|
|
2
|
+
|
|
3
|
+
import { alpha } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
export const useDashboardLayoutStyles = makeStyles()((theme) => ({
|
|
6
|
+
container: {
|
|
7
|
+
'& .react-grid-item': {
|
|
8
|
+
borderRadius: theme.shape.borderRadius,
|
|
9
|
+
transition: theme.transitions.create('all', {
|
|
10
|
+
delay: 0,
|
|
11
|
+
duration: 100,
|
|
12
|
+
easing: theme.transitions.easing.easeOut
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
'& .react-grid-item.react-draggable-dragging': {
|
|
16
|
+
boxShadow: theme.shadows[3]
|
|
17
|
+
},
|
|
18
|
+
'& .react-grid-item.react-grid-placeholder': {
|
|
19
|
+
backgroundColor: alpha(theme.palette.primary.main, 0.7)
|
|
20
|
+
},
|
|
21
|
+
'& .react-grid-item.resizing': {
|
|
22
|
+
boxShadow: theme.shadows[3]
|
|
23
|
+
},
|
|
24
|
+
'& .react-resizable-handle': {
|
|
25
|
+
backgroundColor: theme.palette.action.focus,
|
|
26
|
+
backgroundImage: 'none',
|
|
27
|
+
borderRadius: theme.shape.borderRadius,
|
|
28
|
+
display: 'block',
|
|
29
|
+
opacity: 0,
|
|
30
|
+
position: 'absolute'
|
|
31
|
+
},
|
|
32
|
+
'& .react-resizable-handle.react-resizable-handle-e': {
|
|
33
|
+
cursor: 'ew-resize',
|
|
34
|
+
height: `calc(100% - ${theme.spacing(3)})`,
|
|
35
|
+
marginTop: 0,
|
|
36
|
+
right: 0,
|
|
37
|
+
top: 0,
|
|
38
|
+
transform: 'rotate(0deg)',
|
|
39
|
+
width: theme.spacing(1)
|
|
40
|
+
},
|
|
41
|
+
'& .react-resizable-handle.react-resizable-handle-s': {
|
|
42
|
+
bottom: 0,
|
|
43
|
+
cursor: 'ns-resize',
|
|
44
|
+
height: theme.spacing(1),
|
|
45
|
+
left: 0,
|
|
46
|
+
marginLeft: 0,
|
|
47
|
+
transform: 'rotate(0deg)',
|
|
48
|
+
width: `calc(100% - ${theme.spacing(3)})`
|
|
49
|
+
},
|
|
50
|
+
'& .react-resizable-handle.react-resizable-handle-se': {
|
|
51
|
+
bottom: 0,
|
|
52
|
+
cursor: 'nwse-resize',
|
|
53
|
+
height: theme.spacing(2),
|
|
54
|
+
right: 0,
|
|
55
|
+
transform: 'rotate(0deg)',
|
|
56
|
+
width: theme.spacing(2)
|
|
57
|
+
},
|
|
58
|
+
'& .react-resizable-handle::after': {
|
|
59
|
+
content: 'none'
|
|
60
|
+
},
|
|
61
|
+
'& .react-resizable-handle:hover': {
|
|
62
|
+
opacity: 1
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
export const useDashboardItemStyles = makeStyles()((theme) => ({
|
|
68
|
+
widgetContainer: {
|
|
69
|
+
height: '100%',
|
|
70
|
+
width: '100%'
|
|
71
|
+
},
|
|
72
|
+
widgetContent: {
|
|
73
|
+
height: '100%',
|
|
74
|
+
padding: theme.spacing(1, 2)
|
|
75
|
+
},
|
|
76
|
+
widgetHeader: {
|
|
77
|
+
'&:hover': {
|
|
78
|
+
backgroundColor: theme.palette.action.hover
|
|
79
|
+
},
|
|
80
|
+
cursor: 'move',
|
|
81
|
+
padding: theme.spacing(0.5, 2)
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ComponentMeta } from '@storybook/react';
|
|
2
|
+
import { Layout } from 'react-grid-layout';
|
|
3
|
+
|
|
4
|
+
import { Typography } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
import FluidTypography from '../Typography/FluidTypography';
|
|
7
|
+
|
|
8
|
+
import { DashboardLayout } from '.';
|
|
9
|
+
|
|
10
|
+
interface CustomLayout extends Layout {
|
|
11
|
+
content: string;
|
|
12
|
+
shouldUseFluidTypography: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const dashboardLayout: Array<CustomLayout> = [
|
|
16
|
+
{
|
|
17
|
+
content: 'Hello world',
|
|
18
|
+
h: 4,
|
|
19
|
+
i: 'a',
|
|
20
|
+
shouldUseFluidTypography: false,
|
|
21
|
+
w: 6,
|
|
22
|
+
x: 0,
|
|
23
|
+
y: 0
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
content: 'This is a panel',
|
|
27
|
+
h: 3,
|
|
28
|
+
i: 'b',
|
|
29
|
+
minW: 2,
|
|
30
|
+
shouldUseFluidTypography: false,
|
|
31
|
+
w: 7,
|
|
32
|
+
x: 1,
|
|
33
|
+
y: 7
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
content: 'And the last panel with fluid typography',
|
|
37
|
+
h: 7,
|
|
38
|
+
i: 'c',
|
|
39
|
+
shouldUseFluidTypography: true,
|
|
40
|
+
w: 6,
|
|
41
|
+
x: 6,
|
|
42
|
+
y: 6
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const generateLayout = (maxElements: number): Array<CustomLayout> => {
|
|
47
|
+
return Array(maxElements)
|
|
48
|
+
.fill(0)
|
|
49
|
+
.map((_, i): CustomLayout => {
|
|
50
|
+
return {
|
|
51
|
+
content: `${i}`,
|
|
52
|
+
h: 3,
|
|
53
|
+
i: i.toString(),
|
|
54
|
+
shouldUseFluidTypography: false,
|
|
55
|
+
w: 3,
|
|
56
|
+
x: (i * 3) % 12,
|
|
57
|
+
y: Math.floor(i / 12)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
interface DashboardTemplateProps {
|
|
63
|
+
header?: JSX.Element;
|
|
64
|
+
layout?: Array<CustomLayout>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Header = (): JSX.Element => (
|
|
68
|
+
<Typography variant="body2">The title</Typography>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const DashboardTemplate = ({
|
|
72
|
+
header,
|
|
73
|
+
layout = dashboardLayout
|
|
74
|
+
}: DashboardTemplateProps): JSX.Element => (
|
|
75
|
+
<DashboardLayout.Layout<CustomLayout> layout={layout}>
|
|
76
|
+
{layout.map(({ i, content, shouldUseFluidTypography }) => (
|
|
77
|
+
<DashboardLayout.Item header={header} key={i}>
|
|
78
|
+
{shouldUseFluidTypography ? (
|
|
79
|
+
<FluidTypography text={content} />
|
|
80
|
+
) : (
|
|
81
|
+
<Typography>{content}</Typography>
|
|
82
|
+
)}
|
|
83
|
+
</DashboardLayout.Item>
|
|
84
|
+
))}
|
|
85
|
+
</DashboardLayout.Layout>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
argTypes: {},
|
|
90
|
+
component: DashboardTemplate,
|
|
91
|
+
title: 'Dashboard'
|
|
92
|
+
} as ComponentMeta<typeof DashboardTemplate>;
|
|
93
|
+
|
|
94
|
+
export const normal = DashboardTemplate.bind({});
|
|
95
|
+
|
|
96
|
+
export const withManyPanels = DashboardTemplate.bind({});
|
|
97
|
+
withManyPanels.args = {
|
|
98
|
+
layout: generateLayout(1000)
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const withItemHeader = DashboardTemplate.bind({});
|
|
102
|
+
withItemHeader.args = {
|
|
103
|
+
header: <Header />
|
|
104
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FC, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Grid as VisxGrid } from '@visx/visx';
|
|
4
|
+
import { scaleLinear } from '@visx/scale';
|
|
5
|
+
|
|
6
|
+
import { useTheme } from '@mui/material';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable-next-line import/no-named-as-default */
|
|
9
|
+
import useMemoComponent from '../utils/useMemoComponent';
|
|
10
|
+
|
|
11
|
+
import { maxColumns, rowHeight } from './utils';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
columns: number;
|
|
15
|
+
height: number;
|
|
16
|
+
width: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Grid: FC<Props> = ({ width, height, columns }) => {
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
|
|
22
|
+
const xScale = useMemo(
|
|
23
|
+
() =>
|
|
24
|
+
scaleLinear({
|
|
25
|
+
domain: [0, maxColumns],
|
|
26
|
+
range: [0, width]
|
|
27
|
+
}),
|
|
28
|
+
[width]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const numberOfRows = Math.floor(height / (rowHeight + 16));
|
|
32
|
+
|
|
33
|
+
const yScale = useMemo(
|
|
34
|
+
() =>
|
|
35
|
+
scaleLinear({
|
|
36
|
+
domain: [0, numberOfRows],
|
|
37
|
+
range: [0, height]
|
|
38
|
+
}),
|
|
39
|
+
[height]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const tick = maxColumns / columns;
|
|
43
|
+
|
|
44
|
+
const xTickValues = Array(columns)
|
|
45
|
+
.fill(0)
|
|
46
|
+
.map((_, index) => index * tick);
|
|
47
|
+
|
|
48
|
+
return useMemoComponent({
|
|
49
|
+
Component: (
|
|
50
|
+
<svg style={{ height, position: 'absolute', width }}>
|
|
51
|
+
<VisxGrid.GridColumns
|
|
52
|
+
height={height}
|
|
53
|
+
scale={xScale}
|
|
54
|
+
stroke={theme.palette.divider}
|
|
55
|
+
tickValues={xTickValues}
|
|
56
|
+
width={width}
|
|
57
|
+
/>
|
|
58
|
+
<VisxGrid.GridRows
|
|
59
|
+
height={height}
|
|
60
|
+
scale={yScale}
|
|
61
|
+
stroke={theme.palette.divider}
|
|
62
|
+
top={-10}
|
|
63
|
+
width={width}
|
|
64
|
+
/>
|
|
65
|
+
</svg>
|
|
66
|
+
),
|
|
67
|
+
memoProps: [height, width, columns]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default Grid;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CSSProperties, ForwardedRef, forwardRef, MouseEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { isNil } from 'ramda';
|
|
4
|
+
|
|
5
|
+
import { Card } from '@mui/material';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable-next-line import/no-named-as-default */
|
|
8
|
+
import useMemoComponent from '../utils/useMemoComponent';
|
|
9
|
+
|
|
10
|
+
import { useDashboardItemStyles } from './Dashboard.styles';
|
|
11
|
+
|
|
12
|
+
interface DashboardItemProps {
|
|
13
|
+
children: JSX.Element;
|
|
14
|
+
className?: string;
|
|
15
|
+
header?: JSX.Element;
|
|
16
|
+
key: string;
|
|
17
|
+
onMouseDown?: (e: MouseEvent<HTMLDivElement>) => void;
|
|
18
|
+
onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void;
|
|
19
|
+
onTouchEnd?: (e) => void;
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const Item = forwardRef(
|
|
24
|
+
(
|
|
25
|
+
{
|
|
26
|
+
children,
|
|
27
|
+
key,
|
|
28
|
+
style,
|
|
29
|
+
className,
|
|
30
|
+
header,
|
|
31
|
+
onMouseDown,
|
|
32
|
+
onMouseUp,
|
|
33
|
+
onTouchEnd
|
|
34
|
+
}: DashboardItemProps,
|
|
35
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
36
|
+
): JSX.Element => {
|
|
37
|
+
const { classes } = useDashboardItemStyles();
|
|
38
|
+
|
|
39
|
+
const hasHeader = !isNil(header);
|
|
40
|
+
|
|
41
|
+
const listeners = {
|
|
42
|
+
onMouseDown,
|
|
43
|
+
onMouseUp,
|
|
44
|
+
onTouchEnd
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const cardContainerListeners = !hasHeader ? listeners : {};
|
|
48
|
+
|
|
49
|
+
return useMemoComponent({
|
|
50
|
+
Component: (
|
|
51
|
+
<div
|
|
52
|
+
className={className}
|
|
53
|
+
key={key}
|
|
54
|
+
ref={ref}
|
|
55
|
+
style={style}
|
|
56
|
+
{...cardContainerListeners}
|
|
57
|
+
>
|
|
58
|
+
<Card className={classes.widgetContainer}>
|
|
59
|
+
{header && (
|
|
60
|
+
<div {...listeners} className={classes.widgetHeader}>
|
|
61
|
+
{header}
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
<div className={classes.widgetContent}>{children}</div>
|
|
65
|
+
</Card>
|
|
66
|
+
</div>
|
|
67
|
+
),
|
|
68
|
+
memoProps: [key, style, className, header]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export default Item;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Responsive } from '@visx/visx';
|
|
4
|
+
import GridLayout, { WidthProvider, Layout } from 'react-grid-layout';
|
|
5
|
+
import 'react-grid-layout/css/styles.css';
|
|
6
|
+
|
|
7
|
+
import { Responsive as ResponsiveHeight, useMemoComponent } from '..';
|
|
8
|
+
|
|
9
|
+
import { useDashboardLayoutStyles } from './Dashboard.styles';
|
|
10
|
+
import { getColumnsFromScreenSize, getLayout, rowHeight } from './utils';
|
|
11
|
+
import Grid from './Grid';
|
|
12
|
+
|
|
13
|
+
const ReactGridLayout = WidthProvider(GridLayout);
|
|
14
|
+
|
|
15
|
+
interface DashboardLayoutProps<T> {
|
|
16
|
+
changeLayout?: (newLayout: Array<Layout>) => void;
|
|
17
|
+
children: Array<JSX.Element>;
|
|
18
|
+
displayGrid?: boolean;
|
|
19
|
+
layout: Array<T>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Layout = <T extends Layout>({
|
|
23
|
+
children,
|
|
24
|
+
changeLayout,
|
|
25
|
+
displayGrid,
|
|
26
|
+
layout
|
|
27
|
+
}: DashboardLayoutProps<T>): JSX.Element => {
|
|
28
|
+
const { classes } = useDashboardLayoutStyles();
|
|
29
|
+
|
|
30
|
+
const [columns, setColumns] = useState(getColumnsFromScreenSize());
|
|
31
|
+
|
|
32
|
+
const resize = (): void => {
|
|
33
|
+
setColumns(getColumnsFromScreenSize());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
window.addEventListener('resize', resize);
|
|
38
|
+
|
|
39
|
+
return (): void => {
|
|
40
|
+
window.removeEventListener('resize', resize);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
return useMemoComponent({
|
|
45
|
+
Component: (
|
|
46
|
+
<ResponsiveHeight>
|
|
47
|
+
<Responsive.ParentSize>
|
|
48
|
+
{({ width, height }): JSX.Element => (
|
|
49
|
+
<div className={classes.container}>
|
|
50
|
+
{displayGrid && (
|
|
51
|
+
<Grid columns={columns} height={height} width={width} />
|
|
52
|
+
)}
|
|
53
|
+
<ReactGridLayout
|
|
54
|
+
cols={columns}
|
|
55
|
+
containerPadding={[4, 0]}
|
|
56
|
+
layout={getLayout(layout)}
|
|
57
|
+
margin={[20, 20]}
|
|
58
|
+
resizeHandles={['s', 'e', 'se']}
|
|
59
|
+
rowHeight={rowHeight}
|
|
60
|
+
width={width}
|
|
61
|
+
onLayoutChange={changeLayout}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</ReactGridLayout>
|
|
65
|
+
</div>
|
|
66
|
+
)}
|
|
67
|
+
</Responsive.ParentSize>
|
|
68
|
+
</ResponsiveHeight>
|
|
69
|
+
),
|
|
70
|
+
memoProps: [columns, layout, displayGrid]
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default Layout;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { lt } from 'ramda';
|
|
2
|
+
import { Layout } from 'react-grid-layout';
|
|
3
|
+
|
|
4
|
+
export const maxColumns = 12;
|
|
5
|
+
const minColumns = 1;
|
|
6
|
+
const breakpoint = 768;
|
|
7
|
+
|
|
8
|
+
export const rowHeight = 64;
|
|
9
|
+
|
|
10
|
+
export const getIsSmallScreenSize = (): boolean =>
|
|
11
|
+
lt(window.innerWidth, breakpoint);
|
|
12
|
+
|
|
13
|
+
export const getColumnsFromScreenSize = (): number =>
|
|
14
|
+
getIsSmallScreenSize() ? minColumns : maxColumns;
|
|
15
|
+
|
|
16
|
+
export const getLayout = <T extends Layout>(layout: Array<T>): Array<T> => {
|
|
17
|
+
const isSmallScreenSize = getIsSmallScreenSize();
|
|
18
|
+
if (!isSmallScreenSize) {
|
|
19
|
+
return layout;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return layout
|
|
23
|
+
.sort((a, b) => a.x + a.y - (b.x + b.y))
|
|
24
|
+
.map((widget) => ({
|
|
25
|
+
...widget,
|
|
26
|
+
w: 1
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Formik,
|
|
3
|
+
FormikHelpers,
|
|
4
|
+
FormikSharedConfig,
|
|
5
|
+
FormikValues
|
|
6
|
+
} from 'formik';
|
|
2
7
|
import * as Yup from 'yup';
|
|
3
8
|
|
|
4
9
|
import FormButtons from './FormButtons';
|
|
5
10
|
import Inputs from './Inputs';
|
|
6
11
|
import { Group, InputProps } from './Inputs/models';
|
|
12
|
+
import { useStyles } from './Form.styles';
|
|
7
13
|
|
|
8
14
|
export enum GroupDirection {
|
|
9
15
|
Horizontal = 'horizontal',
|
|
10
16
|
Vertical = 'vertical'
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
export type FormProps<T> = {
|
|
14
20
|
Buttons?: React.ComponentType;
|
|
15
21
|
groupDirection?: GroupDirection;
|
|
16
22
|
groups?: Array<Group>;
|
|
@@ -21,7 +27,7 @@ interface Props<T> {
|
|
|
21
27
|
submit: (values: T, bag: FormikHelpers<T>) => void | Promise<void>;
|
|
22
28
|
validate?: (values: FormikValues) => void;
|
|
23
29
|
validationSchema: Yup.SchemaOf<T>;
|
|
24
|
-
}
|
|
30
|
+
} & Omit<FormikSharedConfig<T>, 'isInitialValid'>;
|
|
25
31
|
|
|
26
32
|
const Form = <T extends object>({
|
|
27
33
|
initialValues,
|
|
@@ -33,8 +39,11 @@ const Form = <T extends object>({
|
|
|
33
39
|
Buttons = FormButtons,
|
|
34
40
|
isLoading = false,
|
|
35
41
|
isCollapsible = false,
|
|
36
|
-
groupDirection = GroupDirection.Vertical
|
|
37
|
-
|
|
42
|
+
groupDirection = GroupDirection.Vertical,
|
|
43
|
+
...formikSharedConfig
|
|
44
|
+
}: FormProps<T>): JSX.Element => {
|
|
45
|
+
const { classes } = useStyles();
|
|
46
|
+
|
|
38
47
|
if (isLoading) {
|
|
39
48
|
return (
|
|
40
49
|
<Inputs
|
|
@@ -48,15 +57,13 @@ const Form = <T extends object>({
|
|
|
48
57
|
|
|
49
58
|
return (
|
|
50
59
|
<Formik<T>
|
|
51
|
-
enableReinitialize
|
|
52
|
-
validateOnBlur
|
|
53
|
-
validateOnMount
|
|
54
60
|
initialValues={initialValues}
|
|
55
61
|
validate={validate}
|
|
56
62
|
validationSchema={validationSchema}
|
|
57
63
|
onSubmit={submit}
|
|
64
|
+
{...formikSharedConfig}
|
|
58
65
|
>
|
|
59
|
-
<div>
|
|
66
|
+
<div className={classes.form}>
|
|
60
67
|
<Inputs
|
|
61
68
|
groupDirection={groupDirection}
|
|
62
69
|
groups={groups}
|
|
@@ -69,4 +76,4 @@ const Form = <T extends object>({
|
|
|
69
76
|
);
|
|
70
77
|
};
|
|
71
78
|
|
|
72
|
-
export
|
|
79
|
+
export { Form };
|
package/src/Form/FormButtons.tsx
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Form';
|
package/src/Form/storiesData.tsx
CHANGED
|
@@ -81,9 +81,7 @@ export const basicFormValidationSchema = Yup.object().shape({
|
|
|
81
81
|
scopes: Yup.array().of(
|
|
82
82
|
Yup.string().min(3, '3 characters min').required('Required')
|
|
83
83
|
),
|
|
84
|
-
sports: Yup.array()
|
|
85
|
-
.of(selectEntryValidationSchema.required('Required'))
|
|
86
|
-
.min(2, 'Choose at least 2 sports')
|
|
84
|
+
sports: Yup.array().of(selectEntryValidationSchema.required('Required'))
|
|
87
85
|
});
|
|
88
86
|
|
|
89
87
|
const roleEntries: Array<SelectEntry> = [
|
|
@@ -85,7 +85,7 @@ const AutoSizeAutocompleteField = ({
|
|
|
85
85
|
endAdornment,
|
|
86
86
|
customPadding
|
|
87
87
|
}: AutoSizeAutocompleteFieldProps): JSX.Element => {
|
|
88
|
-
const [value, setValue] = React.useState(
|
|
88
|
+
const [value, setValue] = React.useState(null);
|
|
89
89
|
|
|
90
90
|
const change = (_, newValue): void => {
|
|
91
91
|
setValue(newValue);
|
|
@@ -108,12 +108,3 @@ const AutoSizeAutocompleteField = ({
|
|
|
108
108
|
export const autoSize = (): JSX.Element => {
|
|
109
109
|
return <AutoSizeAutocompleteField />;
|
|
110
110
|
};
|
|
111
|
-
|
|
112
|
-
export const autoSizeWithCustomPadding = (): JSX.Element => {
|
|
113
|
-
return (
|
|
114
|
-
<AutoSizeAutocompleteField
|
|
115
|
-
customPadding={5}
|
|
116
|
-
endAdornment={<EndAdornment />}
|
|
117
|
-
/>
|
|
118
|
-
);
|
|
119
|
-
};
|