Skip to content

Instantly share code, notes, and snippets.

@shahab65
Last active June 9, 2020 03:32
Show Gist options
  • Save shahab65/8ae1bb74b6ba04fbfd40f06f81d81e40 to your computer and use it in GitHub Desktop.
Save shahab65/8ae1bb74b6ba04fbfd40f06f81d81e40 to your computer and use it in GitHub Desktop.

function with if in styled components

const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
  ${() => {
    let a = 1 + 2 + 3 + 4;
    let b = a / 2;
    if (b < 6) {
      return `
      color: blue;
      background: green;
      `;
    }
  }}
`;

everything in js is possible in styled components

  font-size: ${2 + 0.5 + "em"};

props

background: ${({type}) => (type === 'cancel' ? 'tomato' : 'indigo')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment