Fork me on GitHub
#reagent
<
2017-01-11
>
pesterhazy08:01:24

@ejelome we use that kind of thing extensively with react-native

pesterhazy08:01:38

I think you can also specify multiple styles as a vector

pesterhazy08:01:45

hmm no I'm wrong, at least on react-web that doesn't work

pesterhazy08:01:08

merge is your best bet then

pesterhazy08:01:16

in react-native you only have inline styles anyway

ejelome08:01:17

I was hoping there's a more efficient way than merge

ejelome08:01:17

I think it's timtowtdi anyway, and most likely I will end up just using classnames

ejelome08:01:27

for style switching

pesterhazy08:01:32

lookbook uses macros to merge styles at compile time

ejelome08:01:12

so probably merge with map for multiple sources of styles

ejelome08:01:45

thanks @pesterhazy, great addition to my perspective how to do/solve styles 😄

pesterhazy08:01:28

I'd love to see more discussion about Inline Styles in Reagent

pesterhazy08:01:34

also reusable styles

pesterhazy08:01:42

for reusable components

pesterhazy08:01:58

including an additional css file is a hassle (plus global namespace)

ejelome08:01:32

I thought he even attempted to compose the massive color list of react native 😂

ejelome09:01:10

funny trivia about colors in react native, #0f0 is called lime, and green is #080

selfsame18:01:17

@pesterhazy sort of related: I've been using reagent to mount style nodes in the head. Works wonders if you need reactive css, like layouts based on a window size ratom.

richiardiandrea21:01:12

so what am I doing wrong?

Warning: Unknown prop `tranform` on <g> tag. Remove this prop from the element. For details, see 
    in g (created by rest_resources_viz.core.viz)
    in svg (created by rest_resources_viz.core.viz)
    in div (created by rest_resources_viz.core.viz)
    in rest_resources_viz.core.viz (created by rest_resources_viz.core.landing)
    in h2 (created by rest_resources_viz.core.landing)
    in rest_resources_viz.core.landing

richiardiandrea21:01:58

looks like I cannot specify the transform attribute

gadfly36121:01:31

Can you show code snippet?

richiardiandrea21:01:20

I am a bit rusty sooo 🙂

[:svg {:width width
            :height height}
      [:g {:tranform (str "translate(" (:left margin) "," (:top margin) ")")}]]

richiardiandrea21:01:53

lol there is a typo there 😊

gadfly36121:01:23

haha typo's are hard, glad you caught it bc i missed it too 😉

cfleming23:01:00

I asked this over in #clojurescript, but this might be a better place: Any tips for debugging “Uncaught TypeError: Cannot read property 'getHostNode' of null” in a reagent app?

cfleming23:01:10

Reading the React issues, it seems like this is due to React getting into a funky state when previous errors are swallowed using e.g. promises, but I don’t have anything like that, unless reagent uses them internally.

cfleming23:01:25

This appears to be due to a checkbox I’m using - does this look ok?

cfleming23:01:32

[:input {:type      :checkbox
             :id        :reseller?
             :name      :reseller?
             :checked   (boolean (:reseller? @app-state false))
             :on-change #(swap! app-state update :reseller? not)}]

cfleming23:01:46

(very new to reagent, not sure if this is the right way to do things)

cfleming23:01:26

I can’t find a lot of good examples of checkbox state handling online.

cfleming23:01:41

That error happens when I click the checkbox

juhoteperi23:01:32

:value is unnecessary for checkbox, but I don't think that should cause the problem

cfleming23:01:22

No, I’ve updated the snippet to my latest version - not sure what’s going on there.

gadfly36123:01:56

@cfleming is another component listening to :reseller? in your app?

cfleming23:01:30

@gadfly361 I’m not sure what that means, sorry - do you mean using the value of (:reseller? @app-state)?

gadfly36123:01:08

yeah, is another component using that value?

gadfly36123:01:51

I ask, because i do not think the checkbox component itself is the problem. However, when it changes :reseller? in your app-state, then something, somewhere else is going wrong

cfleming23:01:45

I use that value to hide/show another component with (when (:reseller? @app-state) …), but that component doesn’t directly use the value.

gadfly36123:01:02

can you show the snipped of that when block

gadfly36123:01:15

i am guessing the problem is there

cfleming23:01:21

Interestingly, clicking the checkbox doesn’t cause the checked state to change, so I suspect something is funky there.

cfleming23:01:39

(defn reseller-field []
  [:div
   [:label
    [:input {:type      :checkbox
             :id        :reseller?
             :name      :reseller?
             :checked   (:reseller? @app-state false)
             :on-change #(swap! app-state update :reseller? not)
             :key       :reseller-id}]
    [:span.label-body "Are you a reseller?"]]
   (when (:reseller? @app-state false)
     [:div
      [:label {:for "reseller-id"} "Enter your reseller ID"]
      [:input {:name      "reseller-id"
               :id        "reseller-id"
               :type      "text"
               :class     (str "u-full-width"
                               (when (get-in @app-state [:errors :reseller-id]) " has-error"))
               :value     (:reseller-id-field @app-state "")
               :on-change #(swap! app-state assoc :reseller-id-field (-> % .-target .-value))
               :on-blur   validate-reseller-id-field
               :on-focus  #(clear-error! :reseller-id)}]
      (when-let [error (get-in @app-state [:errors :reseller-id])]
        [:p.error-label error])
      [:p.note "If you do not have a reseller ID, please "
       [:a {:href ""} "contact us"] "."]])])