solid-styled-jsx icon indicating copy to clipboard operation
solid-styled-jsx copied to clipboard

Doesn't work with global

Open klm127 opened this issue 11 months ago • 0 comments

Say I style a component

const MyButton = ()=> {
  return <button class="common-button">
     Hello
     <style jsx global>{`
        .common-button {
          background-color: slateblue;
        }
      `}</style>
    </button>
}

And I use it

<div>
  <MyButton />
  <MyButton />
</div>

I would expect that the shared style would be extrapolated into a single

<button class="common-button">Hello<style>.common-button{ background-color=slateblue; }</style></button>
<button class="common-button">Hello<style>.common-button{ background-color=slateblue; }</style></button>

I think the solution is to use a css outside of the component, but there doesn't seem to be a way to do that with solid-styled-jsx.

Eg, for regular styled-jsx you would go:

import css from `styled-jsx/css`
const MyButton = ()=> {
  return <button class="common-button">
     Hello
     <style jsx>{butstyle}</style>
    </button>
}
const butstyle = css`
        .common-button {
          background-color: slateblue;
        }
`      

klm127 avatar Mar 26 '24 20:03 klm127