Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:badge icon completed #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/Badge/Badge.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.badgeBase {
@apply inline-block;
}
5 changes: 5 additions & 0 deletions src/components/Badge/Badge.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface BadgeProps {
asifmehmood101 marked this conversation as resolved.
Show resolved Hide resolved
size: number;
name: 'star';
color: string;
}
18 changes: 18 additions & 0 deletions src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { Badge } from './Badge';

export default {
title: 'UI-Library/Badge',
component: Badge,
//argTypes: {},
} as ComponentMeta<typeof Badge>;

const Template: ComponentStory<typeof Badge> = args => <Badge {...args} />;

export const BadgeMain = Template.bind({});
BadgeMain.args = {
size: 24,
asifmehmood101 marked this conversation as resolved.
Show resolved Hide resolved
name: 'star',
color: 'red',
};
20 changes: 20 additions & 0 deletions src/components/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
//import renderer from 'react-test-renderer';
import { Badge } from './index';

describe('Badge', () => {
it('render Badge with default text content', () => {
const text = 'Welcome to Badge Component';
render(<Badge size={24} name="star" color="red" />);
expect(screen.getByText(text)).toBeInTheDocument();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tailwind custom classes sm, md ,..etc and test for them in the document,
e.g size = "sm" => test case that looks for sm in the document, you don't need to cover all variations, 2 is enough

});
});

//snapshot
/*
describe('renders correctly', () => {
asifmehmood101 marked this conversation as resolved.
Show resolved Hide resolved
const tree = renderer.create(<Badge />).toJSON();
expect(tree).toMatchSnapshot();
});
*/
26 changes: 26 additions & 0 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BadgeProps } from './Badge.d';
import './Badge.css';

export const Badge = ({
name,
size = 24,
color = 'currentColor',
...rest
}: BadgeProps): JSX.Element => {
const icons = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store the icon in a separate file, as its own component, refer to Star Icon for example, you can use the same icon/component here.

star: 'M33.5784 12.2983C33.3634 11.6683 32.795 11.2233 32.1317 11.1716L22.63 10.4166L18.5184 1.31498C18.25 0.716646 17.655 0.333313 17 0.333313C16.345 0.333313 15.75 0.716646 15.4817 1.31331L11.37 10.4166L1.86838 11.1716C1.21671 11.2233 0.655046 11.6516 0.433379 12.2666C0.211713 12.8816 0.36838 13.57 0.836713 14.0266L7.85838 20.8716L5.37505 31.625C5.22171 32.29 5.49005 32.9816 6.05171 33.37C6.33838 33.5667 6.66838 33.6666 7.00005 33.6666C7.32171 33.6666 7.64505 33.5733 7.92505 33.3867L17 27.3366L26.075 33.3867C26.655 33.7733 27.4167 33.7583 27.9834 33.3466C28.5467 32.935 28.795 32.2133 28.6034 31.5433L25.555 20.8766L33.115 14.0733C33.6101 13.6266 33.7917 12.93 33.5784 12.2983Z" fill="#3E413F"',
};

return (
<svg
width={size}
height={size}
viewBox={`0 0 ${size + 10} ${size + 10}`}
fill={color}
xmlns="http://www.w3.org/2000/svg"
{...rest}
>
<path d={icons[name]} />
</svg>
);
};
1 change: 1 addition & 0 deletions src/components/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Badge';