Skip to content

Commit

Permalink
Jim/74989/card component ts migration (#6455)
Browse files Browse the repository at this point in the history
* 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
jim-deriv and carolsachdeva committed Sep 27, 2022
1 parent 7ff41b7 commit c8ff13c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
37 changes: 0 additions & 37 deletions packages/components/src/components/card/card.jsx

This file was deleted.

52 changes: 52 additions & 0 deletions packages/components/src/components/card/card.tsx
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;
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;

0 comments on commit c8ff13c

Please sign in to comment.