noredink-ui/styleguide-app/View.elm

226 lines
7.2 KiB
Elm
Raw Normal View History

2018-02-13 00:32:38 +03:00
module View exposing (view)
import Css exposing (..)
import Css.Foreign exposing (Snippet)
import DEPRECATED.Css.File exposing (Stylesheet, compile, stylesheet)
import DEPRECATED.Css.Namespace
2018-02-13 00:32:38 +03:00
import Html exposing (Html, img)
import Html.Attributes exposing (..)
import Html.CssHelpers
import Model exposing (..)
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample, categoryForDisplay)
2018-03-17 03:16:16 +03:00
import Nri.Ui.Colors.V1 as Colors
2018-02-13 00:32:38 +03:00
import Nri.Ui.Css.VendorPrefixed as VendorPrefixed
2018-03-17 03:15:03 +03:00
import Nri.Ui.Fonts.V1 as Fonts
2018-02-13 00:32:38 +03:00
import NriModules as NriModules exposing (nriThemedModules)
import Routes as Routes exposing (Route)
import Update exposing (..)
view : Model -> Html Msg
view model =
Html.div []
[ attachElmCssStyles
, Html.div [ class [ StyleGuideLayout ] ]
[ navigation model.route
, Html.div [ class [ StyleGuideContent ] ]
(case model.route of
Routes.Doodad doodad ->
[ Html.h2 []
[ Html.a [ Html.Attributes.href "#" ] [ Html.text "(see all)" ] ]
, nriThemedModules model.moduleStates
|> List.filter (\m -> m.filename == ("Nri/" ++ doodad))
|> List.map (ModuleExample.view True)
|> Html.div []
|> Html.map UpdateModuleStates
]
Routes.Category category ->
[ Html.section [ class [ Section ] ]
[ newComponentsLink
, Html.h2 [] [ Html.text (toString category) ]
, nriThemedModules model.moduleStates
|> List.filter (\doodad -> category == doodad.category)
|> List.map (ModuleExample.view True)
|> Html.div []
|> Html.map UpdateModuleStates
]
]
Routes.All ->
[ Html.section [ class [ Section ] ]
[ newComponentsLink
, Html.h2 [] [ Html.text "NRI-Themed Modules" ]
, Html.h3 [] [ Html.text "All Categories" ]
, nriThemedModules model.moduleStates
|> List.map (ModuleExample.view True)
|> Html.div []
|> Html.map UpdateModuleStates
]
]
)
]
]
newComponentsLink : Html Msg
newComponentsLink =
Html.div []
[ Html.h2 [] [ Html.text "New Styleguide Components" ]
, Html.div []
[ Html.text "Future styleguide components can be found in "
, Html.a [ href "https://app.zeplin.io/project/5973fb495395bdc871ebb055" ] [ Html.text "this Zepplin" ]
, Html.text "."
]
]
navigation : Route -> Html Msg
navigation route =
let
isActive category =
case route of
Routes.Category routeCategory ->
category == routeCategory
_ ->
False
navLink category =
Html.li []
[ Html.a
[ classList
[ ( ActiveCategory, isActive category )
, ( NavLink, True )
]
, Html.Attributes.href <| "#category/" ++ toString category
]
[ Html.text (categoryForDisplay category) ]
]
in
Html.div [ class [ CategoryMenu ] ]
[ Html.h4 []
[ Html.text "Categories" ]
, Html.ul [ class [ CategoryLinks ] ] <|
Html.li []
[ Html.a
[ Html.Attributes.href "#"
, classList
[ ( ActiveCategory, route == Routes.All )
, ( NavLink, True )
]
]
[ Html.text "All" ]
]
:: List.map
navLink
[ Text
2018-03-02 00:34:44 +03:00
, TextWriting
2018-03-17 01:33:42 +03:00
, Fonts
2018-02-13 00:32:38 +03:00
, Colors
, Layout
, Inputs
, Buttons
, Icons
, Behaviors
, Messaging
, Modals
, Writing
, DynamicSymbols
, Pages
, QuestionTypes
]
]
type Classes
= Section
| StyleGuideLayout
| StyleGuideContent
| CategoryMenu
| CategoryLinks
| ActiveCategory
| NavLink
layoutFixer : List Snippet
2018-02-13 00:32:38 +03:00
layoutFixer =
-- TODO: remove when universal header seizes power
[ Css.Foreign.selector "#header-menu"
2018-02-13 00:32:38 +03:00
[ Css.property "float" "none"
]
, Css.Foreign.selector "#page-container"
2018-02-13 00:32:38 +03:00
[ maxWidth (px 1400)
]
, Css.Foreign.selector ".anonymous .log-in-button"
2018-02-13 00:32:38 +03:00
[ Css.property "float" "none"
, right zero
, top zero
]
, Css.Foreign.selector ".l-inline-blocks"
2018-02-13 00:32:38 +03:00
[ textAlign right
]
, Css.Foreign.everything
2018-02-13 00:32:38 +03:00
[ Fonts.baseFont
]
]
styles : Stylesheet
2018-02-13 00:32:38 +03:00
styles =
(stylesheet << DEPRECATED.Css.Namespace.namespace "Page-StyleGuide-") <|
2018-02-13 00:32:38 +03:00
List.concat
[ [ Css.Foreign.class Section
2018-02-13 00:32:38 +03:00
[ margin2 (px 40) zero
]
, Css.Foreign.class StyleGuideLayout
2018-02-13 00:32:38 +03:00
[ displayFlex
, alignItems flexStart
]
, Css.Foreign.class StyleGuideContent
2018-02-13 00:32:38 +03:00
[ flexGrow (int 1)
]
, Css.Foreign.class CategoryMenu
2018-02-13 00:32:38 +03:00
[ flexBasis (px 300)
, backgroundColor Colors.gray92
, marginRight (px 40)
, padding (px 25)
, VendorPrefixed.value "position" "sticky"
, top (px 150)
, flexShrink zero
]
, Css.Foreign.class CategoryLinks
2018-02-13 00:32:38 +03:00
[ margin4 zero zero (px 40) zero
, Css.Foreign.children
[ Css.Foreign.selector "li"
2018-02-13 00:32:38 +03:00
[ margin2 (px 10) zero
]
]
]
, Css.Foreign.class NavLink
2018-02-13 00:32:38 +03:00
[ backgroundColor transparent
, borderStyle none
, color Colors.azure
]
, Css.Foreign.class ActiveCategory
2018-02-13 00:32:38 +03:00
[ color Colors.navy
]
]
, layoutFixer
]
{ id, class, classList } =
Html.CssHelpers.withNamespace "Page-StyleGuide-"
attachElmCssStyles : Html msg
attachElmCssStyles =
Html.CssHelpers.style <|
.css <|
compile <|
2018-02-13 00:32:38 +03:00
List.concat
[ [ styles ]
, NriModules.styles
]