Multiple Props Options for Styled Components

前端 未结 5 1592
死守一世寂寞
死守一世寂寞 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:20

    Something more elegant (I guess) and modern would be a combination of destructuring the props and using the switch statement such as:

    const Button = styled.button`
      ${({primary, secondary}) => {
          switch(true) {
            case primary:
              return `background-color : green`
            case secondary:
              return `background-color : red`
          }
        }
      }
    `
    

提交回复
热议问题