/
Styles.purs
38 lines (30 loc) · 1.41 KB
/
Styles.purs
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
module Lumi.Styles
( module Lumi.Styles
, module Emotion
) where
import Prelude
import Data.Foldable (fold)
import Lumi.Components (PropsModifier, propsModifier)
import Lumi.Styles.Theme (LumiTheme)
import React.Basic.Emotion hiding (element,style) as Emotion
type StyleModifier = forall props. PropsModifier props
-- | Lift a themed set of styles into a `StyleModifier` for composition with other modifiers.
style :: (LumiTheme -> Emotion.Style) -> StyleModifier
style f = propsModifier \props -> props { css = props.css <> f }
-- | Lift a static set of styles into a `StyleModifier` for composition with other modifiers.
style_ :: Emotion.Style -> StyleModifier
style_ = style <<< const
-- | Lift an array of themed styles into a `StyleModifier` for composition with other modifiers.
styles :: Array (LumiTheme -> Emotion.Style) -> StyleModifier
styles = style <<< fold
-- | Lift an array of static styles into a `StyleModifier` for composition with other modifiers.
styles_ :: Array Emotion.Style -> StyleModifier
styles_ = style_ <<< fold
-- | Flatten a `PropsModifier` and extract the Emotion styles for use with `React.Basic.Emotion.element`.
-- | This function is mainly used inside component implementations where the `LumiComponent` boundary
-- | gives way to DOM components or other `ReactComponent`s.
toCSS ::
PropsModifier () ->
LumiTheme ->
Emotion.Style
toCSS m = (m identity { className: "", css: mempty }).css