Skip to content

Commit

Permalink
TEC-4404: Badge component (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsalmeida authored Nov 11, 2024
1 parent ae7ef26 commit 6fa9fd5
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chardonnay",
"version": "1.0.39",
"version": "1.0.40",
"description": "A mobile first frontend framework made with wine",
"homepage": "https://vissimo-group.github.io/chardonnay/",
"main": "./dist/index.js",
Expand Down Expand Up @@ -107,4 +107,4 @@
},
"readme": "ERROR: No README data found!",
"_id": "[email protected]"
}
}
94 changes: 94 additions & 0 deletions src/components/Badge/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Money } from 'semillon'
import { Badge } from '.'

const meta: Meta<typeof Badge> = {
component: Badge,
tags: ['autodocs'],
argTypes: {
size: {
control: { type: 'select' },
options: ['small', 'normal'],
description: 'The size of the Badge.',
},
backgroundColor: {
control: { type: 'color' },
description: 'The background color of the Badge.',
},
fullWidth: {
control: { type: 'boolean' },
description:
'If true, the Badge will take up the full width of its container.',
},
},
decorators: [
(Story) => (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Story />
</div>
),
],
}

export default meta
type Story = StoryObj<typeof Badge>

export const Small: Story = {
args: {
size: 'small',
},
render: (args) => <Badge {...args}>A nice label</Badge>,
}

export const Normal: Story = {
args: {
size: 'normal',
},
render: (args) => <Badge {...args}>A nice label</Badge>,
}

export const WithFullWidth: Story = {
args: {
size: 'normal',
fullWidth: true,
},
render: (args) => <Badge {...args}>A nice label</Badge>,
}

export const WithIcon: Story = {
args: {
size: 'normal',
},
render: (args) => (
<Badge {...args}>
<Money color="white" size={16} />A nice label
</Badge>
),
}

export const WithCustomTextColor: Story = {
args: {
size: 'normal',
},
render: (args) => (
<Badge {...args}>
<Money color="#1B6AA3" size={16} />

<span style={{ color: '#1B6AA3', fontSize: '12px', lineHeight: '1' }}>
A nice label
</span>
</Badge>
),
}

export const WithCustomBackgroundColor: Story = {
args: {
backgroundColor: '#CE2A36',
size: 'normal',
},
render: (args) => (
<Badge {...args}>
<Money size={16} />A nice label
</Badge>
),
}
22 changes: 22 additions & 0 deletions src/components/Badge/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BadgeProps } from './type'
import { BadgeStyled } from './style'
import { Colors } from '../../tokens'

const Badge = ({
size = 'small',
backgroundColor = `${Colors.light.feedback.feedbackInfo100}`,
children,
fullWidth = false,
}: BadgeProps) => {
return (
<BadgeStyled
$size={size}
$backgroundColor={backgroundColor}
$fullWidth={fullWidth}
>
{children}
</BadgeStyled>
)
}

export { Badge }
22 changes: 22 additions & 0 deletions src/components/Badge/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import styled from 'styled-components'

const BadgeStyled = styled.div<{
$size?: string
$backgroundColor?: string
$fullWidth?: boolean
}>`
display: flex;
align-items: center;
justify-content: center;
gap: 0.25rem;
width: ${(props) => (props.$fullWidth ? '100%' : 'fit-content')};
padding: ${(props) => (props.$size === 'small' ? '4px 6px' : '6px 8px')};
border-radius: 4px;
background-color: ${(props) =>
props.$backgroundColor ? `${props.$backgroundColor}` : '#2391E1'};
color: white;
font-size: 0.75rem;
line-height: 1;
`

export { BadgeStyled }
8 changes: 8 additions & 0 deletions src/components/Badge/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type BadgeProps = {
size?: 'small' | 'normal'
backgroundColor?: string
children?: React.ReactNode
fullWidth?: boolean
}

export type { BadgeProps }
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as RadioTag from './RadioTag'
import * as PaymentMethod from './PaymentMethods'
import * as PurchaseSummary from './PurchaseSummary/PurchaseSummary'
import { CreditCard } from './CreditCard'
import { Badge } from './Badge'

export {
Border,
Expand Down Expand Up @@ -60,4 +61,5 @@ export {
PaymentMethod,
PurchaseSummary,
CreditCard,
Badge,
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
PaymentMethod,
PurchaseSummary,
CreditCard,
Badge,
} from './components'

export {
Expand Down Expand Up @@ -69,4 +70,5 @@ export {
PaymentMethod,
PurchaseSummary,
CreditCard,
Badge,
}

0 comments on commit 6fa9fd5

Please sign in to comment.