Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
¿Cómo hacer diferentes variantes de componentes basadas en accesorios usando MUI con estilo?

Estoy tratando de hacer que mi componente se vea diferente en función de accesorios como, por ejemplo, "variante" usando la función de styled como se muestra a continuación:

 import { styled } from '@mui/material/styles'; const RemoveButton = styled(Button)(({ theme }) => ({ backgroundColor: 'lightgreen', })); function App() { return ( <> <RemoveButton>Remove Button</RemoveButton> </> ); } export default App;

Entonces, por ejemplo, ¿qué puedo hacer si quiero que mi componente sea rojo cuando variant="contained" y azul cuando variant="outlined" ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si desea diseñar el componente en función de sus accesorios usando styled :

 const RemoveButton = styled(Button)(({ variant }) => ({ ...(variant === "contained" && { backgroundColor: "red" }), ...(variant === "outlined" && { backgroundColor: "blue" }) }));

También puede crear su propia variante personalizada usando createTheme , consulte esta respuesta para obtener más detalles.

about 4 years ago · Juan Pablo Isaza Report

0

De acuerdo, no importa, lo descubro por mi cuenta, es esa solución recomendada por mui, pero eso funciona para mí, así que:

 const RemoveButton = styled(Button)(({ theme, ...otherProps }) => ({ backgroundColor: {"contained":"red","outlined":"green"}[otherProps.variant], padding: theme.spacing(1), }));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!