@pautena/react-design-system 0.6.1 → 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/drawers/drawer-provider/drawer.provider.d.ts +2 -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/drawers/drawer-provider/drawer.provider.d.ts +2 -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 +44 -20
- 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/drawers/drawer-provider/drawer-provider.test.tsx +16 -1
- package/src/components/drawers/drawer-provider/drawer.provider.tsx +11 -4
- 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
|
@@ -2,38 +2,40 @@ import React from "react";
|
|
|
2
2
|
import { ValueBoolean } from "../value-boolean/value-boolean";
|
|
3
3
|
import { ValueRating } from "../value-rating";
|
|
4
4
|
import { ValueText } from "../value-text";
|
|
5
|
-
import { GroupValueCard, GroupValueCardProps
|
|
5
|
+
import { GroupValueCard, GroupValueCardProps } from "./group-value-card";
|
|
6
|
+
import { ValueItem } from "../value-item";
|
|
6
7
|
|
|
7
|
-
export const GroupValueCardDummy = (
|
|
8
|
+
export const GroupValueCardDummy = ({ dense, ...rest }: GroupValueCardProps) => {
|
|
8
9
|
return (
|
|
9
|
-
<GroupValueCard {...
|
|
10
|
-
<
|
|
11
|
-
<ValueText label="Hello world" value="Lorem ipsum sit amet" />
|
|
12
|
-
</
|
|
13
|
-
<
|
|
14
|
-
<ValueBoolean label="Enabled" value />
|
|
15
|
-
</
|
|
16
|
-
<
|
|
17
|
-
<ValueText label="Quantity" value="1200" />
|
|
18
|
-
</
|
|
19
|
-
<
|
|
20
|
-
<ValueText label="Currency" value="EUR" />
|
|
21
|
-
</
|
|
22
|
-
<
|
|
10
|
+
<GroupValueCard {...rest} dense={dense}>
|
|
11
|
+
<ValueItem xs={12} sm={6} md={4}>
|
|
12
|
+
<ValueText dense={dense} label="Hello world" value="Lorem ipsum sit amet" />
|
|
13
|
+
</ValueItem>
|
|
14
|
+
<ValueItem xs={12} sm={6} md={2}>
|
|
15
|
+
<ValueBoolean dense={dense} label="Enabled" value />
|
|
16
|
+
</ValueItem>
|
|
17
|
+
<ValueItem xs={12} sm={6} md={3}>
|
|
18
|
+
<ValueText dense={dense} label="Quantity" value="1200" />
|
|
19
|
+
</ValueItem>
|
|
20
|
+
<ValueItem xs={12} sm={6} md={3}>
|
|
21
|
+
<ValueText dense={dense} label="Currency" value="EUR" />
|
|
22
|
+
</ValueItem>
|
|
23
|
+
<ValueItem xs={12} sm={6} md={6}>
|
|
23
24
|
<ValueText
|
|
25
|
+
dense={dense}
|
|
24
26
|
label="I am Batman"
|
|
25
27
|
value=" Does it come in black? It's ends here. Hero can be anyone"
|
|
26
28
|
/>
|
|
27
|
-
</
|
|
28
|
-
<
|
|
29
|
-
<ValueText label="Status" value="Open" />
|
|
30
|
-
</
|
|
31
|
-
<
|
|
32
|
-
<ValueText label="Level" value="2144" />
|
|
33
|
-
</
|
|
34
|
-
<
|
|
35
|
-
<ValueRating label="Rating" value={3} />
|
|
36
|
-
</
|
|
29
|
+
</ValueItem>
|
|
30
|
+
<ValueItem xs={12} sm={6} md={3}>
|
|
31
|
+
<ValueText dense={dense} label="Status" value="Open" />
|
|
32
|
+
</ValueItem>
|
|
33
|
+
<ValueItem xs={12} sm={6} md={3}>
|
|
34
|
+
<ValueText dense={dense} label="Level" value="2144" />
|
|
35
|
+
</ValueItem>
|
|
36
|
+
<ValueItem xs={12} sm={6} md={3}>
|
|
37
|
+
<ValueRating dense={dense} label="Rating" value={3} />
|
|
38
|
+
</ValueItem>
|
|
37
39
|
</GroupValueCard>
|
|
38
40
|
);
|
|
39
41
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { GroupValueCard
|
|
2
|
+
import { GroupValueCard } from "./group-value-card";
|
|
3
3
|
import { withPadding } from "../../../storybook";
|
|
4
4
|
import { GroupValueCardDummy } from "./group-value-card.mock";
|
|
5
5
|
import { ValueImage } from "../value-image";
|
|
@@ -7,6 +7,7 @@ import workInProgressImg from "../../../stories/assets/work-in-progress.jpg";
|
|
|
7
7
|
import React from "react";
|
|
8
8
|
import { ValueContent } from "../value-content";
|
|
9
9
|
import { DatatablePlaceholder } from "~/tests/datatable-placeholder";
|
|
10
|
+
import { ValueItem } from "../value-item";
|
|
10
11
|
|
|
11
12
|
export default {
|
|
12
13
|
title: "Components/Value displays/GroupValueCard",
|
|
@@ -25,6 +26,14 @@ export const Default: Story = {
|
|
|
25
26
|
},
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
export const Dense: Story = {
|
|
30
|
+
args: {
|
|
31
|
+
title: "Hello world",
|
|
32
|
+
subtitle: "Lorem ipsum sit amet",
|
|
33
|
+
dense: true,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
28
37
|
export const WihtoutSubtitle: Story = {
|
|
29
38
|
args: {
|
|
30
39
|
title: "Hello world",
|
|
@@ -33,18 +42,18 @@ export const WihtoutSubtitle: Story = {
|
|
|
33
42
|
|
|
34
43
|
export const WithImage = () => (
|
|
35
44
|
<GroupValueCard centered title="Hello world" subtitle="Lorem ipsum sit amet">
|
|
36
|
-
<
|
|
45
|
+
<ValueItem xs={12} bordered={false}>
|
|
37
46
|
<ValueImage label="Lorem ipsum" value={workInProgressImg} />
|
|
38
|
-
</
|
|
47
|
+
</ValueItem>
|
|
39
48
|
</GroupValueCard>
|
|
40
49
|
);
|
|
41
50
|
|
|
42
51
|
export const WithDataTable = () => (
|
|
43
52
|
<GroupValueCard title="Hello world" subtitle="Lorem ipsum sit amet">
|
|
44
|
-
<
|
|
53
|
+
<ValueItem xs={12} bordered={false}>
|
|
45
54
|
<ValueContent label="lorem ipsum">
|
|
46
55
|
<DatatablePlaceholder />
|
|
47
56
|
</ValueContent>
|
|
48
|
-
</
|
|
57
|
+
</ValueItem>
|
|
49
58
|
</GroupValueCard>
|
|
50
59
|
);
|
|
@@ -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 }}>
|