-
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 all 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, | ||||||
DialogProps as MuiDialogProps, | ||||||
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 type DialogProps = ThemedComponentBaseProps<{ | ||||||
iconButton: typeof MuiIconButton; | ||||||
root: typeof MuiDialog; | ||||||
dialogTitle: typeof MuiDialogTitle; | ||||||
titleWrapper: "div"; | ||||||
}> & { | ||||||
children?: ReactNode; | ||||||
title?: ReactNode; | ||||||
onClose?: () => void; | ||||||
iconMapping?: { | ||||||
closeIcon?: ReactNode; | ||||||
}; | ||||||
} & MuiDialogProps; | ||||||
|
||||||
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", | ||||||
})(); | ||||||
|
||||||
const DialogTitle = createComponentSlot(MuiDialogTitle)<DialogClassKey>({ | ||||||
componentName: "Dialog", | ||||||
slotName: "dialogTitle", | ||||||
})(css` | ||||||
display: flex; | ||||||
align-items: center; | ||||||
`); | ||||||
|
||||||
const IconButton = createComponentSlot(MuiIconButton)<DialogClassKey>({ | ||||||
componentName: "Dialog", | ||||||
slotName: "iconButton", | ||||||
})(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. 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"; | ||||||||||||
|
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.
Technically a
div
is not allowed insideh2
.