-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jim/74989/card component ts migration (#6455)
* refactor: migrate card component to ts * chore: add new line between type declarations * chore: render only if truthy Co-authored-by: Carol Sachdeva <58209918+carol-binary@users.noreply.github.com>
- Loading branch information
1 parent
7ff41b7
commit c8ff13c
Showing
3 changed files
with
53 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import classNames from 'classnames'; | ||
import React, { HTMLProps } from 'react'; | ||
|
||
type TGeneralCardComponentsProps = HTMLProps<HTMLDivElement>; | ||
|
||
type TCardProps = HTMLProps<HTMLDivElement> & { | ||
header: React.ReactNode; | ||
renderHeader: () => React.ReactNode; | ||
content: React.ReactNode; | ||
renderContent: () => React.ReactNode; | ||
footer: React.ReactNode; | ||
renderFooter: () => React.ReactNode; | ||
}; | ||
|
||
const CardRoot = ({ children, className, ...props }: TGeneralCardComponentsProps) => ( | ||
<div className={classNames('dc-card__wrapper', className)} {...props}> | ||
{children} | ||
</div> | ||
); | ||
|
||
const CardHeader = ({ children }: TGeneralCardComponentsProps) => ( | ||
<div className='dc-card__header-wrapper'>{children}</div> | ||
); | ||
|
||
const CardContent = ({ children }: TGeneralCardComponentsProps) => ( | ||
<div className='dc-card__content-wrapper'>{children}</div> | ||
); | ||
|
||
const CardFooter = ({ children }: TGeneralCardComponentsProps) => ( | ||
<div className='dc-card__footer-wrapper'>{children}</div> | ||
); | ||
|
||
const Card = ({ | ||
className, | ||
header, | ||
content, | ||
footer, | ||
renderHeader, | ||
renderContent, | ||
renderFooter, | ||
...props | ||
}: TCardProps) => { | ||
return ( | ||
<CardRoot className={classNames('dc-card', className)} {...props}> | ||
{renderHeader ? renderHeader() : !!header && <CardHeader>{header}</CardHeader>} | ||
{renderContent ? renderContent() : !!content && <CardContent>{content}</CardContent>} | ||
{renderFooter ? renderFooter() : !!footer && <CardFooter>{footer}</CardFooter>} | ||
</CardRoot> | ||
); | ||
}; | ||
|
||
export default Card; |
2 changes: 1 addition & 1 deletion
2
...s/components/src/components/card/index.js → ...s/components/src/components/card/index.ts
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,4 +1,4 @@ | ||
import Card from './card.jsx'; | ||
import Card from './card'; | ||
import './card.scss'; | ||
|
||
export default Card; |