@pautena/react-design-system 0.6.2 → 0.7.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/value-displays/group-value-card/group-value-card.d.ts +4 -13
- package/dist/cjs/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/value-base/value-displays.types.d.ts +5 -0
- package/dist/cjs/types/components/value-displays/value-boolean/value-boolean.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-content/value-content.d.ts +6 -1
- package/dist/cjs/types/components/value-displays/value-datetime/value-datetime.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-image/value-image.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-item/index.d.ts +1 -0
- package/dist/cjs/types/components/value-displays/value-item/value-item.d.ts +13 -0
- package/dist/cjs/types/components/value-displays/value-rating/value-rating.d.ts +1 -1
- package/dist/cjs/types/components/value-displays/value-text/value-text.d.ts +1 -1
- package/dist/cjs/types/generators/generators.mock.d.ts +2 -0
- package/dist/cjs/types/generators/generators.model.d.ts +17 -4
- package/dist/cjs/types/generators/object-details/object-details.d.ts +2 -1
- package/dist/cjs/types/utils/breakpoints.d.ts +13 -0
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/value-displays/group-value-card/group-value-card.d.ts +4 -13
- package/dist/esm/types/components/value-displays/group-value-card/group-value-card.mock.d.ts +1 -1
- package/dist/esm/types/components/value-displays/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/value-base/value-displays.types.d.ts +5 -0
- package/dist/esm/types/components/value-displays/value-boolean/value-boolean.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-content/value-content.d.ts +6 -1
- package/dist/esm/types/components/value-displays/value-datetime/value-datetime.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-image/value-image.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-item/index.d.ts +1 -0
- package/dist/esm/types/components/value-displays/value-item/value-item.d.ts +13 -0
- package/dist/esm/types/components/value-displays/value-rating/value-rating.d.ts +1 -1
- package/dist/esm/types/components/value-displays/value-text/value-text.d.ts +1 -1
- package/dist/esm/types/generators/generators.mock.d.ts +2 -0
- package/dist/esm/types/generators/generators.model.d.ts +17 -4
- package/dist/esm/types/generators/object-details/object-details.d.ts +2 -1
- package/dist/esm/types/utils/breakpoints.d.ts +13 -0
- package/dist/index.d.ts +42 -19
- package/package.json +1 -1
- package/src/components/alerts/expandable-alert/expandable-alert.stories.tsx +1 -1
- package/src/components/containers/center-container/center-container.stories.tsx +1 -1
- package/src/components/data-display/markdown/markdown.stories.tsx +0 -1
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.stories.tsx +1 -1
- package/src/components/drawers/drawer-item/drawer-item.stories.tsx +6 -11
- package/src/components/inputs/search-input/search-input.stories.tsx +0 -1
- package/src/components/navigation/tab/tab-card/tab-card.stories.tsx +0 -1
- package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +28 -26
- package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +14 -5
- package/src/components/value-displays/group-value-card/group-value-card.tsx +28 -40
- package/src/components/value-displays/index.ts +1 -0
- package/src/components/value-displays/value-base/value-displays.types.ts +6 -0
- package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +8 -0
- package/src/components/value-displays/value-boolean/value-boolean.tsx +3 -2
- package/src/components/value-displays/value-content/value-content.stories.tsx +7 -2
- package/src/components/value-displays/value-content/value-content.tsx +16 -3
- package/src/components/value-displays/value-datetime/value-datetime.stories.tsx +9 -0
- package/src/components/value-displays/value-datetime/value-datetime.tsx +3 -2
- package/src/components/value-displays/value-displays.stories.mdx +1 -0
- package/src/components/value-displays/value-image/value-image.stories.tsx +8 -0
- package/src/components/value-displays/value-image/value-image.tsx +4 -2
- package/src/components/value-displays/value-item/index.ts +1 -0
- package/src/components/value-displays/value-item/value-item.stories.tsx +45 -0
- package/src/components/value-displays/value-item/value-item.test.tsx +20 -0
- package/src/components/value-displays/value-item/value-item.tsx +54 -0
- package/src/components/value-displays/value-rating/value-rating.stories.tsx +8 -0
- package/src/components/value-displays/value-rating/value-rating.tsx +4 -2
- package/src/components/value-displays/value-text/value-text.stories.tsx +8 -0
- package/src/components/value-displays/value-text/value-text.tsx +3 -2
- package/src/generators/generators.mock.ts +64 -0
- package/src/generators/generators.model.test.ts +7 -0
- package/src/generators/generators.model.ts +35 -13
- package/src/generators/model-form/model-form.test.tsx +5 -0
- package/src/generators/model-form/model-form.tsx +21 -3
- package/src/generators/model-router/model-router.test.tsx +10 -1
- package/src/generators/model-router/stories/templates.tsx +0 -1
- package/src/generators/object-details/object-details.stories.tsx +13 -3
- package/src/generators/object-details/object-details.tsx +96 -15
- package/src/providers/notification-center/notification-center.stories.tsx +1 -1
- package/src/tests/assertions.ts +10 -1
- package/src/utils/breakpoints.test.ts +42 -0
- package/src/utils/breakpoints.ts +62 -0
|
@@ -1,60 +1,48 @@
|
|
|
1
|
-
import { Grid, Paper,
|
|
2
|
-
import React
|
|
1
|
+
import { Grid, Paper, Box, Typography, useTheme } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
3
|
import { useGetDefaultThemeColor } from "../../../utils/theme";
|
|
4
|
-
|
|
5
|
-
export type GroupValueItemProps = PropsWithChildren<
|
|
6
|
-
Omit<GridProps, "item" | "container"> & { bordered?: boolean }
|
|
7
|
-
>;
|
|
8
|
-
export type GroupValueItemComponent = FunctionComponent<GroupValueItemProps>;
|
|
9
|
-
export type GroupValueItemElement = ReactElement<GroupValueItemProps, GroupValueItemComponent>;
|
|
10
|
-
|
|
11
|
-
export const groupValueItemClasses = {
|
|
12
|
-
root: "RdsGroupValueItem-root",
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const GroupValueItem: GroupValueItemComponent = ({
|
|
16
|
-
children,
|
|
17
|
-
bordered = true,
|
|
18
|
-
...rest
|
|
19
|
-
}: GroupValueItemProps) => {
|
|
20
|
-
const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<Grid item className={groupValueItemClasses.root} {...rest}>
|
|
24
|
-
<Box
|
|
25
|
-
px={1}
|
|
26
|
-
sx={{
|
|
27
|
-
borderLeft: bordered ? `solid ${defaultColor} 1px` : "none",
|
|
28
|
-
}}
|
|
29
|
-
>
|
|
30
|
-
{children}
|
|
31
|
-
</Box>
|
|
32
|
-
</Grid>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
4
|
+
import { ValueItemElement } from "../value-item/value-item";
|
|
35
5
|
|
|
36
6
|
export interface GroupValueCardProps {
|
|
37
7
|
title: string;
|
|
38
8
|
subtitle?: string;
|
|
39
9
|
centered?: boolean;
|
|
40
|
-
children:
|
|
10
|
+
children: ValueItemElement | ValueItemElement[];
|
|
11
|
+
dense?: boolean;
|
|
41
12
|
}
|
|
42
13
|
|
|
43
|
-
export const GroupValueCard = ({
|
|
14
|
+
export const GroupValueCard = ({
|
|
15
|
+
title,
|
|
16
|
+
subtitle,
|
|
17
|
+
centered,
|
|
18
|
+
children,
|
|
19
|
+
dense,
|
|
20
|
+
}: GroupValueCardProps) => {
|
|
21
|
+
const { typography } = useTheme();
|
|
44
22
|
const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
|
|
45
23
|
|
|
46
24
|
return (
|
|
47
25
|
<Paper
|
|
48
26
|
sx={{
|
|
49
|
-
paddingBottom: 1,
|
|
27
|
+
paddingBottom: dense ? 0 : 1,
|
|
50
28
|
}}
|
|
51
29
|
>
|
|
52
|
-
<Box
|
|
53
|
-
|
|
30
|
+
<Box
|
|
31
|
+
bgcolor={defaultColor}
|
|
32
|
+
px={dense ? 1 : 2}
|
|
33
|
+
py={dense ? 0.5 : 1}
|
|
34
|
+
lineHeight={dense ? 0 : undefined}
|
|
35
|
+
>
|
|
36
|
+
<Typography variant={dense ? "body1" : "h6"} role="heading" aria-level={1}>
|
|
54
37
|
{title}
|
|
55
38
|
</Typography>
|
|
56
39
|
{subtitle && (
|
|
57
|
-
<Typography
|
|
40
|
+
<Typography
|
|
41
|
+
variant={dense ? "caption" : "body2"}
|
|
42
|
+
role="heading"
|
|
43
|
+
aria-level={2}
|
|
44
|
+
lineHeight={dense ? typography.pxToRem(15) : undefined}
|
|
45
|
+
>
|
|
58
46
|
{subtitle}
|
|
59
47
|
</Typography>
|
|
60
48
|
)}
|
|
@@ -62,7 +50,7 @@ export const GroupValueCard = ({ title, subtitle, centered, children }: GroupVal
|
|
|
62
50
|
<Grid
|
|
63
51
|
container
|
|
64
52
|
padding={1}
|
|
65
|
-
rowSpacing={2}
|
|
53
|
+
rowSpacing={dense ? 1 : 2}
|
|
66
54
|
justifyContent={centered ? "center" : "flex-start"}
|
|
67
55
|
>
|
|
68
56
|
{children}
|
|
@@ -13,6 +13,12 @@ export interface BaseValueProps<T> {
|
|
|
13
13
|
* String rendered if value is undefined
|
|
14
14
|
*/
|
|
15
15
|
placeholder?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The value has to be displayed as compact or not.
|
|
19
|
+
* False by default
|
|
20
|
+
*/
|
|
21
|
+
dense?: boolean;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export interface EditableValueProps<T> {
|
|
@@ -22,16 +22,17 @@ export const ValueBoolean = ({
|
|
|
22
22
|
value,
|
|
23
23
|
placeholder = DefaultPlaceholder,
|
|
24
24
|
editable,
|
|
25
|
+
dense,
|
|
25
26
|
onEdit = () => null,
|
|
26
27
|
}: ValueBooleanProps) => {
|
|
27
28
|
const { typography } = useTheme();
|
|
28
29
|
const { isEditing, editValue, startEdit, cancelEdit, setEditValue, submitEdit } =
|
|
29
30
|
useEditableValueDisplay(value, onEdit);
|
|
30
31
|
|
|
31
|
-
const iconSx = { fontSize: typography.h5.fontSize };
|
|
32
|
+
const iconSx = { fontSize: dense ? typography.h6.fontSize : typography.h5.fontSize };
|
|
32
33
|
|
|
33
34
|
return (
|
|
34
|
-
<ValueContent label={label}>
|
|
35
|
+
<ValueContent label={label} dense={dense}>
|
|
35
36
|
{isEditing ? (
|
|
36
37
|
<Box display="flex" alignItems="center">
|
|
37
38
|
<Switch checked={editValue} onChange={(e) => setEditValue(e.target.checked)} />
|
|
@@ -11,8 +11,8 @@ export default {
|
|
|
11
11
|
parameters: {
|
|
12
12
|
layout: "centered",
|
|
13
13
|
},
|
|
14
|
-
render: () => (
|
|
15
|
-
<ValueContent label="lorem ipsum">
|
|
14
|
+
render: (args) => (
|
|
15
|
+
<ValueContent {...args} label="lorem ipsum">
|
|
16
16
|
<Typography>Demo content</Typography>
|
|
17
17
|
</ValueContent>
|
|
18
18
|
),
|
|
@@ -20,3 +20,8 @@ export default {
|
|
|
20
20
|
type Story = StoryObj<typeof ValueContent>;
|
|
21
21
|
|
|
22
22
|
export const Default: Story = {};
|
|
23
|
+
export const Dense: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
dense: true,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Box, Tooltip, Typography } from "@mui/material";
|
|
1
|
+
import { Box, Tooltip, Typography, useTheme } from "@mui/material";
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
4
|
export const getValueContentLabelId = (label: string): string =>
|
|
@@ -24,6 +24,12 @@ export interface ValueContentProps {
|
|
|
24
24
|
* Component that's going to be renderd under the label
|
|
25
25
|
*/
|
|
26
26
|
children: React.ReactElement<any, any>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The value has to be displayed as compact or not.
|
|
30
|
+
* False by default
|
|
31
|
+
*/
|
|
32
|
+
dense?: boolean;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
/**
|
|
@@ -34,12 +40,19 @@ export const ValueContent = ({
|
|
|
34
40
|
tooltip,
|
|
35
41
|
tooltipEnterDelay = 2000,
|
|
36
42
|
children,
|
|
43
|
+
dense,
|
|
37
44
|
}: ValueContentProps) => {
|
|
45
|
+
const { typography } = useTheme();
|
|
38
46
|
const id = getValueContentLabelId(label);
|
|
39
47
|
|
|
40
48
|
return (
|
|
41
|
-
<Box width={1}>
|
|
42
|
-
<Typography
|
|
49
|
+
<Box width={1} lineHeight={dense ? 0 : undefined}>
|
|
50
|
+
<Typography
|
|
51
|
+
variant={dense ? "caption" : "subtitle2"}
|
|
52
|
+
role="label"
|
|
53
|
+
id={id}
|
|
54
|
+
lineHeight={dense ? typography.pxToRem(15) : undefined}
|
|
55
|
+
>
|
|
43
56
|
{label}
|
|
44
57
|
</Typography>
|
|
45
58
|
{tooltip ? (
|
|
@@ -20,6 +20,15 @@ export const Default: Story = {
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
export const Dense: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
label: "Lorem",
|
|
26
|
+
value: new Date(2022, 8, 22),
|
|
27
|
+
format: "yyyy/MM/dd",
|
|
28
|
+
dense: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
23
32
|
export const Placeholder: Story = {
|
|
24
33
|
args: {
|
|
25
34
|
label: "Lorem",
|
|
@@ -35,6 +35,7 @@ export const ValueDatetime = ({
|
|
|
35
35
|
placeholder = DefaultPlaceholder,
|
|
36
36
|
editable,
|
|
37
37
|
editInputType = "datetime",
|
|
38
|
+
dense,
|
|
38
39
|
onEdit = () => null,
|
|
39
40
|
}: ValueDatetimeProps) => {
|
|
40
41
|
const { isEditing, editValue, startEdit, cancelEdit, setEditValue, submitEdit } =
|
|
@@ -50,7 +51,7 @@ export const ValueDatetime = ({
|
|
|
50
51
|
: DatePicker;
|
|
51
52
|
|
|
52
53
|
return (
|
|
53
|
-
<ValueContent label={label} tooltip={value}>
|
|
54
|
+
<ValueContent label={label} tooltip={value} dense={dense}>
|
|
54
55
|
{isEditing ? (
|
|
55
56
|
<EditPickerComponent
|
|
56
57
|
value={editValue}
|
|
@@ -79,7 +80,7 @@ export const ValueDatetime = ({
|
|
|
79
80
|
/>
|
|
80
81
|
) : (
|
|
81
82
|
<Box display="flex" alignItems="center">
|
|
82
|
-
<Typography variant="h5" noWrap aria-labelledby={id}>
|
|
83
|
+
<Typography variant={dense ? "body1" : "h5"} noWrap aria-labelledby={id}>
|
|
83
84
|
{value}
|
|
84
85
|
</Typography>
|
|
85
86
|
{editable && (
|
|
@@ -14,4 +14,5 @@ import LinkTo from '@storybook/addon-links/react';
|
|
|
14
14
|
<li><LinkTo kind="Components/Value displays/ValueImage">ValueImage</LinkTo></li>
|
|
15
15
|
<li><LinkTo kind="Components/Value displays/ValueText">ValueText</LinkTo></li>
|
|
16
16
|
<li><LinkTo kind="Components/Value displays/ValueRating">ValueRating</LinkTo></li>
|
|
17
|
+
<li><LinkTo kind="Components/Value displays/ValueItem">ValueItem</LinkTo></li>
|
|
17
18
|
</ul>
|
|
@@ -11,13 +11,15 @@ export interface ValueImageProps extends BaseValueProps<string> {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const DefaultSize = 100;
|
|
14
|
+
const DefaultDenseSize = 50;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Displays a image value with a label
|
|
17
18
|
*/
|
|
18
|
-
export const ValueImage = ({ label, value, size
|
|
19
|
+
export const ValueImage = ({ label, value, size: sizeArg, dense }: ValueImageProps) => {
|
|
20
|
+
const size = sizeArg || (dense ? DefaultDenseSize : DefaultSize);
|
|
19
21
|
return (
|
|
20
|
-
<ValueContent label={label}>
|
|
22
|
+
<ValueContent label={label} dense={dense}>
|
|
21
23
|
<Box component="img" src={value} alt={label} sx={{ width: size, height: size }} />
|
|
22
24
|
</ValueContent>
|
|
23
25
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./value-item";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { ValueItem } from "./value-item";
|
|
3
|
+
import { ValueText } from "../value-text";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Components/Value displays/ValueItem",
|
|
8
|
+
component: ValueItem,
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: "centered",
|
|
11
|
+
},
|
|
12
|
+
render: (args) => (
|
|
13
|
+
<ValueItem {...args}>
|
|
14
|
+
<ValueText label="Hello world" value="Lorem ipsum sit amet" />
|
|
15
|
+
</ValueItem>
|
|
16
|
+
),
|
|
17
|
+
} satisfies Meta<typeof ValueItem>;
|
|
18
|
+
type Story = StoryObj<typeof ValueItem>;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Borderless: Story = {
|
|
25
|
+
args: {
|
|
26
|
+
bordered: false,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const BreakpointsBorder: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
bordered: {
|
|
33
|
+
xs: false,
|
|
34
|
+
sm: true,
|
|
35
|
+
md: false,
|
|
36
|
+
lg: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const BreakpointsArrayBorder: Story = {
|
|
42
|
+
args: {
|
|
43
|
+
bordered: [false, true, false, true],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { render, screen } from "~/tests/testing-library";
|
|
2
|
+
import { ValueItem } from "./value-item";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Typography } from "@mui/material";
|
|
5
|
+
|
|
6
|
+
describe("ValueItem", () => {
|
|
7
|
+
const renderComponent = () => {
|
|
8
|
+
render(
|
|
9
|
+
<ValueItem>
|
|
10
|
+
<Typography>test content</Typography>
|
|
11
|
+
</ValueItem>,
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
it("should render the children", () => {
|
|
16
|
+
renderComponent();
|
|
17
|
+
|
|
18
|
+
expect(screen.getByText(/test content/i)).toBeVisible();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { GridProps, Grid, Box } from "@mui/material";
|
|
2
|
+
import { ResponsiveStyleValue } from "@mui/system";
|
|
3
|
+
import React, { PropsWithChildren, FunctionComponent, ReactElement } from "react";
|
|
4
|
+
import { useGetDefaultThemeColor } from "~/utils";
|
|
5
|
+
|
|
6
|
+
export type ValueItemProps = PropsWithChildren<
|
|
7
|
+
Omit<GridProps, "item" | "container"> & { bordered?: ResponsiveStyleValue<boolean> }
|
|
8
|
+
>;
|
|
9
|
+
export type ValueItemComponent = FunctionComponent<ValueItemProps>;
|
|
10
|
+
export type ValueItemElement = ReactElement<ValueItemProps, ValueItemComponent>;
|
|
11
|
+
|
|
12
|
+
export const valueItemClasses = {
|
|
13
|
+
root: "RdsValueItem-root",
|
|
14
|
+
content: "RdsValueItem-content",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const resolveBorderStyle = (bordered: ResponsiveStyleValue<boolean>, color: string) => {
|
|
18
|
+
const borderStyle = `solid ${color} 1px`;
|
|
19
|
+
const noBorder = "none";
|
|
20
|
+
|
|
21
|
+
if (!bordered) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(bordered)) {
|
|
26
|
+
return bordered.map((b) => (b ? borderStyle : noBorder));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof bordered === "object") {
|
|
30
|
+
const style: Record<string, string | undefined> = {};
|
|
31
|
+
Object.entries(bordered).forEach(([key, value]) => {
|
|
32
|
+
style[key] = value ? borderStyle : noBorder;
|
|
33
|
+
});
|
|
34
|
+
return style;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return borderStyle;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const ValueItem: ValueItemComponent = ({
|
|
41
|
+
children,
|
|
42
|
+
bordered = true,
|
|
43
|
+
...rest
|
|
44
|
+
}: ValueItemProps) => {
|
|
45
|
+
const defaultColor = useGetDefaultThemeColor({ lightWeight: 200, darkWeight: 800 });
|
|
46
|
+
const borderLeft = resolveBorderStyle(bordered, defaultColor);
|
|
47
|
+
return (
|
|
48
|
+
<Grid item className={valueItemClasses.root} {...rest}>
|
|
49
|
+
<Box className={valueItemClasses.content} px={1} borderLeft={borderLeft}>
|
|
50
|
+
{children}
|
|
51
|
+
</Box>
|
|
52
|
+
</Grid>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -17,6 +17,7 @@ export const ValueRating = ({
|
|
|
17
17
|
value = 0,
|
|
18
18
|
maxRating = 5,
|
|
19
19
|
editable,
|
|
20
|
+
dense,
|
|
20
21
|
onEdit = () => null,
|
|
21
22
|
}: ValueRatingProps) => {
|
|
22
23
|
const { isEditing, editValue, startEdit, cancelEdit, setEditValue, submitEdit } =
|
|
@@ -24,14 +25,15 @@ export const ValueRating = ({
|
|
|
24
25
|
const id = getValueContentLabelId(label);
|
|
25
26
|
|
|
26
27
|
return (
|
|
27
|
-
<ValueContent label={label} tooltip={value.toString()}>
|
|
28
|
+
<ValueContent label={label} tooltip={value.toString()} dense={dense}>
|
|
28
29
|
<Box display="flex" alignItems="center">
|
|
29
30
|
<Rating
|
|
30
31
|
aria-labelledby={id}
|
|
31
32
|
readOnly={!isEditing}
|
|
32
33
|
max={maxRating}
|
|
34
|
+
size={dense ? "small" : "medium"}
|
|
33
35
|
value={isEditing ? editValue : value}
|
|
34
|
-
onChange={(_, newValue) => setEditValue(newValue
|
|
36
|
+
onChange={(_, newValue) => newValue && setEditValue(newValue)}
|
|
35
37
|
/>
|
|
36
38
|
{editable && !isEditing && (
|
|
37
39
|
<IconButton size="small" onClick={startEdit} sx={{ ml: 1 }}>
|
|
@@ -20,6 +20,7 @@ export const ValueText = ({
|
|
|
20
20
|
value: valueProp,
|
|
21
21
|
placeholder = DefaultPlaceholder,
|
|
22
22
|
editable,
|
|
23
|
+
dense,
|
|
23
24
|
onEdit = () => null,
|
|
24
25
|
}: ValueTextProps) => {
|
|
25
26
|
const { isEditing, editValue, startEdit, cancelEdit, setEditValue, submitEdit } =
|
|
@@ -28,7 +29,7 @@ export const ValueText = ({
|
|
|
28
29
|
const value = valueProp?.toString() || placeholder;
|
|
29
30
|
|
|
30
31
|
return (
|
|
31
|
-
<ValueContent label={label} tooltip={value}>
|
|
32
|
+
<ValueContent label={label} tooltip={value} dense={dense}>
|
|
32
33
|
{isEditing ? (
|
|
33
34
|
<TextField
|
|
34
35
|
value={editValue}
|
|
@@ -39,7 +40,7 @@ export const ValueText = ({
|
|
|
39
40
|
}}
|
|
40
41
|
/>
|
|
41
42
|
) : (
|
|
42
|
-
<Typography variant="h5" noWrap aria-labelledby={id}>
|
|
43
|
+
<Typography variant={dense ? "body1" : "h5"} noWrap aria-labelledby={id}>
|
|
43
44
|
{value}
|
|
44
45
|
{editable && (
|
|
45
46
|
<IconButton size="small" onClick={startEdit} sx={{ ml: 1 }}>
|
|
@@ -185,6 +185,48 @@ export const mockModel: Model = {
|
|
|
185
185
|
xs: 12,
|
|
186
186
|
sm: 5,
|
|
187
187
|
},
|
|
188
|
+
{
|
|
189
|
+
id: "codes",
|
|
190
|
+
type: "string[]",
|
|
191
|
+
description: "Lorem ipsum",
|
|
192
|
+
name: "Codes",
|
|
193
|
+
xs: 12,
|
|
194
|
+
sm: 5,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: "identifiers",
|
|
198
|
+
type: "number[]",
|
|
199
|
+
description: "Lorem ipsum",
|
|
200
|
+
name: "Identifiers",
|
|
201
|
+
xs: 12,
|
|
202
|
+
sm: 4,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: "carsHistory",
|
|
206
|
+
type: "group[]",
|
|
207
|
+
description: "Lorem ipsum",
|
|
208
|
+
name: "Cars History",
|
|
209
|
+
xs: 12,
|
|
210
|
+
sm: 4,
|
|
211
|
+
value: [
|
|
212
|
+
{
|
|
213
|
+
id: "model",
|
|
214
|
+
type: "string",
|
|
215
|
+
description: "Lorem ipsum",
|
|
216
|
+
name: "Model",
|
|
217
|
+
xs: 12,
|
|
218
|
+
sm: 5,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
id: "manufacturer",
|
|
222
|
+
type: "string",
|
|
223
|
+
description: "Lorem ipsum",
|
|
224
|
+
name: "Manufacturer",
|
|
225
|
+
xs: 12,
|
|
226
|
+
sm: 5,
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
188
230
|
],
|
|
189
231
|
};
|
|
190
232
|
|
|
@@ -210,6 +252,8 @@ export interface MockInstance {
|
|
|
210
252
|
currency: string;
|
|
211
253
|
tradeDate: Date;
|
|
212
254
|
[key: string]: FieldType;
|
|
255
|
+
codes: string[];
|
|
256
|
+
identifiers: string[];
|
|
213
257
|
}
|
|
214
258
|
|
|
215
259
|
const mockFieldValue: Record<string, () => FieldType> = {
|
|
@@ -235,6 +279,8 @@ const mockFieldValue: Record<string, () => FieldType> = {
|
|
|
235
279
|
available: faker.datatype.boolean,
|
|
236
280
|
currency: () => "MXN",
|
|
237
281
|
tradeDate: () => new Date(2012, 2, 11, 8, 25),
|
|
282
|
+
codes: () => [faker.word.noun(), faker.word.noun(), faker.word.noun()],
|
|
283
|
+
identifiers: () => [faker.datatype.number(), faker.datatype.number(), faker.datatype.number()],
|
|
238
284
|
};
|
|
239
285
|
|
|
240
286
|
export const createModelInstance = <T extends BasicModelInstance>(model: Model, seed = 100): T => {
|
|
@@ -251,6 +297,20 @@ export const createModelInstance = <T extends BasicModelInstance>(model: Model,
|
|
|
251
297
|
{},
|
|
252
298
|
),
|
|
253
299
|
};
|
|
300
|
+
} else if (field.type === "group[]") {
|
|
301
|
+
const numElements = faker.datatype.number({ min: 2, max: 5 });
|
|
302
|
+
return {
|
|
303
|
+
...acc,
|
|
304
|
+
[field.id]: new Array(numElements).fill(0).map(() =>
|
|
305
|
+
field.value.reduce(
|
|
306
|
+
(acc, arrayField) => ({
|
|
307
|
+
...acc,
|
|
308
|
+
[arrayField.id]: getModelFieldValue(arrayField),
|
|
309
|
+
}),
|
|
310
|
+
{},
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
};
|
|
254
314
|
} else {
|
|
255
315
|
return {
|
|
256
316
|
...acc,
|
|
@@ -260,6 +320,10 @@ export const createModelInstance = <T extends BasicModelInstance>(model: Model,
|
|
|
260
320
|
}, {} as T);
|
|
261
321
|
};
|
|
262
322
|
|
|
323
|
+
/*
|
|
324
|
+
|
|
325
|
+
*/
|
|
326
|
+
|
|
263
327
|
const getModelFieldValue = ({ id }: ModelField): FieldType => {
|
|
264
328
|
const fieldGenerator = mockFieldValue[id];
|
|
265
329
|
if (!fieldGenerator) {
|
|
@@ -27,6 +27,9 @@ describe("utilities", () => {
|
|
|
27
27
|
middleName: "",
|
|
28
28
|
quantity: 0,
|
|
29
29
|
tradeDate: new Date(2022, 8, 12, 9, 0),
|
|
30
|
+
codes: [],
|
|
31
|
+
identifiers: [],
|
|
32
|
+
carsHistory: [],
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
|
|
@@ -48,6 +51,7 @@ describe("utilities", () => {
|
|
|
48
51
|
},
|
|
49
52
|
available: true,
|
|
50
53
|
gender: "female",
|
|
54
|
+
identifiers: ["1", "2"],
|
|
51
55
|
});
|
|
52
56
|
|
|
53
57
|
expect(instance).toStrictEqual({
|
|
@@ -71,6 +75,9 @@ describe("utilities", () => {
|
|
|
71
75
|
middleName: "",
|
|
72
76
|
quantity: 0,
|
|
73
77
|
tradeDate: new Date(2022, 8, 12, 9, 0),
|
|
78
|
+
codes: [],
|
|
79
|
+
identifiers: ["1", "2"],
|
|
80
|
+
carsHistory: [],
|
|
74
81
|
});
|
|
75
82
|
});
|
|
76
83
|
});
|