Multiple Props Options for Styled Components

前端 未结 5 1585
死守一世寂寞
死守一世寂寞 2021-02-06 11:55

I have a navbar component that I have created using Styled Components. I would like to create some props that change the background-color and/or text color.

For instanc

5条回答
  •  日久生厌
    2021-02-06 12:06

    This is the solution I ended up using:

    export const Navbar = styled.nav`
      width: 100%;
    
      ...  // rest of the regular CSS code
    
      ${props => {
        if (props.dark) {
          return `
            background: ${colors.dark};
            color: ${colors.light};
        `
        } else if (props.light) {
          return `
            background: ${colors.light};
            color: ${colors.dark};
        `
        } else {
          return `
            background: ${colors.light};
            color: ${colors.dark};
        `
        }
      }}
    `
    

提交回复
热议问题