rtfeldman / elm-css

Typed CSS in Elm.
https://package.elm-lang.org/packages/rtfeldman/elm-css/latest
BSD 3-Clause "New" or "Revised" License
1.23k stars 196 forks source link

Passing generated classnames to other functions #531

Closed mradke closed 1 year ago

mradke commented 3 years ago

What I'd like to do is to pass class names from a parent (using Html.Styled) to a child view (using plain elm/html), so that the parent styles can be reused.

The motivation for this is that I'd like to use a library that is not using elm-css but offers to pass custom class names (https://github.com/sporto/elm-select/).

As far as I understood the docs I would currently have to use Css.Global, where I'd loose the scoping feature of elm-css. I'd like to avoid that.

Is this already possible?

ktosiek commented 1 year ago

I know this is old, but in case someone finds this question:

You can use Css.Global.descendants [ Css.Global.class "my-select-class" [ {- your styles -} ] ] inside Html.Styled.Attributes.css. This way you can have a named class scoped to your component. Ellie with an example: https://ellie-app.com/nFx7HM8jLCka1

mradke commented 1 year ago

Thanks! I think this answers the question, so I'm gonna close the issue :-)