-
Notifications
You must be signed in to change notification settings - Fork 47
/
Card.tsx
44 lines (40 loc) · 1.18 KB
/
Card.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { FC, HTMLAttributes, ReactNode } from 'react';
import styles from './card.module.css';
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
css?: string;
isSkinned?: boolean;
isAnimated?: boolean;
isStacked?: boolean;
isShadow?: boolean;
isBorder?: boolean;
isRounded?: boolean;
type?: 'success' | 'info' | 'warning' | 'error';
children?: ReactNode;
}
export const Card: FC<CardProps> = ({
isAnimated = false,
isStacked = false,
isShadow = false,
isBorder = false,
isRounded = false,
isSkinned = true,
css = '',
type,
children,
}) => {
// Type might be empty string so we only capitalize if it's truthy
const typeCapitalized = type ? `${type.slice(0, 1).toUpperCase()}${type.slice(1)}` : '';
const classes = [
isSkinned ? styles.card : styles.cardBase,
isAnimated ? styles.cardAnimated : '',
isStacked ? styles.cardStacked : '',
isShadow ? styles.cardShadow : '',
isRounded ? styles.cardRounded : '',
isBorder ? styles.cardBorder : '',
type ? styles[`card${typeCapitalized}`] : '',
css ? `${css}` : '',
]
.filter((cls) => cls.length)
.join(' ');
return <div className={classes}>{children}</div>;
};