This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-23
Channels
- # aws-lambda (1)
- # bangalore-clj (3)
- # beginners (80)
- # boot (8)
- # clojars (1)
- # clojure (200)
- # clojure-dev (37)
- # clojure-greece (26)
- # clojure-italy (11)
- # clojure-norway (3)
- # clojure-russia (14)
- # clojure-spec (21)
- # clojure-uk (30)
- # clojurescript (50)
- # core-logic (10)
- # core-matrix (1)
- # cursive (15)
- # data-science (21)
- # datomic (45)
- # devcards (2)
- # emacs (4)
- # fulcro (12)
- # garden (2)
- # jobs (5)
- # juxt (1)
- # lambdaisland (1)
- # leiningen (4)
- # luminus (20)
- # lumo (26)
- # off-topic (33)
- # onyx (27)
- # parinfer (1)
- # pedestal (3)
- # perun (5)
- # re-frame (20)
- # reagent (27)
- # ring (1)
- # ring-swagger (21)
- # shadow-cljs (259)
- # spacemacs (14)
- # yada (3)
What are some strategies for encapsulating the functionality inside of a component, but leaving the styling of its constituents open for customization by the user? For example, a group of radio-like buttons all have the same behavior, but may differ in styling; e.g. arranged in a grid, arranged in a menu, the "none of the above" button should be a different color, etc...
You can
(defn my-styleable-button [style]
[:button {:on-click something
:on-blur something-else
:style style}])
Seems like the most straightforward solution to me
couldn’t a consumer reliably call (assoc-in (my-component) [1 :style] {.....})
and expect that to work?
as long as the component returns a vector, and I’d be surprised at ones that don’t
There are those that return fns 😊
Which in turn returns vectors.
And will your vector be a list or a vector after assoc-in? I can never tell, but it matters to reagent/render.
vectors are associative, like maps, they are keys of their indices. therefore, assoc works, because it is associative; and it therefore returns an associative structure, in this case, a vector. lists are not associative.
assoc-in breaks on lists and never returns lists
yeah, it wouldn’t work if you return a fun, but that’s a decent reason not to return a fun, and let people use assoc-in (maybe…)
Returning an fn is perfectly normal if you want to close over some state in Reagent. It's right there on the front page of "Introduction to Reagent". And I would say that a function with a clearly defined signature would be more straightforward in intent than some more or less implicit convention that goes against normal reagent expectations. But you could do it, sure!
Meant to put a link to "Introduction to Reagent" here: https://reagent-project.github.io/ And btw, I do mean it; with Reagent code consisting mostly of native Clojure data structures, you can do whatever manipulations with them that you want. That is completely within your power. And that is awesome 😄
@reefersleep is the style
attribute different from class
?
The :style
should be a map, with e.g. {:background :red, :padding "0.1em"}
all of your css attributes
if you want to do it with a vector of classes
(defn my-classy-button [vector-of-class-names]
[:button {:on-click something
:on-blur something-else
:class vector-of-class-names}])
omg I'm really tired of indentation in code blocks on Slack
Call it like
[my-classy-button ["fancy-flat-styling-class" "class-for-making-stuff-draggable"]]
Meant to put a link to "Introduction to Reagent" here: https://reagent-project.github.io/ And btw, I do mean it; with Reagent code consisting mostly of native Clojure data structures, you can do whatever manipulations with them that you want. That is completely within your power. And that is awesome 😄
@reefersleep thanks a lot. This is really helpful! 🍻