DEV Community

Cover image for Material Ui com Styled Components no React
Raphael Melo
Raphael Melo

Posted on

2 2

Material Ui com Styled Components no React

Quando comecei a aprender material ui não tinha noção da sua proporção e possibilidades, pra mim era apenas uma lib engessada, com seus components iguais em todos os sites, criei essa prerrogativa na cabeça porque não sabia como editar seu estilo.

Até que descobri o método styled() do Styled-Components que nos permite estilizar componentes usando exatamente a mesma sintaxe de uma folha de estilo CSS.

Código:

import React from "react";
import Card from "@material-ui/core/Card";
import Typography from "@material-ui/core/Typography";

import styled from "styled-components";

const CardStyled = styled(Card)`
  text-align: center;
  width: 200px;
`;

const TextStyled = styled(Typography)`
  width: 200px;
  height: 100px;
  font-size: 24px;
  color: blue;
  background-color: wheat;
`;

export default function Index() {
  return (
    <CardStyled>
      <TextStyled>Meu Card MUI com texto azul</TextStyled>
    </CardStyled>
  );
}
}

Resultado:

Alt Text

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (1)

Collapse
 
antoniel profile image
Antoniel Magalhães

Dahora cara, tô usando material ui em um projeto e tô achando um saco mas não sabia dessa funcionalidade do styled components, taí vou experimentar.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay