Skip to content
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

[material-next] Add documentation on how to provide a custom theme for the Material You components #37601

Open
2 tasks done
Onibenjo opened this issue Jun 15, 2023 · 7 comments
Assignees
Labels
component: button This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted

Comments

@Onibenjo
Copy link

Onibenjo commented Jun 15, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:
https://codesandbox.io/s/pedantic-architecture-yjt5x5?file=/src/App.js
Steps:

  1. Wrap app with ThemeProvider
  2. use material-next button
  3. app breaks

Current behavior 😯

Cannot read properties of undefined (reading 'color')
But it works fine without the ThemeProvider.
I want to change the theme of the buttons and get the above error

Expected behavior 🤔

It should work fine as the @mui/material button and should also work fine as it does without the ThemeProvider

Context 🔦

No response

Your environment 🌎

npx @mui/envinfo
 System:
    OS: macOS 13.3.1
  Binaries:
    Node: 20.2.0 - ~/.nvm/versions/node/v20.2.0/bin/node
    Yarn: Not Found
    npm: 9.6.6 - ~/.nvm/versions/node/v20.2.0/bin/npm
  Browsers:
    Chrome: 114.0.5735.106
    Edge: Not Found
    Firefox: Not Found
    Safari: 16.4
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.1
    @emotion/styled: ^11.11.0 => 11.11.0
    @mui/base:  5.0.0-beta.4
    @mui/core-downloads-tracker:  5.13.4
    @mui/material: ^5.13.5 => 5.13.5
    @mui/material-next: ^6.0.0-alpha.89 => 6.0.0-alpha.89
    @mui/private-theming:  5.13.1
    @mui/styled-engine:  5.13.2
    @mui/system:  5.13.5
    @mui/types:  7.2.4
    @mui/utils:  5.13.1
    @types/react: ^17.0.0 => 17.0.59
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    typescript: ^4.9.5 => 4.9.5
@Onibenjo Onibenjo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 15, 2023
@zannager zannager added component: button This is the name of the generic UI component, not the React module! package: system Specific to @mui/system customization: theme Centered around the theming features labels Jun 16, 2023
@ZeeshanTamboli
Copy link
Member

It doesn't look like this bug report has enough info for one of us to reproduce it.

Please provide a CodeSandbox (https://mui.com/r/issue-template), a link to a repository on GitHub, or provide a proper minimal code example that reproduces the problem.

@ZeeshanTamboli ZeeshanTamboli removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 26, 2023
@ZeeshanTamboli ZeeshanTamboli added status: waiting for author Issue with insufficient information and removed package: system Specific to @mui/system labels Jun 26, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title My app breaks when I try to use material-next button with ThemeProvider [Button][material-next] My app breaks when I try to use material-next button with ThemeProvider Jun 26, 2023
@Onibenjo
Copy link
Author

hey @ZeeshanTamboli updated the desc with a CodeSandbox link
Here is it also below
https://codesandbox.io/s/pedantic-architecture-yjt5x5?file=/src/App.js

thanks

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jun 26, 2023
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Jun 26, 2023

Thank you for the CodeSandbox! You need to provide a theme to the ThemeProvider. The default theme can be obtained from the extendTheme function in @mui/material-next/styles. See https://codesandbox.io/s/pensive-diffie-zyzd4n?file=/src/App.js.

There is currently missing documentation on this. To address that, we can include the documentation on providing a theme for Material You components in the Button and Slider component pages. For instance, we can add it here: https://mui.com/material-ui/react-button/#material-you-version.

@ZeeshanTamboli ZeeshanTamboli added docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted labels Jun 26, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Button][material-next] My app breaks when I try to use material-next button with ThemeProvider [Button][material-next] Add documentation on how to provide a custom theme for the Material You components Jun 26, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [Button][material-next] Add documentation on how to provide a custom theme for the Material You components [material-next] Add documentation on how to provide a custom theme for the Material You components Jun 26, 2023
@DiegoAndai
Copy link
Member

DiegoAndai commented Aug 24, 2023

Thanks for reporting this issue, I'll look into adding the proper documentation

@DiegoAndai DiegoAndai self-assigned this Aug 24, 2023
@miklepositive
Copy link

miklepositive commented Dec 20, 2023

@ZeeshanTamboli but how to use custom theme colours for Buttons?
I have a theme, wrap it and colours don't work for [material-next] Button, but they work for @mui/material/Button

import { extendTheme } from '@mui/material-next/styles';
import { Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles';

const brandTheme = extendTheme(theme);
        <CssVarsProvider theme={brandTheme}>
                 <Button color="primary"   variant="contained" />               
        </CssVarsProvider>
theme: {
        colorSchemes: {
            light: {
                palette: {
                    primary: {
                        main: '#1a98be',
                    },
                    secondary: {
                        main: '#C0E8F4',
                    },
                },
            },
        },
    },

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli but how to use custom theme colours for Buttons? I have a theme, wrap it and colours don't work for [material-next] Button, but they work for @mui/material/Button

import { extendTheme } from '@mui/material-next/styles';
import { Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles';

const brandTheme = extendTheme(theme);
        <CssVarsProvider theme={brandTheme}>
                 <Button color="primary"   variant="contained" />               
        </CssVarsProvider>
theme: {
        colorSchemes: {
            light: {
                palette: {
                    primary: {
                        main: '#1a98be',
                    },
                    secondary: {
                        main: '#C0E8F4',
                    },
                },
            },
        },
    },

@miklepositive I haven't verified it, but Material Next is still in early development. You could create a new issue with a reproduction to help us track it more effectively.

@DiegoAndai
Copy link
Member

@miklepositive, you should be able to modify the Material 3 color tokens; remember that they have a different structure than Material 2: For example, you can modify the primary color via colorSchemes.light.sys.color.primary. Here's an example of how to achieve this: https://codesandbox.io/p/sandbox/late-pond-ht8lqp?file=%2Fsrc%2FApp.tsx%3A13%2C7

The components follow the Material 3 specs, so if you modify the tokens specified there it should work.

I'm sorry we don't have more documentation on this yet. I will try to get it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: button This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants