Skip to content

Commit a69713a

Browse files
committed
Declaration = Property :. Value
1 parent f7c3b78 commit a69713a

15 files changed

Lines changed: 190 additions & 180 deletions

File tree

src/Web/Atomic/CSS.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module Web.Atomic.CSS
1414
, pointer
1515
) where
1616

17-
import Data.Text (Text)
1817
import Web.Atomic.CSS.Box
1918
import Web.Atomic.CSS.Layout
2019
import Web.Atomic.CSS.Reset
@@ -23,7 +22,7 @@ import Web.Atomic.CSS.Text
2322
import Web.Atomic.CSS.Transition
2423
import Web.Atomic.Types
2524
import Web.Atomic.Types.Style
26-
import Web.Atomic.Types.Styleable (CSS, Styleable, cls, css, utility, utility', (~))
25+
import Web.Atomic.Types.Styleable (CSS, Styleable, cls, css, utility, (~))
2726

2827

2928
{- | Set the list style of an item
@@ -35,13 +34,13 @@ import Web.Atomic.Types.Styleable (CSS, Styleable, cls, css, utility, utility',
3534
-}
3635
list :: (ToClassName l, PropertyStyle ListType l, Styleable h) => l -> CSS h -> CSS h
3736
list a =
38-
utility ("list" -. a) "list-style-type" (propertyStyle @ListType a)
37+
utility ("list" -. a) ["list-style-type" :. propertyStyle @ListType a]
3938

4039

4140
data ListType
4241
= Decimal
4342
| Disc
44-
deriving (Show, ToClassName, ToStyleValue)
43+
deriving (Show, ToClassName, ToStyle)
4544
instance PropertyStyle ListType ListType
4645
instance PropertyStyle ListType None
4746

@@ -57,4 +56,4 @@ Button-like elements:
5756
> el btn "Sign Up"
5857
-}
5958
pointer :: (Styleable h) => CSS h -> CSS h
60-
pointer = utility @Text "pointer" "cursor" "pointer"
59+
pointer = utility "pointer" ["cursor" :. "pointer"]

src/Web/Atomic/CSS/Box.hs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
module Web.Atomic.CSS.Box where
22

3-
import Data.Text
43
import Web.Atomic.Types
54

65

76
-- | Cut off the contents of the element
87
truncate :: (Styleable h) => CSS h -> CSS h
98
truncate =
10-
utility'
9+
utility
1110
"truncate"
12-
[ prop @Text "white-space" "nowrap"
13-
, prop @Text "overflow" "hidden"
14-
, prop @Text "text-overflow" "ellipsis"
11+
[ "white-space" :. "nowrap"
12+
, "overflow" :. "hidden"
13+
, "text-overflow" :. "ellipsis"
1514
]
1615

1716

@@ -26,16 +25,16 @@ To create even spacing around and between all elements:
2625
-}
2726
pad :: (Styleable h) => Sides Length -> CSS h -> CSS h
2827
pad (All n) =
29-
utility ("pad" -. n) "padding" n
28+
utility ("p" -. n) ["padding" :. style n]
3029
pad (Y n) = pad (T n) . pad (B n)
3130
pad (X n) = pad (L n) . pad (R n)
3231
pad (XY x y) = pad (X x) . pad (Y y)
3332
pad (TRBL t r b l) =
3433
pad (T t) . pad (R r) . pad (B b) . pad (L l)
35-
pad (T x) = utility ("padt" -. x) "padding-top" x
36-
pad (R x) = utility ("padr" -. x) "padding-right" x
37-
pad (B x) = utility ("padb" -. x) "padding-bottom" x
38-
pad (L x) = utility ("padl" -. x) "padding-left" x
34+
pad (T x) = utility ("pt" -. x) ["padding-top" :. style x]
35+
pad (R x) = utility ("pr" -. x) ["padding-right" :. style x]
36+
pad (B x) = utility ("pb" -. x) ["padding-bottom" :. style x]
37+
pad (L x) = utility ("pl" -. x) ["padding-left" :. style x]
3938
pad (TR t r) = pad (TRBL t r 0 0)
4039
pad (TL t l) = pad (TRBL t 0 0 l)
4140
pad (BR b r) = pad (TRBL 0 r b 0)
@@ -44,7 +43,25 @@ pad (BL b l) = pad (TRBL 0 0 b l)
4443

4544
-- | The space between child elements. See 'pad'
4645
gap :: (Styleable h) => Length -> CSS h -> CSS h
47-
gap n = utility ("gap" -. n) "gap" n
46+
gap n = utility ("gap" -. n) ["gap" :. style n]
47+
48+
49+
margin :: (Styleable h) => Sides Length -> CSS h -> CSS h
50+
margin (All n) =
51+
utility ("m" -. n) ["margin" :. style n]
52+
margin (Y n) = margin (T n) . margin (B n)
53+
margin (X n) = margin (L n) . margin (R n)
54+
margin (XY x y) = margin (X x) . margin (Y y)
55+
margin (TRBL t r b l) =
56+
margin (T t) . margin (R r) . margin (B b) . margin (L l)
57+
margin (T x) = utility ("mt" -. x) ["margin-top" :. style x]
58+
margin (R x) = utility ("mr" -. x) ["margin-right" :. style x]
59+
margin (B x) = utility ("mb" -. x) ["margin-bottom" :. style x]
60+
margin (L x) = utility ("ml" -. x) ["margin-left" :. style x]
61+
margin (TR t r) = margin (TRBL t r 0 0)
62+
margin (TL t l) = margin (TRBL t 0 0 l)
63+
margin (BR b r) = margin (TRBL 0 r b 0)
64+
margin (BL b l) = margin (TRBL 0 0 b l)
4865

4966

5067
{- | Add a drop shadow to an element
@@ -54,7 +71,7 @@ gap n = utility ("gap" -. n) "gap" n
5471
-}
5572
shadow :: (Styleable h, PropertyStyle Shadow a, ToClassName a) => a -> CSS h -> CSS h
5673
shadow a =
57-
utility ("shadow" -. a) "box-shadow" (propertyStyle @Shadow a)
74+
utility ("shadow" -. a) ["box-shadow" :. propertyStyle @Shadow a]
5875

5976

6077
data Shadow
@@ -72,26 +89,26 @@ instance PropertyStyle Shadow Inner where
7289

7390
-- | Set the background color. See 'Web.View.Types.ToColor'
7491
bg :: (ToColor clr, Styleable h) => clr -> CSS h -> CSS h
75-
bg c = utility ("bg" -. colorName c) "background-color" (colorValue c)
92+
bg c = utility ("bg" -. colorName c) ["background-color" :. style (colorValue c)]
7693

7794

7895
data BorderStyle
7996
= Solid
8097
| Dashed
81-
deriving (Show, ToStyleValue, ToClassName)
98+
deriving (Show, ToStyle, ToClassName)
8299

83100

84101
border :: (Styleable h) => Sides PxRem -> CSS h -> CSS h
85102
border s = borderWidth s . borderStyle Solid
86103

87104

88105
borderStyle :: (Styleable h) => BorderStyle -> CSS h -> CSS h
89-
borderStyle s = utility ("brds" -. s) "border-style" s
106+
borderStyle s = utility ("brds" -. s) ["border-style" :. style s]
90107

91108

92109
-- | Round the corners of the element
93110
rounded :: (Styleable h) => Length -> CSS h -> CSS h
94-
rounded n = utility ("rnd" -. n) "border-radius" n
111+
rounded n = utility ("rnd" -. n) ["border-radius" :. style n]
95112

96113

97114
{- | Set a border around the element
@@ -101,16 +118,16 @@ rounded n = utility ("rnd" -. n) "border-radius" n
101118
-}
102119
borderWidth :: (Styleable h) => Sides PxRem -> CSS h -> CSS h
103120
borderWidth (All n) =
104-
utility ("brd" -. n) "border-width" n
121+
utility ("brd" -. n) ["border-width" :. style n]
105122
borderWidth (Y n) = borderWidth (T n) . borderWidth (B n)
106123
borderWidth (X n) = borderWidth (L n) . borderWidth (R n)
107124
borderWidth (XY x y) = borderWidth (X x) . borderWidth (Y y)
108125
borderWidth (TRBL t r b l) =
109126
borderWidth (T t) . borderWidth (R r) . borderWidth (B b) . borderWidth (L l)
110-
borderWidth (T x) = utility ("brdt" -. x) "border-top-width" x
111-
borderWidth (R x) = utility ("brdt" -. x) "border-right-width" x
112-
borderWidth (B x) = utility ("brdt" -. x) "border-bottom-width" x
113-
borderWidth (L x) = utility ("brdt" -. x) "border-left-width" x
127+
borderWidth (T x) = utility ("brdt" -. x) ["border-top-width" :. style x]
128+
borderWidth (R x) = utility ("brdt" -. x) ["border-right-width" :. style x]
129+
borderWidth (B x) = utility ("brdt" -. x) ["border-bottom-width" :. style x]
130+
borderWidth (L x) = utility ("brdt" -. x) ["border-left-width" :. style x]
114131
borderWidth (TR t r) = borderWidth (TRBL t r 0 0)
115132
borderWidth (TL t l) = borderWidth (TRBL t 0 0 l)
116133
borderWidth (BR b r) = borderWidth (TRBL 0 r b 0)
@@ -120,9 +137,9 @@ borderWidth (BL b l) = borderWidth (TRBL 0 0 b l)
120137
-- | Set a border color. See 'Web.View.Types.ToColor'
121138
borderColor :: (ToColor clr, Styleable h) => clr -> CSS h -> CSS h
122139
borderColor c =
123-
utility ("brdc" -. colorName c) "border-color" (colorValue c)
140+
utility ("brdc" -. colorName c) ["border-color" :. style (colorValue c)]
124141

125142

126143
opacity :: (Styleable h) => Float -> CSS h -> CSS h
127144
opacity n =
128-
utility ("opacity" -. n) "opacity" n
145+
utility ("opacity" -. n) ["opacity" :. style n]

0 commit comments

Comments
 (0)