Skip to content

Commit

Permalink
feat(components): badge
Browse files Browse the repository at this point in the history
  • Loading branch information
zuramai committed Nov 15, 2023
1 parent 01b8c08 commit f53436c
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/badge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@bootwind/badge",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"peerDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.14",
"react": "^18.2.0"
},
"dependencies": {
"tailwind-merge": "^2.0.0"
}
}
45 changes: 45 additions & 0 deletions packages/badge/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { ReactElement } from 'react';
import { ReactNode } from 'react';

type ButtonSize = 'sm' | 'md' ;
type BadgeVariant = 'primary' | 'neutral' | 'warning' | 'success' | 'error';

export interface BadgeProps {
variant?: BadgeVariant;
type?: "light" | "strong"
size?: ButtonSize;
children?: ReactNode
}

export const Badge = ({
variant = 'primary',
size = 'sm',
type = "light",
children,
...props
}: BadgeProps) => {
const baseStyles = ''

const sizeStyles = {
sm: 'px-2 py-0.5 text-xs rounded-md',
md: 'px-4 py-2 text-base rounded-md',
};

const colorStyles = {
primary: 'bg-light-primary text-primary',
neutral: 'bg-slate-500 text-slate-100',
warning: 'bg-slate-500 text-slate-100',
success: 'bg-slate-500 text-slate-100',
error: 'bg-slate-500 text-slate-100',
};

const badgeStyles = `${baseStyles} ${sizeStyles[size]} ${colorStyles[variant]}`;

return (
<>
<span className={badgeStyles} {...props}>
{children}
</span>
</>
);
};
56 changes: 56 additions & 0 deletions packages/badge/stories/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { Meta } from '@storybook/react';
import { Badge, BadgeProps } from '../src/index';

import { FaRegEnvelope } from 'react-icons/fa6'; // Import ikon dari react-icons atau dari sumber lain

export default {
title: 'Components/Badge',
component: Badge,
argTypes: {
variant: {
control: { type: 'radio', options: ['primary', 'secondary', 'ghost'] },
},
size: {
control: { type: 'radio', options: ['sm', 'md', 'lg', 'xl'] },
},
},
} as Meta;

export const Variants = (args: BadgeProps) => {
const variants = [
'slate',
'gray',
'zinc',
'neutral',
'stone',
'red',
'orange',
'amber',
'yellow',
'lime',
'green',
'emerald',
'teal',
'cyan',
'sky',
'blue',
'indigo',
'violet',
'purple',
'fuchsia',
'pink',
'rose',
];
return (
<div >
<Badge>Primary</Badge>
</div>
)
}

export const Sizes = (args: BadgeProps) => (
<div className="flex flex-col space-y-4 mt-8">

</div>
);
4 changes: 4 additions & 0 deletions packages/badge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../tsconfig.json"],
"include": ["src"]
}
3 changes: 3 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module.exports = {
extend: {
colors: {
primary: '#5E72E4',
light: {
primary: '#F2F5FF'
}
},
},
},
Expand Down

0 comments on commit f53436c

Please sign in to comment.