-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add progress bar and limit questions
- Loading branch information
Anmol Varma
committed
Apr 2, 2020
1 parent
6d7f2ae
commit 6b84704
Showing
7 changed files
with
89 additions
and
12 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
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 PropTypes from "prop-types" | ||
import React from "react" | ||
|
||
import { GetPercentage } from "../utils/style" | ||
import styles from "./progress-bar.module.css" | ||
|
||
const generateCircles = (count, key) => ( | ||
<> | ||
{ | ||
[...Array(count).keys()].map(value => <div key={`${key}_${value}`} className={styles.quesTrack} />) | ||
} | ||
</> | ||
) | ||
|
||
const ProgressBar = ({ current, total }) => { | ||
const length = GetPercentage(current, total); | ||
return ( | ||
<div className={styles.barWrapper}> | ||
<div className={styles.activeBar} style={{ width: `${length}%` }}>{generateCircles(current, 'done')}</div> | ||
<div className={styles.bar} style={{ width: `${100 - length}%` }}>{generateCircles(total - current, 'left')}</div> | ||
</div> | ||
) | ||
} | ||
|
||
ProgressBar.propTypes = { | ||
current: PropTypes.number, | ||
total: PropTypes.number | ||
} | ||
|
||
ProgressBar.defaultProps = { | ||
current: 1, | ||
total: 10 | ||
} | ||
|
||
export default ProgressBar |
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,29 @@ | ||
.barWrapper{ | ||
display: flex; | ||
background: #ddd; | ||
border-radius: 50px; | ||
} | ||
|
||
.bar{ | ||
height: 30px; | ||
border-radius: 50px; | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
} | ||
|
||
.activeBar{ | ||
background: #2b8a9d; | ||
height: 30px; | ||
border-radius: 50px; | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
} | ||
|
||
.quesTrack{ | ||
border-radius: 50%; | ||
height: 10px; | ||
width: 10px; | ||
background: #fff; | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const NUMBER_OF_QUESTIONS = 10 | ||
const TIME_FOR_EACH_QUESTION = 15 | ||
const TIME_INTERVAL_BETWEEN_QUESTIONS = 1500 | ||
|
||
export default { | ||
NUMBER_OF_QUESTIONS, | ||
TIME_FOR_EACH_QUESTION | ||
TIME_FOR_EACH_QUESTION, | ||
TIME_INTERVAL_BETWEEN_QUESTIONS | ||
} |
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
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
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,6 @@ | ||
export const GetPercentage = (current, total) => Math.ceil(((current / total) * 100)); | ||
|
||
export const GetQuizQuestionIndexes = (length, total) => { | ||
const array = [...Array(total).keys()] | ||
return array.sort(() => { return .5 - Math.random() }).slice(0, length) | ||
} |