2018-11-12 23:25:37 +03:00
|
|
|
module Examples.Tabs exposing
|
|
|
|
( example
|
2020-03-31 22:43:32 +03:00
|
|
|
, State, Msg
|
2018-11-12 23:25:37 +03:00
|
|
|
)
|
2018-11-10 01:01:11 +03:00
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example
|
2020-03-31 22:43:32 +03:00
|
|
|
@docs State, Msg
|
2018-11-10 01:01:11 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2020-06-10 00:51:00 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2020-06-10 00:51:00 +03:00
|
|
|
import Html.Styled as Html exposing (Html, fromUnstyled)
|
2020-06-10 01:12:30 +03:00
|
|
|
import List.Zipper exposing (Zipper)
|
2020-06-10 00:51:00 +03:00
|
|
|
import Nri.Ui.Tabs.V5 as Tabs exposing (Alignment(..))
|
2018-11-10 01:01:11 +03:00
|
|
|
|
|
|
|
|
2020-06-10 00:51:00 +03:00
|
|
|
type alias State =
|
|
|
|
{ selected : Id
|
2020-06-10 00:55:39 +03:00
|
|
|
, settings : Control Settings
|
2020-06-10 00:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ selected = First
|
2020-06-10 00:55:39 +03:00
|
|
|
, settings = initSettings
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Settings =
|
|
|
|
{ title : Maybe String
|
|
|
|
, alignment : Alignment
|
2020-06-10 00:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-10 00:55:39 +03:00
|
|
|
initSettings : Control Settings
|
|
|
|
initSettings =
|
|
|
|
Control.record Settings
|
|
|
|
|> Control.field "title" (Control.maybe False (Control.string "Title"))
|
|
|
|
|> Control.field "alignment"
|
|
|
|
(Control.choice
|
|
|
|
[ ( "Left", Control.value Left )
|
|
|
|
, ( "Center", Control.value Center )
|
|
|
|
, ( "Right", Control.value Right )
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-06-10 00:51:00 +03:00
|
|
|
type Id
|
2018-11-10 01:01:11 +03:00
|
|
|
= First
|
|
|
|
| Second
|
2020-06-10 01:12:30 +03:00
|
|
|
| Third
|
|
|
|
| Fourth
|
2018-11-10 01:01:11 +03:00
|
|
|
|
|
|
|
|
2020-06-10 00:51:00 +03:00
|
|
|
type Msg
|
|
|
|
= SelectTab Id
|
2020-06-10 00:55:39 +03:00
|
|
|
| SetSettings (Control Settings)
|
2020-06-10 00:51:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> State
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
SelectTab id ->
|
|
|
|
{ model | selected = id }
|
|
|
|
|
2020-06-10 00:55:39 +03:00
|
|
|
SetSettings settings ->
|
|
|
|
{ model | settings = settings }
|
2020-03-31 22:43:32 +03:00
|
|
|
|
2018-11-12 23:25:37 +03:00
|
|
|
|
2020-03-31 23:20:03 +03:00
|
|
|
example : Example State Msg
|
2020-03-31 22:43:32 +03:00
|
|
|
example =
|
2020-06-10 00:21:42 +03:00
|
|
|
{ name = "Nri.Ui.Tabs.V5"
|
2020-03-31 22:43:32 +03:00
|
|
|
, categories = [ Layout ]
|
2020-06-10 00:51:00 +03:00
|
|
|
, state = init
|
|
|
|
, update = \msg model -> ( update msg model, Cmd.none )
|
2020-03-31 22:48:26 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2020-03-31 22:43:32 +03:00
|
|
|
, view =
|
2020-06-10 00:51:00 +03:00
|
|
|
\model ->
|
2020-06-10 00:55:39 +03:00
|
|
|
let
|
|
|
|
settings =
|
|
|
|
Control.currentValue model.settings
|
|
|
|
in
|
|
|
|
[ Control.view SetSettings model.settings |> fromUnstyled
|
2020-06-10 00:51:00 +03:00
|
|
|
, Tabs.view
|
2020-06-10 00:55:39 +03:00
|
|
|
{ title = settings.title
|
2020-06-10 00:51:00 +03:00
|
|
|
, onSelect = SelectTab
|
2020-03-31 22:43:32 +03:00
|
|
|
, tabs =
|
2020-06-10 01:12:30 +03:00
|
|
|
List.Zipper.from [] First [ Second, Third, Fourth ]
|
|
|
|
|> List.Zipper.find ((==) model.selected)
|
|
|
|
|> Maybe.withDefault (List.Zipper.from [] First [ Second, Third, Fourth ])
|
|
|
|
, idToString = idToString
|
|
|
|
, viewTab = viewTab
|
|
|
|
, viewPanel = viewPanel
|
2020-06-10 00:55:39 +03:00
|
|
|
, alignment = settings.alignment
|
2020-03-31 22:43:32 +03:00
|
|
|
}
|
|
|
|
, Tabs.links
|
|
|
|
{ title = Nothing
|
|
|
|
, content = Html.text "Links"
|
|
|
|
, alignment = Tabs.Left
|
|
|
|
, tabs =
|
|
|
|
List.Zipper.from
|
|
|
|
[]
|
|
|
|
(Tabs.NormalLink { label = "Nowhere", href = Nothing })
|
|
|
|
[ Tabs.NormalLink { label = "Elm", href = Just "http://elm-lang.org" }
|
2020-06-10 00:51:00 +03:00
|
|
|
, Tabs.SpaLink { label = "Spa", href = "/#category/Layout", msg = SelectTab Second }
|
2020-03-31 22:43:32 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2018-11-10 01:01:11 +03:00
|
|
|
}
|
2020-06-10 01:12:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
idToString : Id -> String
|
|
|
|
idToString id =
|
|
|
|
case id of
|
|
|
|
First ->
|
|
|
|
"tab-0"
|
|
|
|
|
|
|
|
Second ->
|
|
|
|
"tab-1"
|
|
|
|
|
|
|
|
Third ->
|
|
|
|
"tab-2"
|
|
|
|
|
|
|
|
Fourth ->
|
|
|
|
"tab-3"
|
|
|
|
|
|
|
|
|
|
|
|
viewTab : Id -> Html msg
|
|
|
|
viewTab id =
|
|
|
|
case id of
|
|
|
|
First ->
|
|
|
|
Html.text "First Tab"
|
|
|
|
|
|
|
|
Second ->
|
|
|
|
Html.text "Second Tab"
|
|
|
|
|
|
|
|
Third ->
|
|
|
|
Html.text "Third Tab"
|
|
|
|
|
|
|
|
Fourth ->
|
|
|
|
Html.text "Fourth Tab"
|
|
|
|
|
|
|
|
|
|
|
|
viewPanel : Id -> Html msg
|
|
|
|
viewPanel id =
|
|
|
|
case id of
|
|
|
|
First ->
|
|
|
|
Html.text "First"
|
|
|
|
|
|
|
|
Second ->
|
|
|
|
Html.text "Second"
|
|
|
|
|
|
|
|
Third ->
|
|
|
|
Html.text "Third"
|
|
|
|
|
|
|
|
Fourth ->
|
|
|
|
Html.text "Fourth"
|