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

Allow variant overrides in Card #27267

Open
1 task done
svrin opened this issue Jul 14, 2021 · 6 comments
Open
1 task done

Allow variant overrides in Card #27267

svrin opened this issue Jul 14, 2021 · 6 comments
Labels
component: card This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@svrin
Copy link

svrin commented Jul 14, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Allow customizing the variants of card, similar to other elements. There is already CardPropsColorOverrides, so there should be a CardPropsVariantOverrides as well.

Motivation 🔦

We use the Card Componente for our product teaser and instead of wrapping the component, we would like directly to style the different variants.

@svrin svrin added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 14, 2021
@mnajdova
Copy link
Member

Related to #27130 Basically if I understand correctly the issue, is about adding a new variant prop on the component, although it doesn't exist by default. Then this prop could be used for styling the component differently.

@mnajdova mnajdova added component: card This is the name of the generic UI component, not the React module! new feature New feature or request package: system Specific to @mui/system and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer package: system Specific to @mui/system labels Jul 16, 2021
@svrin
Copy link
Author

svrin commented Jul 19, 2021

@mnajdova Yes, this sums it well.

@karlo-humanmanaged
Copy link

Looking at the Card, it seems to use PaperPropsVariantOverrides . So I created:

declare module "@mui/material/Paper" {
  // These variants should apply to Paper and any components that inherits Paper. e.g. Card
  export interface PaperPropsVariantOverrides {
    homeCard: true;
  }
}

but, Intellisense in Visual Studio Code is still unable to detect it:
image

@ameshkin
Copy link

I am also unable to create custom variants for MuiCard. I use php storm and it does recognize my custom variant. However, the variant simply doesn't work.

@JerdoAve
Copy link

JerdoAve commented Jun 22, 2023

I've found the following workaround in order to add variant to Card component:

  1. Add variant to the Paper component
  2. Add variant with the same name to the Card

Something like this:

    MuiPaper: {
      variants: [
        {
          props: { variant: 'gray' },
          style: {
            backgroundColor: 'gray
          }
        }
      ]
    },
  MuiCard: {
        variants: [
          {
            props: { variant: 'gray' },
            style: {
              border: 'none'
            }
          }
        ]
  }
  1. Modify d.ts file
declare module '@mui/material/Paper' {
  interface PaperPropsVariantOverrides {
    gray: true
  }
}

@nocodehummel
Copy link

nocodehummel commented Nov 17, 2023

@JerdoAve solution is working.
However it did not resolve my use-case to also utilize the variant for the CardHeader and CardContent.
My requirement would be that component variant classes are promoted to related sub-components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: card This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants