@@ -15,24 +15,15 @@ import Data.Array (mapMaybe, concatMap, singleton)
15
15
import Data.Either (Either )
16
16
import Data.Foldable (foldMap )
17
17
import Data.Maybe (Maybe (..), fromMaybe )
18
- import Data.Newtype ( class Newtype )
18
+ import Data.MediaType ( MediaType (..) )
19
19
import Data.StrMap as SM
20
20
import Data.String (joinWith )
21
21
import Data.Tuple (Tuple (..))
22
22
23
23
import Halogen.HTML as HH
24
- import Halogen.HTML.Core (HTML , Prop , class IsProp , prop , propName , attrName )
25
24
import Halogen.HTML.Elements as HE
26
- import Halogen.HTML.Properties as P
27
-
28
- -- | A newtype for CSS styles
29
- newtype Styles = Styles (SM.StrMap String )
30
-
31
- derive instance newtypeStyles ∷ Newtype Styles _
32
-
33
- instance stylesIsProp ∷ IsProp Styles where
34
- toPropString _ _ (Styles m) =
35
- joinWith " ; " $ SM .foldMap (\key value → [key <> " : " <> value]) m
25
+ import Halogen.HTML.Properties as HP
26
+ import Halogen.HTML.Core as HC
36
27
37
28
-- | Render a set of rules as an inline style.
38
29
-- |
@@ -43,13 +34,16 @@ instance stylesIsProp ∷ IsProp Styles where
43
34
-- | display block ]
44
35
-- | [ ... ]
45
36
-- | ```
46
- style ∷ ∀ i . CSS → Prop i
37
+ style ∷ ∀ i r . CSS → HP.IProp ( style ∷ String | r ) i
47
38
style =
48
- prop (propName " style " ) ( Just $ attrName " style" )
49
- <<< Styles
39
+ HP. prop (HC.PropName " style" )
40
+ <<< toString
50
41
<<< rules
51
42
<<< runS
52
43
where
44
+ toString ∷ SM.StrMap String → String
45
+ toString = joinWith " ; " <<< SM.foldMap (\key val → [ key <> " : " <> val ])
46
+
53
47
rules ∷ Array Rule → SM.StrMap String
54
48
rules rs = SM.fromFoldable properties
55
49
where
@@ -64,8 +58,8 @@ style =
64
58
rights = concatMap $ foldMap singleton
65
59
66
60
-- | Render a set of rules as a `style` element.
67
- stylesheet ∷ ∀ p i . CSS → HTML p i
61
+ stylesheet ∷ ∀ p i . CSS → HC. HTML p i
68
62
stylesheet css =
69
- HE .style [ P .type_ " text/css" ] [ HH .text content ]
63
+ HE .style [ HP .type_ $ MediaType " text/css" ] [ HH .text content ]
70
64
where
71
65
content = fromMaybe " " $ renderedSheet $ render css
0 commit comments