Skip to content

Commit 6222103

Browse files
committed
1.6.3
1 parent fd66cca commit 6222103

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.6.3
2+
- Spec macros
3+
- Add `deps.edn`
4+
- Fix multiple style blocks not being inserted into the DOM
5+
- Add **limited** support for nested selectors `{"a" {:color "red"}}`
6+
17
## 1.6.2
28
- Added ability to refer to styles in *.clj namespaces for `inject-global` and `font-face` macros
39

README.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Ask questions on #cljss chat at [Clojuarians Slack](http://clojurians.net/)
1313
<img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="40px" />
1414
</a>
1515

16-
`[org.roman01la/cljss "1.6.2"]`
16+
`[org.roman01la/cljss "1.6.3"]`
1717

1818
## Table of Contents
19+
1920
- [Why write CSS in ClojureScript?](#why-write-css-in-clojurescript)
2021
- [Features](#features)
2122
- [How it works](#how-it-works)
@@ -39,10 +40,12 @@ Thease are some resources that can give you more context:
3940
- [“The road to styled components: CSS in component-based systems”](https://www.youtube.com/watch?v=MT4D_DioYC8) by Glen Maddern
4041

4142
## Features
43+
4244
- Automatic scoped styles by generating unique names
4345
- CSS pseudo-classes and pseudo-elements
4446
- CSS animations via `@keyframes` at-rule
4547
- CSS Media Queries
48+
- Nested CSS selectors
4649
- Injects styles into `<style>` tag at run-time
4750
- Debuggable styles in development (set via `goog.DEBUG`)
4851
- Fast, 10000 insertions in ~200ms
@@ -97,6 +100,7 @@ _NOTE: Dynamic props that are used only to compute styles are also passed onto R
97100
#### predicate attributes in `defstyled`
98101

99102
Sometimes you want toggle between two values. In this example a menu item can switch between active and non-active styles using `:active?` attribute.
103+
100104
```clojure
101105
(defstyled MenuItem :li
102106
{:color (with-meta #(if % "black" "grey") :active?)})
@@ -105,6 +109,7 @@ Sometimes you want toggle between two values. In this example a menu item can sw
105109
```
106110

107111
Because this pattern is so common there's a special treatment for predicate attributes (keywords ending with `?`) in styles definition.
112+
108113
```clojure
109114
(defstyled MenuItem :li
110115
{:color "grey"
@@ -114,12 +119,28 @@ Because this pattern is so common there's a special treatment for predicate attr
114119
```
115120

116121
### pseudo-classes
117-
CSS pseudo classes can be added using parent selector syntax `&` which is popular in CSS pre-processors.
122+
123+
CSS pseudo classes can be expressed as a keyword using parent selector syntax `&` which is popular in CSS pre-processors or as a string if selector is not a valid keyword e.g. `&:nth-child(4)`.
124+
118125
```clojure
119126
(defstyles button [bg]
120127
{:font-size "14px"
121128
:background-color blue
122-
:&:hover {:background-color light-blue}})
129+
:&:hover {:background-color light-blue}
130+
"&:nth-child(3)" {:color "blue"}})
131+
```
132+
133+
### Nested selectors
134+
135+
Sometimes when you want to override library styles you may want to refer to DOM node via its class name, tag or whatever. For this purpose you can use nested CSS selectors via string key.
136+
137+
```clojure
138+
(defstyles error-form []
139+
{:border "1px solid red"
140+
".material-ui--input" {:color "red"}})
141+
142+
[:form {:class (error-form)} ;; .css-817253 {border: 1px solid red}
143+
(mui/Input)] ;; .css-817253 .material-ui--input {color: red}
123144
```
124145

125146
### `:css` attribute
@@ -152,7 +173,7 @@ _NOTE: This feature is supported only for Rum/Sablono elements_
152173

153174
`font-face` macro allows to define custom fonts via `@font-face` CSS at-rule. The macro generates CSS string and injects it at runtime. The syntax is defined in example below.
154175

155-
_The macro supports referring to styles declaration in a separate *.clj namespace._
176+
_The macro supports referring to styles declaration in a separate \*.clj namespace._
156177

157178
```clojure
158179
(require '[cljss.core :refer [font-face]])
@@ -176,7 +197,7 @@ _The macro supports referring to styles declaration in a separate *.clj namespac
176197

177198
`inject-global` macro allows to defined global styles, such as to reset user agent default styles. The macro generates CSS string and injects it at runtime. The syntax is defined in example below.
178199

179-
_The macro supports referring to styles declaration in a separate *.clj namespace._
200+
_The macro supports referring to styles declaration in a separate \*.clj namespace._
180201

181202
```clojure
182203
(require '[cljss.core :refer [inject-global]])
@@ -208,28 +229,34 @@ The syntax is specified as of [CSS Media Queries Level 4 spec](https://www.w3.or
208229
More examples of a query:
209230

210231
#### Boolean query
232+
211233
```clojure
212234
[[:monochrome]]
213235
```
214236

215237
#### Simple conditional query
238+
216239
```clojure
217240
[[:max-width "460px"]]
218241
```
219242

220243
#### Multiple (comma separated) queries
244+
221245
```clojure
222246
[[:screen :and [:max-width "460px"]]
223247
[:print :and [:color]]]
224248
```
225249

226250
#### Basic range query
251+
227252
_Supported operators for range queries_ `#{'= '< '<= '> '>=}`
253+
228254
```clojure
229255
'[[:max-width > "400px"]]
230256
```
231257

232258
#### Complex range query
259+
233260
```clojure
234261
'[["1200px" >= :max-width > "400px"]]
235262
```
@@ -260,6 +287,7 @@ _Supported operators for range queries_ `#{'= '< '<= '> '>=}`
260287
- `styles` a hash map of styles definition
261288

262289
Using [Sablono](https://github.com/r0man/sablono) templating for [React](https://facebook.github.io/react/)
290+
263291
```clojure
264292
(ns example.core
265293
(:require [sablono.core :refer [html]]
@@ -276,6 +304,7 @@ Using [Sablono](https://github.com/r0man/sablono) templating for [React](https:/
276304
```
277305

278306
Dynamically injected CSS:
307+
279308
```css
280309
.css-43697 {
281310
padding: 16px;
@@ -298,19 +327,18 @@ Because CSS is generated at compile-time it's not possible to compose styles as
298327
:margin-bottom y
299328
:margin-left x
300329
:margin-right x})
301-
330+
302331
(defstyles button [bg]
303332
{:padding "8px 24px"
304333
:background-color bg})
305-
334+
306335
(clojure.string/join " " [(button "blue") (margin :y "16px")]) ;; ".css-817263 .css-912834"
307336
```
308337

309338
## Development workflow
310339

311340
When developing with Figwheel in order to deduplicate styles between reloads it is recommended to use Figwheel's `:on-jsload` hook to clean injected styles.
312341

313-
314342
```clojure
315343
:figwheel {:on-jsload example.core/on-reload}
316344
```
@@ -338,15 +366,16 @@ Set `goog.DEBUG` to `false` to enable fast path styles injection.
338366
_NOTE: production build enables fast pass styles injection which makes those styles invisible in `<style>` tag on a page._
339367

340368
## Roadmap
369+
341370
- Server-side rendering
342371

343372
## Contributing
373+
344374
- Pick an issue with `help wanted` label (make sure no one is working on it)
345375
- Stick to project's code style as much as possible
346376
- Make small commits with descriptive commit messages
347377
- Submit a PR with detailed description of what was done
348378

349-
350379
## Development
351380

352381
A repl for the example project is provided via [lein-figwheel](https://github.com/bhauman/lein-figwheel).

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.roman01la/cljss "1.6.2"
1+
(defproject org.roman01la/cljss "1.6.3"
22
:description "Clojure Style Sheets"
33

44
:url "https://github.com/roman01la/cljss"

0 commit comments

Comments
 (0)