-
Notifications
You must be signed in to change notification settings - Fork 0
/
at_rules.cljc
76 lines (63 loc) · 2.66 KB
/
at_rules.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(ns tornado.at-rules
"Current available at-rules: @media, @font-face, @keyframes"
(:require [tornado.types :as t])
#?(:clj (:import (tornado.types CSSAtRule))))
(defn cssatrule [id val]
#?(:clj (CSSAtRule. id val)
:cljs (t/CSSAtRule. id val)))
(defn cssatrule? [x]
(instance? #?(:clj CSSAtRule
:cljs t/CSSAtRule) x))
(defn at-media
"Takes a rules map and any number of media changes and creates a CSSAtRule instance
with \"media\" identifier:
(at-media {:screen :only
:max-width (px 600)
:min-width (px 800)}
[:& {:margin (join 15 0 15 20)}]
[:.abc #:def {:margin (px 20)
:padding (join 30 15)}
[:span {:background-color (mix-colors :red :green)}]]
[:footer {:font-size (em 1)}])
The :& selector selects the current element.
As you can see, you can nest the affected CSS hiccup how you only want.
Special rules values: :screen :only => only screen
:screen true => screen
:screen false => not screen
{:screen true
:speech false
:max-width (px 600)
:min-width (px 800)}
=> @media screen and not speech and (min-width: 600px) and (max-width: 800px) {...}"
[rules & changes]
(cssatrule "media" {:rules rules
:changes changes}))
(defn at-font-face
"Can be used for more convenient describing of @font-face. This is how example
props-maps look like:
{:src [[(f/url \"../webfonts/woff2/roboto.woff2\") (f/css-format :woff2)]
[(f/url \"../webfonts/woff/roboto.woff\") (f/css-format :woff)]]
:font-family \"Roboto\"
:font-weight :normal
:font-style :italic}
This function can receive any number of props maps so that you can also write
the example above this way:
{:src [[(f/url \"../webfonts/woff2/roboto.woff2\") (f/css-format :woff2)]]}
{:src [[(f/url \"../webfonts/woff/roboto.woff\") (f/css-format :woff)]]
:font-family \"Roboto\"
:font-weight :normal
:font-style :italic}"
[& props-maps]
(cssatrule "font-face" props-maps))
(defn at-media?
"Returns true if the expression is a CSSAtRule instance with \"media\" identifier."
[expr] (and (cssatrule? expr)
(= (:identifier expr) "media")))
(defn at-font-face?
"Returns true if the expression is a CSSAtRule instance with \"font-face\" identifier."
[expr] (and (cssatrule? expr)
(= (:identifier expr) "font-face")))
(defn at-keyframes?
"Returns true if the expression is a CSSAtRule instance with \"keyframes\" identifier."
[expr] (and (cssatrule? expr)
(= (:identifier expr) "keyframes")))