File tree Expand file tree Collapse file tree 6 files changed +67
-9
lines changed
Expand file tree Collapse file tree 6 files changed +67
-9
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @programmer_network/yail" ,
3- "version" : " 1.0.220 " ,
3+ "version" : " 1.0.221 " ,
44 "description" : " Programmer Network's official UI library for React" ,
55 "author" : " Aleksandar Grbic - (https://programmer.network)" ,
66 "publishConfig" : {
Original file line number Diff line number Diff line change 11import type { Meta , StoryObj } from "@storybook/react" ;
22
33import Badge from "." ;
4+ import { BadgeVariantEnum } from "./types" ;
45
56const meta = {
67 title : "Core/Badge" ,
@@ -15,9 +16,30 @@ const meta = {
1516export default meta ;
1617type Story = StoryObj < typeof meta > ;
1718
19+ export const Empty : Story = {
20+ args : {
21+ title : "Badge" ,
22+ variant : BadgeVariantEnum . PRIMARY
23+ }
24+ } ;
25+
1826export const Filled : Story = {
1927 args : {
2028 title : "Badge" ,
21- className : "yl:bg-primary-500"
29+ variant : BadgeVariantEnum . PRIMARY
30+ }
31+ } ;
32+
33+ export const Beta : Story = {
34+ args : {
35+ title : "Beta" ,
36+ variant : BadgeVariantEnum . BETA
37+ }
38+ } ;
39+
40+ export const New : Story = {
41+ args : {
42+ title : "New" ,
43+ variant : BadgeVariantEnum . NEW
2244 }
2345} ;
Original file line number Diff line number Diff line change 11import { render , screen } from "@testing-library/react" ;
22
33import Badge from "./" ;
4+ import { BadgeVariantEnum } from "./types" ;
45
56describe ( "Badge component" , ( ) => {
67 const testTitle = "Test Badge" ;
78
89 test ( "renders correctly - snapshot test" , ( ) => {
9- const { asFragment } = render ( < Badge title = { testTitle } /> ) ;
10+ const { asFragment } = render (
11+ < Badge title = { testTitle } variant = { BadgeVariantEnum . PRIMARY } />
12+ ) ;
1013 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
1114 } ) ;
1215
1316 test ( "renders the title correctly" , ( ) => {
14- render ( < Badge title = { testTitle } /> ) ;
17+ render ( < Badge title = { testTitle } variant = { BadgeVariantEnum . PRIMARY } /> ) ;
1518 const badgeElement = screen . getByText ( testTitle ) ;
1619 expect ( badgeElement ) . toBeInTheDocument ( ) ;
1720 } ) ;
1821
1922 test ( "applies custom class name" , ( ) => {
2023 const customClass = "custom-class" ;
21- render ( < Badge title = { testTitle } className = { customClass } /> ) ;
24+ render (
25+ < Badge
26+ title = { testTitle }
27+ variant = { BadgeVariantEnum . PRIMARY }
28+ className = { customClass }
29+ />
30+ ) ;
2231 const badgeElement = screen . getByText ( testTitle ) ;
2332 expect ( badgeElement ) . toHaveClass ( customClass ) ;
2433 } ) ;
Original file line number Diff line number Diff line change 33exports [` Badge component > renders correctly - snapshot test 1` ] = `
44<DocumentFragment >
55 <span
6- class = " yl:rounded yl:border yl:border-border yl:px-1 yl:pb-[2px] yl:pt-[1px] yl: text-[10px] yl:text-text "
6+ class = " yl:rounded yl:border yl:border-border yl:px-2 yl:py-1 yl:text-[10px] yl:bg-primary "
77 >
88 Test Badge
99 </span >
Original file line number Diff line number Diff line change 11import classNames from "classnames" ;
22import { FC } from "react" ;
33
4- import { IBadgeProps } from "./types" ;
4+ import { BadgeVariantEnum , IBadgeProps } from "./types" ;
5+
6+ const Badge : FC < IBadgeProps > = ( { title, className, variant } ) => {
7+ const variants = {
8+ [ BadgeVariantEnum . PRIMARY ] : "yl:bg-primary" ,
9+ [ BadgeVariantEnum . SECONDARY ] : "yl:bg-secondary" ,
10+ [ BadgeVariantEnum . SUCCESS ] : "yl:bg-success" ,
11+ [ BadgeVariantEnum . WARNING ] : "yl:bg-warning" ,
12+ [ BadgeVariantEnum . ERROR ] : "yl:bg-error" ,
13+ [ BadgeVariantEnum . BETA ] : "yl:bg-violet-500" ,
14+ [ BadgeVariantEnum . NEW ] : "yl:bg-blue-500"
15+ } ;
16+
17+ const baseClassNames =
18+ "yl:rounded yl:border yl:border-border yl:px-2 yl:py-1 yl:text-[10px]" ;
519
6- const Badge : FC < IBadgeProps > = ( { title, className } ) => {
720 return (
821 < span
922 className = { classNames (
10- "yl:rounded yl:border yl:border-border yl:px-1 yl:pb-[2px] yl:pt-[1px] yl:text-[10px] yl:text-text" ,
23+ baseClassNames ,
24+ {
25+ [ variants [ variant ] ] : variant
26+ } ,
1127 className
1228 ) }
1329 >
Original file line number Diff line number Diff line change 1+ export enum BadgeVariantEnum {
2+ PRIMARY = "primary" ,
3+ SECONDARY = "secondary" ,
4+ SUCCESS = "success" ,
5+ WARNING = "warning" ,
6+ ERROR = "error" ,
7+ BETA = "beta" ,
8+ NEW = "new"
9+ }
10+
111export interface IBadgeProps {
212 title : string ;
313 className ?: string ;
14+ variant : BadgeVariantEnum ;
415}
You can’t perform that action at this time.
0 commit comments