Skip to content

Commit 5cd1e71

Browse files
authored
feat(Dialog): update Dialog according to P+ specs (#4805)
* feat(Dialog): update Dialog according to P+ specs * chore: add borders to content of the Dialog when scrolling * chore: remove icon from the DialogTitle when not wanted * chore: add resize observer to dialog content * chore: review after feedback
1 parent ac1de07 commit 5cd1e71

File tree

14 files changed

+126
-19
lines changed

14 files changed

+126
-19
lines changed

packages/core/src/Dialog/Content/Content.styles.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { theme } from "@hitachivantara/uikit-styles";
44
export const { staticClasses, useClasses } = createClasses("HvDialog-Content", {
55
root: {
66
padding: theme.spacing(0, "sm", "sm"),
7+
borderColor: theme.colors.borderSubtle,
8+
borderTopWidth: "var(--borderW)",
9+
borderBottomWidth: "var(--borderW)",
710
},
811
textContent: {
9-
marginLeft: "42px",
12+
paddingLeft: `calc(42px + ${theme.space.sm})`,
1013
paddingRight: "62px",
1114
overflowY: "auto",
1215
},

packages/core/src/Dialog/Content/Content.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { useEffect, useRef, useState } from "react";
12
import MuiDialogContent, {
23
DialogContentProps as MuiDialogContentProps,
34
} from "@mui/material/DialogContent";
45
import {
6+
mergeStyles,
57
useDefaultProps,
68
type ExtractNames,
79
} from "@hitachivantara/uikit-react-utils";
10+
import { theme } from "@hitachivantara/uikit-styles";
811

912
import { HvTypography } from "../../Typography";
1013
import { staticClasses, useClasses } from "./Content.styles";
@@ -27,19 +30,47 @@ export const HvDialogContent = (props: HvDialogContentProps) => {
2730
className,
2831
children,
2932
indentContent = false,
33+
style,
3034
...others
3135
} = useDefaultProps("HvDialogContent", props);
3236

3337
const { classes, cx } = useClasses(classesProp);
38+
const [hasBorder, setHasBorder] = useState(false);
39+
const elRef = useRef<HTMLDivElement>(null);
40+
41+
useEffect(() => {
42+
if (typeof ResizeObserver !== "undefined") {
43+
const resizeObserver = new ResizeObserver(() => {
44+
const el = elRef.current as HTMLElement | null;
45+
if (el) {
46+
const hasOverflow = el.scrollHeight > el.clientHeight;
47+
setHasBorder(hasOverflow);
48+
}
49+
});
50+
51+
if (elRef.current) {
52+
resizeObserver.observe(elRef.current as HTMLElement);
53+
}
54+
55+
return () => {
56+
resizeObserver.disconnect();
57+
};
58+
}
59+
return undefined;
60+
}, []);
3461

3562
return (
3663
<HvTypography
64+
ref={elRef}
3765
component={MuiDialogContent}
3866
className={cx(
3967
classes.root,
4068
{ [classes.textContent]: !!indentContent },
4169
className,
4270
)}
71+
style={mergeStyles(style, {
72+
"--borderW": hasBorder ? "1px" : "0px",
73+
})}
4374
{...others}
4475
>
4576
{children}

packages/core/src/Dialog/Dialog.styles.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export const { staticClasses, useClasses } = createClasses("HvDialog", {
1313
borderColor: theme.colors.border,
1414
borderRadius: theme.radii.round,
1515
},
16-
fullscreen: {},
16+
fullscreen: {
17+
borderRadius: 0,
18+
},
19+
1720
fullHeight: {
1821
height: "100%",
1922
},

packages/core/src/Dialog/Title/Title.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
type ExtractNames,
77
} from "@hitachivantara/uikit-react-utils";
88

9+
import { HvStatusIcon } from "../../StatusIcon";
910
import { HvTypography } from "../../Typography";
10-
import { iconVariant } from "../../utils/iconVariant";
1111
import { useDialogContext } from "../context";
1212
import { staticClasses, useClasses } from "./Title.styles";
1313

@@ -48,7 +48,7 @@ export const HvDialogTitle = (props: HvDialogTitleProps) => {
4848
const { classes, cx } = useClasses(classesProp);
4949
const { fullScreen } = useDialogContext();
5050

51-
const icon = customIcon || (showIcon && iconVariant(variant));
51+
const icon = customIcon || (showIcon && <HvStatusIcon variant={variant} />);
5252

5353
return (
5454
<HvTypography

packages/core/src/Dialog/stories/FormStory.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ export const FormStory = () => {
6464
</form>
6565
</HvDialogContent>
6666
<HvDialogActions>
67-
<HvButton type="submit" form="create-post">
68-
Create
69-
</HvButton>
7067
<HvButton variant="secondaryGhost" onClick={() => setOpen(false)}>
7168
Cancel
7269
</HvButton>
70+
<HvButton type="submit" form="create-post">
71+
Create
72+
</HvButton>
7373
</HvDialogActions>
7474
</HvDialog>
7575
</>

packages/core/src/Dialog/stories/MainStory.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ export const MainStory = (props: HvDialogProps) => {
2323
visualization. You will need to re-select your fields.
2424
</HvDialogContent>
2525
<HvDialogActions>
26-
<HvButton variant="secondaryGhost" onClick={() => setOpen(false)}>
27-
Apply
28-
</HvButton>
2926
<HvButton
3027
autoFocus
3128
variant="secondaryGhost"
3229
onClick={() => setOpen(false)}
3330
>
3431
Cancel
3532
</HvButton>
33+
<HvButton variant="secondaryGhost" onClick={() => setOpen(false)}>
34+
Apply
35+
</HvButton>
3636
</HvDialogActions>
3737
</HvDialog>
3838
</div>

packages/core/src/Dialog/stories/SemanticVariantsStory.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
HvDialogContent,
88
HvDialogProps,
99
HvDialogTitle,
10+
HvStatusIcon,
1011
} from "@hitachivantara/uikit-react-core";
1112
import { Ungroup } from "@hitachivantara/uikit-react-icons";
1213

@@ -50,16 +51,16 @@ const SimpleDialog = ({
5051
</HvDialogContent>
5152
<HvDialogActions>
5253
<HvButton
53-
variant={variant ? buttonVariantMap[variant] : "secondaryGhost"}
54+
variant={variant ? "secondarySubtle" : "secondaryGhost"}
5455
onClick={() => setOpen(false)}
5556
>
56-
Apply
57+
Cancel
5758
</HvButton>
5859
<HvButton
59-
variant={variant ? "secondarySubtle" : "secondaryGhost"}
60+
variant={variant ? buttonVariantMap[variant] : "secondaryGhost"}
6061
onClick={() => setOpen(false)}
6162
>
62-
Cancel
63+
Apply
6364
</HvButton>
6465
</HvDialogActions>
6566
</HvDialog>
@@ -72,7 +73,7 @@ export const SemanticVariantsStory = () => (
7273
<SimpleDialog
7374
buttonMessage="Warning"
7475
variant="warning"
75-
title={<HvDialogTitle variant="error">Warning</HvDialogTitle>}
76+
title={<HvDialogTitle variant="warning">Warning</HvDialogTitle>}
7677
/>
7778
<SimpleDialog
7879
buttonMessage="Success"
@@ -91,7 +92,14 @@ export const SemanticVariantsStory = () => (
9192
<SimpleDialog
9293
buttonMessage="Custom"
9394
title={
94-
<HvDialogTitle customIcon={<Ungroup iconSize="S" />}>
95+
<HvDialogTitle
96+
customIcon={
97+
<HvStatusIcon
98+
variant="default"
99+
customIcon={<div className="i-ph-tree-structure" />}
100+
/>
101+
}
102+
>
95103
Custom
96104
</HvDialogTitle>
97105
}

packages/core/src/Drawer/Drawer.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export const Main: StoryObj<HvDrawerProps> = {
7070
open={open}
7171
{...args}
7272
>
73-
<HvDialogTitle component="div" className={classes.drawerTitle}>
73+
<HvDialogTitle
74+
component="div"
75+
className={classes.drawerTitle}
76+
showIcon={false}
77+
>
7478
Lorem Ipsum
7579
</HvDialogTitle>
7680
<HvDialogContent className={classes.drawerContent}>

packages/core/src/FileUploader/FileUploader.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export const WithPreviewThumbnails: StoryObj<HvFileUploaderProps> = {
306306
}}
307307
/>
308308
<HvDialog open={open} onClose={() => setOpen(false)}>
309-
<HvDialogTitle>{previewTitle}</HvDialogTitle>
309+
<HvDialogTitle showIcon={false}>{previewTitle}</HvDialogTitle>
310310
<HvDialogContent>
311311
<img
312312
alt="Preview of the uploaded file"

packages/core/src/QueryBuilder/ConfirmationDialog/ConfirmationDialog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const ConfirmationDialog = ({
4545
firstFocusable="confirmation-dialog-cancel"
4646
buttonTitle={closeButtonTooltip}
4747
>
48-
<HvDialogTitle variant="warning">{title}</HvDialogTitle>
48+
<HvDialogTitle variant="warning" showIcon={false}>
49+
{title}
50+
</HvDialogTitle>
4951
<HvDialogContent indentContent>{message}</HvDialogContent>
5052
<HvDialogActions>
5153
<HvButton variant="primaryGhost" onClick={onConfirm}>

0 commit comments

Comments
 (0)