Skip to content

Commit

Permalink
fix: re-write Badge to use badge-{color} classes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmars committed Mar 28, 2024
1 parent 1e19e03 commit c920062
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export const Default = () => (
);

export const Pills = () => (
<div>
<div className="d-flex gap-3">
{colors.map((color) => (
<div>
<Badge pill color={color}>
{color}
</Badge>
</div>
<Badge pill color={color}>
{color}
</Badge>
))}
</div>
);
29 changes: 28 additions & 1 deletion src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
import { Badge } from 'reactstrap';
import classNames from 'classnames';
import React, { type PropsWithChildren } from 'react';

export interface BadgeProps {
className?: string;
color?: string;
href?: string;
pill?: boolean;
tag?: keyof JSX.IntrinsicElements;
[key: string]: any;
}

function Badge({
className,
color = 'secondary',
href,
pill = false,
tag: Tag = 'span',
...props
}: PropsWithChildren<BadgeProps>) {
const classes = classNames(className, 'badge', `badge-${color}`, pill ? 'rounded-pill' : false);

if (href) {
Tag = 'a';
}

return <Tag {...props} className={classes} />;
}

export default Badge;
1 change: 1 addition & 0 deletions src/tooling/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const colors = [
'danger',
'warning',
'info',
'ai',
'light',
'dark',
];
Expand Down

0 comments on commit c920062

Please sign in to comment.