noredink-ui/styleguide-app/NriModules.elm

313 lines
11 KiB
Elm
Raw Normal View History

module NriModules exposing (ModuleStates, Msg, init, nriThemedModules, subscriptions, update)
2018-02-13 00:32:38 +03:00
import Assets exposing (assets)
2018-08-16 01:05:55 +03:00
import Examples.Alert
import Examples.AssignmentIcon
2019-03-21 23:50:59 +03:00
import Examples.BannerAlert
2018-04-30 14:24:03 +03:00
import Examples.Button
2019-08-20 20:38:24 +03:00
import Examples.Callout
2018-06-20 18:06:11 +03:00
import Examples.Checkbox
2019-02-16 01:36:36 +03:00
import Examples.ClickableText
2018-03-17 01:58:00 +03:00
import Examples.Colors
import Examples.DisclosureIndicator
import Examples.Dropdown
2018-03-17 01:27:38 +03:00
import Examples.Fonts
import Examples.Heading
Extract `Nri.Icon` from the monolith The recommendation is to break the styles API rather than the view API when moving something out of the monolith into this repo. `Nri.Icon` is not really setup for that sort of breakage. If we would prefer to have the styles break rather than the view, that will take more work. Work that can be done independent of the extraction. The transition in the monolith ought to look something like: ```elm module Nri.Icon exposing (..) import Html exposing (Html) import Nri.SvgSprite import Nri.Ui.Icon.V1 exposing (Assets, IconType) icon : { alt : String, icon : IconType } -> Html msg icon config = Nri.Ui.Icon.V1.icon assets assets : Assets {} assets = { activity = Nri.SvgSprite.activity , arrowDown = Nri.SvgSprite.arrowDown , attention_svg = Nri.Assets.attention_svg ... } ``` So hopefully, the change is still very small on the monolith side. There's maybe a bigger concern than which API breaks. `Nri.Icon` has some behavior for a11y. We could definitely change the internals over during the extraction. But, since all of these changes are value-level changes, it's very likely that we'll break something in the process. That's a bigger concern because instead of affecting the handful of Engineers working at NRI, we would be affecting the millions of people using the site. We shouldn't fear making those kinds of changes. However, we should make them when we can give them the appropriate attention they deserve. Not when one person is trying to move as fast as possible to avoid race conditions of moving modules between repos.
2018-03-29 03:34:56 +03:00
import Examples.Icon
2018-08-29 22:09:22 +03:00
import Examples.Modal
2018-05-01 18:34:16 +03:00
import Examples.Page
2018-03-24 05:05:34 +03:00
import Examples.SegmentedControl
2018-04-17 01:39:57 +03:00
import Examples.Select
2019-04-11 22:54:14 +03:00
import Examples.Slide
2019-04-05 04:30:12 +03:00
import Examples.SlideModal
2019-07-11 22:46:22 +03:00
import Examples.SortableTable
import Examples.Table
import Examples.Tabs
2018-03-17 01:27:38 +03:00
import Examples.Text
import Examples.Text.Writing
2018-03-01 02:51:49 +03:00
import Examples.TextArea as TextAreaExample
2018-05-25 21:16:54 +03:00
import Examples.TextInput as TextInputExample
import Examples.UiIcon
2018-02-13 00:32:38 +03:00
import Html exposing (Html, img)
import Html.Attributes exposing (..)
import ModuleExample exposing (Category(..), ModuleExample)
import Url exposing (Url)
2018-02-13 00:32:38 +03:00
type alias ModuleStates =
2019-07-12 01:18:49 +03:00
{ buttonExampleState : Examples.Button.State Msg
2019-05-23 00:38:11 +03:00
, bannerAlertExampleState : Examples.BannerAlert.State
, clickableTextExampleState : Examples.ClickableText.State
2018-06-20 18:06:11 +03:00
, checkboxExampleState : Examples.Checkbox.State
2018-04-30 14:14:20 +03:00
, dropdownState : Examples.Dropdown.State Examples.Dropdown.Value
, segmentedControlState : Examples.SegmentedControl.State
2018-04-17 01:39:57 +03:00
, selectState : Examples.Select.State Examples.Select.Value
, tableExampleState : Examples.Table.State
2018-03-24 05:05:34 +03:00
, textAreaExampleState : TextAreaExample.State
2018-05-25 21:16:54 +03:00
, textInputExampleState : TextInputExample.State
, disclosureIndicatorExampleState : Examples.DisclosureIndicator.State
2018-08-29 22:09:22 +03:00
, modalExampleState : Examples.Modal.State
2019-04-05 04:30:12 +03:00
, slideModalExampleState : Examples.SlideModal.State
2019-04-11 22:54:14 +03:00
, slideExampleState : Examples.Slide.State
2019-07-11 22:46:22 +03:00
, sortableTableState : Examples.SortableTable.State
, tabsExampleState : Examples.Tabs.Tab
2018-03-01 02:51:49 +03:00
}
2018-02-13 00:32:38 +03:00
init : ModuleStates
init =
2018-04-30 14:14:20 +03:00
{ buttonExampleState = Examples.Button.init assets
2019-05-23 00:38:11 +03:00
, bannerAlertExampleState = Examples.BannerAlert.init
, clickableTextExampleState = Examples.ClickableText.init assets
2018-06-20 18:06:11 +03:00
, checkboxExampleState = Examples.Checkbox.init
2018-04-30 14:14:20 +03:00
, dropdownState = Examples.Dropdown.init
, segmentedControlState = Examples.SegmentedControl.init assets
2018-04-17 01:39:57 +03:00
, selectState = Examples.Select.init
, tableExampleState = Examples.Table.init
2018-03-24 05:05:34 +03:00
, textAreaExampleState = TextAreaExample.init
2018-05-25 21:16:54 +03:00
, textInputExampleState = TextInputExample.init
, disclosureIndicatorExampleState = Examples.DisclosureIndicator.init
2018-08-29 22:09:22 +03:00
, modalExampleState = Examples.Modal.init
2019-04-05 04:30:12 +03:00
, slideModalExampleState = Examples.SlideModal.init
2019-04-11 22:54:14 +03:00
, slideExampleState = Examples.Slide.init
2019-07-11 22:46:22 +03:00
, sortableTableState = Examples.SortableTable.init
, tabsExampleState = Examples.Tabs.First
2018-03-01 02:51:49 +03:00
}
2018-02-13 00:32:38 +03:00
type Msg
2019-07-12 01:18:49 +03:00
= ButtonExampleMsg (Examples.Button.Msg Msg)
2019-05-23 00:38:11 +03:00
| BannerAlertExampleMsg Examples.BannerAlert.Msg
| ClickableTextExampleMsg Examples.ClickableText.Msg
2018-06-20 18:06:11 +03:00
| CheckboxExampleMsg Examples.Checkbox.Msg
2018-04-30 14:14:20 +03:00
| DropdownMsg Examples.Dropdown.Msg
| SegmentedControlMsg Examples.SegmentedControl.Msg
2018-04-17 01:39:57 +03:00
| SelectMsg Examples.Select.Msg
2018-03-24 05:05:34 +03:00
| ShowItWorked String String
| TableExampleMsg Examples.Table.Msg
2018-03-01 02:51:49 +03:00
| TextAreaExampleMsg TextAreaExample.Msg
2018-05-25 21:16:54 +03:00
| TextInputExampleMsg TextInputExample.Msg
| DisclosureIndicatorExampleMsg Examples.DisclosureIndicator.Msg
2018-08-29 22:09:22 +03:00
| ModalExampleMsg Examples.Modal.Msg
2019-04-05 04:30:12 +03:00
| SlideModalExampleMsg Examples.SlideModal.Msg
2019-04-11 22:54:14 +03:00
| SlideExampleMsg Examples.Slide.Msg
2019-07-11 22:46:22 +03:00
| SortableTableMsg Examples.SortableTable.Msg
| TabsExampleMsg Examples.Tabs.Tab
2018-02-13 00:32:38 +03:00
| NoOp
update : Msg -> ModuleStates -> ( ModuleStates, Cmd Msg )
update outsideMsg moduleStates =
case outsideMsg of
2018-04-30 14:14:20 +03:00
ButtonExampleMsg msg ->
let
( buttonExampleState, cmd ) =
Examples.Button.update msg moduleStates.buttonExampleState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | buttonExampleState = buttonExampleState }
, Cmd.map ButtonExampleMsg cmd
)
2018-06-20 18:06:11 +03:00
2019-05-23 00:38:11 +03:00
BannerAlertExampleMsg msg ->
( { moduleStates
| bannerAlertExampleState =
Examples.BannerAlert.update msg moduleStates.bannerAlertExampleState
}
, Cmd.none
)
ClickableTextExampleMsg msg ->
let
( clickableTextExampleState, cmd ) =
Examples.ClickableText.update msg moduleStates.clickableTextExampleState
in
( { moduleStates | clickableTextExampleState = clickableTextExampleState }
, Cmd.map ClickableTextExampleMsg cmd
)
2018-06-20 18:06:11 +03:00
CheckboxExampleMsg msg ->
let
( checkboxExampleState, cmd ) =
Examples.Checkbox.update msg moduleStates.checkboxExampleState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | checkboxExampleState = checkboxExampleState }, Cmd.map CheckboxExampleMsg cmd )
2018-04-30 14:14:20 +03:00
DropdownMsg msg ->
let
( dropdownState, cmd ) =
Examples.Dropdown.update msg moduleStates.dropdownState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | dropdownState = dropdownState }
, Cmd.map DropdownMsg cmd
)
2018-03-24 05:05:34 +03:00
SegmentedControlMsg msg ->
let
( segmentedControlState, cmd ) =
Examples.SegmentedControl.update msg moduleStates.segmentedControlState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | segmentedControlState = segmentedControlState }
, Cmd.map SegmentedControlMsg cmd
)
2018-03-24 05:05:34 +03:00
2018-04-17 01:39:57 +03:00
SelectMsg msg ->
let
( selectState, cmd ) =
Examples.Select.update msg moduleStates.selectState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | selectState = selectState }
, Cmd.map SelectMsg cmd
)
2018-04-17 01:39:57 +03:00
2018-02-13 00:32:38 +03:00
ShowItWorked group message ->
let
_ =
Debug.log group message
in
2018-06-20 23:15:33 +03:00
( moduleStates, Cmd.none )
2018-03-01 02:51:49 +03:00
TableExampleMsg msg ->
let
( tableExampleState, cmd ) =
Examples.Table.update msg moduleStates.tableExampleState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | tableExampleState = tableExampleState }
, Cmd.map TableExampleMsg cmd
)
2018-03-01 02:51:49 +03:00
TextAreaExampleMsg msg ->
let
( textAreaExampleState, cmd ) =
TextAreaExample.update msg moduleStates.textAreaExampleState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | textAreaExampleState = textAreaExampleState }
, Cmd.map TextAreaExampleMsg cmd
)
2018-02-13 00:32:38 +03:00
2018-05-25 21:16:54 +03:00
TextInputExampleMsg msg ->
let
( textInputExampleState, cmd ) =
TextInputExample.update msg moduleStates.textInputExampleState
in
2018-06-20 23:15:33 +03:00
( { moduleStates | textInputExampleState = textInputExampleState }
, Cmd.map TextInputExampleMsg cmd
)
2018-05-25 21:16:54 +03:00
DisclosureIndicatorExampleMsg msg ->
let
( disclosureIndicatorExampleState, cmd ) =
Examples.DisclosureIndicator.update msg moduleStates.disclosureIndicatorExampleState
in
( { moduleStates | disclosureIndicatorExampleState = disclosureIndicatorExampleState }
, Cmd.map DisclosureIndicatorExampleMsg cmd
)
2018-08-29 22:09:22 +03:00
ModalExampleMsg msg ->
let
( modalExampleState, cmd ) =
Examples.Modal.update msg moduleStates.modalExampleState
in
( { moduleStates | modalExampleState = modalExampleState }
, Cmd.map ModalExampleMsg cmd
)
2019-04-05 04:30:12 +03:00
SlideModalExampleMsg msg ->
let
( slideModalExampleState, cmd ) =
Examples.SlideModal.update msg moduleStates.slideModalExampleState
in
( { moduleStates | slideModalExampleState = slideModalExampleState }
, Cmd.map SlideModalExampleMsg cmd
)
2019-04-11 22:54:14 +03:00
SlideExampleMsg msg ->
let
( slideExampleState, cmd ) =
Examples.Slide.update msg moduleStates.slideExampleState
in
( { moduleStates | slideExampleState = slideExampleState }
, Cmd.map SlideExampleMsg cmd
)
2019-07-11 22:46:22 +03:00
SortableTableMsg msg ->
let
( sortableTableState, cmd ) =
Examples.SortableTable.update msg moduleStates.sortableTableState
in
( { moduleStates | sortableTableState = sortableTableState }
, Cmd.map SortableTableMsg cmd
)
TabsExampleMsg tab ->
( { moduleStates | tabsExampleState = tab }
, Cmd.none
)
2018-02-13 00:32:38 +03:00
NoOp ->
( moduleStates, Cmd.none )
subscriptions : ModuleStates -> Sub Msg
subscriptions moduleStates =
Sub.batch
[ Sub.map ModalExampleMsg (Examples.Modal.subscriptions moduleStates.modalExampleState)
]
2018-02-13 00:32:38 +03:00
{-| A container with a visually-apparent size for demonstrating how style guide components
fill their parents.
-}
container : Int -> List (Html msg) -> Html msg
container width children =
Html.div
[ Html.Attributes.class "demo-container"
, style "width" (Debug.toString width ++ "px")
2018-02-13 00:32:38 +03:00
]
children
nriThemedModules : ModuleStates -> List (ModuleExample Msg)
nriThemedModules model =
2018-08-16 01:05:55 +03:00
[ Examples.Alert.example
2019-05-23 00:38:11 +03:00
, Examples.BannerAlert.example BannerAlertExampleMsg model.bannerAlertExampleState
2019-03-28 02:56:54 +03:00
, Examples.Button.example (exampleMessages ButtonExampleMsg) model.buttonExampleState
2019-08-20 20:38:24 +03:00
, Examples.Callout.example
, Examples.ClickableText.example (exampleMessages ClickableTextExampleMsg) model.clickableTextExampleState
2018-06-20 18:06:11 +03:00
, Examples.Checkbox.example CheckboxExampleMsg model.checkboxExampleState
2018-04-30 14:14:20 +03:00
, Examples.Dropdown.example DropdownMsg model.dropdownState
, Examples.AssignmentIcon.example
, Examples.UiIcon.example
, Examples.Icon.example
2018-05-01 18:34:16 +03:00
, Examples.Page.example NoOp
, Examples.SegmentedControl.example SegmentedControlMsg model.segmentedControlState
2018-04-17 01:39:57 +03:00
, Examples.Select.example SelectMsg model.selectState
, Examples.Heading.example
2018-03-24 05:05:34 +03:00
, Examples.Text.example
2018-03-17 01:27:38 +03:00
, Examples.Text.Writing.example
, Examples.Fonts.example
, Examples.Table.example TableExampleMsg model.tableExampleState
2018-03-01 02:51:49 +03:00
, TextAreaExample.example TextAreaExampleMsg model.textAreaExampleState
2018-05-25 21:16:54 +03:00
, TextInputExample.example TextInputExampleMsg model.textInputExampleState
, Examples.DisclosureIndicator.example DisclosureIndicatorExampleMsg model.disclosureIndicatorExampleState
2018-03-17 01:58:00 +03:00
, Examples.Colors.example
2018-08-29 22:09:22 +03:00
, Examples.Modal.example ModalExampleMsg model.modalExampleState
2019-04-05 04:30:12 +03:00
, Examples.SlideModal.example SlideModalExampleMsg model.slideModalExampleState
2019-04-11 22:54:14 +03:00
, Examples.Slide.example SlideExampleMsg model.slideExampleState
2019-07-11 22:46:22 +03:00
, Examples.SortableTable.example SortableTableMsg model.sortableTableState
, Examples.Tabs.example TabsExampleMsg model.tabsExampleState
2018-02-13 00:32:38 +03:00
]
exampleMessages : (msg -> Msg) -> String -> ModuleExample.ModuleMessages msg Msg
exampleMessages exampleMessageWrapper exampleName =
{ noOp = NoOp
, showItWorked = ShowItWorked exampleName
, wrapper = exampleMessageWrapper
}
route : Url -> Maybe String
2018-02-13 00:32:38 +03:00
route location =
location.fragment
|> Maybe.map (String.dropLeft 1)