2021-09-29 00:21:09 +03:00
|
|
|
module Examples.Balloon exposing (example, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Category exposing (Category(..))
|
|
|
|
import Css
|
2021-09-29 00:26:37 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2021-09-29 00:21:09 +03:00
|
|
|
import Example exposing (Example)
|
|
|
|
import Examples.IconExamples as IconExamples
|
2021-09-29 00:26:37 +03:00
|
|
|
import Html.Styled exposing (Html, div, fromUnstyled, text)
|
2021-09-29 00:39:13 +03:00
|
|
|
import Html.Styled.Attributes exposing (css)
|
2021-09-29 00:21:09 +03:00
|
|
|
import KeyboardSupport exposing (Direction(..), Key(..))
|
|
|
|
import Nri.Ui.Balloon.V1 as Balloon
|
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
|
|
|
{ name = "Balloon"
|
|
|
|
, version = 1
|
|
|
|
, categories = [ Messaging ]
|
|
|
|
, keyboardSupport = []
|
2021-09-29 00:26:37 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2021-09-29 00:21:09 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
|
|
|
, view = view
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-29 00:26:37 +03:00
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
Control Settings
|
|
|
|
|
|
|
|
|
|
|
|
type alias Settings =
|
|
|
|
{ copy : String
|
2021-09-29 00:39:13 +03:00
|
|
|
, theme : Maybe ( String, Balloon.Attribute Css.Px Css.Px Css.Px )
|
|
|
|
, position : Maybe ( String, Balloon.Attribute Css.Px Css.Px Css.Px )
|
2021-09-29 00:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-29 00:39:13 +03:00
|
|
|
init : Control Settings
|
2021-09-29 00:26:37 +03:00
|
|
|
init =
|
|
|
|
Control.record Settings
|
2021-09-29 00:39:13 +03:00
|
|
|
|> Control.field "copy" (Control.string "Hello, world!")
|
|
|
|
|> Control.field "theme" (Control.maybe False themeOptions)
|
|
|
|
|> Control.field "position" (Control.maybe False positionOptions)
|
|
|
|
|
|
|
|
|
|
|
|
themeOptions : Control ( String, Balloon.Attribute width padding paddingUnits )
|
|
|
|
themeOptions =
|
|
|
|
Control.choice
|
|
|
|
[ ( "green", Control.value ( "Balloon.green", Balloon.green ) )
|
|
|
|
, ( "purple", Control.value ( "Balloon.purple", Balloon.purple ) )
|
|
|
|
, ( "orange", Control.value ( "Balloon.orange", Balloon.orange ) )
|
|
|
|
, ( "white", Control.value ( "Balloon.white", Balloon.white ) )
|
|
|
|
, ( "navy", Control.value ( "Balloon.navy", Balloon.navy ) )
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
positionOptions : Control ( String, Balloon.Attribute width padding paddingUnits )
|
|
|
|
positionOptions =
|
|
|
|
Control.choice
|
|
|
|
[ ( "onBottom", Control.value ( "Balloon.onBottom", Balloon.onBottom ) )
|
|
|
|
, ( "onLeft", Control.value ( "Balloon.onLeft", Balloon.onLeft ) )
|
|
|
|
, ( "onRight", Control.value ( "Balloon.onRight", Balloon.onRight ) )
|
|
|
|
, ( "onTop", Control.value ( "Balloon.onTop", Balloon.onTop ) )
|
|
|
|
]
|
2021-09-29 00:26:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= SetDebugControlsState (Control Settings)
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
SetDebugControlsState newDebugControlsState ->
|
|
|
|
( newDebugControlsState
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
view : State -> List (Html Msg)
|
|
|
|
view state =
|
2021-09-29 00:21:09 +03:00
|
|
|
let
|
2021-09-29 00:26:37 +03:00
|
|
|
settings =
|
|
|
|
Control.currentValue state
|
2021-09-29 00:39:13 +03:00
|
|
|
|
|
|
|
attributes =
|
|
|
|
List.filterMap identity [ settings.theme, settings.position ]
|
2021-09-29 00:21:09 +03:00
|
|
|
in
|
2021-09-29 00:26:37 +03:00
|
|
|
[ Control.view SetDebugControlsState state |> fromUnstyled
|
2021-09-29 00:39:13 +03:00
|
|
|
, Html.Styled.code [ css [ Css.display Css.block ] ]
|
|
|
|
[ text <|
|
|
|
|
"Balloon.balloon [ "
|
|
|
|
++ String.join ", " (List.map Tuple.first attributes)
|
|
|
|
++ " ] "
|
|
|
|
++ "\""
|
|
|
|
++ settings.copy
|
|
|
|
++ "\""
|
|
|
|
]
|
|
|
|
, Balloon.balloon (List.map Tuple.second attributes) (text settings.copy)
|
2021-09-29 00:21:09 +03:00
|
|
|
]
|