ensolabs/designsystemet-elm/1.0.0

Designsystemet.Button

Buttons start actions.

Mirrors Button from @digdir/designsystemet-react.

Button.view [ Events.onClick Save ] [ Html.text "Lagre" ]


Button.view [ Button.secondary, Ds.color Color.danger, Events.onClick Delete ]
    [ Html.text "Slett" ]

Buttons default to type="button" so they never submit a form by accident. Pass Attr.type_ "submit" for a submit button.

React → Elm

  • <Button> → Button.view []
  • variant="secondary" → Button.secondary
  • loading → Button.loading Busy []
  • icon + aria-label → Button.icon { label = "…", icon = … } []
  • asChild + <a> → Button.viewAs Html.a [ Attr.href "…" ]
  • command / commandfor → Dialog.showModal id, Popover.toggle id, …
view : List (Attribute msg) -> List (Html msg) -> Html msg

A <button class="ds-button" type="button">.

(List (Attribute msg) -> List (Html msg) -> Html msg)
-> List (Attribute msg)
-> List (Html msg)
-> Html msg

A button rendered as another element than <button> (React's asChild).

Button.viewAs Html.a [ Attr.href "/ny" ] [ Html.text "Ny sak" ]

Variants

primary : Attribute msg

The default, for the main action in a context.

secondary : Attribute msg

For actions next to a primary one.

tertiary : Attribute msg

For low-emphasis actions.

Busy buttons

loading : Loading msg -> List (Attribute msg) -> List (Html msg) -> Html msg

A button that can be busy. While busy it gets aria-busy="true" and a spinner before its label.

Button.loading
    (if model.saving then
        Busy


     else
        Idle
    )
    [ Events.onClick Save ]
    [ Html.text "Lagre" ]

Prefer mapping your own state to Loading over an if:

Button.loading (Request.toLoading model.save) [ Events.onClick Save ] [ Html.text "Lagre" ]
type Loading msg
= Idle
| Busy
| BusyWith (Html msg)

Whether a button is waiting for something.

BusyWith replaces the spinner with your own loader.

Icon buttons

{ label : String
, icon : Html msg
}
-> List (Attribute msg)
-> Html msg

An icon-only button. The label is required and becomes the aria-label, since screen readers can't read the icon.

Button.icon { label = "Lukk", icon = FeatherIcons.x |> FeatherIcons.toHtml [] }
    [ Button.tertiary, Events.onClick Close ]
Loading msg
-> { label : String
, icon : Html msg
}
-> List (Attribute msg)
-> Html msg

An icon button that can be busy. While busy, the spinner takes the icon's place.