Adds disabled/enabled helper

This commit is contained in:
Tessa Kelly 2021-11-22 10:36:22 -08:00
parent d38d18f1f8
commit ad0116ac2c
2 changed files with 48 additions and 69 deletions

View File

@ -15,6 +15,7 @@ module Nri.Ui.RadioButton.V3 exposing
- list based API instead of record based - list based API instead of record based
- add disclosure to show rich content when the radio is selected - add disclosure to show rich content when the radio is selected
- when the radio button is disabled don't attach onSelect listener
@docs view, Attribute @docs view, Attribute
@docs disabled, enabled @docs disabled, enabled

View File

@ -96,92 +96,56 @@ viewRadioButtons selectionSettings selectedValue =
div [] div []
[ RadioButton.view [ RadioButton.view
(selectionToString Dogs) (selectionToString Dogs)
[ RadioButton.enabled ([ RadioButton.value Dogs
, RadioButton.value Dogs , RadioButton.name "pets"
, RadioButton.name "pets" , RadioButton.selectedValue selectedValue
, RadioButton.selectedValue selectedValue , RadioButton.onSelect Select
, RadioButton.onSelect Select , RadioButton.valueToString selectionToString
, RadioButton.valueToString selectionToString , RadioButton.describedBy [ "dogs-description" ]
, RadioButton.describedBy , RadioButton.block
[ "dogs-description" ] ]
, RadioButton.block ++ List.map Tuple.second selectionSettings.dogs
] )
, RadioButton.view , RadioButton.view
(selectionToString Cats) (selectionToString Cats)
[ RadioButton.enabled ([ RadioButton.value Cats
, RadioButton.value Cats , RadioButton.name "pets"
, RadioButton.name "pets" , RadioButton.selectedValue selectedValue
, RadioButton.selectedValue selectedValue , RadioButton.onSelect Select
, RadioButton.onSelect Select , RadioButton.valueToString selectionToString
, RadioButton.valueToString selectionToString , if selectedValue == Just Cats then
, if selectedValue == Just Cats then
RadioButton.batch RadioButton.batch
[ RadioButton.describedBy [ "cats-description" ] [ RadioButton.describedBy [ "cats-description" ]
, RadioButton.hiddenLabel , RadioButton.hiddenLabel
] ]
else else
RadioButton.none RadioButton.none
, RadioButton.disclosure , RadioButton.disclosure
[ span [ span
[ Attributes.id "cats-description" ] [ Attributes.id "cats-description" ]
[ Text.smallBody [ Text.plaintext "Cats kind of do their own thing" ] ] [ Text.smallBody [ Text.plaintext "Cats kind of do their own thing" ] ]
] ]
, RadioButton.block , RadioButton.block
] ]
++ List.map Tuple.second selectionSettings.cats
)
, RadioButton.view , RadioButton.view
(selectionToString Robots) (selectionToString Robots)
[ RadioButton.premium ([ RadioButton.premium
{ teacherPremiumLevel = PremiumLevel.Premium { teacherPremiumLevel = PremiumLevel.Premium
, contentPremiumLevel = PremiumLevel.PremiumWithWriting , contentPremiumLevel = PremiumLevel.PremiumWithWriting
} }
, RadioButton.value Robots , RadioButton.value Robots
, RadioButton.name "pets" , RadioButton.name "pets"
, RadioButton.selectedValue selectedValue , RadioButton.selectedValue selectedValue
, RadioButton.onSelect Select , RadioButton.onSelect Select
, RadioButton.valueToString selectionToString , RadioButton.valueToString selectionToString
, RadioButton.showPennant <| OpenModal "" , RadioButton.showPennant <| OpenModal ""
, RadioButton.block , RadioButton.block
] ]
, RadioButton.view ++ List.map Tuple.second selectionSettings.robots
(selectionToString Robots) )
[ RadioButton.premium
{ teacherPremiumLevel = PremiumLevel.Premium
, contentPremiumLevel = PremiumLevel.PremiumWithWriting
}
, RadioButton.value Robots
, RadioButton.name "pets"
, RadioButton.selectedValue selectedValue
, RadioButton.onSelect Select
, RadioButton.valueToString selectionToString
, RadioButton.showPennant <| OpenModal "pets-robots"
, RadioButton.inline
]
, RadioButton.view
(selectionToString Robots)
[ RadioButton.premium
{ teacherPremiumLevel = PremiumLevel.PremiumWithWriting
, contentPremiumLevel = PremiumLevel.Premium
}
, RadioButton.value Robots
, RadioButton.name "pets"
, RadioButton.selectedValue selectedValue
, RadioButton.onSelect Select
, RadioButton.valueToString selectionToString
, RadioButton.inline
, RadioButton.showPennant <| OpenModal "pets-robots"
, if selectedValue == Just Robots then
RadioButton.hiddenLabel
else
RadioButton.none
, RadioButton.disclosure
[ Text.smallBody
[ Text.plaintext "With apologies to Karel Čapek"
, Text.css [ Css.display Css.inlineBlock ]
]
]
]
, p , p
[ Attributes.id "dogs-description" ] [ Attributes.id "dogs-description" ]
[ text "Dogs are gregarious" ] [ text "Dogs are gregarious" ]
@ -242,6 +206,20 @@ initSelectionSettings =
controlAttributes : Control (List ( String, RadioButton.Attribute Selection Msg )) controlAttributes : Control (List ( String, RadioButton.Attribute Selection Msg ))
controlAttributes = controlAttributes =
ControlExtra.list ControlExtra.list
|> ControlExtra.listItem "disabled" disabledOrEnabled
disabledOrEnabled : Control ( String, RadioButton.Attribute Selection Msg )
disabledOrEnabled =
Control.map
(\isDisabled ->
if isDisabled then
( "RadioButton.disabled", RadioButton.disabled )
else
( "RadioButton.enabled", RadioButton.enabled )
)
(Control.bool False)
type Msg type Msg