-
Notifications
You must be signed in to change notification settings - Fork 751
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
9cbc7c4
commit 49a9c26
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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,17 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Bar = styled.div` | ||
background-color: ${({ theme }) => theme.colors.secondary}; | ||
border-radius: 32px; | ||
height: 16px; | ||
transition: width 200ms ease; | ||
`; | ||
|
||
const StyledProgress = styled.div` | ||
background-color: ${({ theme }) => theme.colors.input}; | ||
border-radius: 32px; | ||
box-shadow: ${({ theme }) => theme.shadows.inset}; | ||
height: 16px; | ||
`; | ||
|
||
export default StyledProgress; |
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,27 @@ | ||
import React, { useState } from "react"; | ||
import random from "lodash/random"; | ||
import Button from "../Button"; | ||
import Progress from "./index"; | ||
|
||
export default { | ||
title: "Progress", | ||
component: Progress, | ||
argTypes: {}, | ||
}; | ||
|
||
export const Default: React.FC = () => { | ||
const [progress, setProgress] = useState(random(1, 100)); | ||
|
||
const handleClick = () => setProgress(random(1, 100)); | ||
|
||
return ( | ||
<div style={{ padding: "32px", width: "400px" }}> | ||
<Progress step={progress} /> | ||
<div style={{ marginTop: "32px" }}> | ||
<Button type="button" size="sm" onClick={handleClick}> | ||
Random Progress | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,28 @@ | ||
import React from "react"; | ||
import StyledProgress, { Bar } from "./StyledProgress"; | ||
|
||
export interface ProgressProps { | ||
step?: number; | ||
} | ||
|
||
const stepGuard = (step: number) => { | ||
if (step < 0) { | ||
return 0; | ||
} | ||
|
||
if (step > 100) { | ||
return 100; | ||
} | ||
|
||
return step; | ||
}; | ||
|
||
const Progress: React.FC<ProgressProps> = ({ step = 0 }) => { | ||
return ( | ||
<StyledProgress> | ||
<Bar style={{ width: `${stepGuard(step)}%` }} /> | ||
</StyledProgress> | ||
); | ||
}; | ||
|
||
export default Progress; |
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