-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update card list item component (#1113)
* feat: update card list item component * feat: update card list item component * chore: update card list items documentation * test: update tests * style: add mixincode * style: update card list item style * chore: remove unused background color
- Loading branch information
1 parent
89bb744
commit 1c8cf3d
Showing
4 changed files
with
210 additions
and
64 deletions.
There are no files selected for viewing
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
154 changes: 111 additions & 43 deletions
154
packages/ocean-react/src/CardListItem/CardListItem.tsx
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 |
---|---|---|
@@ -1,59 +1,127 @@ | ||
import React from 'react'; | ||
import React, { ComponentPropsWithoutRef, forwardRef } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
interface CardListItemProps { | ||
type CardListItemProps = { | ||
/* | ||
* The title of the card list item. | ||
*/ | ||
title: string; | ||
/* | ||
* The description of the card list item. | ||
*/ | ||
description?: string; | ||
/* | ||
* The caption of the card list item. | ||
*/ | ||
caption?: string; | ||
/* | ||
* The action icon of the card list item. | ||
*/ | ||
actionIcon?: React.ReactNode; | ||
/* | ||
* The leading icon of the card list item. | ||
*/ | ||
leadingIcon?: React.ReactNode; | ||
/* | ||
* The size of the card list item. | ||
*/ | ||
size?: 'small' | 'medium'; | ||
/* | ||
* Whether the card list item is disabled. | ||
*/ | ||
disabled?: boolean; | ||
/* | ||
* Whether the card list item is full width. | ||
*/ | ||
fullWidth?: boolean; | ||
/* | ||
* The function to call when the card list item is clicked. | ||
*/ | ||
onClick?: () => void; | ||
} | ||
/* | ||
* Whether the card list item is loading. | ||
*/ | ||
loading?: boolean; | ||
} & ComponentPropsWithoutRef<'div'>; | ||
|
||
const CardListItem = ({ | ||
title, | ||
description, | ||
caption, | ||
leadingIcon, | ||
actionIcon, | ||
size = 'medium', | ||
disabled = false, | ||
fullWidth = false, | ||
onClick, | ||
}: CardListItemProps): JSX.Element => ( | ||
<div | ||
data-testid="card-list-item" | ||
className={classNames( | ||
'ods-card-list-item', | ||
`ods-card-list-item--size-${size}`, | ||
{ 'ods-card-list-item--disabled': disabled }, | ||
{ 'ods-card-list-item--full-width': fullWidth } | ||
)} | ||
onClick={() => { | ||
if (!disabled && onClick) onClick(); | ||
}} | ||
> | ||
{leadingIcon && ( | ||
<div className="ods-card-list-item__leading-icon">{leadingIcon}</div> | ||
)} | ||
<div className="ods-card-list-item__content"> | ||
<div className="ods-card-list-item__content__title">{title}</div> | ||
{description && ( | ||
<div className="ods-card-list-item__content__description"> | ||
{description} | ||
const CardListItem = forwardRef<HTMLDivElement, CardListItemProps>( | ||
( | ||
{ | ||
title, | ||
description, | ||
caption, | ||
leadingIcon, | ||
actionIcon, | ||
size = 'medium', | ||
disabled = false, | ||
fullWidth = false, | ||
onClick, | ||
loading, | ||
...rest | ||
}, | ||
ref | ||
): JSX.Element => | ||
loading ? ( | ||
<div | ||
ref={ref} | ||
{...rest} | ||
data-testid="card-list-item" | ||
className={classNames( | ||
'ods-card-list-item', | ||
`ods-card-list-item--size-${size}`, | ||
{ 'ods-card-list-item--full-width': fullWidth }, | ||
{ | ||
'ods-card-list-item--loading': loading, | ||
} | ||
)} | ||
> | ||
<div className="ods-card-list-item__circle" /> | ||
<div className="ods-card-list-item__lines"> | ||
<div className="ods-card-list-item__lines__line1" /> | ||
<div className="ods-card-list-item__lines__line2" /> | ||
{size === 'medium' && ( | ||
<div className="ods-card-list-item__lines__line3" /> | ||
)} | ||
</div> | ||
)} | ||
{caption && size === 'medium' && ( | ||
<div className="ods-card-list-item__content__caption">{caption}</div> | ||
)} | ||
</div> | ||
{actionIcon && ( | ||
<div className="ods-card-list-item__action">{actionIcon}</div> | ||
)} | ||
</div> | ||
</div> | ||
) : ( | ||
<div | ||
ref={ref} | ||
{...rest} | ||
data-testid="card-list-item" | ||
className={classNames( | ||
'ods-card-list-item', | ||
`ods-card-list-item--size-${size}`, | ||
{ 'ods-card-list-item--disabled': disabled }, | ||
{ 'ods-card-list-item--full-width': fullWidth } | ||
)} | ||
onClick={() => { | ||
if (!disabled && onClick) onClick(); | ||
}} | ||
> | ||
{leadingIcon && ( | ||
<div className="ods-card-list-item__leading-icon">{leadingIcon}</div> | ||
)} | ||
<div className="ods-card-list-item__content"> | ||
<div className="ods-card-list-item__content__title">{title}</div> | ||
{description && ( | ||
<div className="ods-card-list-item__content__description"> | ||
{description} | ||
</div> | ||
)} | ||
{caption && size === 'medium' && ( | ||
<div className="ods-card-list-item__content__caption"> | ||
{caption} | ||
</div> | ||
)} | ||
</div> | ||
{actionIcon && ( | ||
<div className="ods-card-list-item__action">{actionIcon}</div> | ||
)} | ||
</div> | ||
) | ||
); | ||
|
||
CardListItem.displayName = 'CardListItem'; | ||
|
||
export default CardListItem; |
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