Cards contain content and actions about a single subject.
import Html exposing (Html, text)
import Material.Button exposing (buttonConfig)
import Material.Card
exposing
( card
, cardActionButton
, cardActionIcon
, cardActions
, cardBlock
, cardConfig
)
import Material.Icon exposing (iconConfig)
main =
card cardConfig
{ blocks =
[ cardBlock <|
Html.div []
[ Html.h2 [] [ text "Title" ]
, Html.h3 [] [ text "Subtitle" ]
]
, cardBlock <|
Html.div []
[ Html.p [] [ text "Lorem ipsum…" ] ]
]
, actions =
Just <|
cardActions
{ buttons =
[ cardActionButton buttonConfig
"Visit"
]
, icons =
[ cardActionIcon iconConfig
"favorite"
]
}
}Card view function
Configuration of a card
The content of a card is comprised of blocks and actions.
A card may have a border by settings its outlined configuration field to
True.
card { cardConfig | outlined = True }
{ blocks =
[ cardBlock <|
Html.div [] [ Html.h1 [] [ text "Card" ] ]
]
, actions = Nothing
}A card's content is primary comprised of blocks. Blocks may be comprised of
arbitrary HTML (generic cardBlock) or a media element (cardMedia).
Optionally, a group of card blocks can be marked as the card's primary action
which makes the group of card blocks interactable.
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.
cardBlock <|
Html.div []
[ Html.h2 [] [ text "Title" ]
, Html.h3 [] [ text "Subtitle" ]
]An arbitrary card block
cardBlock <|
Html.div [] [ text "Lorem ipsum…" ]Card 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 view function
cardMedia cardMediaConfig "media-image.jpg"Default configuration of a card's media block
Configuration of a card's media block
Card media block's 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.
cardPrimaryAction
{ cardPrimaryActionConfig
| onClick = Just CardClicked
}
[ cardBlock <|
Html.h2 [] [ text "Title" ]
, cardBlock <|
Html.p [] [ text "Lorem ipsum…" ]
]Default configuration of a card's primary action block
A card's primary action block
cardPrimaryAction
{ cardPrimaryActionConfig
| onClick = Just CardClicked
}
[ cardBlock <|
Html.div []
[ Html.h1 [] [ text "Title" ] ]
, cardBlock <|
Html.div []
[ Html.p [] [ text "Lorem ipsum…" ] ]
]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.
cardActions
{ buttons =
[ cardActionButton buttonConfig "View" ]
, actions =
[ cardActionIcon iconConfig "favorite" ]
}Card actions
A card may contain as actions buttons as well as icons.
Card actions type
A card action button
cardActionButton buttonConfig "Visit"Card action icon
cardActionIcon iconConfig "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.
cardFullBleedActions
(cardActionButton buttonConfig [ text "Visit" ])
Card view function