linaria icon indicating copy to clipboard operation
linaria copied to clipboard

Support merging CSS for more convenient reuse of CSS.

Open s97712 opened this issue 2 years ago • 2 comments

Describe the feature

Support merging CSS for more convenient reuse of CSS.

Motivation

Possible implementations


const glass = css`
  backgroup: white;
`
const Btn = styled(Button)`
  ${glass.styles}
  backgroup: black;
`

Related Issues

s97712 avatar Aug 16 '23 12:08 s97712

Hi,

looking at how linaria works I don't think this is possible with any reasonable amount of effort. Being a code-mod/-transform, linaria will replace css`...` with a generated class name and it is that class name - a simple string - that should be reused by either passing it to <Btn className={glass} /> or <Button className={cx(css`background: black`, glass)} />.

I am not saying it's not possible at all but I'd rather not see linaria introduce the complexity required to implement what is already supported by other syntactic flavours.

Should you primarily aim for code reuse in the output, have a look at linaria's docs on atomic CSS.

espretto avatar Mar 25 '25 12:03 espretto