lambdaisland / ornament

Clojure Styled Components
Mozilla Public License 2.0
118 stars 13 forks source link

Overload style rules on a styled component with custom render fn? #21

Closed GetBitOutdoors closed 1 year ago

GetBitOutdoors commented 1 year ago

How can I pass and update a styled component with a render body? Something like this:

(defstyled component :div
   :font-bold 
  ([] 
   [:<> [:span "hello"]]))

(defstyled component2 component 
  :text-red-500)

=> (render [component2])
=> <div class="ns_component2"><span>hello</span></div>

=> (defined-styles)
=> ".ns_component2 {font-weight: bold; color: red}"

Should return the composition of the perent component, but also the rendered body of the parent? Or is there another patern for this?

One thing this pattern would allow is to inherit the behavior of a styled component with a custom render fn, and override it's styling with garden/girouette/tailwind keyword-based css-token syntax. I know I can now pass html attrs to a custom-render component. But I don't think that solves this case...

GetBitOutdoors commented 1 year ago

Maybe being able to pass a render function to a defstyled component would help this case. I could not seem to do that.

plexus commented 1 year ago

Inheritence of function tails wasn't implemented yet, I've added it in 0.8.84

GetBitOutdoors commented 1 year ago

Awesome! Thanks.

Is passing a render function the best way to approach composition of custom rendered elements? Am I missing anthing on way to declare high-level css token sytax style on components that are not top-level defs. (or is there an example on parsing those tokens al'acarte in some nested composition? )

plexus commented 1 year ago

That's a very abstract question which I'm having difficulty parsing. Maybe you can give some examples of what you're trying to do?

Ornament only provides mechanisms, we don't really dictate what the right way is to use it, but I'm happy to try to give you some suggestions if you show me what you're trying to do.

You might also want to look into setting custom tokens on the girouette level, see the README for info on that.

GetBitOutdoors commented 1 year ago

I guess I was describing the code example in the first comment. That is not supported right? What is the best approach for something like that? (using the default Girouette tokens)

plexus commented 1 year ago

It's supported since 0.8.84.