design-discussion-elm-ui-2
design-discussion-elm-ui-2 copied to clipboard
Consider making checkbox more generic
It's common in a list UI to have a checkbox at the top with three possible states -- None selected ( ), All selected (✓), or some selected (-). If Checkbox was parameterized on the datatype, the icon function could return a type-specific icon permitting this use case, along with other future cases requiring even more states. Something like this:
checkbox:
List (Attribute msg)
->
{ onChange : s -> msg -- the state sent is the old state; update computes the new one
, icon : s -> Element msg
, state : s
, label : Label msg
}
-> Element msg
Interesting!
I think for your given usecase you probably just need to specify a custom icon, which keys off of some other state than just the Bool. Something like:
...
icon = always (allSomeOrNoneIcon model.selected)
onChange can still communicate something meaningful to your update
True-> select everythingFalse-> deselect everything
Fair point. Although I'm not sure the onChange argument is useful once I'm storing state in model.selected; onClick is all I really need at that point and I can derive my next state from my current one. At which point, maybe I should just use a button? But I worry that it won't style exactly like the checkbox even if I use the same icons...?