Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support composition #1

Closed
dhleong opened this issue Aug 27, 2019 · 0 comments · Fixed by #3
Closed

Support composition #1

dhleong opened this issue Aug 27, 2019 · 0 comments · Fixed by #3
Assignees
Labels
enhancement New feature or request

Comments

@dhleong
Copy link
Owner

dhleong commented Aug 27, 2019

I think we could very easily support this by supporting a special keyword :composes in the root style. Here you just pass a class name, or a vector of class names, presumably from calling a defclass style (eg: (style-class)), or by doing a (:class (style-attrs)) thing, if you really want to. So it might look like this:

(defclass ship []
  {:background "#999"}
  [:.wings {:background "#777"}])
  
(defattrs stealth-ship []
  {:composes (ship)
   :background "#777"})

Seems very intuitive to me.

@dhleong dhleong added the enhancement New feature or request label Aug 27, 2019
dhleong added a commit that referenced this issue Aug 28, 2019
Refs #1

Uses the same `composes` key that css-modules uses.

This is actually pretty straightforward. By just using the method
call within the style factory, we know that the style element will
be inserted, and we are given the class name directly, so we can
just insert that into the string of classes returned from our
method.

It'd be cool to support :composes in child definitions, but since
it's implemented by concat'ing class names it doesn't seem possible.
For that purpose you would just create a separate def* and use it
on the children directly.
dhleong added a commit that referenced this issue Aug 28, 2019
* Add support for top-level style composition

Refs #1

Uses the same `composes` key that css-modules uses.

This is actually pretty straightforward. By just using the method
call within the style factory, we know that the style element will
be inserted, and we are given the class name directly, so we can
just insert that into the string of classes returned from our
method.

It'd be cool to support :composes in child definitions, but since
it's implemented by concat'ing class names it doesn't seem possible.
For that purpose you would just create a separate def* and use it
on the children directly.

* Allow using defattrs styles in :composes without `(:class)` wrapper
@dhleong dhleong self-assigned this Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant