Make a compilable code example for Accordion

This commit is contained in:
Tessa Kelly 2022-04-12 17:08:59 -07:00
parent f65530582f
commit 4918939201
17 changed files with 81 additions and 4 deletions

View File

@ -19,6 +19,7 @@ view :
, version : Int , version : Int
, update : Control a -> msg , update : Control a -> msg
, settings : Control a , settings : Control a
, mainType : String
, toExampleCode : a -> List { sectionName : String, code : String } , toExampleCode : a -> List { sectionName : String, code : String }
} }
-> Html msg -> Html msg
@ -46,7 +47,7 @@ view config =
viewExampleCode : viewExampleCode :
(EllieLink.SectionExample -> Html msg) (EllieLink.SectionExample -> Html msg)
-> { component | name : String, version : Int } -> { component | name : String, version : Int, mainType : String }
-> List { sectionName : String, code : String } -> List { sectionName : String, code : String }
-> Html msg -> Html msg
viewExampleCode ellieLink component values = viewExampleCode ellieLink component values =
@ -68,6 +69,7 @@ viewExampleCode ellieLink component values =
{ fullModuleName = Example.fullName component { fullModuleName = Example.fullName component
, name = component.name , name = component.name
, sectionName = example.sectionName , sectionName = example.sectionName
, mainType = component.mainType
, code = example.code , code = example.code
} }
, code , code

View File

@ -16,6 +16,7 @@ type alias SectionExample =
{ name : String { name : String
, fullModuleName : String , fullModuleName : String
, sectionName : String , sectionName : String
, mainType : String
, code : String , code : String
} }
@ -76,12 +77,13 @@ generateElmExampleModule config example =
, "import Html.Styled exposing (..)" , "import Html.Styled exposing (..)"
, "import Nri.Ui.Colors.V1 as Colors" , "import Nri.Ui.Colors.V1 as Colors"
, "import Nri.Ui.UiIcon.V1 as UiIcon" , "import Nri.Ui.UiIcon.V1 as UiIcon"
, "import Nri.Ui.Svg.V1 as Svg"
, "import " ++ example.fullModuleName ++ " as " ++ example.name , "import " ++ example.fullModuleName ++ " as " ++ example.name
, "" , ""
, "" , ""
] ]
++ maybeErrorMessages ++ maybeErrorMessages
++ [ "main : RootHtml.Html msg" ++ [ "main : " ++ example.mainType
, "main =" , "main ="
, " " ++ example.code , " " ++ example.code
, " |> toUnstyled" , " |> toUnstyled"

View File

@ -13,6 +13,7 @@ module Examples.Accordion exposing
import Accessibility.Styled as Html exposing (Html) import Accessibility.Styled as Html exposing (Html)
import Browser.Dom as Dom import Browser.Dom as Dom
import Category exposing (Category(..)) import Category exposing (Category(..))
import CommonControls
import Css exposing (..) import Css exposing (..)
import Css.Global import Css.Global
import Debug.Control as Control exposing (Control) import Debug.Control as Control exposing (Control)
@ -93,13 +94,58 @@ defaultCaret =
{-| -} {-| -}
view : EllieLink.Config -> State -> List (Html Msg) view : EllieLink.Config -> State -> List (Html Msg)
view ellieLinkConfig model = view ellieLinkConfig model =
let
settings_ =
Control.currentValue model.settings
in
[ ControlView.view [ ControlView.view
{ ellieLinkConfig = ellieLinkConfig { ellieLinkConfig = ellieLinkConfig
, name = moduleName , name = moduleName
, version = version , version = version
, update = UpdateControls , update = UpdateControls
, settings = model.settings , settings = model.settings
, toExampleCode = \settings -> [] , mainType = "RootHtml.Html String"
, toExampleCode =
\settings ->
[ { sectionName = "Basic example"
, code =
String.join "\n"
[ "Accordion.view"
, " { entries ="
, " [ Accordion.AccordionEntry"
, " { caret = " ++ Tuple.first settings.icon
, " , content = \\_ -> text \"TODO\""
, " , entryClass = \"customizable-example\""
, " , headerContent = text \"TODO\""
, " , headerId = \"customizable-example-header\""
, " , headerLevel = Accordion.H4"
, " , isExpanded = True"
, " , toggle = Nothing"
, " }"
, " []"
, " ]"
, " , -- When using Accordion, be sure to wire up Focus management correctly!"
, " focus = identity"
, " }"
]
}
]
}
, Accordion.view
{ entries =
[ AccordionEntry
{ caret = Tuple.second settings_.icon
, content = \_ -> Html.text "TODO"
, entryClass = "customizable-example"
, headerContent = Html.text "TODO"
, headerId = "customizable-example-header"
, headerLevel = Accordion.H4
, isExpanded = True
, toggle = Nothing
}
[]
]
, focus = Focus
} }
, Accordion.view , Accordion.view
{ entries = { entries =
@ -286,12 +332,25 @@ type alias State =
type alias Settings = type alias Settings =
{} { icon : ( String, Bool -> Html Msg )
}
initSettings : Control Settings initSettings : Control Settings
initSettings = initSettings =
Control.record Settings Control.record Settings
|> Control.field "icon" controlIcon
controlIcon : Control ( String, Bool -> Html Msg )
controlIcon =
Control.map
(\( code, icon ) ->
( "\\_ -> Svg.toHtml " ++ code
, \_ -> Svg.toHtml icon
)
)
CommonControls.uiIcon
type Msg type Msg

View File

@ -148,6 +148,7 @@ view ellieLinkConfig state =
, version = version , version = version
, update = SetAttributes , update = SetAttributes
, settings = state.attributes , settings = state.attributes
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\attrs -> \attrs ->
[ { sectionName = "Balloon" [ { sectionName = "Balloon"

View File

@ -201,6 +201,7 @@ viewButtonExamples ellieLinkConfig state =
, version = version , version = version
, update = SetDebugControlsState , update = SetDebugControlsState
, settings = state.debugControlsState , settings = state.debugControlsState
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\{ label, attributes } -> \{ label, attributes } ->
let let

View File

@ -64,6 +64,7 @@ example =
, version = version , version = version
, update = SetControls , update = SetControls
, settings = state.settings , settings = state.settings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\{ label, icon, attributes } -> \{ label, icon, attributes } ->
let let

View File

@ -142,6 +142,7 @@ viewExamples ellieLinkConfig (State control) =
, version = version , version = version
, update = SetState , update = SetState
, settings = control , settings = control
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\{ label, attributes } -> \{ label, attributes } ->
let let

View File

@ -57,6 +57,7 @@ example =
, version = version , version = version
, update = UpdateControl , update = UpdateControl
, settings = state.settings , settings = state.settings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> [ { sectionName = "TODO", code = "TODO" } ] \settings -> [ { sectionName = "TODO", code = "TODO" } ]
} }

View File

@ -62,6 +62,7 @@ example =
, version = version , version = version
, update = UpdateControl , update = UpdateControl
, settings = state.control , settings = state.control
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -57,6 +57,7 @@ example =
, version = version , version = version
, update = UpdateSettings , update = UpdateSettings
, settings = state.settings , settings = state.settings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -63,6 +63,7 @@ example =
, version = version , version = version
, update = UpdateControl , update = UpdateControl
, settings = state.control , settings = state.control
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -86,6 +86,7 @@ view ellieLinkConfig state =
, version = version , version = version
, update = UpdateControls , update = UpdateControls
, settings = state.settings , settings = state.settings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -157,6 +157,7 @@ example =
, version = version , version = version
, update = UpdateControl , update = UpdateControl
, settings = state.control , settings = state.control
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -69,6 +69,7 @@ example =
, version = version , version = version
, update = ChangeOptions , update = ChangeOptions
, settings = state.optionsControl , settings = state.optionsControl
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
[ { sectionName = "view" [ { sectionName = "view"

View File

@ -88,6 +88,7 @@ view ellieLinkConfig state =
, version = version , version = version
, update = SetControls , update = SetControls
, settings = state.settings , settings = state.settings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\{ entries } -> \{ entries } ->
[ { sectionName = "View" [ { sectionName = "View"

View File

@ -58,6 +58,7 @@ example =
, version = version , version = version
, update = UpdateControl , update = UpdateControl
, settings = state.control , settings = state.control
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\settings -> \settings ->
let let

View File

@ -286,6 +286,7 @@ viewCustomizableExample ellieLinkConfig controlSettings =
, version = version , version = version
, update = SetControl , update = SetControl
, settings = controlSettings , settings = controlSettings
, mainType = "RootHtml.Html msg"
, toExampleCode = , toExampleCode =
\controls -> \controls ->
[ { sectionName = "Example" [ { sectionName = "Example"