2022-03-05 02:12:31 +03:00
|
|
|
|
module CommonControls exposing
|
|
|
|
|
( css, mobileCss, quizEngineMobileCss, notMobileCss
|
2022-03-05 04:04:56 +03:00
|
|
|
|
, choice
|
2022-03-10 02:01:06 +03:00
|
|
|
|
, icon, iconNotCheckedByDefault, uiIcon
|
2022-03-10 02:07:57 +03:00
|
|
|
|
, content
|
2022-03-15 21:06:13 +03:00
|
|
|
|
, romeoAndJulietQuotation, httpError
|
|
|
|
|
, disabledListItem, premiumDisplay
|
2022-03-05 02:12:31 +03:00
|
|
|
|
)
|
2021-05-14 23:01:02 +03:00
|
|
|
|
|
2022-03-05 02:12:31 +03:00
|
|
|
|
{-|
|
|
|
|
|
|
|
|
|
|
@docs css, mobileCss, quizEngineMobileCss, notMobileCss
|
2022-03-05 04:04:56 +03:00
|
|
|
|
@docs choice
|
2022-03-10 02:01:06 +03:00
|
|
|
|
@docs icon, iconNotCheckedByDefault, uiIcon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Content
|
|
|
|
|
|
2022-03-10 02:07:57 +03:00
|
|
|
|
@docs content
|
2022-03-15 21:06:13 +03:00
|
|
|
|
@docs romeoAndJulietQuotation, httpError
|
2022-03-05 02:12:31 +03:00
|
|
|
|
|
|
|
|
|
-}
|
2021-05-14 23:01:02 +03:00
|
|
|
|
|
2022-03-05 01:21:02 +03:00
|
|
|
|
import Css
|
2021-05-14 23:01:02 +03:00
|
|
|
|
import Debug.Control as Control exposing (Control)
|
2022-03-05 00:51:31 +03:00
|
|
|
|
import Debug.Control.Extra as ControlExtra
|
2021-10-27 22:19:29 +03:00
|
|
|
|
import Html.Styled as Html exposing (Html)
|
2021-05-14 23:01:02 +03:00
|
|
|
|
import Http
|
2022-03-10 02:26:42 +03:00
|
|
|
|
import Nri.Ui.ClickableText.V3 as ClickableText
|
2022-03-10 04:16:13 +03:00
|
|
|
|
import Nri.Ui.Colors.V1 as Colors
|
2022-03-10 22:18:14 +03:00
|
|
|
|
import Nri.Ui.Data.PremiumDisplay as PremiumDisplay exposing (PremiumDisplay)
|
2022-03-05 00:43:01 +03:00
|
|
|
|
import Nri.Ui.Svg.V1 exposing (Svg)
|
|
|
|
|
import Nri.Ui.UiIcon.V1 as UiIcon
|
2021-11-22 22:01:46 +03:00
|
|
|
|
|
|
|
|
|
|
2022-03-07 23:15:01 +03:00
|
|
|
|
premiumDisplay : Control ( String, PremiumDisplay )
|
|
|
|
|
premiumDisplay =
|
|
|
|
|
Control.choice
|
2022-03-12 00:54:18 +03:00
|
|
|
|
[ ( "Free", Control.value ( "PremiumDisplay.Free", PremiumDisplay.Free ) )
|
|
|
|
|
, ( "Premium Locked", Control.value ( "PremiumDisplay.PremiumLocked", PremiumDisplay.PremiumLocked ) )
|
|
|
|
|
, ( "Premium Unlocked", Control.value ( "PremiumDisplay.PremiumUnlocked", PremiumDisplay.PremiumUnlocked ) )
|
2022-03-07 23:15:01 +03:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2021-05-14 23:01:02 +03:00
|
|
|
|
httpError : Control Http.Error
|
|
|
|
|
httpError =
|
|
|
|
|
Control.choice
|
|
|
|
|
[ ( "Bad Url", Control.value (Http.BadUrl "/request-url") )
|
|
|
|
|
, ( "Timeout", Control.value Http.Timeout )
|
|
|
|
|
, ( "Network Error", Control.value Http.NetworkError )
|
|
|
|
|
, ( "Bad Status: 401", Control.value (Http.BadStatus 401) )
|
|
|
|
|
, ( "Bad Status: 404", Control.value (Http.BadStatus 404) )
|
|
|
|
|
, ( "Bad Status: ???", Control.value (Http.BadStatus 500) )
|
|
|
|
|
, ( "Bad Body (often, a JSON decoding problem)"
|
|
|
|
|
, Control.value
|
|
|
|
|
(Http.BadBody
|
|
|
|
|
"""
|
|
|
|
|
The Json.Decode.oneOf at json.draft failed in the following 2 ways:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(1) Problem with the given value:
|
|
|
|
|
|
|
|
|
|
null
|
|
|
|
|
|
|
|
|
|
Expecting an OBJECT with a field named `content`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(2) Problem with the given value:
|
|
|
|
|
|
|
|
|
|
null
|
|
|
|
|
|
|
|
|
|
Expecting an OBJECT with a field named `code`
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
]
|
2021-10-27 22:19:29 +03:00
|
|
|
|
|
|
|
|
|
|
2022-03-10 02:07:57 +03:00
|
|
|
|
content :
|
|
|
|
|
{ moduleName : String
|
|
|
|
|
, plaintext : String -> attribute
|
2022-03-18 03:30:50 +03:00
|
|
|
|
, markdown : Maybe (String -> attribute)
|
2022-03-10 02:07:57 +03:00
|
|
|
|
, html : List (Html msg) -> attribute
|
2022-03-10 02:59:41 +03:00
|
|
|
|
, httpError : Maybe (Http.Error -> attribute)
|
2022-03-10 02:07:57 +03:00
|
|
|
|
}
|
|
|
|
|
-> Control ( String, attribute )
|
|
|
|
|
content ({ moduleName } as config) =
|
|
|
|
|
Control.choice
|
2022-03-10 02:59:41 +03:00
|
|
|
|
([ ( "plain text (short)"
|
|
|
|
|
, Control.string quickBrownFox
|
2022-03-10 02:07:57 +03:00
|
|
|
|
|> Control.map
|
|
|
|
|
(\str ->
|
|
|
|
|
( moduleName ++ ".plaintext \"" ++ str ++ "\""
|
|
|
|
|
, config.plaintext str
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-03-10 02:59:41 +03:00
|
|
|
|
)
|
|
|
|
|
, ( "plain text (long, no newlines)"
|
|
|
|
|
, Control.string longPangrams
|
2022-03-10 02:07:57 +03:00
|
|
|
|
|> Control.map
|
|
|
|
|
(\str ->
|
|
|
|
|
( moduleName ++ ".plaintext \"" ++ str ++ "\""
|
|
|
|
|
, config.plaintext str
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-03-10 02:59:41 +03:00
|
|
|
|
)
|
|
|
|
|
, ( "plain text (long, with newlines)"
|
|
|
|
|
, Control.stringTextarea romeoAndJulietQuotation
|
2022-03-10 02:07:57 +03:00
|
|
|
|
|> Control.map
|
|
|
|
|
(\str ->
|
|
|
|
|
( moduleName ++ ".plaintext\n\t\t\"\"\"" ++ str ++ "\t\t\"\"\""
|
|
|
|
|
, config.plaintext str
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-03-10 02:59:41 +03:00
|
|
|
|
)
|
|
|
|
|
]
|
2022-03-18 03:30:50 +03:00
|
|
|
|
++ (case config.markdown of
|
|
|
|
|
Just markdown_ ->
|
|
|
|
|
[ ( "markdown"
|
|
|
|
|
, Control.string markdown
|
|
|
|
|
|> Control.map
|
|
|
|
|
(\str ->
|
|
|
|
|
( moduleName ++ ".markdown \"" ++ str ++ "\""
|
|
|
|
|
, markdown_ str
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
|
[]
|
|
|
|
|
)
|
|
|
|
|
++ ( "HTML"
|
|
|
|
|
, Control.value
|
|
|
|
|
( moduleName ++ ".html [ ... ]"
|
|
|
|
|
, config.html exampleHtml
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
:: (case config.httpError of
|
2022-03-10 02:59:41 +03:00
|
|
|
|
Just httpError_ ->
|
|
|
|
|
[ ( "httpError"
|
|
|
|
|
, Control.map
|
|
|
|
|
(\error ->
|
|
|
|
|
( moduleName ++ ".httpError error"
|
|
|
|
|
, httpError_ error
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
httpError
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
|
[]
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-03-10 02:07:57 +03:00
|
|
|
|
|
|
|
|
|
|
2021-10-27 22:19:29 +03:00
|
|
|
|
quickBrownFox : String
|
|
|
|
|
quickBrownFox =
|
|
|
|
|
"The quick brown fox jumps over the lazy dog."
|
|
|
|
|
|
|
|
|
|
|
2022-03-10 02:01:06 +03:00
|
|
|
|
longPangrams : String
|
|
|
|
|
longPangrams =
|
|
|
|
|
"Waltz, bad nymph, for quick jigs vex. Glib jocks quiz nymph to vex dwarf. Sphinx of black quartz, judge my vow. How vexingly quick daft zebras jump!"
|
|
|
|
|
|
|
|
|
|
|
2021-10-27 22:19:29 +03:00
|
|
|
|
romeoAndJulietQuotation : String
|
|
|
|
|
romeoAndJulietQuotation =
|
|
|
|
|
"""
|
|
|
|
|
Two households, both alike in dignity,
|
|
|
|
|
In fair Verona, where we lay our scene,
|
|
|
|
|
From ancient grudge break to new mutiny,
|
|
|
|
|
Where civil blood makes civil hands unclean.
|
|
|
|
|
From forth the fatal loins of these two foes
|
|
|
|
|
A pair of star-cross’d lovers take their life;
|
|
|
|
|
Whose misadventured piteous overthrows
|
|
|
|
|
Do with their death bury their parents’ strife.
|
|
|
|
|
The fearful passage of their death-mark’d love,
|
|
|
|
|
And the continuance of their parents’ rage,
|
|
|
|
|
Which, but their children’s end, nought could remove,
|
|
|
|
|
Is now the two hours’ traffic of our stage;
|
|
|
|
|
The which if you with patient ears attend,
|
|
|
|
|
What here shall miss, our toil shall strive to mend.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2022-03-10 02:01:06 +03:00
|
|
|
|
markdown : String
|
|
|
|
|
markdown =
|
|
|
|
|
"_Katie's dad suggests:_ Don't tip too much, or your waitress will **fall over**!"
|
|
|
|
|
|
|
|
|
|
|
2021-10-27 22:19:29 +03:00
|
|
|
|
exampleHtml : List (Html msg)
|
|
|
|
|
exampleHtml =
|
|
|
|
|
[ Html.text "This is a "
|
|
|
|
|
, Html.strong [] [ Html.text "bolded phrase" ]
|
|
|
|
|
, Html.text ". "
|
2022-03-10 02:26:42 +03:00
|
|
|
|
, ClickableText.link quickBrownFox
|
|
|
|
|
[ ClickableText.small
|
|
|
|
|
, ClickableText.icon UiIcon.starFilled
|
|
|
|
|
, ClickableText.href "http://www.noredink.com"
|
2021-10-27 22:19:29 +03:00
|
|
|
|
]
|
|
|
|
|
, Html.text " When I stepped out, into the bright sunlight from the darkness of the movie house, I had only two things on my mind: Paul Newman, and a ride home."
|
|
|
|
|
]
|
2022-03-05 00:43:01 +03:00
|
|
|
|
|
|
|
|
|
|
2022-03-05 04:13:22 +03:00
|
|
|
|
icon :
|
|
|
|
|
String
|
|
|
|
|
-> (Svg -> value)
|
|
|
|
|
-> Control (List ( String, value ))
|
|
|
|
|
-> Control (List ( String, value ))
|
|
|
|
|
icon moduleName f =
|
|
|
|
|
ControlExtra.optionalListItemDefaultChecked "icon"
|
|
|
|
|
(Control.map
|
|
|
|
|
(\( iconName, iconValue ) ->
|
|
|
|
|
( moduleName ++ ".icon " ++ iconName, f iconValue )
|
|
|
|
|
)
|
|
|
|
|
uiIcon
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2022-03-10 02:01:06 +03:00
|
|
|
|
iconNotCheckedByDefault :
|
|
|
|
|
String
|
|
|
|
|
-> (Svg -> value)
|
|
|
|
|
-> Control (List ( String, value ))
|
|
|
|
|
-> Control (List ( String, value ))
|
|
|
|
|
iconNotCheckedByDefault moduleName f =
|
|
|
|
|
ControlExtra.optionalListItem "icon"
|
|
|
|
|
(Control.map
|
|
|
|
|
(\( iconName, iconValue ) ->
|
|
|
|
|
( moduleName ++ ".icon " ++ iconName, f iconValue )
|
|
|
|
|
)
|
|
|
|
|
uiIcon
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2022-03-05 00:43:01 +03:00
|
|
|
|
uiIcon : Control ( String, Svg )
|
|
|
|
|
uiIcon =
|
|
|
|
|
[ ( "arrowLeft", UiIcon.arrowLeft )
|
|
|
|
|
, ( "unarchive", UiIcon.unarchive )
|
|
|
|
|
, ( "share", UiIcon.share )
|
|
|
|
|
, ( "preview", UiIcon.preview )
|
|
|
|
|
, ( "skip", UiIcon.skip )
|
|
|
|
|
, ( "copyToClipboard", UiIcon.copyToClipboard )
|
|
|
|
|
, ( "gift", UiIcon.gift )
|
|
|
|
|
, ( "home", UiIcon.home )
|
|
|
|
|
, ( "library", UiIcon.library )
|
|
|
|
|
, ( "searchInCicle", UiIcon.searchInCicle )
|
|
|
|
|
]
|
2022-03-05 04:04:56 +03:00
|
|
|
|
|> choice "UiIcon"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
choice : String -> List ( String, value ) -> Control ( String, value )
|
|
|
|
|
choice moduleName options =
|
|
|
|
|
options
|
2022-03-05 00:43:01 +03:00
|
|
|
|
|> List.map
|
|
|
|
|
(\( name, value ) ->
|
2022-03-05 04:04:56 +03:00
|
|
|
|
( name, Control.value ( moduleName ++ "." ++ name, value ) )
|
2022-03-05 00:43:01 +03:00
|
|
|
|
)
|
|
|
|
|
|> Control.choice
|
2022-03-05 00:51:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
disabledListItem : String -> (Bool -> b) -> Control (List ( String, b )) -> Control (List ( String, b ))
|
2022-03-10 04:18:15 +03:00
|
|
|
|
disabledListItem moduleName disabled =
|
2022-03-05 00:51:31 +03:00
|
|
|
|
ControlExtra.optionalBoolListItem "disabled"
|
2022-03-10 04:18:15 +03:00
|
|
|
|
( moduleName ++ ".disabled True"
|
|
|
|
|
, disabled True
|
2022-03-05 00:51:31 +03:00
|
|
|
|
)
|
2022-03-05 01:21:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css :
|
2022-03-10 04:16:13 +03:00
|
|
|
|
{ moduleName : String, use : List Css.Style -> b }
|
2022-03-05 02:12:31 +03:00
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
css =
|
|
|
|
|
css_ "css"
|
2022-03-10 04:16:13 +03:00
|
|
|
|
( "[ Css.border3 (Css.px 4) Css.dashed Colors.red ]"
|
|
|
|
|
, [ Css.border3 (Css.px 4) Css.dashed Colors.red ]
|
|
|
|
|
)
|
2022-03-05 02:12:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mobileCss :
|
2022-03-10 04:16:13 +03:00
|
|
|
|
{ moduleName : String, use : List Css.Style -> b }
|
2022-03-05 02:12:31 +03:00
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
mobileCss =
|
|
|
|
|
css_ "mobileCss"
|
2022-03-10 04:16:13 +03:00
|
|
|
|
( "[ Css.border3 (Css.px 4) Css.dotted Colors.orange ]"
|
|
|
|
|
, [ Css.border3 (Css.px 4) Css.dotted Colors.orange ]
|
|
|
|
|
)
|
2022-03-05 02:12:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quizEngineMobileCss :
|
2022-03-10 04:16:13 +03:00
|
|
|
|
{ moduleName : String, use : List Css.Style -> b }
|
2022-03-05 02:12:31 +03:00
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
quizEngineMobileCss =
|
|
|
|
|
css_ "quizEngineMobileCss"
|
2022-03-10 04:16:13 +03:00
|
|
|
|
( "[ Css.border3 (Css.px 4) Css.solid Colors.aqua |> Css.important ]"
|
|
|
|
|
, [ Css.border3 (Css.px 4) Css.solid Colors.aqua |> Css.important ]
|
|
|
|
|
)
|
2022-03-05 02:12:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notMobileCss :
|
2022-03-10 04:16:13 +03:00
|
|
|
|
{ moduleName : String, use : List Css.Style -> b }
|
2022-03-05 02:12:31 +03:00
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
notMobileCss =
|
|
|
|
|
css_ "notMobileCss"
|
2022-03-10 04:16:13 +03:00
|
|
|
|
( "[ Css.backgroundColor Colors.purple ]"
|
|
|
|
|
, [ Css.backgroundColor Colors.purple ]
|
|
|
|
|
)
|
2022-03-05 02:12:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css_ :
|
|
|
|
|
String
|
2022-03-10 04:16:13 +03:00
|
|
|
|
-> ( String, List Css.Style )
|
2022-03-05 02:12:31 +03:00
|
|
|
|
->
|
|
|
|
|
{ moduleName : String
|
|
|
|
|
, use : List Css.Style -> b
|
|
|
|
|
}
|
2022-03-05 01:21:02 +03:00
|
|
|
|
-> Control (List ( String, b ))
|
|
|
|
|
-> Control (List ( String, b ))
|
2022-03-10 04:16:13 +03:00
|
|
|
|
css_ helperName ( styles, default ) { moduleName, use } =
|
2022-03-05 01:21:02 +03:00
|
|
|
|
ControlExtra.optionalListItem helperName
|
2022-03-10 04:16:13 +03:00
|
|
|
|
(Control.value
|
|
|
|
|
( moduleName ++ "." ++ helperName ++ " " ++ styles
|
|
|
|
|
, use default
|
2022-03-05 01:21:02 +03:00
|
|
|
|
)
|
|
|
|
|
)
|