2023-06-26 15:33:46 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
|
|
|
|
|
const baseClass = "card";
|
|
|
|
|
|
2023-10-10 22:00:45 +00:00
|
|
|
type BorderRadiusSize = "small" | "medium" | "large";
|
|
|
|
|
type CardColor = "white" | "gray" | "purple" | "yellow";
|
2023-06-26 15:33:46 +00:00
|
|
|
|
|
|
|
|
interface ICardProps {
|
|
|
|
|
children?: React.ReactNode;
|
2024-03-26 14:46:33 +00:00
|
|
|
/** The size of the border radius. Defaults to `small`. */
|
2023-10-10 22:00:45 +00:00
|
|
|
borderRadiusSize?: BorderRadiusSize;
|
|
|
|
|
/** Includes the card shadows. Defaults to `false` */
|
|
|
|
|
includeShadow?: boolean;
|
|
|
|
|
/** The color of the card. Defaults to `white` */
|
|
|
|
|
color?: CardColor;
|
2023-06-26 15:33:46 +00:00
|
|
|
className?: string;
|
2024-03-26 14:46:33 +00:00
|
|
|
/** The size of the padding around the content of the card. Defaults to `large`.
|
|
|
|
|
*
|
|
|
|
|
* These correspond to the padding sizes in the design system. Look at `padding.scss` for values */
|
|
|
|
|
paddingSize?: "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
|
|
|
/** NOTE: DEPRICATED. Use `paddingSize` prop instead.
|
|
|
|
|
*
|
|
|
|
|
* Increases to 40px padding. Defaults to `false` */
|
2024-03-04 20:47:42 +00:00
|
|
|
largePadding?: boolean;
|
2023-06-26 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A generic card component that will be used to render content within a card with a border and
|
|
|
|
|
* and selected background color.
|
|
|
|
|
*/
|
2023-10-10 22:00:45 +00:00
|
|
|
const Card = ({
|
|
|
|
|
children,
|
|
|
|
|
borderRadiusSize = "small",
|
|
|
|
|
includeShadow = false,
|
|
|
|
|
color = "white",
|
|
|
|
|
className,
|
2024-03-04 20:47:42 +00:00
|
|
|
largePadding = false,
|
2024-03-26 14:46:33 +00:00
|
|
|
paddingSize = "large",
|
2023-10-10 22:00:45 +00:00
|
|
|
}: ICardProps) => {
|
|
|
|
|
const classNames = classnames(
|
|
|
|
|
baseClass,
|
|
|
|
|
`${baseClass}__${color}`,
|
|
|
|
|
`${baseClass}__radius-${borderRadiusSize}`,
|
2024-03-04 20:47:42 +00:00
|
|
|
{
|
2024-03-26 14:46:33 +00:00
|
|
|
// TODO: simplify this when we've replaced largePadding prop with paddingSize
|
|
|
|
|
[`${baseClass}__padding-${paddingSize}`]:
|
|
|
|
|
!largePadding && paddingSize !== undefined,
|
2024-03-04 20:47:42 +00:00
|
|
|
[`${baseClass}__shadow`]: includeShadow,
|
|
|
|
|
[`${baseClass}__large-padding`]: largePadding,
|
|
|
|
|
},
|
2023-10-10 22:00:45 +00:00
|
|
|
className
|
|
|
|
|
);
|
2023-06-26 15:33:46 +00:00
|
|
|
|
|
|
|
|
return <div className={classNames}>{children}</div>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Card;
|