-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-react): Introduce Card component #1535
- Loading branch information
1 parent
47c76d1
commit 091248e
Showing
53 changed files
with
4,149 additions
and
0 deletions.
There are no files selected for viewing
403 changes: 403 additions & 0 deletions
403
packages/web-react/docs/stories/examples/CardComposition.stories.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React, { ElementType } from 'react'; | ||
import { Direction } from '../../constants'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardProps> = { | ||
direction: Direction.VERTICAL, | ||
elementType: 'article', | ||
isBoxed: false, | ||
}; | ||
|
||
const Card = <T extends ElementType = 'article'>(props: SpiritCardProps<T>) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { elementType: ElementTag = 'article', direction, isBoxed, children, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ direction, isBoxed }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<ElementTag {...otherProps} className={classNames(classProps.root, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</ElementTag> | ||
); | ||
}; | ||
|
||
export default Card; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { AlignmentX } from '../../constants'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardArtworkProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardArtworkProps> = { | ||
alignmentX: AlignmentX.LEFT, | ||
}; | ||
|
||
const CardArtwork = (props: SpiritCardArtworkProps) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { children, alignmentX, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ artworkAlignmentX: alignmentX }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div {...otherProps} className={classNames(classProps.artwork, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardArtwork; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardBodyProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardBodyProps> = { | ||
isSelectable: false, | ||
}; | ||
|
||
const CardBody = (props: SpiritCardBodyProps) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { children, isSelectable, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ isSelectable }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div {...otherProps} className={classNames(classProps.body, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardBody; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardEyebrowProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const CardEyebrow = (props: SpiritCardEyebrowProps) => { | ||
const { children, ...restProps } = props; | ||
const { classProps } = useCardStyleProps(); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div {...otherProps} className={classNames(classProps.eyebrow, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardEyebrow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { AlignmentX } from '../../constants'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardFooterProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardFooterProps> = { | ||
alignmentX: AlignmentX.LEFT, | ||
}; | ||
|
||
const CardFooter = (props: SpiritCardFooterProps) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { children, alignmentX, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ footerAlignmentX: alignmentX }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<footer {...otherProps} className={classNames(classProps.footer, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</footer> | ||
); | ||
}; | ||
|
||
export default CardFooter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React, { ElementType, forwardRef } from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { PolymorphicRef, SpiritCardLinkProps, SpiritLinkProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardLinkProps> = { | ||
elementType: 'a', | ||
}; | ||
|
||
/* We need an exception for components exported with forwardRef */ | ||
/* eslint no-underscore-dangle: ['error', { allow: ['_CardLink'] }] */ | ||
const _CardLink = <E extends ElementType = 'a'>(props: SpiritCardLinkProps<E>, ref: PolymorphicRef<E>): JSX.Element => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { | ||
elementType: ElementTag = defaultProps.elementType as ElementType, | ||
children, | ||
...restProps | ||
} = propsWithDefaults; | ||
const { classProps } = useCardStyleProps(); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<ElementTag | ||
{...otherProps} | ||
{...styleProps} | ||
href={restProps.href} | ||
className={classNames(classProps.link, styleProps.className)} | ||
ref={ref} | ||
> | ||
{children} | ||
</ElementTag> | ||
); | ||
}; | ||
|
||
const CardLink = forwardRef<HTMLAnchorElement, SpiritLinkProps<ElementType>>(_CardLink); | ||
|
||
export default CardLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardLogoProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const CardLogo = (props: SpiritCardLogoProps) => { | ||
const { children, ...restProps } = props; | ||
const { classProps } = useCardStyleProps(); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div {...otherProps} className={classNames(classProps.logo, styleProps.className)} style={{ ...styleProps.style }}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardLogo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { CardSizes, SpiritCardMediaProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardMediaProps> = { | ||
hasFilledHeight: false, | ||
isExpanded: false, | ||
size: CardSizes.AUTO, | ||
}; | ||
|
||
const CardMedia = (props: SpiritCardMediaProps) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { children, size, isExpanded, hasFilledHeight, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ size, isExpanded, hasFilledHeight }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<div {...otherProps} className={classNames(classProps.media, styleProps.className)} style={styleProps.style}> | ||
<div className={classProps.mediaCanvas}>{children}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CardMedia; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
|
||
import classNames from 'classnames'; | ||
import React, { ElementType } from 'react'; | ||
import { useStyleProps } from '../../hooks'; | ||
import { SpiritCardTitleProps } from '../../types'; | ||
import { useCardStyleProps } from './useCardStyleProps'; | ||
|
||
const defaultProps: Partial<SpiritCardTitleProps> = { | ||
elementType: 'h4', | ||
isHeading: true, | ||
}; | ||
|
||
const CardTitle = <T extends ElementType = 'h4'>(props: SpiritCardTitleProps<T>) => { | ||
const propsWithDefaults = { ...defaultProps, ...props }; | ||
const { elementType: ElementTag = 'h4', children, isHeading, ...restProps } = propsWithDefaults; | ||
const { classProps } = useCardStyleProps({ isHeading }); | ||
const { styleProps, props: otherProps } = useStyleProps(restProps); | ||
|
||
return ( | ||
<ElementTag {...otherProps} className={classNames(classProps.title, styleProps.className)} style={styleProps.style}> | ||
{children} | ||
</ElementTag> | ||
); | ||
}; | ||
|
||
export default CardTitle; |
Oops, something went wrong.