-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Override main views and buttons styles and props using MUI themes #10771
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
base: customizable-components
Are you sure you want to change the base?
Conversation
f9586d4
to
a27f996
Compare
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.
Awesome :)
<AdminContext | ||
dataProvider={dataProvider} | ||
theme={deepmerge(defaultLightTheme, { | ||
components: { | ||
RaBulkDeleteButton: { | ||
defaultProps: { | ||
label: 'Bulk Delete', | ||
className: 'custom-class', | ||
'data-testid': 'themed-button', | ||
}, | ||
}, | ||
}, | ||
} as ThemeOptions)} | ||
> | ||
<ListContextProvider | ||
value={ | ||
{ | ||
selectedIds: [123], | ||
onUnselectItems: () => {}, | ||
} as any | ||
} | ||
> | ||
<BulkDeleteButton | ||
resource="books" | ||
mutationMode="pessimistic" | ||
/> | ||
</ListContextProvider> | ||
</AdminContext> |
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.
This should be a story
<CoreAdminContext dataProvider={dataProvider}> | ||
<ThemeProvider | ||
theme={deepmerge(theme, { | ||
components: { | ||
RaBulkExportButton: { | ||
defaultProps: { | ||
label: 'Bulk Export', | ||
className: 'custom-class', | ||
'data-testid': 'themed-button', | ||
}, | ||
}, | ||
}, | ||
} as ThemeOptions)} | ||
> | ||
<ListContextProvider | ||
value={{ selectedIds: ['selectedId'] }} | ||
> | ||
<BulkExportButton | ||
resource="test" | ||
exporter={exporter} | ||
meta={{ pass: 'meta' }} | ||
/> | ||
</ListContextProvider> | ||
</ThemeProvider> | ||
</CoreAdminContext> |
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.
This should be a story.
|
||
declare module '@mui/material/styles' { | ||
interface ComponentsPropsList { | ||
[PREFIX]: Partial<BulkUpdateButtonProps>; |
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.
I didn't expect referring to PREFIX
would work here but it does. TIL 👍
We could simplify some other components I worked on.
<AdminContext | ||
theme={deepmerge(defaultLightTheme, { | ||
components: { | ||
RaCloneButton: { | ||
defaultProps: { | ||
label: 'Clone', | ||
className: 'custom-class', | ||
'data-testid': 'themed-button', | ||
}, | ||
}, | ||
}, | ||
} as ThemeOptions)} | ||
> | ||
<CloneButton | ||
resource="posts" | ||
record={{ id: 123, foo: 'bar' }} | ||
/> | ||
</AdminContext> |
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.
This should be a story.
Problem
Overriding React-admin defaults is cumbersome for many components, especially the most important ones: views and important actions such as
<DeleteButton>
.Concrete use cases (to be implemented as stories and used for documentation):
Solution
In
ra-ui-materialui
there's a mechanism for that already: the theme. Although we use it for some components (see #10655), we now do it for views such as<List>
,<Edit>
,<Create>
,<Show>
and buttons that has variants such as<DeleteButton>
,<UpdateButton>
,<BulkDeleteButton>
and<BulkUpdateButton>
.How To Test
From Storybook
View a list, detail view or button you want to test with and try to change the default theme.
From simple example
To set the creation as undoable in every Create:
Additional Checks
master
for a bugfix or a documentation fix, ornext
for a feature