Multiple Props Options for Styled Components

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

    you can also do something like this:

    
     const colorType= {
       dark: '#454545',
       light: '#0a0a0a',
       normal: '#dedede'
    };
    
    
    
    export const Navbar= styled.nav`
       background: ${({color}) => colorType[color] || `${color}`};
    
    `;
    
    

    and Here you are :

    
    
    
    

提交回复
热议问题