@@ -2,21 +2,53 @@ import React from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import classNames from 'classnames' ;
4
4
5
+ import type { ComponentWithAsProp , BsPropsWithAs } from '../utils/types/bootstrap' ;
6
+
7
+ // @ts -ignore
5
8
import CardBody from './CardBody' ;
6
9
7
10
const BASE_CARD_CLASSNAME = 'card' ;
8
11
9
- const BaseCard = React . forwardRef (
12
+ const colorVariants = [
13
+ 'primary' ,
14
+ 'secondary' ,
15
+ 'success' ,
16
+ 'danger' ,
17
+ 'warning' ,
18
+ 'info' ,
19
+ 'dark' ,
20
+ 'light' ,
21
+ ] as const ;
22
+
23
+ const textVariants = [
24
+ 'white' ,
25
+ 'muted' ,
26
+ ] as const ;
27
+
28
+ type ColorVariant = typeof colorVariants [ number ] ;
29
+ type TextVariant = typeof textVariants [ number ] ;
30
+ interface Props extends BsPropsWithAs {
31
+ prefix ?: string ;
32
+ bgColor ?: ColorVariant ;
33
+ textColor ?: ColorVariant | TextVariant ;
34
+ borderColor ?: ColorVariant ;
35
+ hasBody : boolean ;
36
+ className ?: string ;
37
+ children : React . ReactNode ;
38
+ }
39
+ type BaseCardType = ComponentWithAsProp < 'div' , Props > ;
40
+
41
+ const BaseCard : BaseCardType = React . forwardRef < HTMLDivElement , Props > (
10
42
(
11
43
{
12
44
prefix,
13
45
className,
14
46
bgColor,
15
47
textColor,
16
48
borderColor,
17
- hasBody,
49
+ hasBody = false ,
18
50
children,
19
- as : Component ,
51
+ as : Component = 'div' ,
20
52
...props
21
53
} ,
22
54
ref ,
@@ -37,24 +69,13 @@ const BaseCard = React.forwardRef(
37
69
} ,
38
70
) ;
39
71
40
- const colorVariants = [
41
- 'primary' ,
42
- 'secondary' ,
43
- 'success' ,
44
- 'danger' ,
45
- 'warning' ,
46
- 'info' ,
47
- 'dark' ,
48
- 'light' ,
49
- ] ;
50
-
51
72
BaseCard . propTypes = {
52
73
/** Prefix for component CSS classes. */
53
74
prefix : PropTypes . string ,
54
75
/** Background color of the card. */
55
76
bgColor : PropTypes . oneOf ( colorVariants ) ,
56
77
/** Text color of the card. */
57
- textColor : PropTypes . oneOf ( [ ...colorVariants , 'white' , 'muted' ] ) ,
78
+ textColor : PropTypes . oneOf ( [ ...colorVariants , ... textVariants ] ) ,
58
79
/** Border color of the card. */
59
80
borderColor : PropTypes . oneOf ( colorVariants ) ,
60
81
/** Determines whether the card should render its children inside a `CardBody` wrapper. */
0 commit comments