2020-05-15 20:15:35 +03:00
|
|
|
module Examples.Confetti exposing (example, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-05-15 20:33:38 +03:00
|
|
|
import Browser.Events
|
2020-05-15 20:15:35 +03:00
|
|
|
import Category exposing (Category(..))
|
2022-03-30 01:23:06 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
|
|
|
import Debug.Control.Extra as ControlExtra
|
|
|
|
import Debug.Control.View as ControlView
|
2020-05-15 20:15:35 +03:00
|
|
|
import Example exposing (Example)
|
|
|
|
import Nri.Ui.Button.V10 as Button
|
2020-06-05 21:50:22 +03:00
|
|
|
import Nri.Ui.Confetti.V2 as Confetti
|
2022-03-30 01:23:06 +03:00
|
|
|
import Nri.Ui.Html.V3 exposing (viewJust)
|
|
|
|
|
2022-03-30 01:41:01 +03:00
|
|
|
|
2022-03-30 01:23:06 +03:00
|
|
|
moduleName : String
|
|
|
|
moduleName =
|
|
|
|
"Confetti"
|
|
|
|
|
|
|
|
|
|
|
|
version : Int
|
|
|
|
version =
|
|
|
|
2
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
2022-03-30 01:23:06 +03:00
|
|
|
{ name = moduleName
|
|
|
|
, version = version
|
2020-05-15 20:15:35 +03:00
|
|
|
, categories = [ Animations ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2022-03-30 01:23:06 +03:00
|
|
|
, state = init
|
2020-05-15 20:15:35 +03:00
|
|
|
, update = update
|
2020-05-15 20:33:38 +03:00
|
|
|
, subscriptions =
|
|
|
|
\state ->
|
2022-03-30 01:41:01 +03:00
|
|
|
case state.model of
|
|
|
|
Just model ->
|
2022-03-30 01:23:06 +03:00
|
|
|
Sub.batch
|
|
|
|
[ Browser.Events.onResize WindowResized
|
2022-03-30 01:41:01 +03:00
|
|
|
, Confetti.subscriptions ConfettiMsg model
|
|
|
|
]
|
|
|
|
|
2022-03-30 01:23:06 +03:00
|
|
|
Nothing ->
|
2022-03-30 01:41:01 +03:00
|
|
|
Sub.none
|
2021-11-05 21:19:08 +03:00
|
|
|
, preview = []
|
2020-05-15 20:15:35 +03:00
|
|
|
, view =
|
2022-03-29 20:19:32 +03:00
|
|
|
\ellieLinkConfig state ->
|
2022-03-30 01:41:01 +03:00
|
|
|
[ viewJust Confetti.view state.model
|
|
|
|
, ControlView.view
|
|
|
|
{ ellieLinkConfig = ellieLinkConfig
|
2022-03-30 01:23:06 +03:00
|
|
|
, name = moduleName
|
|
|
|
, version = version
|
|
|
|
, update = UpdateControl
|
|
|
|
, settings = state.settings
|
|
|
|
, toExampleCode =
|
2022-03-30 01:41:01 +03:00
|
|
|
\settings -> [ { sectionName = "TODO", code = "TODO" } ]
|
|
|
|
}
|
|
|
|
, Button.button "Launch confetti!"
|
2020-05-15 20:15:35 +03:00
|
|
|
[ Button.onClick LaunchConfetti
|
|
|
|
, Button.small
|
|
|
|
, Button.secondary
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2022-03-30 01:41:01 +03:00
|
|
|
{ settings : Control Settings
|
|
|
|
, model : Maybe Confetti.Model
|
|
|
|
}
|
|
|
|
|
2022-03-30 01:23:06 +03:00
|
|
|
|
|
|
|
init : State
|
2022-03-30 01:41:01 +03:00
|
|
|
init =
|
|
|
|
{ settings = initSettings
|
|
|
|
, model = Nothing
|
2022-03-30 01:23:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Settings =
|
2022-03-30 01:41:01 +03:00
|
|
|
{ center : Float
|
2022-03-30 01:23:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initSettings : Control Settings
|
2022-03-30 01:41:01 +03:00
|
|
|
initSettings =
|
2022-03-30 01:23:06 +03:00
|
|
|
Control.record Settings
|
|
|
|
|> Control.field "center" (ControlExtra.float 700)
|
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
|
2022-03-30 01:23:06 +03:00
|
|
|
| UpdateControl (Control Settings)
|
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 ->
|
2022-03-30 01:41:01 +03:00
|
|
|
{ state | model = Just (Confetti.burst (Confetti.init (Control.currentValue state.settings).center)) }
|
2020-05-15 20:15:35 +03:00
|
|
|
|
|
|
|
ConfettiMsg confettiMsg ->
|
2022-03-30 01:23:06 +03:00
|
|
|
{ state | model = Maybe.map (Confetti.update confettiMsg) state.model }
|
2020-05-15 20:33:38 +03:00
|
|
|
|
|
|
|
WindowResized width _ ->
|
2022-03-30 01:23:06 +03:00
|
|
|
{ state | model = Maybe.map (Confetti.updatePageWidth width) state.model }
|
2022-03-30 01:41:01 +03:00
|
|
|
|
|
|
|
UpdateControl newControl ->
|
|
|
|
{ state | settings = newControl }
|
2020-06-05 21:50:22 +03:00
|
|
|
, Cmd.none
|
|
|
|
)
|