design-discussion-elm-ui-2 icon indicating copy to clipboard operation
design-discussion-elm-ui-2 copied to clipboard

Consider making checkbox more generic

Open jhbrown94 opened this issue 6 years ago • 2 comments

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

jhbrown94 avatar Aug 12 '19 14:08 jhbrown94

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 everything
  • False -> deselect everything

mdgriffith avatar Aug 13 '19 15:08 mdgriffith

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...?

jhbrown94 avatar Aug 13 '19 15:08 jhbrown94