Skip to main content
Version: 1.2.0

Card

Card is basically a wrapper of an individual widget and gives a nice border, title, and container for it. It also handles row and column spanning, in case a widget takes more space vertically or horizontally and handles the hassle of widths and heights dynamically!

Live Editor

Usage

1 . Import Card after installation

import { Card } from "@k2/ui";

2 . Then use in jsx/tsx as shown below:

<Card width="300px" title="Card Title">
<div>Hello K2</div>
</Card>

Examples

Card with title component and actions component: Demo

<Card
title={() => <div>Card Title</div>}
width="600px"
actions={() => <div>[any component here]</div>}
hasBoxShadow={false}
>
<div />
</Card>

Card with border radius: Demo

<Card
title="Card with border radius"
hasBoxShadow={false}
width="300px"
height="200px"
style={{ borderRadius: "10px" }}
>
<div />
</Card>

Card with box shadow: Demo

<Card
title="Card with box shadow"
width="300px"
height="200px"
hasBorder={false}
>
<div />
</Card>

Card with different body and header padding: Demo

<Card
title="Card Title"
width="300px"
height="200px"
hasBorder={false}
classes={{
header: "card-header-custom-padding",
body: "card-body-custom-padding",
}}
>
<div style={{ background: "blue", height: "100%" }} />
</Card>

CSS:

.card-header-custom-padding.card-header-custom-padding {
padding: 10px 20px;
}
.card-body-custom-padding.card-body-custom-padding {
padding: 10px 40px;
}

Click here for more variations of card.

Props

PropertyTypeRequiredDefault valueDescription
widthUnitsnumber | Breakpointsno1No. of Width units that the Card takes. Different units for each breakpoint can be set by passing Breakpoints Object e.g {lg:2,xs:1} if used within responsive GridLayout
heightUnitsnumberno1No. of Height units that the Card takes. Different units for each breakpoint can be set by passing Breakpoints Object e.g {lg:2,xs:1} if used within responsive GridLayout
titleReactNodenoNoneDisplayed on top of Card.
subtitleReactNodenoNoneDisplayed next to the Title.
actionsReactNodenoNoneActions displayed on right end of the Header.
widthstring | numbernoNoneThe width is automatically calculated by Layout, but the user may overwrite using this prop.
heightstring | numbernoNoneThe height is automatically calculated by Layout, but the user may overwrite using this prop.
hasBorderbooleannotrueToggle Card border.
hasBoxShadowbooleannotrueToggle Card box shadow.
hasHeaderBorderbooleannotrueToggle header border seperating header and border.
styleCSSPropertiesnoNoneStyles applied to the root element of card.
classNamestringnoNoneClass applied to the root element of card.
classesClassesnoNoneClasses of card.

Some Props mentioned above can be set in the theme prop of Theme Provider. These values will be used as default values of the Card component unless explicitly provided.

Custom Types

Classes

Classes enable customization and styling of card elements through their classes.

ClassNameTypeRequiredDefault valueDescription
rootstringnoNoneApplied to root element of card.
headerstringnoNoneApplied to header of card.
titlestringnoNoneApplied to title of card.
subtitlestringnoNoneApplied to subtitle of card.
bodystringnoNoneApplied to body of card.
actionsstringnoNoneApplied to actions element of card.

Please see Class Specificity for correctly defining it.