-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@comet/admin": minor | ||
--- | ||
|
||
Add new custom `Dialog` | ||
|
||
- `title` props allows setting DialogTitle | ||
- optional `onClose` prop adds Close Button to the Component | ||
|
||
Example: | ||
|
||
- `<Dialog title="Dialog Title" onClose={() => {...}} />` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||
import { Close } from "@comet/admin-icons"; | ||||||
import { | ||||||
ComponentsOverrides, | ||||||
css, | ||||||
Dialog as MUIDialog, | ||||||
DialogTitle as MUIDialogTitle, | ||||||
IconButton as MUIIconButton, | ||||||
Theme, | ||||||
useThemeProps, | ||||||
} from "@mui/material"; | ||||||
import { ReactNode } from "react"; | ||||||
|
||||||
import { createComponentSlot } from "../helpers/createComponentSlot"; | ||||||
import { ThemedComponentBaseProps } from "../helpers/ThemedComponentBaseProps"; | ||||||
|
||||||
export type DialogClassKey = "root" | "iconButton" | "titleWrapper" | "dialogTitle"; | ||||||
|
||||||
export interface DialogProps | ||||||
extends ThemedComponentBaseProps<{ | ||||||
iconButton: typeof MUIIconButton; | ||||||
root: typeof MUIDialog; | ||||||
dialogTitle: typeof MUIDialogTitle; | ||||||
titleWrapper: "div"; | ||||||
}> { | ||||||
children?: ReactNode; | ||||||
title: ReactNode; | ||||||
open?: boolean; | ||||||
onClose?: () => void; | ||||||
iconMapping?: { | ||||||
closeIcon?: ReactNode; | ||||||
}; | ||||||
} | ||||||
export function Dialog(inProps: DialogProps) { | ||||||
const { | ||||||
slotProps, | ||||||
open = false, | ||||||
title, | ||||||
iconMapping = {}, | ||||||
children, | ||||||
onClose, | ||||||
...restProps | ||||||
} = useThemeProps({ props: inProps, name: "CometAdminDialog" }); | ||||||
const { closeIcon = <Close color="inherit" /> } = iconMapping; | ||||||
return ( | ||||||
<Root open={open} {...slotProps?.root} {...restProps}> | ||||||
<DialogTitle {...slotProps?.dialogTitle}> | ||||||
<TitleWrapper {...slotProps?.titleWrapper}>{title}</TitleWrapper> | ||||||
{onClose && ( | ||||||
<IconButton {...slotProps?.iconButton} onClick={onClose}> | ||||||
{closeIcon} | ||||||
</IconButton> | ||||||
)} | ||||||
</DialogTitle> | ||||||
{children} | ||||||
</Root> | ||||||
); | ||||||
} | ||||||
|
||||||
const Root = createComponentSlot(MUIDialog)<DialogClassKey>({ | ||||||
componentName: "Dialog", | ||||||
slotName: "root", | ||||||
})(css``); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
const DialogTitle = createComponentSlot(MUIDialogTitle)<DialogClassKey>({ | ||||||
componentName: "Dialog", | ||||||
slotName: "dialogTitle", | ||||||
})(css` | ||||||
display: flex; | ||||||
align-items: center; | ||||||
`); | ||||||
|
||||||
const IconButton = createComponentSlot(MUIIconButton)<DialogClassKey>({ | ||||||
componentName: "Dialog", | ||||||
slotName: "iconButton", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
})(css` | ||||||
color: inherit; | ||||||
position: absolute; | ||||||
right: 20px; | ||||||
`); | ||||||
|
||||||
const TitleWrapper = createComponentSlot("div")<DialogClassKey>({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically a
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't the styles of |
||||||
componentName: "Dialog", | ||||||
slotName: "titleWrapper", | ||||||
})(css` | ||||||
color: inherit; | ||||||
width: 100%; | ||||||
Comment on lines
+85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be the default when using a
Suggested change
|
||||||
padding-right: 40px; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
min-height: 20px; | ||||||
`); | ||||||
|
||||||
declare module "@mui/material/styles" { | ||||||
interface ComponentsPropsList { | ||||||
CometAdminDialog: DialogProps; | ||||||
} | ||||||
|
||||||
interface ComponentNameToClassKey { | ||||||
CometAdminDialog: DialogClassKey; | ||||||
} | ||||||
|
||||||
interface Components { | ||||||
CometAdminDialog?: { | ||||||
defaultProps?: Partial<ComponentsPropsList["CometAdminDialog"]>; | ||||||
styleOverrides?: ComponentsOverrides<Theme>["CometAdminDialog"]; | ||||||
}; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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"; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably add an import restriction to prevent using MUIs comet/packages/eslint-config/react.js Lines 42 to 46 in f8ae084
|
||||||||||||
export { FieldSet, FieldSetClassKey, FieldSetProps } from "./common/FieldSet"; | ||||||||||||
export { HoverActions, HoverActionsClassKey, HoverActionsProps } from "./common/HoverActions"; | ||||||||||||
export { Loading, LoadingProps } from "./common/Loading"; | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||
import { Dialog } from "@comet/admin"; | ||||
import { DialogContent, Typography } from "@mui/material"; | ||||
import { storiesOf } from "@storybook/react"; | ||||
import React from "react"; | ||||
|
||||
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) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be combined with the existing Maybe extend the existing one and add knobs for comet/storybook/src/admin/mui/Dialog.tsx Line 29 in f8ae084
|
||||
.add("Dialog", () => ( | ||||
<Dialog open title="Title"> | ||||
<DialogContent> | ||||
<Typography>{textContent}</Typography> | ||||
</DialogContent> | ||||
</Dialog> | ||||
)) | ||||
.add("Dialog with Close Button", () => ( | ||||
<Dialog open title="Title" onClose={() => {}}> | ||||
<DialogContent> | ||||
<Typography>{textContent}</Typography> | ||||
</DialogContent> | ||||
</Dialog> | ||||
)) | ||||
.add("Dialog with empty title", () => ( | ||||
<Dialog open title="" onClose={() => {}}> | ||||
<DialogContent> | ||||
<Typography>{textContent}</Typography> | ||||
</DialogContent> | ||||
</Dialog> | ||||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
Mui
instead ofMUI
to stay consistent with other import renames.