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] Replace dot notation color value to work with Pigment CSS #43288

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Aug 14, 2024

Context

Reported by #43278 (comment).

The dot notation should be used in sx prop.

For the color prop, the value should be a range of string so I have to add textPrimary and textSecondary to Typography because some components are using text.secondary internally.

Adjusted the color types to show autocomplete for supported color but still allow any string to that it does not break the app in v5.

Current change

Add textPrimary and textSecondary to Typography's color prop

Another option

Add text.primary and text.secondary to the Typography's variants:

export const TypographyRoot = styled('span', {
  name: 'MuiTypography',
  slot: 'Root',
  overridesResolver: (props, styles) => {
    const { ownerState } = props;

    return [
      styles.root,
    ];
  },
})(({ theme }) => ({
  margin: 0,
  variants: [
    ,
    { props: { color: 'text.primary' }, style: { color: theme.palette.text.primary },
    { props: { color: 'text.secondary' }, style: { color: theme.palette.text.secondary },
  ],
}));

With this, it works with Pigment CSS and there is no need other internal usage of <Typography color="text.secondary">. However, I feel that it's a bit inconsistent with other components that has color prop.

Anyway, I am fine with both of the options.


@mui-bot
Copy link

mui-bot commented Aug 14, 2024

Netlify deploy preview

https://deploy-preview-43288--material-ui.netlify.app/

Link: parsed: +0.73% , gzip: +0.21%
@material-ui/core: parsed: +0.10% , gzip: +0.04%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against f126e59

@aarongarciah
Copy link
Member

I left a question in the issue #43278 (comment)

@siriwatknp
Copy link
Member Author

I left a question in the issue #43278 (comment)

Another option is to add text.primary and text.secondary to the Typography's variants:

export const TypographyRoot = styled('span', {
  name: 'MuiTypography',
  slot: 'Root',
  overridesResolver: (props, styles) => {
    const { ownerState } = props;

    return [
      styles.root,
    ];
  },
})(({ theme }) => ({
  margin: 0,
  variants: [
    ,
    { props: { color: 'text.primary' }, style: { color: theme.palette.text.primary },
    { props: { color: 'text.secondary' }, style: { color: theme.palette.text.secondary },
  ],
}));

With this, it works with Pigment CSS and there is no need other internal usage of <Typography color="text.secondary">. However, I feel that it's a bit inconsistent with other components that has color prop.

Anyway, I am fine with both of the options.

@aarongarciah
Copy link
Member

After the discussion in #43278, I agree adding textPrimary and textSecondary is the way to go given our current theme palette shape. But for completeness, I think we should also add textDisabled, so we cover all values under the text key in the theme:

image

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

@siriwatknp should we add a small section to the pigment migration about this?

@siriwatknp
Copy link
Member Author

siriwatknp commented Aug 14, 2024

@siriwatknp should we add a small section to the pigment migration about this?

Good point, adding it. It turns out that the migration guide already include the system props migration. I think it's enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. package: material-ui Specific to @mui/material v6.x
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants