A card's primary action block
Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/aforemny/material-components-web-elm.
What we checked: Tag 6.0.0 is still on github.com/aforemny/material-components-web-elm; its commit fa5f16f0eddc is from 2020-10-08 13:01 UTC, before the version was published (2020-10-08 13:03 UTC); every file Elm uses matches a copy in a Lamdera package cache from 2021-02-13, from before the change; elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one (GitHub's zip no longer comes out byte for byte the same), so the contents were checked instead.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/aforemny/material-components-web-elm/zipball/6.0.0/
Cards contain content and actions about a single subject.
import Html exposing (Html, text)
import Material.Button as Button
import Material.Card as Card
import Material.IconButton as IconButton
main =
Card.card Card.config
{ blocks =
[ Card.block <|
Html.div []
[ Html.h2 [] [ text "Title" ]
, Html.h3 [] [ text "Subtitle" ]
]
, Card.block <|
Html.div []
[ Html.p [] [ text "Lorem ipsum…" ] ]
]
, actions =
Just <|
Card.actions
{ buttons =
[ Card.button Button.config "Visit" ]
, icons =
[ Card.icon IconButton.config
(IconButton.icon "favorite")
]
}
}Specify whether a card should have a visual outline
Specify additional attributes
The content of a card is comprised of blocks and actions.
A card may display a border by setting its setOutlined configuration option
to True.
Card.card
(Card.config |> Card.setOutlined True)
{ blocks =
[ Card.block <|
Html.div [] [ Html.h1 [] [ text "Card" ] ]
]
, actions = Nothing
}A card's primary content is comprised of blocks. Blocks may be comprised of arbitrary HTML or a media element. Optionally, a group of card blocks can be marked as the card's primary action which makes that group of blocks interactable.
A card's content block
Generic card blocks are the most common and allow you to specify card content using arbitrary HTML. Note that you will have to carefully adjust styling such as padding and typography yourself.
Card.block <|
Html.div []
[ Html.h2 [] [ text "Title" ]
, Html.h3 [] [ text "Subtitle" ]
]Card block containing arbitrary HTML
Card.block <|
Html.div [] [ text "Lorem ipsum…" ]Cards may contain a media block usually as the first content block. The media will be displayed using a background image, and you may chose from square or a 16 to 9 aspect ratio.
Card media block with a square aspect ratio
Card media block with a 16:9 aspect ratio
A group of card blocks can be marked as the primary action of the card. A primary action block may be clicked upon and displays a visual interaction effect.
Card.primaryAction
[ Html.Events.onClick CardClicked ]
[ Card.block <|
Html.h2 [] [ text "Title" ]
, Card.block <|
Html.p [] [ text "Lorem ipsum…" ]
]A card's primary action block
Card actions are comprised of buttons and icons. These are exposed as variants to the standard buttons and icons, but they do share the same configuration.
Card.actions
{ buttons =
[ Card.button Button.config "View" ]
, icons =
[ Card.icon IconButton.config
(IconButton.icon "favorite")
]
}Card actions type
Card actions
A card may contain as actions buttons as well as icons.
Card action's button type
Card action's icon type
Card action icon
Card.icon IconButton.config
(IconButton.icon "favorite")While a card's action buttons are usually left-aligned, a special case exists when there is only a single button as card action.
Card full bleed action
If a card's action is comprised of a single button, that button can be made
full width by using cardFullBleedActions.
Card.fullBleedActions
(Card.button Button.config "Visit")You may programatically focus a card by assigning an id attribute to it and use
Browser.Dom.focus.
Note that cards must have a primary action element to be focusable.
Card.card
(Card.config
|> Card.setAttributes
[ Html.Attributes.id "my-card" ]
)
{ blocks = Card.primaryAction [] []
, actions = Nothing
}
Configuration of a card