Skip to content

Commit 83e855b

Browse files
author
Bruce Hauman
committed
Merge pull request bhauman#53 from codebeige/classname-option
Add option for providing a custom classname [close bhauman#44]
2 parents 636bfff + 5658dca commit 83e855b

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.red-box {
2+
border: 5px solid red;
3+
}

example-resources/public/devcards/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<!-- <link id="com-rigsomelight-devcards-css" href="/devcards/css/com_rigsomelight_devcards.css"
1313
rel="stylesheet" type="text/css"> -->
1414
<link href="/devcards/css/two-zero.css" rel="stylesheet" type="text/css">
15+
<link href="/devcards/css/devcard-api.css" rel="stylesheet" type="text/css">
1516
</head>
1617
<body>
1718
<script src="/devcards/js/compiled/devdemos.js" type="text/javascript"></script>

example_src/devdemos/defcard_api.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@
392392
:inspect-data false ;; wether to display the data in the card atom
393393
:watch-atom true ;; wether to watch the atom and render on change
394394
:history false ;; wether to record a change history of the atom
395+
:classname "" ;; provide card with a custom classname
395396
}
396397
```
397398
@@ -418,6 +419,11 @@
418419
{}
419420
{:padding false})
420421

422+
(defcard custom-classname
423+
(str " this card has a custom class `.red-box`")
424+
{}
425+
{:classname "red-box"})
426+
421427
(defcard inspect-data
422428
(fn [data-atom owner]
423429
(sab/html [:div [:h3 "Inspecting data on this Counter: " (:count @data-atom)]

src/devcards/core.cljs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@
134134
;; returns a react component of rendered edn
135135

136136
(defn- naked-card [children card]
137-
(sab/html
138-
[:div
139-
{:class
140-
(str devcards.system/devcards-rendered-card-class
141-
(if (get-in card [:options :padding]) " com-rigsomelight-devcards-devcard-padding" "")) }
142-
children]))
137+
(let [classname (get-in card [:options :classname])
138+
padding? (get-in card [:options :padding])]
139+
(sab/html
140+
[:div
141+
{:class
142+
(cond-> devcards.system/devcards-rendered-card-class
143+
padding? (str " com-rigsomelight-devcards-devcard-padding")
144+
(not-empty classname) (str " " classname))}
145+
children])))
143146

144147
(defn- frame
145148
([children]

0 commit comments

Comments
 (0)