Merge remote-tracking branch 'origin/master' into bat/fix-heading-level

This commit is contained in:
Tessa Kelly 2022-03-28 14:13:03 -07:00
commit 7cf81c530c
11 changed files with 246 additions and 63 deletions

View File

@ -3,15 +3,20 @@ module Debug.Control.View exposing (codeFromList, view)
import Css exposing (..)
import Css.Media exposing (withMedia)
import Debug.Control as Control exposing (Control)
import Example
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css)
import Nri.Ui.ClickableText.V3 as ClickableText
import Nri.Ui.Heading.V2 as Heading
import Nri.Ui.MediaQuery.V1 exposing (mobile)
import Url.Builder
{-| -}
view :
{ update : Control a -> msg
{ name : String
, version : Int
, update : Control a -> msg
, settings : Control a
, toExampleCode : a -> List { sectionName : String, code : String }
}
@ -31,32 +36,98 @@ view config =
]
[ viewSection "Settings" <|
[ fromUnstyled (Control.view config.update config.settings) ]
, viewExampleCode (config.toExampleCode value)
, viewExampleCode config (config.toExampleCode value)
]
viewExampleCode : List { sectionName : String, code : String } -> Html msg
viewExampleCode values =
viewExampleCode :
{ component | name : String, version : Int }
-> List { sectionName : String, code : String }
-> Html msg
viewExampleCode component values =
viewSection "Generated Code" <|
List.concatMap
(\{ sectionName, code } ->
[ details []
(\example ->
[ details
[]
[ summary []
[ Heading.h4
[ Heading.css [ Css.display Css.inline ]
]
[ text sectionName ]
[ text example.sectionName ]
]
, Html.Styled.code
[ css [ whiteSpace preWrap ]
, ClickableText.link ("View " ++ example.sectionName ++ " example on Ellie")
[ ClickableText.linkExternal (generateEllieLink component example)
, ClickableText.small
]
[ text code ]
, code
[ css
[ display block
, whiteSpace preWrap
, Css.marginTop (px 8)
]
]
[ text example.code ]
]
]
)
values
generateEllieLink : { component | name : String, version : Int } -> { sectionName : String, code : String } -> String
generateEllieLink component { sectionName, code } =
Url.Builder.crossOrigin "https://ellie-app.com/a/example/v1"
[]
[ Url.Builder.string "title" (component.name ++ " | " ++ sectionName)
, Url.Builder.string "elmcode" (generateElmExampleModule component code)
, Url.Builder.string "htmlcode" ellieHtmlSetup
, -- At some point, a system of some kind will be required to keep these values
-- in line with the allowed elm json values.
-- I think in most cases, the API to use a noredink-ui component should require _only_ the following
-- packages. Feel free to add packages if it seems necessary!
Url.Builder.string "packages" "elm/core@1.0.5"
, Url.Builder.string "packages" "elm/html@1.0.0"
, Url.Builder.string "packages" "rtfeldman/elm-css@17.0.5"
, Url.Builder.string "packages" "NoRedInk/noredink-ui@15.8.1"
, Url.Builder.string "packages" "pablohirafuji/elm-markdown@2.0.5"
, Url.Builder.string "elmversion" "0.19.1"
]
generateElmExampleModule : { component | name : String, version : Int } -> String -> String
generateElmExampleModule component code =
[ "module Main exposing (main)"
, ""
, "import Css exposing (Style)"
, "import Html as RootHtml"
, "import Html.Styled exposing (..)"
, "import Nri.Ui.Colors.V1 as Colors"
, "import Nri.Ui.UiIcon.V1 as UiIcon"
, "import " ++ Example.fullName component ++ " as " ++ component.name
, ""
, "main : RootHtml.Html msg"
, "main ="
, " " ++ code
, " |> toUnstyled"
]
|> String.join "\n"
|> String.replace "\t" " "
ellieHtmlSetup : String
ellieHtmlSetup =
"""
<html> <head></head>
<body>
<main></main>
<script>
var app = Elm.Main.init({ node: document.querySelector('main') })
</script>
</body>
</html>
"""
viewSection : String -> List (Html msg) -> Html msg
viewSection name children =
section [ css [ flex (int 1) ] ]

View File

@ -1,4 +1,4 @@
module Example exposing (Example, preview, view, wrapMsg, wrapState)
module Example exposing (Example, fullName, preview, view, wrapMsg, wrapState)
import Accessibility.Styled.Aria as Aria
import Accessibility.Styled.Style as Style
@ -31,7 +31,7 @@ type alias Example state msg =
}
fullName : Example state msg -> String
fullName : { example | version : Int, name : String } -> String
fullName example =
"Nri.Ui." ++ example.name ++ ".V" ++ String.fromInt example.version

View File

@ -15,11 +15,21 @@ import Html.Styled exposing (Html, fromUnstyled, text)
import Nri.Ui.Balloon.V1 as Balloon
moduleName : String
moduleName =
"Balloon"
version : Int
version =
1
{-| -}
example : Example State Msg
example =
{ name = "Balloon"
, version = 1
{ name = moduleName
, version = version
, categories = [ Messaging ]
, keyboardSupport = []
, state = init
@ -132,7 +142,9 @@ view state =
in
[ Control.view SetCopy state.copy |> fromUnstyled
, ControlView.view
{ update = SetAttributes
{ name = moduleName
, version = version
, update = SetAttributes
, settings = state.attributes
, toExampleCode =
\attrs ->

View File

@ -22,11 +22,16 @@ import Nri.Ui.UiIcon.V1 as UiIcon
import Set exposing (Set)
version : Int
version =
10
{-| -}
example : Example State Msg
example =
{ name = "Button"
, version = 10
{ name = moduleName
, version = version
, state = init
, update = update
, subscriptions = \_ -> Sub.none
@ -60,6 +65,11 @@ example =
}
moduleName : String
moduleName =
"Button"
{-| -}
type alias State =
{ debugControlsState : Control Model
@ -137,9 +147,9 @@ initDebugControls =
|> Control.field "label" (Control.string "Label")
|> Control.field "attributes"
(ControlExtra.list
|> CommonControls.icon "Button" Button.icon
|> CommonControls.icon moduleName Button.icon
|> ControlExtra.optionalListItem "width"
(CommonControls.choice "Button"
(CommonControls.choice moduleName
[ ( "exactWidth 120", Button.exactWidth 120 )
, ( "exactWidth 70", Button.exactWidth 70 )
, ( "boundedWidth 100 180", Button.boundedWidth { min = 100, max = 180 } )
@ -148,7 +158,7 @@ initDebugControls =
]
)
|> ControlExtra.optionalListItem "state (button only)"
(CommonControls.choice "Button"
(CommonControls.choice moduleName
[ ( "enabled", Button.enabled )
, ( "disabled", Button.disabled )
, ( "error", Button.error )
@ -160,19 +170,19 @@ initDebugControls =
|> ControlExtra.optionalBoolListItem "hideIconForMobile"
( "Button.hideIconForMobile", Button.hideIconForMobile )
|> CommonControls.css
{ moduleName = "Button"
{ moduleName = moduleName
, use = Button.css
}
|> CommonControls.mobileCss
{ moduleName = "Button"
{ moduleName = moduleName
, use = Button.mobileCss
}
|> CommonControls.quizEngineMobileCss
{ moduleName = "Button"
{ moduleName = moduleName
, use = Button.quizEngineMobileCss
}
|> CommonControls.notMobileCss
{ moduleName = "Button"
{ moduleName = moduleName
, use = Button.notMobileCss
}
)
@ -185,17 +195,20 @@ viewButtonExamples state =
Control.currentValue state.debugControlsState
in
[ ControlView.view
{ update = SetDebugControlsState
{ name = moduleName
, version = version
, update = SetDebugControlsState
, settings = state.debugControlsState
, toExampleCode =
\{ label, attributes } ->
let
toCode fName =
"Button."
moduleName
++ "."
++ fName
++ " \""
++ label
++ "\"\n\t"
++ "\"\t"
++ ControlView.codeFromList attributes
in
[ { sectionName = "Button"

View File

@ -24,11 +24,16 @@ import Nri.Ui.Tooltip.V2 as Tooltip
import Nri.Ui.UiIcon.V1 as UiIcon
version : Int
version =
2
{-| -}
example : Example State Msg
example =
{ name = "ClickableSvg"
, version = 2
{ name = moduleName
, version = version
, categories = [ Buttons, Icons ]
, keyboardSupport = []
, state = init
@ -54,13 +59,16 @@ example =
, view =
\state ->
[ ControlView.view
{ update = SetControls
{ name = moduleName
, version = version
, update = SetControls
, settings = state.settings
, toExampleCode =
\{ label, icon, attributes } ->
let
toCode fName =
"ClickableSvg."
moduleName
++ "."
++ fName
++ " \""
++ label
@ -119,6 +127,11 @@ Tooltip.view
}
moduleName : String
moduleName =
"ClickableSvg"
viewExampleTable : Settings Msg -> Html Msg
viewExampleTable { label, icon, attributes } =
let

View File

@ -21,11 +21,16 @@ import Nri.Ui.Text.V6 as Text
import Nri.Ui.UiIcon.V1 as UiIcon
version : Int
version =
3
{-| -}
example : Example State Msg
example =
{ name = "ClickableText"
, version = 3
{ name = moduleName
, version = version
, state = init
, update = update
, subscriptions = \_ -> Sub.none
@ -52,6 +57,11 @@ example =
}
moduleName : String
moduleName =
"ClickableText"
{-| -}
type State
= State (Control (Settings Msg))
@ -64,25 +74,25 @@ init =
|> Control.field "label" (Control.string "Clickable Text")
|> Control.field "attributes"
(ControlExtra.list
|> CommonControls.icon "ClickableText" ClickableText.icon
|> CommonControls.icon moduleName ClickableText.icon
|> ControlExtra.optionalBoolListItem "hideIconForMobile"
( "ClickableText.hideIconForMobile", ClickableText.hideIconForMobile )
|> ControlExtra.optionalBoolListItem "hideTextForMobile"
( "ClickableText.hideTextForMobile", ClickableText.hideTextForMobile )
|> CommonControls.css
{ moduleName = "ClickableText"
{ moduleName = moduleName
, use = ClickableText.css
}
|> CommonControls.mobileCss
{ moduleName = "ClickableText"
{ moduleName = moduleName
, use = ClickableText.mobileCss
}
|> CommonControls.quizEngineMobileCss
{ moduleName = "ClickableText"
{ moduleName = moduleName
, use = ClickableText.quizEngineMobileCss
}
|> CommonControls.notMobileCss
{ moduleName = "ClickableText"
{ moduleName = moduleName
, use = ClickableText.notMobileCss
}
)
@ -126,7 +136,9 @@ viewExamples (State control) =
List.map Tuple.second settings.attributes
in
[ ControlView.view
{ update = SetState
{ name = moduleName
, version = version
, update = SetState
, settings = control
, toExampleCode =
\{ label, attributes } ->
@ -156,7 +168,7 @@ viewExamples (State control) =
, text " and clickable buttons: "
, ClickableText.button settings.label
(ClickableText.small
:: ClickableText.onClick (ShowItWorked "ClickableText" "in-line button")
:: ClickableText.onClick (ShowItWorked moduleName "in-line button")
:: clickableAttributes
)
, text " to show up in-line."
@ -192,7 +204,7 @@ buttons settings =
(\( size, sizeLabel ) ->
ClickableText.button settings.label
(size
:: ClickableText.onClick (ShowItWorked "ClickableText" sizeLabel)
:: ClickableText.onClick (ShowItWorked moduleName sizeLabel)
:: List.map Tuple.second settings.attributes
)
|> exampleCell

View File

@ -19,11 +19,21 @@ import Nri.Ui.Container.V2 as Container
import Nri.Ui.Heading.V2 as Heading
moduleName : String
moduleName =
"Container"
version : Int
version =
2
{-| -}
example : Example State Msg
example =
{ name = "Container"
, version = 2
{ name = moduleName
, version = version
, categories = [ Layout ]
, keyboardSupport = []
, state = init
@ -47,7 +57,9 @@ example =
List.map Tuple.second (Control.currentValue state.control)
in
[ ControlView.view
{ update = UpdateControl
{ name = moduleName
, version = version
, update = UpdateControl
, settings = state.control
, toExampleCode =
\settings ->
@ -124,7 +136,8 @@ viewExample { name, description } attributes =
viewExampleCode : List String -> String
viewExampleCode attributes =
"Container.view\n [ "
moduleName
++ ".view\n [ "
++ String.join "\n , " attributes
++ "\n ]"

View File

@ -18,11 +18,21 @@ import Nri.Ui.DisclosureIndicator.V2 as DisclosureIndicator
import Nri.Ui.Text.V6 as Text
moduleName : String
moduleName =
"DisclosureIndicator"
version : Int
version =
2
{-| -}
example : Example State Msg
example =
{ name = "DisclosureIndicator"
, version = 2
{ name = moduleName
, version = version
, categories = [ Icons ]
, keyboardSupport = []
, state = init
@ -42,13 +52,16 @@ example =
in
[ Text.smallBodyGray [ Text.plaintext "The disclosure indicator is only the caret. It is NOT a button -- you must create a button or clickabletext yourself!" ]
, ControlView.view
{ update = UpdateSettings
{ name = moduleName
, version = version
, update = UpdateSettings
, settings = state.settings
, toExampleCode =
\settings ->
let
toCode viewName =
"DisclosureIndicator."
moduleName
++ "."
++ viewName
++ " "
++ Tuple.first settings.css

View File

@ -14,6 +14,11 @@ import Nri.Ui.Message.V3 as Message
import ViewHelpers exposing (viewExamples)
version : Int
version =
3
type alias State =
{ show : Bool
, control : Control (List ( String, Message.Attribute Msg ))
@ -28,7 +33,7 @@ init =
|> ControlExtra.optionalListItem "theme" controlTheme
|> ControlExtra.listItem "content"
(CommonControls.content
{ moduleName = "Message"
{ moduleName = moduleName
, plaintext = Message.plaintext
, markdown = Just Message.markdown
, html = Message.html
@ -42,24 +47,29 @@ init =
|> ControlExtra.optionalBoolListItem "hideIconForMobile"
( "Message.hideIconForMobile", Message.hideIconForMobile )
|> CommonControls.css
{ moduleName = "Message"
{ moduleName = moduleName
, use = Message.css
}
|> CommonControls.mobileCss
{ moduleName = "Message"
{ moduleName = moduleName
, use = Message.mobileCss
}
|> CommonControls.quizEngineMobileCss
{ moduleName = "Message"
{ moduleName = moduleName
, use = Message.quizEngineMobileCss
}
|> CommonControls.notMobileCss
{ moduleName = "Message"
{ moduleName = moduleName
, use = Message.notMobileCss
}
}
moduleName : String
moduleName =
"Message"
controlTheme : Control ( String, Message.Attribute msg )
controlTheme =
Control.choice
@ -117,7 +127,7 @@ update msg state =
example : Example State Msg
example =
{ name = "Message"
, version = 3
, version = version
, categories = [ Messaging ]
, keyboardSupport = []
, state = init
@ -142,7 +152,9 @@ example =
text "Nice! The messages were dismissed. 👍"
in
[ ControlView.view
{ update = UpdateControl
{ name = moduleName
, version = version
, update = UpdateControl
, settings = state.control
, toExampleCode =
\settings ->

View File

@ -19,11 +19,16 @@ import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.SideNav.V2 as SideNav
version : Int
version =
2
{-| -}
example : Example State Msg
example =
{ name = "SideNav"
, version = 2
{ name = moduleName
, version = version
, state = init
, update = update
, subscriptions = \_ -> Sub.none
@ -34,6 +39,11 @@ example =
}
moduleName : String
moduleName =
"SideNav"
viewPreview : Html msg
viewPreview =
div
@ -72,14 +82,16 @@ view state =
Control.currentValue state.settings
in
[ ControlView.view
{ update = SetControls
{ name = moduleName
, version = version
, update = SetControls
, settings = state.settings
, toExampleCode =
\{ entries } ->
[ { sectionName = "View"
, code =
String.join ""
[ "SideNav.view"
[ moduleName ++ ".view"
, "\n\t{ isCurrentRoute = (==) \"" ++ settings.currentRoute ++ "\""
, "\n\t, routeToString = identity"
, "\n\t, onSkipNav = SkipToContent"

View File

@ -24,10 +24,15 @@ import Nri.Ui.Tooltip.V2 as Tooltip
import Nri.Ui.UiIcon.V1 as UiIcon
version : Int
version =
2
example : Example State Msg
example =
{ name = "Tooltip"
, version = 2
{ name = moduleName
, version = version
, categories = [ Messaging ]
, keyboardSupport = []
, state = init
@ -63,6 +68,11 @@ example =
}
moduleName : String
moduleName =
"Tooltip"
type alias State =
{ openTooltip : Maybe TooltipType
, staticExampleSettings : Control (List ( String, Tooltip.Attribute Never ))
@ -270,7 +280,9 @@ viewCustomizableExample : Control (List ( String, Tooltip.Attribute Never )) ->
viewCustomizableExample controlSettings =
Html.div []
[ ControlView.view
{ update = SetControl
{ name = moduleName
, version = version
, update = SetControl
, settings = controlSettings
, toExampleCode =
\controls ->