re-com icon indicating copy to clipboard operation
re-com copied to clipboard

title: forces margins inconsistanly

Open hipitihop opened this issue 1 year ago • 3 comments

The title component forces top-margin and bottom-margin by default, not sure why, but it is also difficult/impossible to override as it uses !important

Default: image

[[rc/title
   :level :level2
   :label "My Title"]

If I use :parts :wrapper to set top bottom margin, it is ignored. If I use :style {:margin-bottom "0px" :margin-top "0px"} only the top takes.

I find 9/10 I give up on using title because the defaults don't suit the container and the overrides are as much effort as using normal rc/label and restyle with larger font etc.

hipitihop avatar Nov 05 '24 03:11 hipitihop

I find this annoying too. It seems to throw off our fibonacci-based layout convention.

kimo-k avatar Nov 06 '24 11:11 kimo-k

Hey @kimo-k and @hipitihop !

I've been looking into the issue with title margins and I think I found solution that might work well. Idea is to move margin control from the span element to the wrapper component and make margins optional by default.

  1. Updated default margins to "0":
:or {margin-top "0" margin-bottom "0"}
  1. Moved margin styles to the wrapper component:
wrapper-style (merge
               (get-in parts [:wrapper :style])
               {:margin-top margin-top
                :margin-bottom margin-bottom})

This gives us three flexible ways to control margins:

  1. Direct props (simplest):
[title
 :level :level2
 :margin-top "1em"
 :margin-bottom "0.5em"
 :label "My Title"]
  1. Using :parts (more control):
[title
 :level :level2
 :parts {:wrapper {:style {:margin "2em 0"}}}
 :label "My Title"]
  1. No margins (clean):
[title
 :level :level2
 :label "My Title"]

What do you think? Is this the kind of flexibility we're looking for? Let me know if you'd like to see more examples or if you have any suggestions for improvement. Cheers

dbarabashh avatar Dec 29 '24 17:12 dbarabashh

Sounds like a good direction. What are the implications of declaring a margin on the wrapper instead of the child?

kimo-k avatar Jan 05 '25 12:01 kimo-k