2021-09-29 00:21:09 +03:00
|
|
|
module Examples.Balloon exposing (example, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Category exposing (Category(..))
|
2021-09-29 00:26:37 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2021-10-22 03:20:29 +03:00
|
|
|
import Debug.Control.Extra as ControlExtra
|
2022-03-22 02:50:45 +03:00
|
|
|
import Debug.Control.View as ControlView
|
2022-03-29 20:19:32 +03:00
|
|
|
import EllieLink
|
2021-09-29 00:21:09 +03:00
|
|
|
import Example exposing (Example)
|
2022-04-14 23:57:31 +03:00
|
|
|
import Html.Styled exposing (Html, text)
|
2021-09-29 00:21:09 +03:00
|
|
|
import Nri.Ui.Balloon.V1 as Balloon
|
|
|
|
|
|
|
|
|
2022-03-24 20:03:47 +03:00
|
|
|
moduleName : String
|
|
|
|
moduleName =
|
|
|
|
"Balloon"
|
|
|
|
|
|
|
|
|
|
|
|
version : Int
|
|
|
|
version =
|
|
|
|
1
|
|
|
|
|
|
|
|
|
2021-09-29 00:21:09 +03:00
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
2022-03-24 20:03:47 +03:00
|
|
|
{ name = moduleName
|
|
|
|
, version = version
|
2021-09-29 00:21:09 +03:00
|
|
|
, 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
|
2021-11-05 21:59:39 +03:00
|
|
|
, preview =
|
|
|
|
[ Balloon.balloon
|
|
|
|
[ Balloon.onTop
|
|
|
|
, Balloon.navy
|
2021-11-05 22:04:46 +03:00
|
|
|
, Balloon.paddingPx 15
|
2021-11-05 21:59:39 +03:00
|
|
|
]
|
|
|
|
(text "This is a balloon.")
|
|
|
|
]
|
2021-09-29 00:21:09 +03:00
|
|
|
, view = view
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-29 00:26:37 +03:00
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2022-04-14 23:57:31 +03:00
|
|
|
Control Settings
|
2021-09-29 00:26:37 +03:00
|
|
|
|
|
|
|
|
2021-10-28 18:40:23 +03:00
|
|
|
init : State
|
|
|
|
init =
|
2022-04-14 23:57:31 +03:00
|
|
|
controlSettings
|
|
|
|
|
|
|
|
|
|
|
|
type alias Settings =
|
|
|
|
{ copy : String
|
|
|
|
, attributes : List ( String, Balloon.Attribute )
|
2021-09-29 00:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-14 23:57:31 +03:00
|
|
|
controlSettings : Control Settings
|
|
|
|
controlSettings =
|
|
|
|
Control.record Settings
|
|
|
|
|> Control.field "copy" (Control.string "Hello, world!")
|
|
|
|
|> Control.field "attributes" controlAttributes
|
|
|
|
|
|
|
|
|
2021-10-28 18:40:23 +03:00
|
|
|
controlAttributes : Control (List ( String, Balloon.Attribute ))
|
|
|
|
controlAttributes =
|
|
|
|
ControlExtra.list
|
|
|
|
|> ControlExtra.optionalListItem "theme" themeOptions
|
|
|
|
|> ControlExtra.optionalListItem "position" positionOptions
|
|
|
|
|> ControlExtra.optionalListItem "width" widthOptions
|
|
|
|
|> ControlExtra.optionalListItem "padding" paddingOptions
|
2021-09-29 00:39:13 +03:00
|
|
|
|
|
|
|
|
2021-09-29 01:13:54 +03:00
|
|
|
themeOptions : Control ( String, Balloon.Attribute )
|
2021-09-29 00:39:13 +03:00
|
|
|
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 ) )
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-09-29 01:13:54 +03:00
|
|
|
positionOptions : Control ( String, Balloon.Attribute )
|
2021-09-29 00:39:13 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
2021-09-29 01:13:54 +03:00
|
|
|
widthOptions : Control ( String, Balloon.Attribute )
|
2021-09-29 01:09:32 +03:00
|
|
|
widthOptions =
|
|
|
|
Control.choice
|
|
|
|
[ ( "px"
|
|
|
|
, Control.map
|
|
|
|
(\w -> ( "Balloon.widthPx " ++ String.fromFloat w, Balloon.widthPx w ))
|
2021-10-22 03:20:29 +03:00
|
|
|
(ControlExtra.float 50)
|
2021-09-29 01:09:32 +03:00
|
|
|
)
|
|
|
|
, ( "%"
|
|
|
|
, Control.map
|
|
|
|
(\w -> ( "Balloon.widthPct " ++ String.fromFloat w, Balloon.widthPct w ))
|
2021-10-22 03:20:29 +03:00
|
|
|
(ControlExtra.float 50)
|
2021-09-29 01:09:32 +03:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-09-29 01:15:41 +03:00
|
|
|
paddingOptions : Control ( String, Balloon.Attribute )
|
|
|
|
paddingOptions =
|
|
|
|
Control.map
|
|
|
|
(\w -> ( "Balloon.paddingPx " ++ String.fromFloat w, Balloon.paddingPx w ))
|
2021-10-22 03:20:29 +03:00
|
|
|
(ControlExtra.float 10)
|
2021-09-29 01:09:32 +03:00
|
|
|
|
|
|
|
|
2021-09-29 00:26:37 +03:00
|
|
|
{-| -}
|
|
|
|
type Msg
|
2022-04-14 23:57:31 +03:00
|
|
|
= SetAttributes (Control Settings)
|
2021-09-29 00:26:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
2021-10-28 18:40:23 +03:00
|
|
|
SetAttributes attributes ->
|
2022-04-14 23:57:31 +03:00
|
|
|
( attributes
|
2021-09-29 00:26:37 +03:00
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-03-29 20:19:32 +03:00
|
|
|
view : EllieLink.Config -> State -> List (Html Msg)
|
|
|
|
view ellieLinkConfig state =
|
2021-09-29 00:21:09 +03:00
|
|
|
let
|
2022-04-14 23:57:31 +03:00
|
|
|
currentValue =
|
|
|
|
Control.currentValue state
|
2021-09-29 00:21:09 +03:00
|
|
|
in
|
2022-04-14 23:57:31 +03:00
|
|
|
[ ControlView.view
|
2022-03-29 20:19:32 +03:00
|
|
|
{ ellieLinkConfig = ellieLinkConfig
|
|
|
|
, name = moduleName
|
2022-03-24 20:03:47 +03:00
|
|
|
, version = version
|
|
|
|
, update = SetAttributes
|
2022-04-14 23:57:31 +03:00
|
|
|
, settings = state
|
2022-04-13 03:08:59 +03:00
|
|
|
, mainType = "RootHtml.Html msg"
|
2022-04-13 03:32:46 +03:00
|
|
|
, extraImports = []
|
2022-03-22 02:50:45 +03:00
|
|
|
, toExampleCode =
|
2022-04-14 23:57:31 +03:00
|
|
|
\{ copy, attributes } ->
|
2022-03-22 02:50:45 +03:00
|
|
|
[ { sectionName = "Balloon"
|
|
|
|
, code =
|
2022-03-22 02:53:00 +03:00
|
|
|
"Balloon.balloon\n [ "
|
2022-04-14 23:57:31 +03:00
|
|
|
++ String.join "\n , " (List.map Tuple.first attributes)
|
2022-03-22 02:53:00 +03:00
|
|
|
++ "\n ] "
|
|
|
|
++ "\n (text \""
|
2022-03-22 02:50:45 +03:00
|
|
|
++ copy
|
2022-03-22 02:51:25 +03:00
|
|
|
++ "\")"
|
2022-03-22 02:50:45 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
, Balloon.balloon
|
2022-04-14 23:57:31 +03:00
|
|
|
(List.map Tuple.second currentValue.attributes)
|
|
|
|
(text currentValue.copy)
|
2021-09-29 00:21:09 +03:00
|
|
|
]
|