2020-04-03 04:13:29 +03:00
|
|
|
module Examples.Loading exposing (example, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Browser.Events
|
|
|
|
import Category exposing (Category(..))
|
|
|
|
import Css
|
|
|
|
import Example exposing (Example)
|
|
|
|
import Html.Styled as Html exposing (Html)
|
|
|
|
import Html.Styled.Events as Events
|
|
|
|
import Json.Decode
|
|
|
|
import Nri.Ui.Button.V10 as Button
|
2020-04-03 04:21:04 +03:00
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
2020-04-03 04:13:29 +03:00
|
|
|
import Nri.Ui.Loading.V1 as Loading
|
2020-04-03 04:21:04 +03:00
|
|
|
import Nri.Ui.Svg.V1 as Svg
|
2021-10-27 20:42:23 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2020-04-03 04:13:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
{ showLoadingFadeIn : Bool
|
|
|
|
, showLoading : Bool
|
2020-04-03 04:35:55 +03:00
|
|
|
, showSpinners : Bool
|
2020-04-03 04:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ showLoadingFadeIn = False
|
|
|
|
, showLoading = False
|
2020-04-03 04:35:55 +03:00
|
|
|
, showSpinners = False
|
2020-04-03 04:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= ShowLoadingFadeIn
|
|
|
|
| ShowLoading
|
2020-04-03 04:35:55 +03:00
|
|
|
| ShowSpinners
|
2020-04-03 04:21:04 +03:00
|
|
|
| Close
|
2020-04-03 04:13:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
ShowLoadingFadeIn ->
|
|
|
|
( { model | showLoadingFadeIn = True }
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
ShowLoading ->
|
|
|
|
( { model | showLoading = True }
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
2020-04-03 04:35:55 +03:00
|
|
|
ShowSpinners ->
|
|
|
|
( { model | showSpinners = True }
|
2020-04-03 04:21:04 +03:00
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
Close ->
|
2020-04-03 04:13:29 +03:00
|
|
|
( { model
|
|
|
|
| showLoadingFadeIn = False
|
|
|
|
, showLoading = False
|
2020-04-03 04:35:55 +03:00
|
|
|
, showSpinners = False
|
2020-04-03 04:13:29 +03:00
|
|
|
}
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
subscriptions : State -> Sub Msg
|
2020-04-03 04:35:55 +03:00
|
|
|
subscriptions { showLoadingFadeIn, showLoading, showSpinners } =
|
|
|
|
if showLoadingFadeIn || showLoading || showSpinners then
|
2020-04-03 04:21:04 +03:00
|
|
|
Browser.Events.onClick (Json.Decode.succeed Close)
|
2020-04-03 04:13:29 +03:00
|
|
|
|
|
|
|
else
|
|
|
|
Sub.none
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "Loading"
|
|
|
|
, version = 1
|
2021-11-12 01:53:25 +03:00
|
|
|
, categories = [ Animations ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2020-04-03 04:13:29 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
|
|
|
, subscriptions = subscriptions
|
2022-03-30 18:16:46 +03:00
|
|
|
, preview =
|
|
|
|
[ Loading.spinningDots
|
|
|
|
|> Svg.withCss
|
|
|
|
[ Css.property "animation-name" "none" |> Css.important
|
|
|
|
, Css.alignSelf Css.center
|
|
|
|
]
|
|
|
|
|> Svg.toHtml
|
|
|
|
]
|
2020-04-03 04:13:29 +03:00
|
|
|
, view =
|
2022-03-29 20:19:32 +03:00
|
|
|
\ellieLinkConfig { showLoadingFadeIn, showLoading, showSpinners } ->
|
2020-04-03 04:13:29 +03:00
|
|
|
[ if showLoading then
|
|
|
|
Loading.page
|
|
|
|
|
|
|
|
else
|
|
|
|
Html.text ""
|
2020-04-03 04:21:04 +03:00
|
|
|
, button "Loading.page" ShowLoading showLoadingFadeIn
|
2020-04-03 04:13:29 +03:00
|
|
|
, if showLoadingFadeIn then
|
|
|
|
Loading.fadeInPage
|
|
|
|
|
|
|
|
else
|
|
|
|
Html.text ""
|
2020-04-03 04:21:04 +03:00
|
|
|
, button "Loading.fadeInPage" ShowLoadingFadeIn showLoadingFadeIn
|
2020-04-03 04:35:55 +03:00
|
|
|
, if showSpinners then
|
2020-04-03 04:21:04 +03:00
|
|
|
Html.div []
|
2020-04-03 04:35:55 +03:00
|
|
|
[ Loading.spinningPencil
|
2021-10-28 18:58:34 +03:00
|
|
|
|> Svg.withColor Colors.azure
|
2020-04-03 04:21:04 +03:00
|
|
|
|> Svg.toHtml
|
2021-10-27 21:54:14 +03:00
|
|
|
, Text.caption [ Text.plaintext "By default, the spinningPencil is white. Showing as blue for visibility." ]
|
2020-04-03 04:35:55 +03:00
|
|
|
, Loading.spinningDots
|
|
|
|
|> Svg.toHtml
|
2020-04-03 04:13:29 +03:00
|
|
|
]
|
|
|
|
|
2020-04-03 04:21:04 +03:00
|
|
|
else
|
2020-04-03 04:35:55 +03:00
|
|
|
button "Loading.spinningPencil, Loading.spinningDots" ShowSpinners showLoadingFadeIn
|
2020-04-03 04:13:29 +03:00
|
|
|
]
|
|
|
|
}
|
2020-04-03 04:21:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
button : String -> Msg -> Bool -> Html Msg
|
|
|
|
button name do disabled =
|
|
|
|
Button.button name
|
|
|
|
[ Button.custom
|
|
|
|
[ Events.stopPropagationOn "click"
|
|
|
|
(Json.Decode.map (\m -> ( m, True ))
|
|
|
|
(Json.Decode.succeed do)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, if disabled then
|
|
|
|
Button.disabled
|
|
|
|
|
|
|
|
else
|
|
|
|
Button.secondary
|
|
|
|
, Button.css [ Css.marginRight (Css.px 20) ]
|
|
|
|
]
|