Skip to content

Commit

Permalink
Merge pull request #1376 from vivid-planet/feature/refactor-admin-com…
Browse files Browse the repository at this point in the history
…ponent-theming

[Feature] Refactor theming of Admin components to remove legacy `@mui/styles` package
  • Loading branch information
johnnyomair authored Mar 19, 2024
2 parents 4e1f05a + 3a18e50 commit 0f922dd
Show file tree
Hide file tree
Showing 188 changed files with 6,840 additions and 4,966 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-clocks-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin-color-picker": major
---

Replace the `componentsProps` prop with `slotProps` in `ColorPicker` and remove the `ColorPickerComponentsProps` type
8 changes: 8 additions & 0 deletions .changeset/cyan-drinks-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/admin": major
---

Change theming method of `Menu`

- Rename `permanent` class-key to `permanentDrawer` and `temporary` class-key to `temporaryDrawer`
- Replace the `permanentDrawerProps` and `temporaryDrawerProps` props with `slotProps`
7 changes: 7 additions & 0 deletions .changeset/great-insects-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove the `FieldContainerComponent` component

`FieldContainerComponent` was never intended to be exported, use `FieldContainer` instead.
5 changes: 5 additions & 0 deletions .changeset/happy-ladybugs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": major
---

Rename the `FilterBarMoveFilersClassKey` type to `FilterBarMoreFiltersClassKey`
7 changes: 7 additions & 0 deletions .changeset/khaki-cobras-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove the `disabled` class-key in `TabScrollButton`

Use the `:disabled` selector instead when styling the disabled state.
8 changes: 8 additions & 0 deletions .changeset/long-crabs-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/admin": major
---

Remove the `components` and `componentProps` props from `CopyToClipboardButton`

Instead, for the icons, use the `copyIcon` and `successIcon` props to pass a `ReactNode` instead of separately passing in values to the `components` and `componentProps` objects.
Use `slotPops` to pass props to the remaining elements.
9 changes: 9 additions & 0 deletions .changeset/proud-cheetahs-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@comet/admin-color-picker": patch
"@comet/admin-react-select": patch
"@comet/admin-date-time": patch
"@comet/admin-rte": patch
"@comet/admin": patch
---

Allow partial props in the theme's `defaultProps` instead of requiring all props when setting the `defaultProps` of a component
5 changes: 5 additions & 0 deletions .changeset/quick-foxes-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": major
---

Replace the `componentsProps` prop with `slotProps` in `FieldSet`
5 changes: 5 additions & 0 deletions .changeset/serious-ravens-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": major
---

Replace the `componentsProps` prop with `slotProps` in `InputWithPopper` and remove the `InputWithPopperComponentsProps` type
7 changes: 7 additions & 0 deletions .changeset/strange-steaks-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove the `message` class-key from `Alert`

Use the `.MuiAlert-message` selector instead to style the message of the underlying MUI `Alert` component.
29 changes: 29 additions & 0 deletions .changeset/ten-turkeys-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@comet/admin-date-time": major
---

Rename multiple props and class-keys and remove the `componentsProps` types:

- `DatePicker`:

- Replace the `componentsProps` prop with `slotProps`
- Remove the `DatePickerComponentsProps` type

- `DateRangePicker`:

- Replace the `componentsProps` prop with `slotProps`
- Remove the `DateRangePickerComponentsProps` type
- Rename the `calendar` class-key to `dateRange`

- `DateTimePicker`:

- Replace the `componentsProps` prop with `slotProps`
- Remove the `DateTimePickerComponentsProps` type
- Replace the `formControl` class-key with two separate class-keys: `dateFormControl` and `timeFormControl`

- `TimeRangePicker`:

- Replace the `componentsProps` prop with `slotProps`
- Remove the `TimeRangePickerComponentsProps` and `TimeRangePickerIndividualPickerProps` types
- Replace the `formControl` class-key with two separate class-keys: `startFormControl` and `endFormControl`
- Replace the `timePicker` class-key with two separate class-keys: `startTimePicker` and `endTimePicker`
7 changes: 7 additions & 0 deletions .changeset/tender-dots-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove the `paper` class-key from `FilterBarPopoverFilter`

Instead of using `styleOverrides` for `paper` in the theme, use the `slotProps` and `sx` props.
7 changes: 7 additions & 0 deletions .changeset/thin-ligers-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin-react-select": major
---

Remove `ControlInput` component

`ControlInput` was never intended to be exported, use MUI's `InputBase` instead.
8 changes: 8 additions & 0 deletions .changeset/tough-zoos-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/admin": major
---

Remove the `disabled` and `focusVisible` class-keys and rename the `inner` class-key to `content` in `AppHeaderButton`

Use the `:disabled` selector instead when styling the disabled state.
Use the `:focus` selector instead when styling the focus state.
7 changes: 7 additions & 0 deletions .changeset/twelve-spoons-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/admin": major
---

Remove the `disabled` class-key in `ClearInputButton`

Use the `:disabled` selector instead when styling the disabled state.
5 changes: 5 additions & 0 deletions .changeset/two-lions-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": major
---

`MenuItem` no longer supports props from MUI's `ListItem` but those from `ListItemButton` instead
8 changes: 8 additions & 0 deletions .changeset/violet-wombats-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/admin": major
---

Remove the `popoverPaper` class-key and rename the `popoverRoot` class-key to `popover` in `AppHeaderDropdown`

Instead of using `styleOverrides` for `popoverPaper` in the theme, use the `slotProps` and `sx` props.
Use the `popover` prop instead of `popoverRoot` to override styles.
106 changes: 106 additions & 0 deletions .changeset/yellow-houses-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
"@comet/admin-color-picker": major
"@comet/admin-react-select": major
"@comet/admin-date-time": major
"@comet/blocks-admin": major
"@comet/admin-theme": major
"@comet/admin-rte": major
"@comet/cms-admin": major
"@comet/admin": major
---

Change the method of overriding the styling of Admin components

- Remove dependency on the legacy `@mui/styles` package in favor of `@mui/material/styles`.
- Add the ability to style components using [MUI's `sx` prop](https://mui.com/system/getting-started/the-sx-prop/).
- Add the ability to style individual elements (slots) of a component using the `slotProps` and `sx` props.
- The `$` syntax in the theme's `styleOverrides` is no longer supported, see: https://mui.com/material-ui/migration/v5-style-changes/#migrate-theme-styleoverrides-to-emotion

```diff
const theme = createCometTheme({
components: {
CometAdminMyComponent: {
styleOverrides: {
- root: {
- "&$hasShadow": {
- boxShadow: "2px 2px 5px 0 rgba(0, 0, 0, 0.25)",
- },
- "& $header": {
- backgroundColor: "lime",
- },
- },
+ hasShadow: {
+ boxShadow: "2px 2px 5px 0 rgba(0, 0, 0, 0.25)",
+ },
+ header: {
+ backgroundColor: "lime",
+ },
},
},
},
});
```

- Overriding a component's styles using `withStyles` is no longer supported. Use the `sx` and `slotProps` props instead:

```diff
-import { withStyles } from "@mui/styles";
-
-const StyledMyComponent = withStyles({
- root: {
- backgroundColor: "lime",
- },
- header: {
- backgroundColor: "fuchsia",
- },
-})(MyComponent);
-
-// ...
-
-<StyledMyComponent title="Hello World" />;
+<MyComponent
+ title="Hello World"
+ sx={{
+ backgroundColor: "lime",
+ }}
+ slotProps={{
+ header: {
+ sx: {
+ backgroundColor: "fuchsia",
+ },
+ },
+ }}
+/>
```

- The module augmentation for the `DefaultTheme` type from `@mui/styles/defaultTheme` is no longer needed and needs to be removed from the admins theme file, usually located in `admin/src/theme.ts`:

```diff
-declare module "@mui/styles/defaultTheme" {
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
- export interface DefaultTheme extends Theme {}
-}
```

- Class-keys originating from MUI components have been removed from Comet Admin components, causing certain class-names and `styleOverrides` to no longer be applied.
The components `root` class-key is not affected. Other class-keys will retain the class-names and `styleOverrides` from the underlying MUI component.
For example, in `ClearInputAdornment` (when used with `position="end"`) the class-name `CometAdminClearInputAdornment-positionEnd` and the `styleOverrides` for `CometAdminClearInputAdornment.positionEnd` will no longer be applied.
The component will retain the class-names `MuiInputAdornment-positionEnd`, `MuiInputAdornment-root`, and `CometAdminClearInputAdornment-root`.
Also, the `styleOverrides` for `MuiInputAdornment.positionEnd`, `MuiInputAdornment.root`, and `CometAdminClearInputAdornment.root` will continue to be applied.

This affects the following components:

- `AppHeader`
- `AppHeaderMenuButton`
- `ClearInputAdornment`
- `Tooltip`
- `CancelButton`
- `DeleteButton`
- `OkayButton`
- `SaveButton`
- `StackBackButton`
- `DatePicker`
- `DateRangePicker`
- `TimePicker`

- For more details, see MUI's migration guide: https://mui.com/material-ui/migration/v5-style-changes/#mui-styles
1 change: 0 additions & 1 deletion demo/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@mui/icons-material": "^5.0.0",
"@mui/lab": "^5.0.0-alpha.76",
"@mui/material": "^5.0.0",
"@mui/styles": "^5.0.0",
"@mui/system": "^5.0.0",
"@mui/x-data-grid": "^5.15.2",
"@mui/x-data-grid-pro": "^5.15.2",
Expand Down
6 changes: 0 additions & 6 deletions demo/admin/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { createCometTheme } from "@comet/admin-theme";
import type {} from "@mui/lab/themeAugmentation";
import { Theme } from "@mui/material";

export default createCometTheme();

declare module "@mui/styles/defaultTheme" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DefaultTheme extends Theme {}
}
Loading

0 comments on commit 0f922dd

Please sign in to comment.