2018-09-26 17:02:10 +03:00
|
|
|
module Main exposing (init, main)
|
2018-02-13 00:32:38 +03:00
|
|
|
|
2020-03-24 03:25:24 +03:00
|
|
|
import Browser exposing (Document, UrlRequest(..))
|
2018-12-05 01:36:15 +03:00
|
|
|
import Browser.Navigation exposing (Key)
|
2020-03-24 03:35:08 +03:00
|
|
|
import Category
|
2020-03-24 03:25:24 +03:00
|
|
|
import Css exposing (..)
|
|
|
|
import Html as RootHtml
|
|
|
|
import Html.Attributes
|
|
|
|
import Html.Styled as Html exposing (Html, img)
|
|
|
|
import Html.Styled.Attributes as Attributes exposing (..)
|
2020-03-24 03:33:42 +03:00
|
|
|
import ModuleExample as ModuleExample exposing (ModuleExample)
|
2020-03-24 03:25:24 +03:00
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
|
|
|
import Nri.Ui.Css.VendorPrefixed as VendorPrefixed
|
|
|
|
import Nri.Ui.Fonts.V1 as Fonts
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
|
|
|
import NriModules as NriModules exposing (ModuleStates, nriThemedModules)
|
2018-02-13 00:32:38 +03:00
|
|
|
import Routes as Routes exposing (Route(..))
|
2018-12-05 01:36:15 +03:00
|
|
|
import Url exposing (Url)
|
2018-02-13 00:32:38 +03:00
|
|
|
|
|
|
|
|
2018-12-05 01:36:15 +03:00
|
|
|
main : Program () Model Msg
|
2018-02-13 00:32:38 +03:00
|
|
|
main =
|
2018-12-05 01:36:15 +03:00
|
|
|
Browser.application
|
2018-02-13 00:32:38 +03:00
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, subscriptions = subscriptions
|
2018-12-05 01:36:15 +03:00
|
|
|
, view = view
|
|
|
|
, onUrlRequest = OnUrlRequest
|
|
|
|
, onUrlChange = OnUrlChange
|
2018-02-13 00:32:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-24 03:25:24 +03:00
|
|
|
type alias Model =
|
|
|
|
{ -- Global UI
|
|
|
|
route : Route
|
|
|
|
, moduleStates : ModuleStates
|
|
|
|
, navigationKey : Key
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-05 01:36:15 +03:00
|
|
|
init : () -> Url -> Key -> ( Model, Cmd Msg )
|
2018-12-05 21:56:04 +03:00
|
|
|
init () url key =
|
2018-12-05 01:36:15 +03:00
|
|
|
( { route = Routes.fromLocation url
|
2018-02-13 00:32:38 +03:00
|
|
|
, moduleStates = NriModules.init
|
2018-12-05 21:56:04 +03:00
|
|
|
, navigationKey = key
|
2018-02-13 00:32:38 +03:00
|
|
|
}
|
|
|
|
, Cmd.none
|
|
|
|
)
|
2020-03-24 03:25:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= UpdateModuleStates NriModules.Msg
|
|
|
|
| OnUrlRequest Browser.UrlRequest
|
|
|
|
| OnUrlChange Url
|
|
|
|
| NoOp
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
|
update action model =
|
|
|
|
case action of
|
|
|
|
UpdateModuleStates msg ->
|
|
|
|
let
|
|
|
|
( moduleStates, cmd ) =
|
|
|
|
NriModules.update msg model.moduleStates
|
|
|
|
in
|
|
|
|
( { model | moduleStates = moduleStates }
|
|
|
|
, Cmd.map UpdateModuleStates cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
OnUrlRequest request ->
|
|
|
|
case request of
|
|
|
|
Internal loc ->
|
|
|
|
( model, Browser.Navigation.pushUrl model.navigationKey (Url.toString loc) )
|
|
|
|
|
|
|
|
External loc ->
|
|
|
|
( model, Browser.Navigation.load loc )
|
|
|
|
|
|
|
|
OnUrlChange route ->
|
|
|
|
( { model | route = Routes.fromLocation route }, Cmd.none )
|
|
|
|
|
|
|
|
NoOp ->
|
|
|
|
( model, Cmd.none )
|
|
|
|
|
|
|
|
|
|
|
|
subscriptions : Model -> Sub Msg
|
|
|
|
subscriptions model =
|
|
|
|
Sub.map UpdateModuleStates (NriModules.subscriptions model.moduleStates)
|
|
|
|
|
|
|
|
|
|
|
|
view : Model -> Document Msg
|
|
|
|
view model =
|
|
|
|
{ title = "Style Guide"
|
|
|
|
, body = [ view_ model |> Html.toUnstyled ]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
view_ : Model -> Html Msg
|
|
|
|
view_ model =
|
|
|
|
Html.styled Html.div
|
|
|
|
[ displayFlex
|
|
|
|
, alignItems flexStart
|
|
|
|
, minHeight (vh 100)
|
|
|
|
]
|
|
|
|
[]
|
|
|
|
[ navigation model.route
|
|
|
|
, Html.styled Html.main_
|
|
|
|
[ flexGrow (int 1) ]
|
|
|
|
[]
|
|
|
|
(case model.route of
|
|
|
|
Routes.Doodad doodad ->
|
|
|
|
[ Html.styled Html.section
|
|
|
|
[ sectionStyles ]
|
|
|
|
[]
|
|
|
|
[ Heading.h2 [] [ Html.text ("Viewing " ++ doodad ++ " doodad only") ]
|
|
|
|
, nriThemedModules model.moduleStates
|
|
|
|
|> List.filter (\m -> m.name == doodad)
|
|
|
|
|> List.map (ModuleExample.view False)
|
|
|
|
|> Html.div []
|
|
|
|
|> Html.map UpdateModuleStates
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Routes.Category category ->
|
|
|
|
[ Html.styled Html.section
|
|
|
|
[ sectionStyles ]
|
|
|
|
[]
|
2020-03-24 03:33:42 +03:00
|
|
|
[ Heading.h2 [] [ Html.text (Category.forDisplay category) ]
|
2020-03-24 03:25:24 +03:00
|
|
|
, nriThemedModules model.moduleStates
|
|
|
|
|> List.filter (\doodad -> category == doodad.category)
|
|
|
|
|> List.map (ModuleExample.view True)
|
2020-03-24 03:33:42 +03:00
|
|
|
|> Html.div [ id (Category.forId category) ]
|
2020-03-24 03:25:24 +03:00
|
|
|
|> Html.map UpdateModuleStates
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Routes.All ->
|
|
|
|
[ Html.styled Html.section
|
|
|
|
[ sectionStyles ]
|
|
|
|
[]
|
|
|
|
[ Heading.h2 [] [ Html.text "All" ]
|
|
|
|
, nriThemedModules model.moduleStates
|
|
|
|
|> List.map (ModuleExample.view True)
|
|
|
|
|> Html.div []
|
|
|
|
|> Html.map UpdateModuleStates
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
navigation : Route -> Html Msg
|
|
|
|
navigation route =
|
|
|
|
let
|
|
|
|
isActive category =
|
|
|
|
case route of
|
|
|
|
Routes.Category routeCategory ->
|
|
|
|
category == routeCategory
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
False
|
|
|
|
|
|
|
|
categoryLink active hash displayName =
|
|
|
|
Html.styled Html.a
|
|
|
|
[ backgroundColor transparent
|
|
|
|
, borderStyle none
|
|
|
|
, textDecoration none
|
|
|
|
, if active then
|
|
|
|
color Colors.navy
|
|
|
|
|
|
|
|
else
|
|
|
|
color Colors.azure
|
|
|
|
, Fonts.baseFont
|
|
|
|
]
|
|
|
|
[ Attributes.href hash ]
|
|
|
|
[ Html.text displayName ]
|
|
|
|
|
|
|
|
navLink category =
|
|
|
|
categoryLink (isActive category)
|
|
|
|
("#category/" ++ Debug.toString category)
|
2020-03-24 03:33:42 +03:00
|
|
|
(Category.forDisplay category)
|
2020-03-24 03:25:24 +03:00
|
|
|
|
|
|
|
toNavLi element =
|
|
|
|
Html.li
|
|
|
|
[ css
|
|
|
|
[ margin2 (px 10) zero
|
|
|
|
, listStyle none
|
|
|
|
, textDecoration none
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[ element ]
|
|
|
|
in
|
|
|
|
Html.styled Html.nav
|
|
|
|
[ flexBasis (px 200)
|
|
|
|
, backgroundColor Colors.gray96
|
|
|
|
, marginRight (px 40)
|
|
|
|
, padding (px 25)
|
|
|
|
, VendorPrefixed.value "position" "sticky"
|
|
|
|
, top (px 150)
|
|
|
|
, flexShrink zero
|
|
|
|
]
|
|
|
|
[ id "categories"
|
|
|
|
, attribute "aria-label" "Main Navigation"
|
|
|
|
]
|
|
|
|
[ Heading.h4 [] [ Html.text "Categories" ]
|
|
|
|
, (categoryLink (route == Routes.All) "#" "All"
|
2020-03-24 03:35:08 +03:00
|
|
|
:: List.map navLink Category.all
|
2020-03-24 03:25:24 +03:00
|
|
|
)
|
|
|
|
|> List.map toNavLi
|
|
|
|
|> Html.styled Html.ul
|
|
|
|
[ margin4 zero zero (px 40) zero
|
|
|
|
, padding zero
|
|
|
|
]
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
sectionStyles : Css.Style
|
|
|
|
sectionStyles =
|
|
|
|
Css.batch [ margin2 (px 40) zero ]
|