Skip to content

Commit

Permalink
Merge pull request #364 from rakesh-m-r/fix/className-prop-Badge
Browse files Browse the repository at this point in the history
fix: added className Prop.
  • Loading branch information
MildTomato authored Jul 18, 2022
2 parents 2e9c79d + a5cc8fd commit fc1b794
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 29 deletions.
121 changes: 93 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const large = (args: any) => <Badge {...args}>Hello world</Badge>

export const withDotLarge = (args: any) => <Badge {...args}>Hello world</Badge>

export const withCustomClassNames = (args: any) => (
<Badge {...args}>Hello world</Badge>
)

export const allBadges = () => (
<>
<div className="flex flex-row gap-6 mx-auto my-4">
Expand Down Expand Up @@ -88,3 +92,7 @@ withDotLarge.args = {
size: 'large',
dot: true,
}

withCustomClassNames.args = {
className: 'border-teal-100 border-2'
}
5 changes: 5 additions & 0 deletions src/components/Badge/Badge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ describe('#Badge', () => {
`sbui-badge ${size === 'large' ? 'sbui-badge--large' : ''}`
)
})

it('should render with Classes',()=>{
render(<Badge className='border-2'>Badge</Badge>)
expect(screen.getByText('Badge')).toHaveClass('border-2')
})
})
6 changes: 5 additions & 1 deletion src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ interface Props {
children: string | React.ReactNode
size?: 'large' | 'small'
dot?: boolean
className?: string
}

function Badge({ color = 'brand', children, size, dot }: Props) {
function Badge({ color = 'brand', children, size, dot, className }: Props) {
const __styles = styleHandler('badge')

let classes = [__styles.base]
Expand All @@ -47,6 +48,9 @@ function Badge({ color = 'brand', children, size, dot }: Props) {
if (size === 'large') {
classes.push(__styles.size.large)
}
if (className) {
classes.push(className)
}

return (
<span className={classes.join(' ')}>
Expand Down

0 comments on commit fc1b794

Please sign in to comment.