Show the labels without text

This commit is contained in:
Tessa Kelly 2020-09-08 14:47:38 -07:00
parent 093718d9ed
commit 989ce0821f

View File

@ -62,7 +62,7 @@ example =
, SegmentedControl.viewRadioGroup , SegmentedControl.viewRadioGroup
{ legend = "SegmentedControls 'viewSelectRadio' example" { legend = "SegmentedControls 'viewSelectRadio' example"
, onSelect = SelectRadio , onSelect = SelectRadio
, options = List.take options.count (buildRadioOptions options.icon) , options = List.take options.count (buildRadioOptions options.content)
, selected = state.optionallySelected , selected = state.optionallySelected
, positioning = options.positioning , positioning = options.positioning
} }
@ -94,17 +94,16 @@ type Page
| Activity | Activity
buildOptions : { options | icon : Bool, longContent : Bool, tooltips : Bool } -> Maybe Page -> List (SegmentedControl.Option Page Msg) buildOptions : { options | content : Content, longContent : Bool, tooltips : Bool } -> Maybe Page -> List (SegmentedControl.Option Page Msg)
buildOptions { icon, longContent, tooltips } openTooltip = buildOptions { content, longContent, tooltips } openTooltip =
let let
buildOption value icon_ = buildOption value icon_ =
{ icon = let
if icon then ( icon, label ) =
Just icon_ getIconAndLabel content icon_ (Html.text (Debug.toString value))
in
else { icon = icon
Nothing , label = label
, label = Html.text (Debug.toString value)
, value = value , value = value
, idString = toLower (Debug.toString value) , idString = toLower (Debug.toString value)
, attributes = [] , attributes = []
@ -146,23 +145,22 @@ buildOptions { icon, longContent, tooltips } openTooltip =
] ]
buildRadioOptions : Bool -> List (SegmentedControl.Radio Int msg) buildRadioOptions : Content -> List (SegmentedControl.Radio Int msg)
buildRadioOptions keepIcon = buildRadioOptions content =
let let
buildOption value icon = buildOption value icon =
{ icon = ifIcon icon let
, label = Html.text ("Source " ++ Debug.toString (value + 1)) ( icon_, label ) =
getIconAndLabel content
icon
(Html.text ("Source " ++ Debug.toString (value + 1)))
in
{ icon = icon_
, label = label
, value = value , value = value
, idString = String.fromInt value , idString = String.fromInt value
, attributes = [] , attributes = []
} }
ifIcon icon =
if keepIcon then
Just icon
else
Nothing
in in
List.indexedMap buildOption List.indexedMap buildOption
[ UiIcon.leaderboard [ UiIcon.leaderboard
@ -197,7 +195,7 @@ init =
type alias Options = type alias Options =
{ positioning : SegmentedControl.Positioning { positioning : SegmentedControl.Positioning
, icon : Bool , content : Content
, count : Int , count : Int
, longContent : Bool , longContent : Bool
, tooltips : Bool , tooltips : Bool
@ -214,7 +212,7 @@ optionsControl =
, ( "Center", Control.value SegmentedControl.Center ) , ( "Center", Control.value SegmentedControl.Center )
] ]
) )
|> Control.field "icon" (Control.bool True) |> Control.field "content" controlContent
|> Control.field "count" |> Control.field "count"
(Control.choice (Control.choice
(List.map (\i -> ( String.fromInt i, Control.value i )) (List.range 2 8)) (List.map (\i -> ( String.fromInt i, Control.value i )) (List.range 2 8))
@ -223,6 +221,34 @@ optionsControl =
|> Control.field "tooltips" (Control.bool True) |> Control.field "tooltips" (Control.bool True)
type Content
= TextAndIcon
| Text
| Icon
controlContent : Control Content
controlContent =
Control.choice
[ ( "Text and icon", Control.value TextAndIcon )
, ( "Text", Control.value Text )
, ( "Icon", Control.value Icon )
]
getIconAndLabel : Content -> svg -> Html msg -> ( Maybe svg, Html msg )
getIconAndLabel content icon_ value =
case content of
TextAndIcon ->
( Just icon_, value )
Icon ->
( Just icon_, Html.text "" )
Text ->
( Nothing, value )
{-| -} {-| -}
type Msg type Msg
= FocusAndSelectPage { select : Page, focus : Maybe String } = FocusAndSelectPage { select : Page, focus : Maybe String }