move name into list api

This commit is contained in:
Alex Perkins 2021-11-18 16:43:48 -05:00
parent 6a298e82b6
commit a7efe81cb1
2 changed files with 15 additions and 10 deletions

View File

@ -1,6 +1,7 @@
module Nri.Ui.RadioButton.V3 exposing module Nri.Ui.RadioButton.V3 exposing
( view, premium ( view, premium
, disabled, enabled, value , disabled, enabled
, value, name
) )
{-| Changes from V2: {-| Changes from V2:
@ -8,7 +9,8 @@ module Nri.Ui.RadioButton.V3 exposing
- list based API instead of record based - list based API instead of record based
@docs view, premium @docs view, premium
@docs disabled, enabled, value @docs disabled, enabled
@docs value, name
-} -}
@ -52,6 +54,14 @@ enabled =
\config -> { config | isDisabled = False } \config -> { config | isDisabled = False }
{-| Every radio button in the same group should have the same name
-}
name : String -> Attribute value msg
name name_ =
Attribute emptyEventsAndValues <|
\config -> { config | name = name_ }
{-| -} {-| -}
value : value -> Attribute value msg value : value -> Attribute value msg
value value_ = value value_ =
@ -140,7 +150,6 @@ If used in a group, all radio buttons in the group should have the same name att
-} -}
view : view :
{ label : String { label : String
, name : String
, selectedValue : Maybe value , selectedValue : Maybe value
, onSelect : value -> msg , onSelect : value -> msg
, valueToString : value -> String , valueToString : value -> String
@ -150,7 +159,6 @@ view :
view config = view config =
internalView internalView
{ label = config.label { label = config.label
, name = config.name
, selectedValue = config.selectedValue , selectedValue = config.selectedValue
, isLocked = False , isLocked = False
, onSelect = config.onSelect , onSelect = config.onSelect
@ -194,7 +202,6 @@ premium config =
in in
internalView internalView
{ label = config.label { label = config.label
, name = config.name
, selectedValue = config.selectedValue , selectedValue = config.selectedValue
, isLocked = isLocked , isLocked = isLocked
, onSelect = config.onSelect , onSelect = config.onSelect
@ -221,7 +228,6 @@ premium config =
type alias InternalConfig value msg = type alias InternalConfig value msg =
{ label : String { label : String
, name : String
, selectedValue : Maybe value , selectedValue : Maybe value
, isLocked : Bool , isLocked : Bool
, onSelect : value -> msg , onSelect : value -> msg
@ -253,7 +259,7 @@ internalView config attributes =
Just realValue -> Just realValue ->
let let
id_ = id_ =
config.name ++ "-" ++ dasherize (toLower (config.valueToString realValue)) config_.name ++ "-" ++ dasherize (toLower (config.valueToString realValue))
in in
Html.span Html.span
[ id (id_ ++ "-container") [ id (id_ ++ "-container")
@ -272,7 +278,7 @@ internalView config attributes =
] ]
] ]
] ]
[ radio config.name [ radio config_.name
(config.valueToString realValue) (config.valueToString realValue)
isChecked isChecked
[ id id_ [ id id_

View File

@ -88,7 +88,6 @@ viewVanilla state =
div [] div []
[ RadioButton.view [ RadioButton.view
{ label = "Cats" { label = "Cats"
, name = "radio-button-examples"
, selectedValue = state.selectedValue , selectedValue = state.selectedValue
, onSelect = Debug.log "selected" >> Select , onSelect = Debug.log "selected" >> Select
, valueToString = identity , valueToString = identity
@ -99,13 +98,13 @@ viewVanilla state =
] ]
, RadioButton.view , RadioButton.view
{ label = "Dogs" { label = "Dogs"
, name = "radio-button-examples"
, selectedValue = state.selectedValue , selectedValue = state.selectedValue
, onSelect = Debug.log "selected" >> Select , onSelect = Debug.log "selected" >> Select
, valueToString = identity , valueToString = identity
} }
[ RadioButton.enabled [ RadioButton.enabled
, RadioButton.value "Canines" , RadioButton.value "Canines"
, RadioButton.name "radio-button-examples"
] ]
] ]