Skip to content

Can't figure out how to select child component #190

Answered by harold
hoclun-rigsep asked this question in Q&A
Discussion options

You must be logged in to vote

I think you're looking for this:

(defn >
"Child combinator."
([a]
(selector a))
([a b]
(selector (str (css-selector a) " > " (css-selector b))))
([a b & more]
(->> (cons (> a b) more)
(clojure.core/map css-selector)
(string/join " > ")
(selector))))

And using it looks like this:

garden-test.core> (require '[garden.core :refer [css]])
nil
garden-test.core> (css [(garden.selectors/> :.A :.B) {:background :red}])
".A > .B {\n  background: red;\n}"

Another thing to know is that you can use strings as an escape hatch, so this renders the same:

garden-test.core> (css…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hoclun-rigsep
Comment options

Answer selected by hoclun-rigsep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants