Skip to content

Commit

Permalink
feat: replaced bootstrap BaseCard component
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Dec 4, 2024
1 parent e96baef commit ac63c17
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/Card/BaseCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import CardBody from './CardBody';

const BASE_CARD_CLASSNAME = 'card';

const BaseCard = React.forwardRef(
(
{
prefix,
className,
bgColor,
textColor,
borderColor,
hasBody = false,
children,
as: Component = 'div',
...props
},
ref,
) => {
const classes = classNames(
className,
prefix ? `${prefix}-${BASE_CARD_CLASSNAME}` : BASE_CARD_CLASSNAME,
bgColor && `bg-${bgColor}`,
textColor && `text-${textColor}`,
borderColor && `border-${borderColor}`,
);

return (
<Component ref={ref} {...props} className={classes}>
{hasBody ? <CardBody>{children}</CardBody> : children}
</Component>
);
},
);

const colorVariants = [
'primary',
'secondary',
'success',
'danger',
'warning',
'info',
'dark',
'light',
];

BaseCard.propTypes = {
/** Prefix for component CSS classes. */
prefix: PropTypes.string,
/** Background color of the card. */
bgColor: PropTypes.oneOf(colorVariants),
/** Text color of the card. */
textColor: PropTypes.oneOf([...colorVariants, 'white', 'muted']),
/** Border color of the card. */
borderColor: PropTypes.oneOf(colorVariants),
/** Determines whether the card should render its children inside a `CardBody` wrapper. */
hasBody: PropTypes.bool,
/** Set a custom element for this component. */
as: PropTypes.elementType,
/** Additional CSS class names to apply to the card element. */
className: PropTypes.string,
/** The content to render inside the card. */
children: PropTypes.node,
};

BaseCard.defaultProps = {
prefix: undefined,
hasBody: false,
as: 'div',
borderColor: undefined,
className: undefined,
children: undefined,
bgColor: undefined,
textColor: undefined,
};

export default BaseCard;
2 changes: 1 addition & 1 deletion src/Card/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import BaseCard from 'react-bootstrap/Card';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import BaseCard from './BaseCard';
import CardContext, { CardContextProvider } from './CardContext';
import CardHeader from './CardHeader';
import CardDivider from './CardDivider';
Expand Down

0 comments on commit ac63c17

Please sign in to comment.