Skip to content

Commit

Permalink
feat(react cardnode): add support for applying a custom class to the …
Browse files Browse the repository at this point in the history
…outer node

The CardNode component has a `color` prop which can be used to specify the
colour of the border applied on the outer node. However, this requires the
code to be aware of the active theme, handle dark mode, etc. to select an
appropriate colour in some cases.

For component libraries this can be problematic as now both the components
and their consumers need to be aware of theme rather than relying on this
being handled entirely in (S)CSS.

Add support for applying a custom class to the CardNode component which will
be applied to the outer node and can be used to apply styles to the card and
its children, including specifying the border colour for the card.

resolves carbon-design-system#1221
  • Loading branch information
AlanGreene committed Nov 20, 2021
1 parent e7b0dec commit 19db904
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/react/src/diagrams/CardNode/CardNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const namespace = `${prefix}--cc--card-node`;
const CardNode = ({
as = 'div',
children,
className,
color,
href = null,
onMouseEnter = null,
Expand All @@ -37,6 +38,7 @@ const CardNode = ({
const cardClasses = classnames(namespace, {
[`${namespace}--stacked`]: stacked,
[`${namespace}--${Component}`]: Component,
[className]: className,
});

return (
Expand Down Expand Up @@ -67,6 +69,11 @@ CardNode.propTypes = {
*/
children: PropTypes.node,

/**
* Provide an optional class to be applied on the outer element
*/
className: PropTypes.string,

/**
* Specify the node's border color
*/
Expand Down

0 comments on commit 19db904

Please sign in to comment.