Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Custom DialogTitle to @comet/admin #2609

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fichtnerma
Copy link
Contributor

@fichtnerma fichtnerma commented Oct 7, 2024

Description

Create option to add an onClose callback with a close Button by creating a custom Dialog to replace MUI Dialogs

Example

  • I have verified if my change requires an example

Screenshots/screencasts

image

Changeset

  • I have verified if my change requires a changeset

Related tasks and documents

https://vivid-planet.atlassian.net/browse/COM-1045

Comment on lines 37 to 44
const Title = createComponentSlot(MUIDialogTitle)<DialogTitleClassKey>({
componentName: "DialogTitle",
slotName: "dialogTitle",
})(css`
display: flex;
justify-content: space-between;
align-items: center;
`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this slot should be called "Root" to be consistent with other components

packages/admin/admin/src/common/DialogTitle.tsx Outdated Show resolved Hide resolved
Comment on lines 5 to 11
Add new custom `DialogTitle` to @comet/admin

- optional `onClose` prop adds Close Button to the Component

Example:

- `<DialogTitle onClose={() => {...}} />`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioning "@comet/admin" is not necessary as this changelog is explicitly for "@comet/admin"

@johnnyomair
Copy link
Collaborator

It is not possible to understand why we need this component without reading the JIRA task. Please make sure that a PR can be understood without having to look into the task.

@johnnyomair
Copy link
Collaborator

@jamesricky in the MUI docs they achieve this button using an IconButton and absolute positioning: https://mui.com/material-ui/react-dialog/#customization. Wouldn't this be the preferred way?

@jamesricky
Copy link
Contributor

@jamesricky in the MUI docs they achieve this button using an IconButton and absolute positioning: https://mui.com/material-ui/react-dialog/#customization. Wouldn't this be the preferred way?

Yes, probably a good idea 👍🏼
The title will need some padding-right though to prevent potential overlapping.

Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if it were a custom dialog, and not a dialog title? IMO the onClose prop would make more sense on the dialog.

@johnnyomair
Copy link
Collaborator

Wouldn't it be better if it were a custom dialog, and not a dialog title? IMO the onClose prop would make more sense on the dialog.

@jamesricky @fichtnerma what do you think about this suggestion?

@jamesricky
Copy link
Contributor

Wouldn't it be better if it were a custom dialog, and not a dialog title? IMO the onClose prop would make more sense on the dialog.

@jamesricky @fichtnerma what do you think about this suggestion?

That probably makes sense 👍🏼
So like this I assume, so the <DialogTitle /> is rendered internally, when the title and/or onClose prop is set?

<Dialog
    open={showDialog}
    title="This is a dialog"
    onClose={() => {
        setShowDialog(false);
    }}
>
    {dialogContent}
</Dialog>

This could also be helpful for aligning the Buttons in DialogActions correctly which currently if often done incorrectly as it's not very intuitive. E.g., by adding leftActions and rightActions props.
(Probably as a follow-up task)

@fichtnerma
Copy link
Contributor Author

Wouldn't it be better if it were a custom dialog, and not a dialog title? IMO the onClose prop would make more sense on the dialog.

@jamesricky @fichtnerma what do you think about this suggestion?

Yeah makes more sense to me logically

Comment on lines 5 to 7
Dialog as MUIDialog,
DialogTitle as MUIDialogTitle,
IconButton as MUIIconButton,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Mui instead of MUI to stay consistent with other import renames.

const Root = createComponentSlot(MUIDialog)<DialogClassKey>({
componentName: "Dialog",
slotName: "root",
})(css``);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
})(css``);
})();

const textContent =
"Dialog content. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

storiesOf("@comet/admin/Dialog", module)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be combined with the existing Dialog story: https://storybook.comet-dxp.com/?path=/story/comet-admin-mui--dialog

Maybe extend the existing one and add knobs for title and onClose, similar to Dialog size:

const selectedDialogSize = select("Dialog size", dialogSizeOptions, "sm");

@@ -22,6 +22,7 @@ export { SplitButtonContext, SplitButtonContextOptions } from "./common/buttons/
export { useSplitButtonContext } from "./common/buttons/split/useSplitButtonContext";
export { ClearInputAdornment, ClearInputAdornmentProps } from "./common/ClearInputAdornment";
export { CometLogo } from "./common/CometLogo";
export { Dialog, DialogClassKey, DialogProps } from "./common/Dialog";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add an import restriction to prevent using MUIs Dialog.
This is how it's done for Alert for example:

{
name: "@mui/material",
importNames: ["Alert"],
message: "Please use Alert from @comet/admin instead",
},

Comment on lines 72 to 74
const IconButton = createComponentSlot(MUIIconButton)<DialogClassKey>({
componentName: "Dialog",
slotName: "iconButton",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IconButton is too generic imo, I'd prefer something like CloseButton

})(css`
color: inherit;
width: 100%;
padding-right: 40px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This padding should only be added when there is a close-button, otherwise the spacings left and right of the text are inconsistent.

Comment on lines +85 to +86
color: inherit;
width: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be the default when using a div.

Suggested change
color: inherit;
width: 100%;

right: 20px;
`);

const TitleWrapper = createComponentSlot("div")<DialogClassKey>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically a div is not allowed inside h2.

Suggested change
const TitleWrapper = createComponentSlot("div")<DialogClassKey>({
const TitleWrapper = createComponentSlot("span")<DialogClassKey>({

@johnnyomair
Copy link
Collaborator

So like this I assume, so the <DialogTitle /> is rendered internally, when the title and/or onClose prop is set?

I wouldn't do this. I'd render the button outside of the dialog title using absolute positioning, as MUI does in the example.

This could also be helpful for aligning the Buttons in DialogActions correctly which currently if often done incorrectly as it's not very intuitive. E.g., by adding leftActions and rightActions props.

IMO we shouldn't add to many custom props/components for things which can be implemented easily without custom styling. But you could argue that the positioning is often done incorrectly 🤔

right: 20px;
`);

const TitleWrapper = createComponentSlot("div")<DialogClassKey>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the styles of TitleWrapper just be part of DialogTitle directly? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants