Course map
miso // 20

Styling

Read

Three ways to style

The simplest is a class name and a stylesheet: P.class_ "card". For styles that depend on the model, miso offers a typed CSS DSL in Miso.CSS, applied inline with style_.

import qualified Miso.CSS as CSS

view :: Int -> View () () Int Action
view n =
  H.div_
    [ CSS.style_
        [ CSS.padding (CSS.px 16)
        , CSS.borderRadius (CSS.px 12)
        , CSS.backgroundColor (if n > 5 then CSS.hotpink else CSS.teal)
        , CSS.color CSS.white
        , CSS.fontWeight "600"
        ]
    ]
    [ text (ms n) ]

Each property is a function; units like CSS.px and CSS.pct and named colours are values. A misspelled property is a compile error, not a silently ignored rule.

The third way: P.classList_ [ ("on", isOn), ("big", n > 9) ] toggles class names on conditions, which pairs nicely with a stylesheet.

01 / 04