mdgriffith / design-discussion-elm-ui-2

A repo for discussing changes to Elm UI 2
17 stars 0 forks source link

Consider making checkbox more generic #3

Open jhbrown94 opened 5 years ago

jhbrown94 commented 5 years ago

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
mdgriffith commented 5 years ago

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

jhbrown94 commented 5 years ago

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