Skip to content

Commit 41be99a

Browse files
chore: add typescript types for BaseCard
1 parent f3beb20 commit 41be99a

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/Card/BaseCard.jsx src/Card/BaseCard.tsx

+36-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,53 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
44

5+
import type { ComponentWithAsProp, BsPropsWithAs } from '../utils/types/bootstrap';
6+
7+
// @ts-ignore
58
import CardBody from './CardBody';
69

710
const BASE_CARD_CLASSNAME = 'card';
811

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>(
1042
(
1143
{
1244
prefix,
1345
className,
1446
bgColor,
1547
textColor,
1648
borderColor,
17-
hasBody,
49+
hasBody = false,
1850
children,
19-
as: Component,
51+
as: Component = 'div',
2052
...props
2153
},
2254
ref,
@@ -37,24 +69,13 @@ const BaseCard = React.forwardRef(
3769
},
3870
);
3971

40-
const colorVariants = [
41-
'primary',
42-
'secondary',
43-
'success',
44-
'danger',
45-
'warning',
46-
'info',
47-
'dark',
48-
'light',
49-
];
50-
5172
BaseCard.propTypes = {
5273
/** Prefix for component CSS classes. */
5374
prefix: PropTypes.string,
5475
/** Background color of the card. */
5576
bgColor: PropTypes.oneOf(colorVariants),
5677
/** Text color of the card. */
57-
textColor: PropTypes.oneOf([...colorVariants, 'white', 'muted']),
78+
textColor: PropTypes.oneOf([...colorVariants, ...textVariants]),
5879
/** Border color of the card. */
5980
borderColor: PropTypes.oneOf(colorVariants),
6081
/** Determines whether the card should render its children inside a `CardBody` wrapper. */

0 commit comments

Comments
 (0)