Nicified.

This commit is contained in:
Søren Debois 2016-04-12 15:24:10 +02:00
parent 5aa4cd04f3
commit 26558d8ebb

View file

@ -6,7 +6,7 @@ import Html.Attributes exposing (class, style, key)
import Array exposing (Array) import Array exposing (Array)
import Time exposing (Time, millisecond) import Time exposing (Time, millisecond)
import Material.Helpers exposing (map1st, map2nd, delay) import Material.Helpers exposing (map1st, map2nd, pure, delay)
import Material.Color as Color import Material.Color as Color
import Material.Style exposing (styled, cs, css) import Material.Style exposing (styled, cs, css)
import Material.Snackbar as Snackbar import Material.Snackbar as Snackbar
@ -18,9 +18,11 @@ import Material
import Demo.Page as Page import Demo.Page as Page
-- MODEL -- MODEL
type alias Mdl = type alias Mdl =
Material.Model Material.Model
@ -107,19 +109,13 @@ update action model =
add (\k -> Snackbar.toast k <| "Toast message #" ++ toString k) model add (\k -> Snackbar.toast k <| "Toast message #" ++ toString k) model
Appear k -> Appear k ->
( model |> mapSquare k (\sq -> if sq == Appearing then Waiting else sq) model |> mapSquare k (\sq -> if sq == Appearing then Waiting else sq) |> pure
, none
)
Snackbar (Snackbar.Begin k) -> Snackbar (Snackbar.Begin k) ->
( model |> mapSquare k (always Active) model |> mapSquare k (always Active) |> pure
, none
)
Snackbar (Snackbar.End k) -> Snackbar (Snackbar.End k) ->
( model |> mapSquare k (always Idle) model |> mapSquare k (always Idle) |> pure
, none
)
Snackbar (Snackbar.Click k) -> Snackbar (Snackbar.Click k) ->
( model |> mapSquare k (always Disappearing) ( model |> mapSquare k (always Disappearing)
@ -146,6 +142,7 @@ update action model =
-- VIEW -- VIEW
addSnackbarButton : Button.Instance Mdl Action addSnackbarButton : Button.Instance Mdl Action
addSnackbarButton = addSnackbarButton =
Button.instance 0 MDL Button.instance 0 MDL
@ -172,8 +169,8 @@ transitionLength : Time
transitionLength = 150 * millisecond transitionLength = 150 * millisecond
transitions : (String, String) transitionInner : (String, String)
transitions = transitionInner =
("transition" ("transition"
, "box-shadow 333ms ease-in-out 0s, " , "box-shadow 333ms ease-in-out 0s, "
++ "width " ++ toString transitionLength ++ "ms, " ++ "width " ++ toString transitionLength ++ "ms, "
@ -182,6 +179,14 @@ transitions =
) )
transitionOuter : (String, String)
transitionOuter =
("transition"
, "width " ++ toString transitionLength ++ "ms ease-in-out 0s, "
++ "margin " ++ toString transitionLength ++ "ms ease-in-out 0s"
)
clickView : Model -> Square -> Html clickView : Model -> Square -> Html
clickView model (k, square) = clickView model (k, square) =
let let
@ -210,6 +215,11 @@ clickView model (k, square) =
(boxWidth, boxHeight, "16px 16px", selected') (boxWidth, boxHeight, "16px 16px", selected')
in in
{- In order to get the box appearance and disappearance animations
to start in the lower-left corner, we render boxes as an outer div
(which animates only width, to cause reflow of surrounding boxes),
and an absolutely positioned inner div (to force animation to start
in the lower-left corner. -}
div div
[ style [ style
[ ("height", boxHeight) [ ("height", boxHeight)
@ -217,13 +227,11 @@ clickView model (k, square) =
, ("position", "relative") , ("position", "relative")
, ("display", "inline-block") , ("display", "inline-block")
, ("margin", margin) , ("margin", margin)
, ("transition",
"width " ++ toString transitionLength ++ "ms ease-in-out 0s, "
++ "margin " ++ toString transitionLength ++ "ms ease-in-out 0s"
)
, ("z-index", "0") , ("z-index", "0")
, transitionOuter
] ]
, key <| toString k , key <| toString k
{- Interestingly, not setting key messes up CSS transitions in spectacular ways. -}
] ]
[ styled div [ styled div
[ Color.background color [ Color.background color
@ -231,19 +239,22 @@ clickView model (k, square) =
, Elevation.shadow (if selected then 8 else 2) , Elevation.shadow (if selected then 8 else 2)
] ]
[ style [ style
[ ("display", "inline-flex") [ -- Center contents
("display", "inline-flex")
, ("align-items", "center") , ("align-items", "center")
, ("justify-content", "center") , ("justify-content", "center")
, ("flex", "0 0 auto")
-- Sizing
, ("height", height) , ("height", height)
, ("width", width) , ("width", width)
, ("border-radius", "2px") , ("border-radius", "2px")
, transitions
, ("overflow", "hidden")
, ("box-sizing", "border-box") , ("box-sizing", "border-box")
, ("flex", "0 0 auto") -- Force appearance/disapparenace to be from/to lower-left corner.
, ("position", "absolute") , ("position", "absolute")
, ("bottom", "0") , ("bottom", "0")
, ("left", "0") , ("left", "0")
-- Transitions
, transitionInner
] ]
] ]
[ div [] [ text <| toString k ] ] [ div [] [ text <| toString k ] ]
@ -255,7 +266,7 @@ view : Signal.Address Action -> Model -> Html
view addr model = view addr model =
Page.body "Snackbar & Toast" srcUrl intro references Page.body "Snackbar & Toast" srcUrl intro references
[ p [] [ p []
[ text """Click the buttons below to activate the snackbar. Note that [ text """Click the buttons below to generate toasts and snackbars. Note that
multiple activations are automatically queued.""" multiple activations are automatically queued."""
] ]
, grid [ ] , grid [ ]