Skip to content

Commit

Permalink
[material-ui] Support props callback type in theme variants (#40946)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli authored Mar 2, 2024
1 parent 434cdc1 commit 6d168ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/mui-material/src/styles/createTheme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ const theme = createTheme();
});
}

// props callback in variants
{
createTheme({
components: {
MuiButton: {
variants: [
{
props: (props) => props.color !== 'secondary',
style: ({ theme: { palette } }) => ({
backgroundColor: palette.grey[500],
}),
},
],
},
},
});
}

{
createTheme({
shape: {
Expand Down
8 changes: 7 additions & 1 deletion packages/mui-material/src/styles/variants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { ComponentsPropsList } from './props';

export type ComponentsVariants<Theme = unknown> = {
[Name in keyof ComponentsPropsList]?: Array<{
props: Partial<ComponentsPropsList[Name]>;
props:
| Partial<ComponentsPropsList[Name]>
| ((
props: Partial<ComponentsPropsList[Name]> & {
ownerState: Partial<ComponentsPropsList[Name]>;
},
) => boolean);
style: Interpolation<{ theme: Theme }>;
}>;
};

0 comments on commit 6d168ac

Please sign in to comment.