2020-05-15 20:15:35 +03:00
|
|
|
module Examples.Confetti exposing (example, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-06-19 23:41:28 +03:00
|
|
|
import AtomicDesignType exposing (AtomicDesignType(..))
|
2020-05-15 20:33:38 +03:00
|
|
|
import Browser.Events
|
2020-05-15 20:15:35 +03:00
|
|
|
import Category exposing (Category(..))
|
2020-05-15 20:51:21 +03:00
|
|
|
import Css exposing (Color)
|
|
|
|
import Dict exposing (Dict)
|
2020-05-15 20:15:35 +03:00
|
|
|
import Example exposing (Example)
|
2020-05-15 20:51:21 +03:00
|
|
|
import Html.Styled as Html exposing (Html)
|
2020-05-15 20:15:35 +03:00
|
|
|
import Html.Styled.Attributes as Attributes exposing (css)
|
2020-06-20 00:45:32 +03:00
|
|
|
import KeyboardSupport exposing (Direction(..), Key(..))
|
2020-05-15 20:15:35 +03:00
|
|
|
import Nri.Ui.Button.V10 as Button
|
2020-06-05 21:50:22 +03:00
|
|
|
import Nri.Ui.Confetti.V2 as Confetti
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "Confetti"
|
|
|
|
, version = 2
|
2020-05-15 20:15:35 +03:00
|
|
|
, categories = [ Animations ]
|
2020-06-23 20:21:20 +03:00
|
|
|
, atomicDesignType = Molecule
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2020-06-05 21:50:22 +03:00
|
|
|
, state = Confetti.init 700
|
2020-05-15 20:15:35 +03:00
|
|
|
, update = update
|
2020-05-15 20:33:38 +03:00
|
|
|
, subscriptions =
|
|
|
|
\state ->
|
|
|
|
Sub.batch
|
|
|
|
[ Browser.Events.onResize WindowResized
|
2020-06-05 21:50:22 +03:00
|
|
|
, Confetti.subscriptions ConfettiMsg state
|
2020-05-15 20:33:38 +03:00
|
|
|
]
|
2020-05-15 20:15:35 +03:00
|
|
|
, view =
|
|
|
|
\state ->
|
2020-06-05 21:45:04 +03:00
|
|
|
[ Button.button "Launch confetti!"
|
2020-05-15 20:15:35 +03:00
|
|
|
[ Button.onClick LaunchConfetti
|
|
|
|
, Button.small
|
|
|
|
, Button.secondary
|
|
|
|
]
|
2020-06-05 21:50:22 +03:00
|
|
|
, Confetti.view state
|
2020-05-15 20:15:35 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2020-06-05 21:50:22 +03:00
|
|
|
Confetti.Model
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= LaunchConfetti
|
|
|
|
| ConfettiMsg Confetti.Msg
|
2020-05-15 20:33:38 +03:00
|
|
|
| WindowResized Int Int
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
2020-06-05 21:50:22 +03:00
|
|
|
( case msg of
|
2020-05-15 20:15:35 +03:00
|
|
|
LaunchConfetti ->
|
2020-06-05 21:50:22 +03:00
|
|
|
Confetti.burst state
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
ConfettiMsg confettiMsg ->
|
2020-06-05 21:50:22 +03:00
|
|
|
Confetti.update confettiMsg state
|
2020-05-15 20:33:38 +03:00
|
|
|
|
|
|
|
WindowResized width _ ->
|
2020-06-05 21:50:22 +03:00
|
|
|
Confetti.updatePageWidth width state
|
|
|
|
, Cmd.none
|
|
|
|
)
|