Merge pull request #81 from snowball-tools/ayungavis/T-4837-badge
[T-4837: feat] Badge component
This commit is contained in:
commit
c8f1c58507
43
packages/frontend/src/components/shared/Badge/Badge.theme.ts
Normal file
43
packages/frontend/src/components/shared/Badge/Badge.theme.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { VariantProps, tv } from 'tailwind-variants';
|
||||||
|
|
||||||
|
export const badgeTheme = tv({
|
||||||
|
slots: {
|
||||||
|
wrapper: ['rounded-full', 'grid', 'place-content-center'],
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
primary: {
|
||||||
|
wrapper: ['bg-controls-primary', 'text-elements-on-primary'],
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
wrapper: ['bg-controls-secondary', 'text-elements-on-secondary'],
|
||||||
|
},
|
||||||
|
tertiary: {
|
||||||
|
wrapper: [
|
||||||
|
'bg-controls-tertiary',
|
||||||
|
'border',
|
||||||
|
'border-border-interactive/10',
|
||||||
|
'text-elements-high-em',
|
||||||
|
'shadow-button',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
inset: {
|
||||||
|
wrapper: ['bg-controls-inset', 'text-elements-high-em'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
sm: {
|
||||||
|
wrapper: ['h-5', 'w-5', 'text-xs'],
|
||||||
|
},
|
||||||
|
xs: {
|
||||||
|
wrapper: ['h-4', 'w-4', 'text-2xs', 'font-medium'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: 'primary',
|
||||||
|
size: 'sm',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type BadgeTheme = VariantProps<typeof badgeTheme>;
|
33
packages/frontend/src/components/shared/Badge/Badge.tsx
Normal file
33
packages/frontend/src/components/shared/Badge/Badge.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ComponentPropsWithoutRef } from 'react';
|
||||||
|
import { BadgeTheme, badgeTheme } from './Badge.theme';
|
||||||
|
|
||||||
|
export interface BadgeProps
|
||||||
|
extends ComponentPropsWithoutRef<'div'>,
|
||||||
|
BadgeTheme {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A badge is a small status descriptor for UI elements.
|
||||||
|
* It can be used to indicate a status, a count, or a category.
|
||||||
|
* It is typically used in lists, tables, or navigation elements.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```tsx
|
||||||
|
* <Badge variant="primary" size="sm">1</Badge
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export const Badge = ({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
variant,
|
||||||
|
size,
|
||||||
|
...props
|
||||||
|
}: BadgeProps) => {
|
||||||
|
const { wrapper } = badgeTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...props} className={wrapper({ className, variant, size })}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
1
packages/frontend/src/components/shared/Badge/index.ts
Normal file
1
packages/frontend/src/components/shared/Badge/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './Badge';
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Badge, BadgeProps } from 'components/shared/Badge';
|
||||||
import { Button, ButtonOrLinkProps } from 'components/shared/Button';
|
import { Button, ButtonOrLinkProps } from 'components/shared/Button';
|
||||||
import { Calendar } from 'components/shared/Calendar';
|
import { Calendar } from 'components/shared/Calendar';
|
||||||
import { Checkbox } from 'components/shared/Checkbox';
|
import { Checkbox } from 'components/shared/Checkbox';
|
||||||
@ -79,6 +80,29 @@ const Page = () => {
|
|||||||
|
|
||||||
<div className="w-full h border border-gray-200 px-20 my-10" />
|
<div className="w-full h border border-gray-200 px-20 my-10" />
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-10 items-center justify-between">
|
||||||
|
<h1 className="text-2xl font-bold">Badge</h1>
|
||||||
|
<div className="space-y-5">
|
||||||
|
{['primary', 'secondary', 'tertiary', 'inset'].map(
|
||||||
|
(variant, index) => (
|
||||||
|
<div className="flex gap-5" key={index}>
|
||||||
|
{['sm', 'xs'].map((size) => (
|
||||||
|
<Badge
|
||||||
|
key={size}
|
||||||
|
variant={variant as BadgeProps['variant']}
|
||||||
|
size={size as BadgeProps['size']}
|
||||||
|
>
|
||||||
|
1
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-full h border border-gray-200 px-20 my-10" />
|
||||||
|
|
||||||
<div className="flex flex-col gap-10 items-center justify-between">
|
<div className="flex flex-col gap-10 items-center justify-between">
|
||||||
<h1 className="text-2xl font-bold">Checkbox</h1>
|
<h1 className="text-2xl font-bold">Checkbox</h1>
|
||||||
<div className="flex gap-10 flex-wrap">
|
<div className="flex gap-10 flex-wrap">
|
||||||
|
@ -12,6 +12,10 @@ export default withMT({
|
|||||||
sans: ['Inter', 'sans-serif'],
|
sans: ['Inter', 'sans-serif'],
|
||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
|
fontSize: {
|
||||||
|
'2xs': '0.625rem',
|
||||||
|
'3xs': '0.5rem',
|
||||||
|
},
|
||||||
colors: {
|
colors: {
|
||||||
emerald: {
|
emerald: {
|
||||||
100: '#d1fae5',
|
100: '#d1fae5',
|
||||||
|
Loading…
Reference in New Issue
Block a user