Replies: 2 comments 3 replies
-
Interesting thoughts. I will read more thoroughly over the weekend. Quick reaction: Panda being framework-agnostic means we must achieve this for all frameworks (React, Solid, Vue, Qwik, and Preact). Based on our work on Ark, it's very challenging to make this work in Solid.js and Qwik since they don't exactly use a Virtual DOM. We don't want to add a framework-specific feature to the core of Panda. We'd rather keep them as community plugins instead. |
Beta Was this translation helpful? Give feedback.
-
After a couple of bugs I encountered during testing I adjusted the API slightly. It no longer relies on checking if |
Beta Was this translation helpful? Give feedback.
-
I don't want to bury the lede here: I created a panda plugin that (I think) increases the possibilities of the styled factory. I'd like to get this into panda core if possible!
The code to try it out is here: https://gist.github.com/Jonas-C/c1756b4357d9a22322f83700bcf99eeb.
If you want to try it out as a panda plugin, you can import this file: https://gist.github.com/Jonas-C/0abc53384321e01d2a46616fcf49641f
Hi! I've been heavily using the styled factory to create a component library. In my opinion, it's a great choice for creating named components. However, during my usage I've found several things that are simply impossible to do with it. Here's a couple of scenarios I'd like to see support for:
asChild prop merging
Merging internal component css with external css with a
styled
function.Whilst discussing with Alex on Discord, he proposed adding a
forwardCssProp
option to the styled factory in order to increase flexibility. I ended up implementing this with a panda plugin, but found it much too cumbersome to continually write outforwardCssProp
on pretty much every single component.I then had the idea to reverse the process; By assuming that every component should forward the css prop by default, only the "root" component would need to consume it. Thus, I switched out
forwardCssProp
withconsumeCss
, and placed it wherever the css prop should be consumed (convert itself to a class name).consumeCss
is also cumbersome, but less so. I added an option to thestyled
factory that allowed for removing mostconsumeCss
usage:Disclaimer: You only need to add the
base
prop when you're creating a component that is not aware of how thecss
prop works. The only real scenario where you have to use it is when you'reasChild
-ing onto a component that is not aware of how thecss
prop works. Think of it as a bailout that only works on root components!With a little bit of wrangling, I got a working panda plugin to achieve all of this for me. By modifying the
createStyleContext
function found in park-ui I also got it to cleanly merge slot components!I'll be the first to admit that the API is a bit clunky, but it opens up a whole range of possibilities that the styled factory couldn't do before. You could also make it a more explicit choice in the styled factory, allowing for users to call it like this:
The two mentioned above are my primary motivations, but this could also for instance simplify overriding recipe variants:
As it stands, the styled factory is somewhat of a mine field. You get different results based on the underlying implementation of the component you're styling. This makes the react factory much more streamlined and consistent.
I would love to get this into panda proper! I'm currently in the process of writing a whole bunch of tests for this process, so if you'd be down to develop this further I could contribute those too! Let me know if there's anything I need to add, do or explain better!
Beta Was this translation helpful? Give feedback.
All reactions