internal config helper

This commit is contained in:
Alex Perkins 2021-11-19 16:32:24 -05:00
parent 0d47f37ab9
commit 6d2085a27d
2 changed files with 42 additions and 21 deletions

View File

@ -269,27 +269,13 @@ view label attributes =
eventsAndValues =
applyEvents attributes
config_ : Config
config_ =
config : Config
config =
applyConfig attributes
unvalidatedRadioConfig : ( Maybe value, Maybe String, Maybe (value -> String) )
unvalidatedRadioConfig =
( eventsAndValues.value, config_.name, eventsAndValues.valueToString )
in
case unvalidatedRadioConfig of
( Just value_, Just name_, Just valueToString_ ) ->
let
internalConfig =
{ value = value_
, name = name_
, valueToString = valueToString_
, eventsAndValues = eventsAndValues
, config = config_
, label = label
}
in
case config_.display of
case makeInternalConfig label config eventsAndValues of
Just internalConfig ->
case config.display of
Inline ->
viewInline internalConfig
@ -301,15 +287,35 @@ view label attributes =
type alias InternalConfig value msg =
{ value : value
{ -- user specified values
value : value
, name : String
, valueToString : value -> String
, eventsAndValues : EventsAndValues value msg
, config : Config
, label : String
-- TODO: computed values that both view helpers need
}
makeInternalConfig : String -> Config -> EventsAndValues value msg -> Maybe (InternalConfig value msg)
makeInternalConfig label config eventsAndValues =
case ( eventsAndValues.value, config.name, eventsAndValues.valueToString ) of
( Just value_, Just name_, Just valueToString_ ) ->
Just
{ value = value_
, name = name_
, valueToString = valueToString_
, eventsAndValues = eventsAndValues
, config = config
, label = label
}
_ ->
Nothing
viewBlock : InternalConfig value msg -> Html msg
viewBlock internalConfig =
let

View File

@ -137,12 +137,27 @@ viewVanilla state =
{ teacherPremiumLevel = PremiumLevel.Premium
, contentPremiumLevel = PremiumLevel.PremiumWithWriting
}
, RadioButton.value Robots
, RadioButton.name "pets"
, RadioButton.selectedValue state.selectedValue
, RadioButton.onSelect Select
, RadioButton.valueToString selectionToString
, RadioButton.showPennant <| OpenModal "pets-robots"
, RadioButton.block
, RadioButton.inline
]
, RadioButton.view
(selectionToString Robots)
[ RadioButton.premium
{ teacherPremiumLevel = PremiumLevel.Premium
, contentPremiumLevel = PremiumLevel.PremiumWithWriting
}
, RadioButton.value Robots
, RadioButton.name "pets"
, RadioButton.selectedValue state.selectedValue
, RadioButton.onSelect Select
, RadioButton.valueToString selectionToString
, RadioButton.showPennant <| OpenModal "pets-robots"
, RadioButton.inline
]
, p
[ Attributes.id "dogs-description" ]