Skip to content

Commit

Permalink
Feat(web-react): Introduce Card component #1535
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Nov 26, 2024
1 parent 5a68dcc commit a249f6d
Show file tree
Hide file tree
Showing 52 changed files with 3,455 additions and 0 deletions.
380 changes: 380 additions & 0 deletions packages/web-react/docs/stories/examples/CardComposition.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
import React, { ElementType } from 'react';
import {
Button,
Card,
CardArtwork,
CardBody,
CardEyebrow,
CardFooter,
CardLink,
CardLogo,
CardMedia,
CardTitle,
Container,
Grid,
Icon,
PartnerLogo,
UseCardStyleProps,
} from '../../../src/components';
import { LOGO, MEDIA_IMAGE } from '../../../src/components/Card/demo/constants';
import { AlignmentX, Direction, Sizes } from '../../../src/constants';
import { GridColumns, SizesDictionaryType } from '../../../src/types';

type CardCompositionType = {
cardElementType: ElementType;
cardLogoHasSafeArea: boolean;
cardLogoSize: SizesDictionaryType;
contentText: string;
eyebrowText: string;
gridCols: GridColumns;
image: string;
numCards: number;
showArtwork: boolean;
showContent: boolean;
showEyebrow: boolean;
showFooter: boolean;
showLogo: boolean;
showMedia: boolean;
showTitle: boolean;
titleElementType: ElementType;
titleText: string;
titleWithLink: boolean;
wrapInContainer: boolean;
} & UseCardStyleProps;

export default {
title: 'Examples/Compositions',
argTypes: {
alignmentX: {
control: 'select',
description: 'Alignment inside CardFooter component.',
options: [...Object.values(AlignmentX)],
table: {
category: 'CardFooter',
defaultValue: { summary: AlignmentX.LEFT },
},
},
cardElementType: {
control: 'text',
name: 'elementType',
description: 'Element type for the card.',
table: {
category: 'Card',
defaultValue: { summary: 'article' },
},
},
cardLogoHasSafeArea: {
control: 'boolean',
description: 'If true, the logo will have a safe area.',
name: 'logo safe area',
table: {
category: 'CardLogo',
subcategory: 'Demo settings',
},
},
cardLogoSize: {
control: 'select',
description: 'Size of the logo.',
options: [...Object.values(Sizes)],
name: 'logo size',
table: {
category: 'CardLogo',
subcategory: 'Demo settings',
},
},
contentText: {
control: 'text',
description: 'Text for the user content.',
name: 'children',
table: {
category: 'CardBody',
defaultValue: {
summary: '',
},
},
},
direction: {
control: 'select',
description: 'Direction of the card.',
options: [...Object.values(Direction), 'horizontal-reversed'],
table: {
category: 'Card',
defaultValue: { summary: Direction.VERTICAL },
},
},
eyebrowText: {
control: 'text',
description: 'Text for the CardEyebrow component.',
name: 'children',
table: {
category: 'CardEyebrow',
defaultValue: { summary: '' },
},
},
gridCols: {
control: 'select',
name: 'grid columns',
description: 'Number of columns in the grid.',
options: [1, 2, 3, 4, 5, 6, 12],
},
hasFilledHeight: {
control: 'boolean',
description: 'Fill the height of the media.',
table: {
category: 'CardMedia',
defaultValue: { summary: false },
},
},
image: {
control: 'text',
description: 'Image source for the CardMedia image.',
name: 'image url',
table: {
category: 'CardMedia',
subcategory: 'Demo settings',
},
},
isBoxed: {
control: 'boolean',
description: 'Border around the card.',
table: {
category: 'Card',
defaultValue: { summary: false },
},
},
isExpanded: {
control: 'boolean',
description: 'Expand the media to fill the card. Only works when isBoxed is true.',
table: {
category: 'CardMedia',
defaultValue: { summary: false },
},
},
isHeading: {
control: 'boolean',
description: 'If true, the CardTitle will render as a heading.',
table: {
category: 'CardTitle',
defaultValue: { summary: true },
},
},
numCards: {
control: 'select',
name: 'number of cards',
description: 'Number of cards to display.',
options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
},
showArtwork: {
control: 'boolean',
description: 'Show the CardArtwork component.',
name: 'show artwork',
table: {
category: 'CardArtwork',
subcategory: 'Demo settings',
},
},
showFooter: {
control: 'boolean',
description: 'Show the CardFooter component.',
name: 'show footer',
table: {
category: 'CardFooter',
subcategory: 'Demo settings',
},
},
showLogo: {
control: 'boolean',
description: 'Show the CardLogo component.',
name: 'show logo',
table: {
category: 'CardLogo',
subcategory: 'Demo settings',
},
},
showContent: {
control: 'boolean',
description: 'Show the user content component.',
name: 'show card content',
table: {
category: 'CardBody',
subcategory: 'Demo settings',
},
},
showEyebrow: {
control: 'boolean',
description: 'Show the CardEyebrow component.',
name: 'show eyebrow',
table: {
category: 'CardEyebrow',
subcategory: 'Demo settings',
},
},
showMedia: {
control: 'boolean',
description: 'Show the CardMedia component.',
name: 'show media',
table: {
category: 'CardMedia',
subcategory: 'Demo settings',
},
},
showTitle: {
control: 'boolean',
description: 'Show the CardTitle component.',
name: 'show title',
table: {
category: 'CardTitle',
subcategory: 'Demo settings',
},
},
size: {
control: 'select',
description: 'Size of the media.',
options: [...Object.values(Sizes), 'auto'],
table: {
category: 'CardMedia',
defaultValue: { summary: Sizes.MEDIUM },
},
},
titleElementType: {
control: 'text',
name: 'elementType',
description: 'Element type for the title.',
table: {
category: 'CardTitle',
defaultValue: { summary: 'h4' },
},
},
titleText: {
control: 'text',
description: 'Text for the CardTitle component.',
name: 'children',
table: {
category: 'CardTitle',
defaultValue: { summary: '' },
},
},
titleWithLink: {
control: 'boolean',
description: 'Add a link to the CardTitle component.',
name: 'title as link',
table: {
category: 'CardTitle',
subcategory: 'Demo settings',
},
},
wrapInContainer: {
control: 'boolean',
description: 'Wrap the card in a container.',
name: 'wrap cards in container',
},
},
args: {
alignmentX: AlignmentX.LEFT,
cardElementType: 'article',
cardLogoHasSafeArea: true,
cardLogoSize: Sizes.MEDIUM,
contentText:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan, metus ultrices eleifend gravida, nulla nunc varius lectus, nec rutrum justo nibh eu lectus. Ut vulputate semper dui. Fusce erat. Morbi fringilla convallis sapien. Sed ac felis. Aliquam erat volutpat. Aliquam euismod. Aenean vel lectus. Nunc imperdiet justo nec dolor.',
direction: Direction.VERTICAL,
eyebrowText: 'Eyebrow title',
gridCols: 3,
hasFilledHeight: false,
image: MEDIA_IMAGE,
isBoxed: false,
isExpanded: false,
isHeading: true,
numCards: 3,
showArtwork: false,
showFooter: true,
showLogo: true,
showContent: true,
showEyebrow: true,
showMedia: true,
showTitle: true,
size: Sizes.MEDIUM,
titleElementType: 'h4',
titleText: 'Card Title',
titleWithLink: false,
wrapInContainer: true,
},
};

export const CardComposition = (args: CardCompositionType) => {
const {
alignmentX,
cardElementType,
cardLogoHasSafeArea,
cardLogoSize,
contentText,
direction,
eyebrowText,
gridCols,
hasFilledHeight,
image,
isBoxed,
isExpanded,
isHeading,
numCards,
showArtwork,
showContent,
showEyebrow,
showFooter,
showLogo,
showMedia,
showTitle,
size,
titleElementType,
titleText,
titleWithLink,
wrapInContainer,
...restProps
} = args;

const renderTitle = () => (
<CardTitle isHeading={isHeading} elementType={titleElementType}>
{titleWithLink ? <CardLink href="#">{titleText}</CardLink> : titleText}
</CardTitle>
);

const renderCard = () => (
<Grid cols={gridCols}>
{Array.from({ length: numCards }, (_, index) => (
<Card key={index} elementType={cardElementType} {...restProps} isBoxed={isBoxed} direction={direction}>
{showMedia && (
<CardMedia isExpanded={isExpanded} size={size} hasFilledHeight={hasFilledHeight}>
<img src={image} alt="" />
</CardMedia>
)}
{showArtwork && (
<CardArtwork>
<Icon name="file" />
</CardArtwork>
)}
{showLogo && (
<CardLogo>
<PartnerLogo size={cardLogoSize} hasSafeArea={cardLogoHasSafeArea}>
{LOGO}
</PartnerLogo>
</CardLogo>
)}
{(showEyebrow || showTitle || showContent) && (
<CardBody>
{showEyebrow && <CardEyebrow>{eyebrowText}</CardEyebrow>}
{showTitle && renderTitle()}
{showContent && <p>{contentText}</p>}
</CardBody>
)}
{showFooter && (
<CardFooter alignmentX={alignmentX}>
<Button color="primary">Primary</Button>
<Button color="secondary">Secondary</Button>
</CardFooter>
)}
</Card>
))}
</Grid>
);

return wrapInContainer ? <Container>{renderCard()}</Container> : renderCard();
};
1 change: 1 addition & 0 deletions packages/web-react/scripts/entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const entryPoints = [
{ dirs: ['components', 'Alert'] },
{ dirs: ['components', 'Breadcrumbs'] },
{ dirs: ['components', 'Button'] },
{ dirs: ['components', 'Card'] },
{ dirs: ['components', 'Checkbox'] },
{ dirs: ['components', 'Collapse'] },
{ dirs: ['components', 'Container'] },
Expand Down
Loading

0 comments on commit a249f6d

Please sign in to comment.