-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9990f4b
commit 1b8a0ee
Showing
6 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/elements/src/components/UploadProgress/__tests__/__snapshots__/index.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`UploadProgress should match snapshot 1`] = ` | ||
<div | ||
className="upload-progress has-background-info visible" | ||
> | ||
<span> | ||
Uploading... | ||
</span> | ||
<div | ||
className="upload-progress-inner" | ||
> | ||
<div | ||
className="upload-progress-bg" | ||
style={ | ||
Object { | ||
"width": "100%", | ||
} | ||
} | ||
/> | ||
</div> | ||
<span> | ||
Complete 4/10 | ||
</span> | ||
</div> | ||
`; |
34 changes: 34 additions & 0 deletions
34
packages/elements/src/components/UploadProgress/__tests__/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { UploadProgress, UploadProgressProps } from '../.' | ||
|
||
describe('UploadProgress', () => { | ||
it('should match snapshot', () => { | ||
const mockProps: UploadProgressProps = { | ||
visible: true, | ||
percentage: 100, | ||
totalCount: 10, | ||
completedCount: 4, | ||
} | ||
const wrapper = shallow(<UploadProgress {...mockProps} />) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it('should run correctly when percentage < 0', () => { | ||
const mockProps: UploadProgressProps = { | ||
percentage: -1, | ||
visible: true, | ||
} | ||
const wrapper = shallow(<UploadProgress {...mockProps} />) | ||
expect(wrapper.find('.upload-progress-bg').prop('style')).toEqual({ width: '0%' }) | ||
}) | ||
|
||
it('should run correctly when percentage > 100', () => { | ||
const mockProps: UploadProgressProps = { | ||
percentage: 101, | ||
visible: true, | ||
} | ||
const wrapper = shallow(<UploadProgress {...mockProps} />) | ||
expect(wrapper.find('.upload-progress-bg').prop('style')).toEqual({ width: '100%' }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react' | ||
|
||
export interface UploadProgressProps { | ||
visible: boolean | ||
percentage?: number | ||
totalCount?: number | ||
completedCount?: number | ||
} | ||
|
||
const MAX = 100 | ||
const MIN = 0 | ||
|
||
export const UploadProgress: React.FC<UploadProgressProps> = ({ | ||
visible, | ||
percentage = 0, | ||
totalCount = 0, | ||
completedCount = 0, | ||
}) => { | ||
let validPercentage = percentage | ||
if (percentage > MAX) { | ||
validPercentage = MAX | ||
} | ||
if (percentage < MIN) { | ||
validPercentage = MIN | ||
} | ||
|
||
return ( | ||
<div className={`upload-progress has-background-info ${visible ? 'visible' : ''}`}> | ||
<span>Uploading...</span> | ||
<div className="upload-progress-inner"> | ||
<div className="upload-progress-bg" style={{ width: `${validPercentage}%` }}></div> | ||
</div> | ||
<span>{`Complete ${completedCount}/${totalCount}`}</span> | ||
</div> | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/elements/src/components/UploadProgress/upload-progress.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import { storiesOf } from '@storybook/react' | ||
import { UploadProgress } from './index' | ||
|
||
const Demo = () => { | ||
const [visible, setVisible] = React.useState(false) | ||
const [percentage, setPercentage] = React.useState(0) | ||
|
||
React.useEffect(() => { | ||
setTimeout(() => { | ||
setVisible(true) | ||
}, 500) | ||
|
||
const timer = setInterval(() => { | ||
setPercentage(current => { | ||
return current >= 100 ? 0 : current + Math.random() * 10 | ||
}) | ||
}, 500) | ||
|
||
return () => { | ||
clearInterval(timer) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<UploadProgress | ||
percentage={percentage} | ||
totalCount={10} | ||
completedCount={Math.floor(percentage / 10)} | ||
visible={visible} | ||
/> | ||
) | ||
} | ||
|
||
storiesOf('UploadProgress', module).add('Default', () => <Demo />) |
43 changes: 43 additions & 0 deletions
43
packages/elements/src/styles/components/upload-progress.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@import '../base/layout.scss'; | ||
|
||
.upload-progress { | ||
width: 100%; | ||
padding: $layout-base; | ||
position: fixed; | ||
z-index: 100; | ||
bottom: 0; | ||
left: 0; | ||
transform: translateY(100%); | ||
transition: transform 0.2s ease-in-out; | ||
display: flex; | ||
align-items: center; | ||
color: white; | ||
text-transform: uppercase; | ||
font-size: 1rem; | ||
font-weight: bold; | ||
text-align: center; | ||
|
||
&.visible { | ||
transform: translateY(calc(#{$layout-base} * -1)); | ||
} | ||
|
||
&-inner { | ||
margin-left: $layout-base; | ||
margin-right: $layout-base; | ||
height: 2rem; | ||
width: 100%; | ||
} | ||
|
||
&-bg { | ||
background-color: #88c4e9; | ||
height: 100%; | ||
} | ||
} | ||
|
||
@media screen and (min-width: 768px) { | ||
.upload-progress { | ||
&-inner { | ||
width: 50%; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters