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
|
2021-09-29 00:21:09 +03:00
|
|
|
import Example exposing (Example)
|
2022-03-15 21:06:13 +03:00
|
|
|
import Html.Styled exposing (Html, fromUnstyled, text)
|
2021-09-29 00:21:09 +03:00
|
|
|
import Nri.Ui.Balloon.V1 as Balloon
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
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
|
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 =
|
2021-10-28 18:40:23 +03:00
|
|
|
{ copy : Control String
|
|
|
|
, attributes : Control (List ( String, Balloon.Attribute ))
|
|
|
|
}
|
2021-09-29 00:26:37 +03:00
|
|
|
|
|
|
|
|
2021-10-28 18:40:23 +03:00
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ copy = Control.string "Hello, world!"
|
|
|
|
, attributes = controlAttributes
|
2021-09-29 00:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2021-10-28 18:40:23 +03:00
|
|
|
= SetCopy (Control String)
|
|
|
|
| SetAttributes (Control (List ( String, Balloon.Attribute )))
|
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
|
|
|
SetCopy copy ->
|
|
|
|
( { state | copy = copy }
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
SetAttributes attributes ->
|
|
|
|
( { state | attributes = attributes }
|
2021-09-29 00:26:37 +03:00
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
view : State -> List (Html Msg)
|
|
|
|
view state =
|
2021-09-29 00:21:09 +03:00
|
|
|
let
|
2021-10-28 18:40:23 +03:00
|
|
|
copy =
|
|
|
|
Control.currentValue state.copy
|
2021-09-29 00:21:09 +03:00
|
|
|
in
|
2021-10-28 18:40:23 +03:00
|
|
|
[ Control.view SetCopy state.copy |> fromUnstyled
|
2022-03-22 02:50:45 +03:00
|
|
|
, ControlView.view
|
|
|
|
{ update = SetAttributes
|
|
|
|
, settings = state.attributes
|
|
|
|
, toExampleCode =
|
|
|
|
\attrs ->
|
|
|
|
[ { sectionName = "Balloon"
|
|
|
|
, code =
|
2022-03-22 02:53:00 +03:00
|
|
|
"Balloon.balloon\n [ "
|
|
|
|
++ String.join "\n , " (List.map Tuple.first attrs)
|
|
|
|
++ "\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
|
|
|
|
(List.map Tuple.second (Control.currentValue state.attributes))
|
|
|
|
(text copy)
|
2021-09-29 00:21:09 +03:00
|
|
|
]
|