git.iko.soy/rowtype-yoga/psfp
on 7e2c09a help sign in
92 lines 3.8 kB history raw
1module Yoga.Theme where
3import Prelude
4import CSS (contrast, darken, isLight, lighten, rotateHue, toHexString)
5import Color (Color)
6import Data.Foldable (intercalate)
7import Data.Symbol (SProxy(..))
8import Record.Builder as RB
9import Yoga.Theme.Types (Theme, CSSTheme)
11increaseContrast ∷ Color -> Color -> Color
12increaseContrast contrastWith = go 0
13 where
14 modify = if isLight contrastWith then darken else lighten
16 go i col =
17 if contrast contrastWith col >= 7.5 || i >= 20 then
18 col
19 else
20 go (i + 1) (modify 0.1 col)
22f ∷ ∀ fieldName. SProxy fieldName
23f = SProxy
25fromTheme ∷ Theme -> CSSTheme
26fromTheme theme =
27 RB.build
28 ( {- background -} RB.modify (f ∷ _ "backgroundColour") toHexString
29 >>> RB.insert (f ∷ _ "backgroundColourLighter")
30 (theme.backgroundColour # lighter >>> toHexString)
31 >>> RB.insert (f ∷ _ "backgroundColourLightest")
32 (theme.backgroundColour # lighter # lighter >>> toHexString)
33 >>> RB.insert (f ∷ _ "backgroundColourDarker")
34 (theme.backgroundColour # darker >>> toHexString)
35 >>> RB.insert (f ∷ _ "backgroundColourDarkest")
36 (theme.backgroundColour # darker # darker >>> toHexString)
37 >>> RB.modify (f ∷ _ "interfaceColour") toHexString
38 >>> RB.insert (f ∷ _ "interfaceColourLighter")
39 (theme.interfaceColour # lighter >>> toHexString)
40 >>> RB.insert (f ∷ _ "interfaceColourLightest")
41 (theme.interfaceColour # lighter >>> lighter >>> toHexString)
42 >>> RB.insert (f ∷ _ "interfaceColourDarker")
43 (theme.interfaceColour # darker >>> toHexString)
44 >>> RB.insert (f ∷ _ "interfaceColourDarkest")
45 (theme.interfaceColour # darker >>> darker >>> toHexString)
46 -- foreground
48 >>> RB.modify (f ∷ _ "textColour") toHexString
49 >>> RB.insert (f ∷ _ "textColourLighter")
50 (theme.textColour # lighter >>> toHexString)
51 >>> RB.insert (f ∷ _ "textColourLightest")
52 (theme.textColour # lighter >>> lighter >>> toHexString)
53 >>> RB.insert (f ∷ _ "textColourDarker")
54 (theme.textColour # darker >>> toHexString)
55 >>> RB.insert (f ∷ _ "textColourDarkest")
56 (theme.textColour # darker >>> darker >>> toHexString)
57 -- highlight
59 >>> RB.modify (f ∷ _ "highlightColour") toHexString
60 >>> RB.insert (f ∷ _ "highlightColourDark")
61 (theme.highlightColour # darken 0.2 # rotateHue (-10.0) # toHexString)
62 -- altHighlight
64 >>> RB.modify (f ∷ _ "altHighlightColour") toHexString
65 >>> RB.insert (f ∷ _ "altHighlightColourDark")
66 (theme.altHighlightColour # darken 0.2 # toHexString)
67 -- palette
69 >>> RB.modify (f ∷ _ "yellow") toHexString
70 >>> RB.modify (f ∷ _ "green") toHexString
71 >>> RB.modify (f ∷ _ "pink") toHexString
72 >>> RB.modify (f ∷ _ "orange") toHexString
73 >>> RB.modify (f ∷ _ "turquoise") toHexString
74 >>> RB.modify (f ∷ _ "red") toHexString
75 >>> RB.modify (f ∷ _ "blue") toHexString
76 >>> RB.modify (f ∷ _ "white") toHexString
77 -- fonts
79 >>> RB.modify (f ∷ _ "textFontFamily") (intercalate ",")
80 >>> RB.modify (f ∷ _ "headingFontFamily") (intercalate ",")
81 >>> RB.insert (f ∷ _ "isLight") isLightTheme
82 >>> RB.insert (f ∷ _ "fontWeightBold") "300"
83 )
84 theme
85 where
86 isLightTheme = isLight theme.backgroundColour
88 lighter ∷ Color -> Color
89 lighter = if isLightTheme then lighten 0.04 else lighten 0.02
91 darker ∷ Color -> Color
92 darker = if isLightTheme then darken 0.01 else darken 0.01