2022-04-19 04:57:22 +03:00
|
|
|
module Debug.Control.View exposing (codeFromList, codeFromListWithHardcoded, codeFromListWithIndentLevel, view)
|
2022-03-04 22:21:34 +03:00
|
|
|
|
|
|
|
import Css exposing (..)
|
2022-03-05 04:26:27 +03:00
|
|
|
import Css.Media exposing (withMedia)
|
2022-03-04 22:21:34 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2022-03-29 18:52:58 +03:00
|
|
|
import EllieLink
|
2022-03-23 23:24:19 +03:00
|
|
|
import Example
|
2022-03-04 22:21:34 +03:00
|
|
|
import Html.Styled exposing (..)
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2022-03-05 04:26:27 +03:00
|
|
|
import Nri.Ui.MediaQuery.V1 exposing (mobile)
|
2022-03-25 21:39:05 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2022-03-04 22:21:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
view :
|
2022-03-29 20:19:32 +03:00
|
|
|
{ ellieLinkConfig : EllieLink.Config
|
|
|
|
, name : String
|
2022-03-24 02:05:50 +03:00
|
|
|
, version : Int
|
2022-03-23 23:13:19 +03:00
|
|
|
, update : Control a -> msg
|
2022-03-04 22:21:34 +03:00
|
|
|
, settings : Control a
|
2022-04-13 03:08:59 +03:00
|
|
|
, mainType : String
|
2022-04-13 03:32:46 +03:00
|
|
|
, extraImports : List String
|
2022-03-04 22:21:34 +03:00
|
|
|
, toExampleCode : a -> List { sectionName : String, code : String }
|
|
|
|
}
|
|
|
|
-> Html msg
|
|
|
|
view config =
|
|
|
|
let
|
|
|
|
value =
|
|
|
|
Control.currentValue config.settings
|
2022-03-29 20:19:32 +03:00
|
|
|
|
|
|
|
ellieLink =
|
|
|
|
EllieLink.view config.ellieLinkConfig
|
2022-03-04 22:21:34 +03:00
|
|
|
in
|
2022-03-05 04:26:27 +03:00
|
|
|
div
|
|
|
|
[ css
|
|
|
|
[ displayFlex
|
|
|
|
, Css.flexWrap Css.wrap
|
|
|
|
, Css.property "gap" "10px"
|
|
|
|
, withMedia [ mobile ] [ flexDirection column, alignItems stretch ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[ viewSection "Settings" <|
|
|
|
|
[ fromUnstyled (Control.view config.update config.settings) ]
|
2022-03-29 20:19:32 +03:00
|
|
|
, viewExampleCode ellieLink config (config.toExampleCode value)
|
2022-03-04 22:21:34 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-23 23:24:19 +03:00
|
|
|
viewExampleCode :
|
2022-03-29 20:19:32 +03:00
|
|
|
(EllieLink.SectionExample -> Html msg)
|
2022-04-13 03:32:46 +03:00
|
|
|
-> { component | name : String, version : Int, mainType : String, extraImports : List String }
|
2022-03-24 02:05:50 +03:00
|
|
|
-> List { sectionName : String, code : String }
|
2022-03-23 23:24:19 +03:00
|
|
|
-> Html msg
|
2022-03-29 20:19:32 +03:00
|
|
|
viewExampleCode ellieLink component values =
|
2022-03-25 21:22:20 +03:00
|
|
|
viewSection "Code Sample" <|
|
2022-03-25 21:39:05 +03:00
|
|
|
Text.smallBodyGray
|
|
|
|
[ Text.plaintext "😎 Configure the \"Settings\" on this page to update the code sample, then paste it into your editor!"
|
|
|
|
]
|
|
|
|
:: List.concatMap
|
|
|
|
(\example ->
|
|
|
|
[ details
|
|
|
|
[]
|
|
|
|
[ summary []
|
2022-04-14 22:30:07 +03:00
|
|
|
[ Heading.h3
|
2022-03-25 21:39:05 +03:00
|
|
|
[ Heading.css [ Css.display Css.inline ]
|
2022-04-14 23:38:33 +03:00
|
|
|
, Heading.style Heading.Small
|
2022-03-25 21:39:05 +03:00
|
|
|
]
|
|
|
|
[ text example.sectionName ]
|
2022-03-10 02:11:42 +03:00
|
|
|
]
|
2022-03-29 20:19:32 +03:00
|
|
|
, ellieLink
|
|
|
|
{ fullModuleName = Example.fullName component
|
|
|
|
, name = component.name
|
2022-03-29 18:52:58 +03:00
|
|
|
, sectionName = example.sectionName
|
2022-04-13 03:08:59 +03:00
|
|
|
, mainType = component.mainType
|
2022-04-13 03:32:46 +03:00
|
|
|
, extraImports = component.extraImports
|
2022-03-29 18:52:58 +03:00
|
|
|
, code = example.code
|
|
|
|
}
|
2022-03-25 21:39:05 +03:00
|
|
|
, code
|
|
|
|
[ css
|
|
|
|
[ display block
|
|
|
|
, whiteSpace preWrap
|
|
|
|
, Css.marginTop (px 8)
|
|
|
|
]
|
2022-03-24 02:05:50 +03:00
|
|
|
]
|
2022-03-25 21:39:05 +03:00
|
|
|
[ text example.code ]
|
2022-03-10 02:11:42 +03:00
|
|
|
]
|
2022-03-04 22:21:34 +03:00
|
|
|
]
|
2022-03-25 21:39:05 +03:00
|
|
|
)
|
|
|
|
values
|
2022-03-05 04:26:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
viewSection : String -> List (Html msg) -> Html msg
|
|
|
|
viewSection name children =
|
|
|
|
section [ css [ flex (int 1) ] ]
|
2022-04-14 23:38:33 +03:00
|
|
|
(Heading.h2 [ Heading.style Heading.Subhead ] [ text name ]
|
2022-03-05 04:26:27 +03:00
|
|
|
:: children
|
2022-03-04 22:21:34 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-19 04:57:22 +03:00
|
|
|
codeFromListWithHardcoded : List String -> List ( String, a ) -> String
|
|
|
|
codeFromListWithHardcoded hardcodes elements =
|
|
|
|
List.map (\v -> ( v, () )) hardcodes
|
|
|
|
++ List.map (Tuple.mapSecond (always ())) elements
|
|
|
|
|> codeFromList
|
|
|
|
|
|
|
|
|
2022-03-04 22:21:34 +03:00
|
|
|
codeFromList : List ( String, a ) -> String
|
2022-03-25 00:36:18 +03:00
|
|
|
codeFromList =
|
|
|
|
codeFromListWithIndentLevel 1
|
|
|
|
|
|
|
|
|
|
|
|
codeFromListWithIndentLevel : Int -> List ( String, a ) -> String
|
|
|
|
codeFromListWithIndentLevel indent list =
|
|
|
|
let
|
|
|
|
indents =
|
|
|
|
String.repeat indent "\t"
|
|
|
|
in
|
|
|
|
"\n"
|
|
|
|
++ indents
|
|
|
|
++ "[ "
|
|
|
|
++ String.join ("\n" ++ indents ++ ", ") (List.map Tuple.first list)
|
|
|
|
++ "\n"
|
|
|
|
++ indents
|
|
|
|
++ "] "
|