Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEC-4404: Badge component #35

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'};
gabrielcdiniz marked this conversation as resolved.
Show resolved Hide resolved
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,
}