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

Added Badge component #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/docs/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const ComponentNav = () => {
{ title: 'Avatar', path: 'Avatar' },
{ title: 'Checkbox', path: 'Checkbox' },
{ title: 'Button', path: 'Button' },
{ title: 'Badge', path: 'Badge' },
{ title: 'Heading', path: 'Heading' },
{ title: 'Image', path: 'Image' },
{ title: 'Input', path: 'Input' },
Expand Down
61 changes: 61 additions & 0 deletions packages/docs/src/pages/components/badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react'
import { Badge } from 'react-ui'
import {
Page,
Section,
Props,
Example,
} from '../../components'

const Documentation = () => {
return (
<Page
title="Badge"
tagline="A badge is way to display numerical counter"
>
<Example>
<Example.Preview align="center">
<Badge>99</Badge>
</Example.Preview>
<Example.Code>
{`
<Badge>99</Badge>
`}
</Example.Code>
</Example>

<Section title="Props">
<Props
props={[
{
name: 'variant',
type: 'enum',
description: 'defined in theme',
default: 'primary'
}
]}
/>
</Section>

<Section title="Examples">
<Example title="Variants">

<Example.Preview gap={4}>
<Badge>12</Badge>
<Badge variant="secondary">
0
</Badge>
<Badge variant="destructive">45</Badge>
</Example.Preview>
<Example.Code>{`
<Badge>12</Badge>
<Badge variant="secondary">0</Badge>
<Badge variant="destructive">45</Badge>
`}</Example.Code>
</Example>
</Section>
</Page>
)
}

export default Documentation
1 change: 1 addition & 0 deletions packages/docs/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default as Avatar } from './components/avatar'
export { default as Checkbox } from './components/checkbox'
export { default as Button } from './components/button'
export { default as Badge } from './components/badge'
export { default as Element } from './components/element'
export { default as Heading } from './components/heading'
export { default as Image } from './components/image'
Expand Down
1 change: 1 addition & 0 deletions packages/react-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { version } from './package.json'

export * from './src/components/avatar'
export * from './src/components/button'
export * from './src/components/badge'
export * from './src/components/checkbox'
export * from './src/components/heading'
export * from './src/components/image'
Expand Down
13 changes: 13 additions & 0 deletions packages/react-ui/src/components/badge/badge.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const styles = {
Badge: {
boxSizing: 'border-box',
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
minWidth: 'fit-content',
fontWeight: 'semibold',
minWidth: 'fit-content',
lineHeight: 0
}
}

32 changes: 32 additions & 0 deletions packages/react-ui/src/components/badge/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Element } from '../../primitives'
import { styles } from './badge.styles'
import { merge } from '../../utils'

const Badge = React.forwardRef(function Button(
{ size, css, ...props },
ref
) {

return (
<Element
ref={ref}
as="div"
component="Badge"
css={merge(styles.Badge, css)}
{...props}
/>
)
})

Badge.propTypes = {
/** Description of an Badge prop */
variant: PropTypes.string
}

Badge.defaultProps = {
variant: 'primary'
}

export { Badge }
24 changes: 24 additions & 0 deletions packages/react-ui/src/themes/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ const components = {
}
}
},
Badge: {
fontSize: 2,
borderRadius: 3,
paddingX: 4,
border: '1px solid',
sizes: { small: 6, medium: 8, large: 10 },
variants: {
primary: {
// primary is the default variant for badges
backgroundColor:'lightgrey',
borderColor:'black'
},
secondary: {
backgroundColor: 'black',
color: 'white',
borderColor:'white'
},
destructive: {
backgroundColor:'red',
color:'white',
borderColor:'white'
}
}
},
Checkbox: {
border: '1px solid'
},
Expand Down
25 changes: 25 additions & 0 deletions packages/react-ui/src/themes/dark.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,31 @@ const components = {
}
}
},
Badge: {
fontSize: 2,
borderRadius: 3,
paddingX: 4,
border: '1px solid',

sizes: { small: 6, medium: 8, large: 10 },
variants: {
primary: {
backgroundColor: 'greens.700',
color: 'white',
borderColor: 'greens.700'
},
secondary: {
backgroundColor: 'grays.800',
color: 'text.body',
borderColor: 'grays.800'
},
destructive: {
backgroundColor: 'reds.600',
color: 'white',
borderColor: 'reds.600'
}
}
},
Checkbox: {
border: '1px solid'
},
Expand Down
25 changes: 25 additions & 0 deletions packages/react-ui/src/themes/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ const components = {
}
}
},
Badge: {
fontSize: 2,
borderRadius: 3,
paddingX: 4,
border: '1px solid',

sizes: { small: 6, medium: 8, large: 10 },
variants: {
primary: {
backgroundColor: 'greens.700',
color: 'white',
borderColor: 'greens.700'
},
secondary: {
backgroundColor: 'grays.300',
color: 'text.body',
borderColor: 'grays.300'
},
destructive: {
backgroundColor: 'reds.600',
color: 'white',
borderColor: 'reds.600'
}
}
},
Checkbox: {
border: '1px solid'
},
Expand Down
Loading