Skip to content

Commit ea7ed96

Browse files
GoldGroove06kotAPI
andauthored
Badge color prop with test and docs (#796)
Co-authored-by: Pranay Kothapalli <pranaykothapalli@gmail.com>
1 parent c8ec466 commit ea7ed96

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

docs/app/docs/components/badge/page.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@ export const metadata = SEO.getMetadata(PAGE_NAME)
88

99
import codeUsage from "./docs/codeUsage"
1010

11-
const AvatarDocs = () => {
11+
const BadgeDocs = () => {
12+
const columns = [
13+
{name: 'Prop', id: 'prop'},
14+
{name: 'Type', id: 'type'},
15+
{name: 'Default', id: 'default'},
16+
{name: 'Description', id: 'description'},
17+
];
18+
19+
const data = [
20+
{prop: 'color', type: 'string', default: 'null', description: 'Accent color of the component', id: 'color'},
21+
];
1222
return <div>
1323
<Documentation currentPage={PAGE_NAME} title='Badge' description={`
1424
Badges are used to display a small amount of information. They are used in the sidebar, and in the chat.
1525
`}>
1626
<Documentation.ComponentHero codeUsage={codeUsage}>
1727
<div style={{ display: "flex", gap: 20 }}>
18-
<Badge src="https://i.pravatar.cc/1000" fallback="GG" >Badge</Badge>
28+
<Badge>Badge</Badge>
1929
</div>
2030
</Documentation.ComponentHero>
2131

32+
33+
<div className="max-w-screen-md">
34+
<Documentation.Table columns={columns} data={data} />
35+
</div>
36+
2237
</Documentation>
2338
</div>
2439
}
2540

26-
export default AvatarDocs;
41+
export default BadgeDocs;

src/components/ui/Badge/Badge.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ export type BadgeProps = {
1010
props?: object[],
1111
}
1212

13-
const Badge = ({ children, customRootClass = '', className = '', color, ...props }: BadgeProps) => {
14-
return <BadgeRoot customRootClass={customRootClass} className={className} color={color ?? undefined} {...props}>
13+
const Badge = ({ children, customRootClass = '', className = '', color='', ...props }: BadgeProps) => {
14+
15+
const data_attributes: Record<string, string> = {};
16+
17+
if (color) {
18+
data_attributes['data-accent-color'] = color;
19+
}
20+
21+
return <BadgeRoot customRootClass={customRootClass} className={className} {...data_attributes} {...props}>
1522
<BadgeContent>
1623
{children}
1724
</BadgeContent>

src/components/ui/Badge/tests/Badge.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ describe('Badge', () => {
2626
render(<Badge data-testid='badge'>Badge</Badge>);
2727
expect(screen.getByTestId('badge')).toBeInTheDocument();
2828
});
29+
30+
test('renders Badge component with custom color', () => {
31+
render(<Badge color='blue'>Badge</Badge>);
32+
expect(screen.getByText('Badge')).toHaveAttribute('data-accent-color', 'blue');
33+
});
2934
});

0 commit comments

Comments
 (0)