uncover-co/elm-theme/1.1.1

NOTE: the latest version is 2.0.0

Theme

Creating Themes

new : ThemeData -> Theme
type alias ThemeData =
{ fonts : ThemeFonts
, base : ThemeColorSet
, neutral : ThemeColorSet
, primary : ThemeColorSet
, secondary : ThemeColorSet
, success : ThemeColorSet
, warning : ThemeColorSet
, danger : ThemeColorSet
}
type alias ThemeFonts =
{ title : String
, text : String
, code : String
}
type alias ThemeColorSet =
{ background : Color
, foreground : Color
, aux : Color
}
type Theme

Built-in Themes

Extending Themes

fromTheme : Theme -> ThemeBuilder
toTheme : ThemeBuilder -> Theme
withFonts : ThemeFonts -> ThemeBuilder -> ThemeBuilder
withFontTitle : String -> ThemeBuilder -> ThemeBuilder
withFontText : String -> ThemeBuilder -> ThemeBuilder
withFontCode : String -> ThemeBuilder -> ThemeBuilder
withBase : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withBaseForeground : Color -> ThemeBuilder -> ThemeBuilder
withBaseBackground : Color -> ThemeBuilder -> ThemeBuilder
withBaseAux : Color -> ThemeBuilder -> ThemeBuilder
withNeutral : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withNeutralForeground : Color -> ThemeBuilder -> ThemeBuilder
withNeutralBackground : Color -> ThemeBuilder -> ThemeBuilder
withNeutralAux : Color -> ThemeBuilder -> ThemeBuilder
withPrimary : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withPrimaryForeground : Color -> ThemeBuilder -> ThemeBuilder
withPrimaryBackground : Color -> ThemeBuilder -> ThemeBuilder
withPrimaryAux : Color -> ThemeBuilder -> ThemeBuilder
withSecondary : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withSecondaryForeground : Color -> ThemeBuilder -> ThemeBuilder
withSecondaryBackground : Color -> ThemeBuilder -> ThemeBuilder
withSecondaryAux : Color -> ThemeBuilder -> ThemeBuilder
withSuccess : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withSuccessForeground : Color -> ThemeBuilder -> ThemeBuilder
withSuccessBackground : Color -> ThemeBuilder -> ThemeBuilder
withSuccessAux : Color -> ThemeBuilder -> ThemeBuilder
withWarning : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withWarningForeground : Color -> ThemeBuilder -> ThemeBuilder
withWarningBackground : Color -> ThemeBuilder -> ThemeBuilder
withWarningAux : Color -> ThemeBuilder -> ThemeBuilder
withDanger : ThemeColorSet -> ThemeBuilder -> ThemeBuilder
withDangerForeground : Color -> ThemeBuilder -> ThemeBuilder
withDangerBackground : Color -> ThemeBuilder -> ThemeBuilder
withDangerAux : Color -> ThemeBuilder -> ThemeBuilder
withThemeData : ThemeData -> ThemeBuilder -> ThemeBuilder
withExtraValues : List ( String, String ) -> ThemeBuilder -> ThemeBuilder

Theme Providers

globalProvider : Theme -> Html msg

Used to provide a Theme globally. It will be applied to your body element and it will be available for use anywhere in your application.

main : Html msg
main =
    div []
        [ Theme.globalProvider lightTheme
        , p [ style "color" Theme.baseForeground ]
            [ text "I'm colored using the `base foreground` value!" ]
        ]

Note: You are still able to overwrite this Theme locally.

provider : Theme -> List (Attribute msg) -> List (Html msg) -> Html msg

Used to propagate themes to an specific scope.

main : Html msg
main =
    div []
        [ Theme.globalProvider defaultTheme


        -- section using the default theme
        , section [] [ .. ]


        -- section using the orange theme
        , Theme.provider orangeTheme [] [ .. ]
        ]

Dark Mode

{ light : Theme
, dark : Theme
, strategy : DarkModeStrategy
}
-> Html msg

Used to provide a Theme globally with a dark mode alternative. Themes will automatically switch based on the strategy condition.

main : Html msg
main =
    div []
        [ Theme.globalProviderWithDarkMode
            { light = lightTheme
            , dark = darkTheme
            , strategy = Theme.systemStrategy
            }
        , p [ style "color" Theme.baseForeground ]
            [ text "I'm colored using the `base foreground` value!" ]
        ]

Note: You are still able to overwrite this Theme locally.

{ light : Theme
, dark : Theme
, strategy : DarkModeStrategy
}
-> List (Attribute msg)
-> List (Html msg)
-> Html msg

Used to propagate themes to an specific scope with a dark mode alternative. Themes will automatically switch based on the strategy condition.

main : Html msg
main =
    div []
        [ Theme.globalProviderWithDarkMode
            { light = lightTheme
            , dark = darkTheme
            , strategy = Theme.systemStrategy
            }


        -- section using the default light or dark theme
        , section [] [ .. ]


        -- section using the orange light and dark themes
        , Theme.providerWithDarkMode
            { light = lightOrange
            , dark = darkOrange
            , strategy = Theme.systemStrategy
            }
            [] [ .. ]
        ]

Uses the presence of a given CSS class in the element scope to decide between light and dark mode.

Uses the user system settings to decide between light and dark mode.

Optimized Providers

optimizedProvider : Theme -> ThemeProvider msg
myTheme =
    optimizedProvider theme


body []
    [ myTheme.styles
    , myTheme.provider []
        [ ... ]
    ]
{ light : Theme
, dark : Theme
, strategy : DarkModeStrategy
}
-> ThemeProvider msg
type alias ThemeProvider msg =
{ styles : Html msg
, provider : List (Attribute msg) -> List (Html msg) -> Html msg
}

Theme Sampler

sample : Html msg

Theme Values

fontTitle : String
fontText : String
fontCode : String
baseAux : String
baseForegroundWithAlpha : Float -> String
baseBackgroundWithAlpha : Float -> String
baseAuxWithAlpha : Float -> String
neutralAux : String
neutralForegroundWithAlpha : Float -> String
neutralBackgroundWithAlpha : Float -> String
neutralAuxWithAlpha : Float -> String
primaryAux : String
primaryForegroundWithAlpha : Float -> String
primaryBackgroundWithAlpha : Float -> String
primaryAuxWithAlpha : Float -> String
secondaryAux : String
secondaryAuxWithAlpha : Float -> String
successAux : String
successForegroundWithAlpha : Float -> String
successBackgroundWithAlpha : Float -> String
successAuxWithAlpha : Float -> String
warningAux : String
warningForegroundWithAlpha : Float -> String
warningBackgroundWithAlpha : Float -> String
warningAuxWithAlpha : Float -> String
dangerAux : String
dangerForegroundWithAlpha : Float -> String
dangerBackgroundWithAlpha : Float -> String
dangerAuxWithAlpha : Float -> String

Theme Value Sets

type alias ThemeColorSetValues =
{ foreground : String
, foregroundWithAlpha : Float -> String
, background : String
, backgroundWithAlpha : Float -> String
, aux : String
, auxWithAlpha : Float -> String
}
base : ThemeColorSetValues
neutral : ThemeColorSetValues
primary : ThemeColorSetValues
secondary : ThemeColorSetValues
success : ThemeColorSetValues
warning : ThemeColorSetValues
danger : ThemeColorSetValues