-
Notifications
You must be signed in to change notification settings - Fork 28
/
margin.clj
68 lines (57 loc) · 1.33 KB
/
margin.clj
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
(ns cljss.css.props.margin
(:require [clojure.spec.alpha :as s]
[cljss.css.units :as units]))
(defmulti margin count)
(defmethod margin 1 [_]
(s/and
(s/coll-of ::units/dimension)
(s/conformer
(fn [[v]]
{:top v
:left v
:right v
:bottom v}))))
(defmethod margin 2 [_]
(s/and
(s/coll-of ::units/dimension)
(s/conformer
(fn [[vertical horizontal]]
{:top vertical
:left horizontal
:right horizontal
:bottom vertical}))))
(defmethod margin 3 [_]
(s/and
(s/coll-of ::units/dimension)
(s/conformer
(fn [[top horizontal bottom]]
{:top top
:left horizontal
:right horizontal
:bottom bottom}))))
(defmethod margin 4 [_]
(s/and
(s/coll-of ::units/dimension)
(s/conformer
(fn [[top left right bottom]]
{:top top
:left left
:right right
:bottom bottom}))))
(s/def ::margin
(s/multi-spec margin count))
(s/def ::top
(s/cat
:top ::units/dimension))
(s/def ::right
(s/cat
:right ::units/dimension))
(s/def ::bottom
(s/cat
:bottom ::units/dimension))
(s/def ::left
(s/cat
:left ::units/dimension))
(comment
(s/conform ::margin [[0 :px] [100 :cm] [1.5 :em] [1 :px]])
(s/conform ::top [16 :px]))