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

[Typography] Add custom variants support #22006

Merged
merged 18 commits into from Aug 4, 2020

Conversation

mnajdova
Copy link
Member

This PR adds support for custom variants in the Typography component as part of #21749

@@ -35,6 +36,8 @@ export const styles = (theme) => ({
subtitle2: theme.typography.subtitle2,
/* Styles applied to the root element if `variant="overline"`. */
overline: theme.typography.overline,
/* Styles applied to the root element if `variant="inherit"`. */
inherit: {},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I've added this variant classKey. This way we don't need to update the warnings as the variant classKey will always exists. If we don't want to make this change, I can work on the warning.

@mui-pr-bot
Copy link

mui-pr-bot commented Jul 31, 2020

Details of bundle changes

Generated by 🚫 dangerJS against eb12d8f

@@ -370,150 +370,4 @@ describe('<Button />', () => {
expect(markup.text()).to.equal('Hello World');
});
});

describe('custom theme variants', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered in useThemeVariants.test.js, no need for per component tests

subtitle1: PropTypes.string,
subtitle2: PropTypes.string,
}),
variantMapping: PropTypes /* @typescript-to-proptypes-ignore */.object,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With adding new variants new keys can be added here, so this was relaxed to object.

@@ -314,6 +314,7 @@ export const componentSettings = {
'gutterBottom',
'internalDeprecatedVariant',
'paragraph',
'varaint',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo but why do we want to ignore it? Seems pretty important for prototyping to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variants is now a union of enums + string, my understanding was that we are excluding those props.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding was that we are excluding those props.

Why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

I believe we would need to fix the Framer generation script, not sure it's worth it:

https://github.com/mui-org/material-ui/blob/41e81f229e8f878287ea082b88b5808061a189ad/framer/scripts/framerConfig.js#L289

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@mnajdova mnajdova requested a review from eps1lon August 1, 2020 17:20
@oliviertassinari oliviertassinari added new feature New feature or request component: Typography The React component. labels Aug 2, 2020
@mnajdova mnajdova merged commit 30e912b into mui:next Aug 4, 2020
@cristobalchao
Copy link

Does this PR cover the following use case (see image attached)?

image

From a developer perspective, this would reduce verbosity tremendously

@mbrookes

This comment has been minimized.

@mnajdova
Copy link
Member Author

mnajdova commented Aug 5, 2020

@cristobalchao

That use case is supported, the syntax is a bit different.

const theme = createMuiTheme({
  variants: {
    MuiTypography: [
      {
        props: { variant: 's8' },
        styles: {
          fontSize: 14,
          lineHeight: '20px',
          // other styles...
        },
      },
    ],
  },
});

And than you can use:

<Typography variant="s8">Hello world</Typography>

Here is a docs example: https://next.material-ui.com/customization/theme-components/#adding-new-component-variants that describes this API for the Button component.

@cristobalchao
Copy link

@mnajdova

Thanks for sharing this. I wonder for future versions, if it would make sense to consolidate everything under typography. As we can do now with non-custom variants, which would make everything more streamlined. Have you considered that approach?

@mnajdova
Copy link
Member Author

mnajdova commented Aug 6, 2020

@cristobalchao this is definitely something we want to explore. We are looking into different ways of using dynamic styles based on props. Once we solve that issue, this can be easily implemented.

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 6, 2020

@cristobalchao I believe it will require the same solution to the dynamic color issue #13875. While #15573 focus on allowing the support of new props, right from the theme, #13875 goes a step further. It's meant to bypass the design tokens -> style transformation step. Developers could leverage the design tokens of the theme directly.

@mikeyamato
Copy link

Thanks for making this update! However, I'm still seeing the prop type warning in my console. I wonder if anyone else is seeing the same.

Screen Shot 2020-09-02 at 20 17 25

@mnajdova
Copy link
Member Author

mnajdova commented Sep 3, 2020

@mikeyamato can you please ensure that you are on the latest v5 alpha version? This should not happen as the proptypes is basically relaxed to accept any string. If this is still the case for you, please create an issue.

@mikeyamato
Copy link

@mnajdova totally makes sense. Literally moments before you responded I noticed that this wasn't part of v4.11.0 but rather part of v5.0.0-alpha.6. Okay, going to test it out with v5. Thanks!

@mikeyamato
Copy link

Quick update from my end. I tried to upgrade to v5 but that resulted in various dependency issues with my existing project. Unfortunately I won't be able to take advantage of this feature just quite yet. But looking forward to utilizing it in the near future. Till then I'll need to live with the errors 😢 .

@oliviertassinari
Copy link
Member

@mikeyamato What dependency issues did you face?

@EliRobinson
Copy link

EliRobinson commented Apr 20, 2021

<Typography variant="s8">Hello world</Typography>

Here is a docs example: https://next.material-ui.com/customization/components/#adding-new-component-variants that describes this API for the Button component.

FYI the docs example is here now:
https://next.material-ui.com/customization/theme-components/#adding-new-component-variants

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 20, 2021

@EliRobinson For the typography variant, there is even simpler: https://next.material-ui.com/customization/typography/#adding-amp-disabling-variants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants