elm-mdl/src/Material.elm

128 lines
4 KiB
Elm
Raw Normal View History

2016-03-14 09:42:49 +00:00
module Material
2016-03-19 22:47:21 +00:00
( topWithScheme, top
2016-03-17 12:31:43 +00:00
, Updater', Updater, lift, lift'
2016-03-14 09:42:49 +00:00
) where
{-| Material Design component library for Elm based on Google's
[Material Design Lite](https://www.getmdl.io/).
2016-03-19 22:47:21 +00:00
This module contains only initial CSS setup and convenience function for alleviating
the pain of the missing component architecture in Elm.
2016-03-17 12:31:43 +00:00
# Loading CSS
2016-03-19 22:47:21 +00:00
@docs topWithScheme, top
2016-03-17 12:31:43 +00:00
# Component convienience
@docs Updater', Updater, lift', lift
2016-03-14 09:42:49 +00:00
-}
import String
import Html exposing (..)
import Html.Attributes exposing (..)
2016-03-17 12:31:43 +00:00
import Effects exposing (..)
2016-03-14 09:42:49 +00:00
2016-03-19 22:47:21 +00:00
import Material.Color exposing (Palette(..), Color)
2016-03-14 09:42:49 +00:00
2016-03-19 22:47:21 +00:00
scheme : Palette -> Palette -> String
scheme primary accent =
[ "https://code.getmdl.io/1.1.2/" ++ Material.Color.scheme primary accent
, "https://fonts.googleapis.com/icon?family=Material+Icons"
, "https://fonts.googleapis.com/css?family=Roboto:400,300,500|Roboto+Mono|Roboto+Condensed:400,700&subset=latin,latin-ext"
]
|> List.map (\url -> "@import url(" ++ url ++ ");")
|> String.join "\n"
2016-03-14 09:42:49 +00:00
{-| Top-level container for Material components. This will force loading of
2016-03-19 22:47:21 +00:00
Material Design Lite CSS files Any component you use must be contained
2016-03-14 09:42:49 +00:00
in this container, OR you must manually add something like the following to
your .html file:
<!-- MDL -->
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500|Roboto+Mono|Roboto+Condensed:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
2016-03-19 22:47:21 +00:00
<link rel="stylesheet" href="https://code.getmdl.io/1.1.2/material.min.css" />
2016-03-14 09:42:49 +00:00
Supply primary and accent colors as parameters. Refer to the
Material Design Lite [Custom CSS theme builder](https://www.getmdl.io/customize/index.html)
to preview combinations.
Please be aware that Grey, Blue Grey, and Brown cannot be secondary colors. If
you choose them as such anyway, you will get the default theme.
Using this top-level container is not recommended, as most browsers will load
css concurrently with rendering the initial page, which will produce a flicker
on page load. The container is included only to provide an option to get started
2016-03-17 12:31:43 +00:00
quickly and for use with elm-reactor.
2016-03-14 09:42:49 +00:00
-}
2016-03-19 22:47:21 +00:00
topWithScheme: Palette -> Palette -> Html -> Html
topWithScheme primary accent content =
2016-03-14 09:42:49 +00:00
div [] <|
{- Trick from Peter Damoc to load CSS outside of <head>.
https://github.com/pdamoc/elm-mdl/blob/master/src/Mdl.elm#L63
-}
[ node "style"
[ type' "text/css"]
2016-03-19 22:47:21 +00:00
[ Html.text <| scheme primary accent]
2016-03-14 09:42:49 +00:00
, content
]
{-| Top-level container with default color scheme.
-}
top : Html -> Html
top content =
-- Force default color-scheme by picking an invalid combination.
2016-03-19 22:47:21 +00:00
topWithScheme Grey Grey content
2016-03-17 12:31:43 +00:00
{-| TODO.
-}
type alias Updater' action model =
action -> model -> model
{-| TODO.
-}
type alias Updater action model =
action -> model -> (model, Effects action)
type alias ComponentModel model components =
{ model | components : components }
{-| TODO.
-}
lift' :
(model -> submodel) -> -- get
(model -> submodel -> model) -> -- set
Updater' subaction submodel -> -- update
subaction -> -- action
model -> -- model
(model, Effects action)
lift' get set update action model =
(set model (update action (get model)), Effects.none)
{-| TODO.
-}
lift :
(model -> submodel) -> -- get
(model -> submodel -> model) -> -- set
(subaction -> action) -> -- fwd
Updater subaction submodel -> -- update
subaction -> -- action
model -> -- model
(model, Effects action)
lift get set fwd update action model =
let
(submodel', e) = update action (get model)
in
(set model submodel', Effects.map fwd e)