Tokamak icon indicating copy to clipboard operation
Tokamak copied to clipboard

Custom CSS styles

Open MaxDesiatov opened this issue 4 years ago • 4 comments

I've been thinking about CSS-specific styles that one might want to add to further customize generated styles, somewhat similar in principle to the HTML view that allows injecting arbitrary HTML. I'm still not sure if there should be a modifier that allows adding arbitrary HTML attributes to a rendered HTML node, or specialized modifiers like cssStyle() for specifying styles and cssClassName() for specifying a class name.

I also had in mind something like protocol CustomCSSAttributes which would allow any user to conform their views (or existing views provided by Tokamak) to this protocol, providing their custom global attributes. The use case for this are popular styling libraries (and obviously proprietary design systems that people may use) that have existing CSS code. For example, Semantic UI requires buttons to have ui button classes on them:

<button class="ui button">
  Button
</button>

Tokamak could allow achieving that for all buttons globally like this:

extension Button: CustomCSSAttributes {
  var customAttributes: [String: String] { ["class": "ui button"] }
}

The protocol approach and the modifiers approach would not be mutually exclusive, the reasoning is that modifiers would apply tweaks only locally, while protocol conformance would be visible globally. There's some bikeshedding needed here, but overall what are your thoughts?

Don't know if creating a separate issue for this proposal would be more suitable.

MaxDesiatov avatar Jun 30 '20 14:06 MaxDesiatov

I was looking Into making type-safe version of this (maybe something like .margin(left: 2.em) or something?) but it seemed like a lot of work. Maybe it could be generated automatically?

j-f1 avatar Jun 30 '20 15:06 j-f1

@carson-katri could your swift-css package become relevant in any way?

MaxDesiatov avatar Jun 30 '20 15:06 MaxDesiatov

Yeah, it has pretty much all of the CSS properties input as enumerations. Here's the relevant discussion: https://github.com/swiftwasm/Tokamak/pull/114#issuecomment-650790894

carson-katri avatar Jun 30 '20 15:06 carson-katri

how does this fit into the new fiber renderer concept?

aehlke avatar Nov 01 '22 00:11 aehlke