简体   繁体   English

设置Om组件的样式

[英]Styling Om components

The way to style and Om component is based on how React handles styling. 样式和Om组件的方式基于React处理样式的方式。 It would be a horrible mess to duplicate common CSS rules all over the application so is there a way to define the styles in a function or similar? 在整个应用程序中重复通用的CSS规则将是一团糟,那么是否有一种方法可以在函数或类似物中定义样式?

(defn my-css [] {:border "1px solid #000"})

(defn my-component [state]
  (dom/div #js {:className "the-class-name"
                :style #js (my-css)}))

I've tried using defn and def but I can't find a way to avoid 我试过使用defndef但是我找不到避免的方法

Caused by: clojure.lang.ExceptionInfo: JavaScript literal must use map or vector notation

I use: 我用:

(defn create-style [row]
  {:background-color (utils/get-background-color (:task_status row)) :color (utils/get-color (:task_status row))})

But I am using it with "om-bootstrap". 但是我将其与“ om-bootstrap”一起使用。

I have the #js sometimes before the :style map and sometimes after. #js有时在:style映射之前,有时在之后。 I think it depends on what they library is expecting. 我认为这取决于他们图书馆的期望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM