简体   繁体   中英

how can I use nested css template literals in styled-components, emotion

const someStyle = css`
  colors : ${({theme}) => theme.colors.primary; 
  ${(props) => props.active ? css`
   background-color: ${({theme}) => theme.colors.backgroundColorActive};
  `}
`

const SomeButton = styled.div`
  ${someStyle} 
`

Can I use css template literals nested in another css template literals?

Even easier you can just use a simple Template strings:

const someStyle = `
  color: ${({theme}) => theme.colors.primary; 
  ${(props) => props.active ? `
   background-color: ${({theme}) => theme.colors.backgroundColorActive};
  `}
`

const SomeButton = styled.div`
  ${someStyle} 
`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM