Skip to content

Commit

Permalink
[@mantine/styles] Add access to theme in defaultProps (#2950)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulien-ivanov committed Dec 4, 2022
1 parent d9cb099 commit ae81908
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/mantine-styles/src/theme/MantineProvider.tsx
Expand Up @@ -53,7 +53,10 @@ export function useComponentDefaultProps<T extends Record<string, any>, U extend
[Key in Extract<keyof T, keyof U>]-?: U[Key] & T[Key];
} {
const theme = useMantineTheme();
const contextProps = theme.components[component]?.defaultProps;
const contextPropsPayload = theme.components[component]?.defaultProps;
const contextProps =
typeof contextPropsPayload === 'function' ? contextPropsPayload(theme) : contextPropsPayload;

return { ...defaultProps, ...contextProps, ...filterProps(props) };
}

Expand Down
2 changes: 1 addition & 1 deletion src/mantine-styles/src/theme/types/MantineTheme.ts
Expand Up @@ -106,7 +106,7 @@ export interface MantineTheme {
}

interface ThemeComponent {
defaultProps?: Record<string, any>;
defaultProps?: Record<string, any> | ((theme: MantineTheme) => Record<string, any>);
classNames?: Record<string, string>;
styles?:
| Record<string, CSSObject>
Expand Down

0 comments on commit ae81908

Please sign in to comment.