Card

July 31, 2019 ยท View on GitHub

Displays a small piece of "summary" content - a photo, text, a link - about a single subject, as trigger to more detailed information.

This implementation closely follows the design specification. A number of convenience properties have been added to allow different image formats without having to prepare the right image ratio beforehand.

Main features

  • Flexibly composable with card elements in different order
  • Set shadow depth
  • Set avatar portrait image
  • Tight display
  • Horizontal or vertical orientation of actions
  • Crop image from left, center or right
  • Set image ratio
  • Set image size
  • Image overlay
  • RTL (right-to-left) support

Usage

Options

Card specific options

Options for card

ParameterRequiredTypeDefaultDescription
contentrequiredArrayList of option objects for distinct areas - see below; to pass other content, use children
shadowDepthoptionalNumber 0-51Depth of the shadow
urloptionalObject with href, optionally oncreate (for Mithril 1.x) or onClick (for React) or to (for React Router)URL for the entire card; Mithril 2.x: only use url.href and set element to m.route.Link; Mithril 1.x: for in-app route linking set oncreate : m.route.link; React: for in-app route linking use onClick and a router such as react-router-dom

Next to the card itself, each content parts has a set of options:

  • primary
  • text
  • media
  • header
  • actions

Options for primary

ParameterRequiredTypeDefaultDescription
elementoptionalString"div"HTML element tag
classNameoptionalStringExtra CSS class appended to pe-card__primary
titleoptionalStringTitle text
subtitleoptionalStringSubtitle text
mediaoptionalOptions object, equal to media part belowMedia that is shown in this part
actionsoptionalOptions object, equal to actions part belowActions that are shown in this part
tightoptionalBooleanfalseSet to true to reduce the top and bottom padding
styleoptionalStringStyle object

Options for text

ParameterRequiredTypeDefaultDescription
elementoptionalString"div"HTML tag
classNameoptionalStringExtra CSS class appended to pe-card__text
contentrequiredString, hyperscript or componentText contents
tightoptionalBooleanfalseSet to true to reduce the top and bottom padding
styleoptionalStringStyle object

Options for header

The header is composed from List Tile. The header accepts all options for List Tile, plus icon.

A Material Design header needs one of these options:

  • icon (or front)
  • title
  • info
  • url
ParameterRequiredTypeDefaultDescription
iconoptionalObjectIcon options object; used to show an round "avatar" portrait image

Options for media

ParameterRequiredTypeDefaultDescription
classNameoptionalStringExtra CSS class appended to pe-card__media
contentrequiredString, hyperscript or componentThe image or iframe
elementoptionalString"div"HTML tag
originoptionalString: "start", "center", "end"center"From which side cropping should be done
overlayoptionalOptions object, equal to card options; see belowContent to place on the overlay
showDimmeroptionalBooleanfalseSet to true to create an image dimmer; the dimmer does not have a default style
ratiooptionalString: "landscape" or "square""landscape"Image ratio; "landscape" translates to 16:9 ratio
sizeoptionalString: "small", "medium", "large", "extra-large"For primary media only; defines the image (or iframe) size
styleoptionalStringStyle object

Options for media.overlay

The media overlay part can contain any card content. Additional options:

ParameterRequiredTypeDefaultDescription
sheetoptionalBooleanfalseSet to true to show the overlay as a partly covering sheet

Options for actions

ParameterRequiredTypeDefaultDescription
borderoptionalBooleanfalseSet to true to add a top border
classNameoptionalStringExtra CSS class appended to pe-card__actions
contentrequiredString, hyperscript or componentAction contents, for instance a list of buttons
elementoptionalString"div"HTML tag
layoutoptionalString: "horizontal", "vertical" or "justified""horizontal"Set to "vertical" for a vertical list of actions; use "justified" for a horizontally evenly spread of icons
tightoptionalBooleanfalseSet to true to reduce the top and bottom padding
styleoptionalStringStyle object

Options for any

ParameterRequiredTypeDefaultDescription
elementoptionalString"div"HTML tag
classNameoptionalStringExtra CSS class appended to pe-card__any
contentrequiredString, hyperscript or componentContents
styleoptionalStringStyle object

Common component options

ParameterRequiredTypeDefaultDescription
afteroptionalString, hyperscript or componentExtra content after main content; note that this content is placed right of preceding elements with a higher stacking depth
beforeoptionalString, hyperscript or componentExtra content before main content; note that this content is placed left of subsequent elements with a lower stacking depth
classNameoptionalStringExtra CSS class appended to pe-card
elementoptionalString"a"HTML element tag
eventsoptionalObjectOptions object containing one or more standard events such as onclick (React: onClick)
idoptionalStringHTML element id
styleoptionalStringStyle object
toneoptionalString: "dark" or "light"Renders the component light on dark (sets class pe-dark-tone); use "light" to locally inverse (sets class pe-light-tone)

Composition

Card is optionally composed from:

CSS classes