Material UI/Styled Components Style Guide

by: Leeland Clenistagithub logo

This is a style guide that integrates Material UI and Styled Components to make resuable view components.

github logo

Material UI is a React Component library that implements Google's Material Design. It is the most popular component library with over 46k stars on Github.

github logo

Styled-Components is a library that is used to style React components. It is used to by creating React components without the need of making CSS class names.

How to use Styled Components with Material UI Components

  1. Use the styled() method from Styled-Components to style your Material UI components
  2. import styled, { css } from 'styled-components'

    import Button from '@material-ui/core/Button';

    export default styled(Button)``;

  3. Prioritize the CSS rules of your styled-components over those of the JSS with &&
  4. import styled, { css } from 'styled-components'

    import Button from '@material-ui/core/Button';

    export default styled(Button)`

    //ampersand character makes sure that styled-component styles override JSS styles

    && {

    color: #FF000

    box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.18), 0 4px 8px 0 rgba(0, 0, 0, 0.15);

    }

    `;

  5. Dynamically style your components while avoiding warnings related to DOM attributes
  6. import React from 'react'

    import styled, { css } from 'styled-components'

    import Button from '@material-ui/core/Button';

    export default styled(({ color, ...otherProps }) => <Button {...otherProps} />)`

    color: ${props => props.color};

    `;

  7. Style children of Material UI components
  8. import React from 'react'

    import styled, { css } from 'styled-components'

    import Button from '@material-ui/core/Button';

    export default styled(({ color, ...otherProps }) => <Button {...otherProps} />)`

    color: ${props => props.color};

    & .label {

    font-size: 14px;

    }

    `;

Colors

BlueHex: #1e90ffRGB: 30, 144, 255HSL: 209.6, 100%, 55.9%CMYK: 88, 44, 0, 0
OrangeHex: #ff9f43RGB: 255, 159, 67HSL: 29.4, 100%, 63.1%CMYK: 0, 38, 74, 0
GrayHex: #a4b0beRGB: 164, 176, 190HSL: 212.3, 16.7%, 69.4%CMYK: 14, 7, 0, 25
RedHex: #ee5253RGB: 238, 82, 83HSL: 359.6, 82.1%, 62.7%CMYK: 0, 66, 65, 7
GreenHex: #1dd1a1RGB: 29, 209, 161HSL: 164, 75.6%, 46.7%CMYK: 86, 0, 23, 18
Dark blueHex: #030a1dRGB: 3, 10, 29HSL: 223.8, 81.3%, 6.3%CMYK: 90, 66, 0, 89

Typography

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

This is a body text. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.

Small text

Bold text

Highlighted text

Italicized text

Underlined text

Link defaultLink hoverLink activeLink visitedLink disabled

Buttons

Default
Hover
Active
Disabled

Forms

Default
Active
Disabled
Error