Skip to content

Style material-ui components and its nested children with styled-components.

Notifications You must be signed in to change notification settings

cweise/styled-material-ui

Repository files navigation

Description

Style material ui components with the awesome styled-components library.

How to install

npm install @thepeaklab/styled-material-ui --save

How does it work

Material UI has its own documentation for the integration of the styled-components library. However, one quickly notices that subordinate components cannot be addressed directly. This is possible with this library.

We write all component keys from the Material UI documentation as CSS classes to the respective components and their child components. Thus it is possible to style the components via CSS classes.

TextField Example

import React from "react";
import styled from "styled-components";
import { TextField } from "@thepeaklab/styled-material-ui";
import Selectors from "@thepeaklab/styled-material-ui/Selectors";

const StyledTextField = styled(TextField)`
  ${Selectors.TextField.Input} {
    background-color: #eeeeee;
  }
`;

export default () => <StyledTextField name="my-textfield" />;

Button Example

import React from "react";
import styled from "styled-components";
import { Button } from "@thepeaklab/styled-material-ui";
import Selectors from "@thepeaklab/styled-material-ui/Selectors";

const StyledButton = styled(Button)`
  ${Selectors.Button.Root} {
    border-radius: 10px;
  }

  ${Selectors.Button.ContainedPrimary} {
    background-color: #eeeeee;

    &:hover {
      background-color: #cccccc;
    }
  }
`;

export default () => <StyledButton color="primary" variant="contained" />;

Available Material-UI Components

About

Style material-ui components and its nested children with styled-components.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published