question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give the possibility to create new Components using the Material theming system for unique behavior

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Lets say I use material ui and want to create a generic component of some sort to serve me and my team. For example let’s assume Alert component didn’t exist, and I wanted to create Alert component that would take some stylings from the Theming system of material UI. I’ve seen in the source code that useThemeProps is used but it does not seem to be public or documented. I wanted to ask If you are planning on making it public so I could create my own components and being able to easily use themes and variants for my new components.

Let me know what you think 😃

Examples 🌈

const theme = createTheme({
  components: {
    MyCustomComponent: {
      variants: [
        {
          props: { variant: 'dashed' },
          style: {
            textTransform: 'none',
            border: `2px dashed ${blue[500]}`,
          },
        },
        {
          props: { variant: 'dashed', color: 'secondary' },
          style: {
            border: `4px dashed ${red[500]}`,
          },
        },
      ],
    },
  },
});


export function MyCustomComponent() {
const themeProps = useThemeProps(..., 'MyCustomComponent');

// do stuff with the theme props

return ...
}

Motivation 🔦

The primary motivation would be - Any project that would use material UI would instantly gain much more flexibility and potentially be “complete” because we would be able to accomplish anything as users, creating any component we would like while leveraging the tools material gives us.

Secondly I believe that if this kind of API would be documented and public, It would be easier for people to extend the core of Material and contribute at ease and much more frequently.

Let me know what you think, Cheers

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
siriwatknpcommented, Jul 29, 2022

I’m on this!

3reactions
mnajdovacommented, Jun 3, 2022

Then, use the styled method from @mui/system or @mui/material to support the sx props and allow code like

Always use exports from @mui/material if you are already using this package, and the system otherwise (for example building your own design system with unstyled components). The difference is the default theme that will be used.

I found that all those steps added too much boilerplate to components, so I created a higher order component to do all of those steps. I would love some feedback on this one (I was also wondering why it does not exist in MUI, at least for internal use).

We were considering something similar, but decided to go with the less abstract definition, as it is much more readable and easy to understand for people coming to the codebase for the first time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Theming Angular Material
Angular Material's theming system lets you customize color, typography, and density styles for components in your application. The theming system is based ...
Read more >
Implementing your theme - Material Design
The following techniques can be used to customize and apply your theme color, typography, and shape. Iconography is provided with five unique sets...
Read more >
Angular Material Theming System - Complete Guide
In Angular Material, a theme is a collection of color and typography options. Each theme includes three palettes that determine component colors: primary ......
Read more >
Exploring theming in Jetpack Compose - LogRocket Blog
This is mostly the case when you customize your Material components or create your own component. In this case, you want to get...
Read more >
Wear Material Theming | Android Developers
When you begin changing aspects of your UI such as color and typography, Wear Material Theming tools apply your design vision throughout your ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found