1.0.0 • Published 11 months ago

@element-public/react-card v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Card

Description

Cards contain content and actions related to a single subject. They help to organize content and increase scannability.

See live demos on storybook

Storybook Card Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-card @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Usage

A Card is used to separate information into smaller subjects, or topics, within larger components. Components, such as Expansion Panel and Table, utilize Cards or features similar to them. For example, an Expansion Panel can include multiple List items or Cards and a Table implements a header section similar to the Card component.

Sub Components

Cards are composed of the following sub components:

NameDescription
CardPrimary container for card sub components
CardActionsContainer for actionable buttons and icon buttons. It is most commonly placed at the bottom of the card
CardActionButtonButton button specially formatted for Element Card.
CardActionIconIcon Button button specially formatted for Element Card.
CardBodyCard Body is the main card body. It can either be content or composed of other Element components.
CardContentCard Content contains the semantic content of the card. Non-semantic elements, ie an overlay layer, to a card should live outside this div. Should not be used with Card Media
CardDividerDivider used to separate components of card. Can add a color variant for brand expression.
CardFilterContainer for filtering controls, typically placed directly above filtered content
CardMediaCard Media is for holding a larger, attention grabbing images. Optionally, additional child content may be overlaid on the image.
CardPrimaryActionCard Primary Action is a wrapper component to make all it's children a primary action.
CardTitleContainer for titles, headings and other larger typography, typically placed at the top of the card, but can be placed anywhere, ie, as an overlay in Card Media.

Card Props

NameTypeDefaultRequiredDescription
bodyAlignmentstring'left-top'falseAlignment of the Card Body.Accepted Values: left-center, left-top, left-bottom, centered, right-center, right-top, right-bottom
heightstring'auto'falseHeight style property of card.
loadingCardbooleanfalsefalseIf true the card will be styled for a loading spinner
styleobjectnullfalsePassthrough style object.
themeColorstring'surface'falseBackground color of the card. It is recommended to set to transparent if setting theme color on the Card Title or Card Body.Accepted Values: transparent, surface, surface-variant, primary, primary-variant, primary-50, primary-100, primary-200, primary-300, primary-400, primary-500, primary-600, primary-700, primary-800, primary-900, secondary, secondary-variant, secondary-50, secondary-100, secondary-200, secondary-300, secondary-400, secondary-500, secondary-600, secondary-700, secondary-800, secondary-900, danger, danger-variant, danger-50, danger-100, danger-200, danger-300, danger-400, danger-500, danger-600, danger-700, danger-800, danger-900, ancillary-100, ancillary-200, ancillary-300, ancillary-400, ancillary-500, ancillary-600, ancillary-700, ancillary-800, ancillary-900
variantstring'default'falseVariant options include default (set by theme), flat, outlined, and raised. The flat variant removes elevation. The outlined variant adds border and removes elevation. The raised variant adds elevation.Accepted Values: default, flat, outlined, raised

Card Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the Card. Should be one of CardActions, CardBody, CardContent, CardDivider, CardFilter, CardMedia, or CardTitle.

Card Breaking Changes

Description
outlined (removed): Use variant="outlined" instead.

Card Action Button Props

NameTypeDefaultRequiredDescription
actionButtonThemeColorstring'primary'falseOverride the default (primary) color with the secondary color. Most commonly used when the control is placed on a darker surface.Accepted Values: primary, secondary
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
customRefreferenceundefinedfalseReference to the DOM button. This enables a greater level of integration.
disabledbooleanfalsefalsePrevent the user from interacting with the component.
fullWidthbooleanfalsefalseApplies a full-width style where the button will fill it's container.
hrefstringnullfalseThe button will render as an anchor tag.
labelstringnullfalseThe displayed text. Expects a valid string. If label and children are both set, label will take priority.
leadingIconstring|React.ReactNodenullfalseAdds the given Icon to the left of the button text. May not be used with trailingIcon - if leadingIcon and trailingIcon are both set, leadingIcon will take priority. Expects the name of a valid Material.io icon, however an icon component may be passed in instead for more control,
trailingIconstring|React.ReactNodenullfalseAdds the given Icon to the right of the button text. May not be used with leadingIcon - if leadingIcon and trailingIcon are both set, leadingIcon will take priority. Expects the name of a valid Material.io icon, however an icon component may be passed in instead for more control.
typestring'button'falseThis applies the html button type (button, submit, reset) or the anchor media type when used with the href property.Accepted Values: button, submit, reset

Card Action Button Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the button. Can be used instead label of to provide more flexibility. Accepts any valid markup. Warning, if Label is set, it will be used instead of child content.

Card Action Button Events

NameDefaultRequiredParamsDescription
onClickundefinedfalseThe primary interaction event for button.

Card Action Icon Props

NameTypeDefaultRequiredDescription
activebooleanfalsefalseProgrammatically sets the toggle state of the button when used as a toggle button. If not set, the toggle state will be managed internally.
ariaLabelstringnullfalseAccessibility label for assistive technologies.
ariaLabelledBystringnullfalseId of the component being labeled for assistive technologies.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
disabledbooleanfalsefalseDisables the icon button.
toggleOffAriaLabelstringnullfalseThe aria-label value to be read by a screen-reader when the button is toggled off. Example 'Add to Favorites'. Alternatively, toggleOffAriaLabelledBy may be used instead.
toggleOffAriaLabelledBystringnullfalseThe aria-labelledbyvalue when the button is toggled on. This should be the idof a parent element to be read by a screen reader instead of aria-label.
toggleOnAriaLabelstringnullfalseThe aria-label value to be read by a screen-reader when the button is toggled on. Example 'Remove from Favorites'. Alternatively, toggleOnAriaLabelledBy may be used instead.
toggleOnAriaLabelledBystringnullfalseThe aria-labelledbyvalue when the button is toggled on. This should be the id of a parent element to be read by a screen reader instead of aria-label.
variantstringempty stringfalseVariants prefixed with filled- will add a background color to the icon according to the theme. Variants prefixed with color- will change the color of the icon according to the theme.Accepted Values: filled-danger-alt, filled-danger, filled-primary, filled-secondary, color-primary, color-secondary, color-on-darkDeprecated Values: primary-alt, secondary-alt, primary, danger-alt, danger

Card Action Icon Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseThe content when when using the Card Action Icon Button normally. Expects a string, but a valid custom icon is accepted. For toggle button functionality, use toggleOn and toggleOff instead.
toggleOffReact.ReactNodenullfalseThe content to be rendered when the Card Action Icon Button is toggled off. Expects a string, but a valid custom icon is accepted. The typical use case for a toggle button would be to set an Icon for toggleOn and toggleOff, leaving children blank.
toggleOnReact.ReactNodenullfalseThe content to be rendered when the Card Action Icon Button is toggled on. Expects a string, but a valid custom icon is accepted. The typical use case for a toggle button would be to set an Icon for toggleOn and toggleOff, leaving children blank.

Card Action Icon Events

NameDefaultRequiredParamsDescription
onClickundefinedfalse1. Name: event, Type: event, Description: The javascript eventFired when the user clicks the Card Action Icon Button, will return toggle state, if applicable.

Card Actions Props

NameTypeDefaultRequiredDescription
alignmentstring'leading'falseAligns action buttons and icon buttons. 'center' and 'trailing' only allow buttons.Accepted Values: leading, center, trailing

Card Actions Render Props

NameTypeDefaultRequiredDescription
actionButtonsReact.ReactNodenullfalseAdd buttons to card actions.
actionIconsReact.ReactNodenullfalseAdd icons to card actions.

Card Actions Breaking Changes

Description
children (removed): No longer needed
footerAlignLeft (removed): See alignment="leading".
withOverflow (removed): No longer needed.

Card Body Props

NameTypeDefaultRequiredDescription
themeColorstring'surface'falseBackground color of the card body. It is recommended to set to the Card themeColor to transparent if setting the Card Body color.Accepted Values: surface, surface-variant, primary, primary-variant, primary-50, primary-100, primary-200, primary-300, primary-400, primary-500, primary-600, primary-700, primary-800, primary-900, secondary, secondary-variant, secondary-50, secondary-100, secondary-200, secondary-300, secondary-400, secondary-500, secondary-600, secondary-700, secondary-800, secondary-900, danger, danger-variant, danger-50, danger-100, danger-200, danger-300, danger-400, danger-500, danger-600, danger-700, danger-800, danger-900, ancillary-100, ancillary-200, ancillary-300, ancillary-400, ancillary-500, ancillary-600, ancillary-700, ancillary-800, ancillary-900
typographyTypestring'body2'falseSets typography class for Card Body. This can be overwritten by the children markupAccepted Values: body1, body2, button, caption, display1, display2, display3, display4, display5, display6, overline, subtitle1, subtitle2Deprecated Values: headline1, headline2, headline3, headline4, headline5, headline6

Card Body Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the title block. Accepts any valid markup.

Card Content Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the content block. Accepts any valid markup.

Card Content Breaking Changes

Description
height (removed): No longer needed.
horizontalAlign (removed): No longer needed.
primaryAction (removed): No longer needed.
verticalAlign (removed): No longer needed.

Card Divider Props

NameTypeDefaultRequiredDescription
dividerThemeColorstring'on-surface-stroke'falseTheme color for the Card Divider. Leave empty for gray.Accepted Values: null, on-surface-stroke, primary, primary-variant, primary-50, primary-100, primary-200, primary-300, primary-400, primary-500, primary-600, primary-700, primary-800, primary-900, secondary, secondary-variant, secondary-50, secondary-100, secondary-200, secondary-300, secondary-400, secondary-500, secondary-600, secondary-700, secondary-800, secondary-900, danger, danger-variant, danger-50, danger-100, danger-200, danger-300, danger-400, danger-500, danger-600, danger-700, danger-800, danger-900, ancillary-100, ancillary-200, ancillary-300, ancillary-400
dividerVariantstring'dense'falseChoose between dense and tall variants.Accepted Values: dense, tall

Card Filter Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
filterTypestring'tabs'falseType of filter being used.Accepted Values: tabs, chips, select, select-2

Card Filter Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the title block. Mostly commonly a Select, Textfield component, however any valid components or markup may be used.

Card Horizontal Group Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
rtlbooleanfalsefalseChanges which side of content the Card side media renders on. Improves layout for right-to-left languages.

Card Horizontal Group Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseMost commonly text or a Typography component, but accepts any valid markup.

Card Leading Media Props

NameTypeDefaultRequiredDescription
mediaUrlstringnullfalseUrl for Card media
ratiostring'square'falseApplies aspect ratio style to the card media.Accepted Values: square
widthnumber|string'30%'falseWidth for Card media

Card Media Props

NameTypeDefaultRequiredDescription
contentPlacementstring'bottom'falseAdjust placement of the media content.Accepted Values: bottom, top
imageUrlstringnullfalseImage Url for card background image
overlaybooleanfalsefalseAdds an overlay over to the Card Media.
overlayThemeColorstring'dark'falseOverlay theme color.Accepted Values: dark, light, surface, linear-gradient-white-to-bottom, linear-gradient-white-to-top, linear-gradient-black-to-bottom, linear-gradient-black-to-top, linear-gradient-primary-dark-to-bottom, linear-gradient-primary-dark-to-top, linear-gradient-primary-darker-to-bottom, linear-gradient-primary-darker-to-top, linear-gradient-primary-to-bottom, linear-gradient-primary-to-top, linear-gradient-secondary-dark-to-bottom, linear-gradient-secondary-dark-to-top, linear-gradient-secondary-darker-to-bottom, linear-gradient-secondary-darker-to-top, linear-gradient-secondary-to-bottom, linear-gradient-secondary-to-top
ratiostring'square'falseApplies aspect ratio style to the card media.Accepted Values: square, sixteen-nine, four-three, four-five, two-one

Card Media Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseChild components will be rendered on top of the provided image. Use contentBottom and contentTop to control content positioning. Accepts any valid markup.

Card Media Breaking Changes

Description
contentBottom (removed): see contentPlacement="top" instead.
contentTop (removed): see contentPlacement="bottom" instead.
sixteenNine (removed): see ratio="sixteen-nine" instead.
square (removed): see ratio="square" instead.

Card Overlay Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
overlayThemeColorstring'dark'falseOverlay theme color.Accepted Values: dark, light, surface, linear-gradient-white-to-bottom, linear-gradient-white-to-top, linear-gradient-black-to-bottom, linear-gradient-black-to-top, linear-gradient-primary-dark-to-bottom, linear-gradient-primary-dark-to-top, linear-gradient-primary-darker-to-bottom, linear-gradient-primary-darker-to-top, linear-gradient-primary-to-bottom, linear-gradient-primary-to-top, linear-gradient-secondary-dark-to-bottom, linear-gradient-secondary-dark-to-top, linear-gradient-secondary-darker-to-bottom, linear-gradient-secondary-darker-to-top, linear-gradient-secondary-to-bottom, linear-gradient-secondary-to-top
positionstring'full'falsePosition of the Overlay. Use overlayThemeColor to change the theme color. If set to leading or trailing be sure to set alignment on Card accordingly to have Card Content over the overlay.Accepted Values: full, leading, trailing

Card Overlay Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the Card Overlay. Useful for angles or other non semantic elements displayed in the Card.

Card Primary Action Props

NameTypeDefaultRequiredDescription
tagstring|React.ElementType|React.Component'div'falseBy default a div will be rendered, this allows another tag/component to be used instead. A block type element/component is suggested.

Card Primary Action Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered as the primary action.

Card Primary Action Events

NameDefaultRequiredParamsDescription
onClickundefinedfalseThe primary interaction event for card.

Card Title Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
leadingBlockTypestringempty stringfalseThe type of media that will render in the leading block. See README for size constraints.Accepted Values: avatar, icon, icon-with-background, thumbnail
placementstring'top'falseWhere title appears in card.Accepted Values: top, middle, bottom
stackedbooleanfalsefalseProp that makes card title stackable.
themeColorstring'surface'falseBackground color of the CardTitle.Accepted Values: surface, primary, secondary
trailingBlockTypestringempty stringfalseThe type of media that will render in the trailing block. See README for size constraints.Accepted Values: title-actions, avatar, badge, icon, icon-with-background, thumbnail

Card Title Render Props

NameTypeDefaultRequiredDescription
leadingBlockReact.ReactNodenullfalseContent to be displayed in the leading block container. See README for types supported.
overlineTextReact.ReactNodenullfalseContent to be displayed in the Overline text of the title. Expects a string, but can be any valid markup.
primaryTextReact.ReactNodenullfalseContent to be displayed in the Primary text of the title. Expects a string, but can be any valid markup.
secondaryTextReact.ReactNodenullfalseContent to be displayed in the Secondary text of the title. Expects a string, but can be any valid markup.
stackedSecondaryTextReact.ReactNodenullfalseContent to be displayed in the Secondary text of the title and could be used to make Card title stackable. Expects a string, but can be any valid markup.
trailingBlockReact.ReactNodenullfalseContent to be displayed in the trailing block container. See README for types supported.

Card Title Breaking Changes

Description
children (removed): Use the content props/slots to populate the Card Title.
height (removed): No longer needed.
large (removed): no longer needed
titleBigText (removed): See trailingBlock and TypoDisplay.
titleFilters (removed): See trailingBlock.
titleIcons (removed): See trailingBlock and trailingBlockType=icon.
withOverflow (removed): No longer needed.