Skip to content

Commit

Permalink
feat(components): loading bar added (#490)
Browse files Browse the repository at this point in the history
Co-authored-by: leonardogarreto <leonardo.cantanhede@aiqfome.com>
  • Loading branch information
Nhed1 and leonardogarreto authored Aug 20, 2024
1 parent 80ea59f commit 82b5469
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/LoadingBar/LoadingBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

import { Flex } from '../Flex'

import { createPageExport } from '../../utils/storybook'
import { LoadingBar } from './LoadingBar'

export const Basic = () => (
<Flex justifyContent='center' alignItems='center' height='100vh' gap='22px'>
<LoadingBar percent={0} />
<LoadingBar percent={50} />
<LoadingBar percent={100} />
</Flex>
)

export default createPageExport(Basic, 'LoadingBar', ['color', 'size'])
24 changes: 24 additions & 0 deletions src/components/LoadingBar/LoadingBar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'

import { render } from '../utils/test/render'

import { LoadingBar } from './LoadingBar'

describe('LoadingBar', () => {
it('should have to render without crashing', () => {
const component = render(<LoadingBar />)
expect(component).toBeTruthy()
})

it('should render an empty bar when percent is 0', () => {
const { getByTestId } = render(<LoadingBar percent={0} />)
const bar = getByTestId('loading-bar')
expect(bar).toHaveStyle(`width: 0%`)
})

it('should render a full bar when percent is 100', () => {
const { getByTestId } = render(<LoadingBar percent={100} />)
const bar = getByTestId('loading-bar')
expect(bar).toHaveStyle(`width: 100%`)
})
})
31 changes: 31 additions & 0 deletions src/components/LoadingBar/LoadingBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import { Flex, Props } from '../Flex'

interface LoadingBarProps extends Props {
colorBar?: string
percent?: number
}

export const LoadingBar = ({
percent = 0,
colorBar = 'darkPink',
...props
}: LoadingBarProps) => {
return (
<Flex
backgroundColor='mediumGrey'
height='12px'
width='160px'
borderRadius='8px'
{...props}
>
<Flex
data-testid='loading-bar'
backgroundColor={colorBar}
height='100%'
width={`${percent}%`}
borderRadius='8px'
/>
</Flex>
)
}
1 change: 1 addition & 0 deletions src/components/LoadingBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LoadingBar'
1 change: 1 addition & 0 deletions src/providers/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const colors = {
// common
red: '#DE4E51',
pink: '#EB5387',
darkPink: '#9824D4',
purple: '#A652B4',
deepPurple: '#8654DE',
indigo: '#4C60D0',
Expand Down

0 comments on commit 82b5469

Please sign in to comment.