File tree 6 files changed +67
-9
lines changed
6 files changed +67
-9
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @programmer_network/yail" ,
3
- "version" : " 1.0.220 " ,
3
+ "version" : " 1.0.221 " ,
4
4
"description" : " Programmer Network's official UI library for React" ,
5
5
"author" : " Aleksandar Grbic - (https://programmer.network)" ,
6
6
"publishConfig" : {
Original file line number Diff line number Diff line change 1
1
import type { Meta , StoryObj } from "@storybook/react" ;
2
2
3
3
import Badge from "." ;
4
+ import { BadgeVariantEnum } from "./types" ;
4
5
5
6
const meta = {
6
7
title : "Core/Badge" ,
@@ -15,9 +16,30 @@ const meta = {
15
16
export default meta ;
16
17
type Story = StoryObj < typeof meta > ;
17
18
19
+ export const Empty : Story = {
20
+ args : {
21
+ title : "Badge" ,
22
+ variant : BadgeVariantEnum . PRIMARY
23
+ }
24
+ } ;
25
+
18
26
export const Filled : Story = {
19
27
args : {
20
28
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
22
44
}
23
45
} ;
Original file line number Diff line number Diff line change 1
1
import { render , screen } from "@testing-library/react" ;
2
2
3
3
import Badge from "./" ;
4
+ import { BadgeVariantEnum } from "./types" ;
4
5
5
6
describe ( "Badge component" , ( ) => {
6
7
const testTitle = "Test Badge" ;
7
8
8
9
test ( "renders correctly - snapshot test" , ( ) => {
9
- const { asFragment } = render ( < Badge title = { testTitle } /> ) ;
10
+ const { asFragment } = render (
11
+ < Badge title = { testTitle } variant = { BadgeVariantEnum . PRIMARY } />
12
+ ) ;
10
13
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
11
14
} ) ;
12
15
13
16
test ( "renders the title correctly" , ( ) => {
14
- render ( < Badge title = { testTitle } /> ) ;
17
+ render ( < Badge title = { testTitle } variant = { BadgeVariantEnum . PRIMARY } /> ) ;
15
18
const badgeElement = screen . getByText ( testTitle ) ;
16
19
expect ( badgeElement ) . toBeInTheDocument ( ) ;
17
20
} ) ;
18
21
19
22
test ( "applies custom class name" , ( ) => {
20
23
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
+ ) ;
22
31
const badgeElement = screen . getByText ( testTitle ) ;
23
32
expect ( badgeElement ) . toHaveClass ( customClass ) ;
24
33
} ) ;
Original file line number Diff line number Diff line change 3
3
exports [` Badge component > renders correctly - snapshot test 1` ] = `
4
4
<DocumentFragment >
5
5
<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 "
7
7
>
8
8
Test Badge
9
9
</span >
Original file line number Diff line number Diff line change 1
1
import classNames from "classnames" ;
2
2
import { FC } from "react" ;
3
3
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]" ;
5
19
6
- const Badge : FC < IBadgeProps > = ( { title, className } ) => {
7
20
return (
8
21
< span
9
22
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
+ } ,
11
27
className
12
28
) }
13
29
>
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
+
1
11
export interface IBadgeProps {
2
12
title : string ;
3
13
className ?: string ;
14
+ variant : BadgeVariantEnum ;
4
15
}
You can’t perform that action at this time.
0 commit comments