mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-22 21:21:52 +03:00
Adds disabled/enabled helper
This commit is contained in:
parent
d38d18f1f8
commit
ad0116ac2c
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user