Skip to content

Commit d746cd3

Browse files
committed
Adds ProgressBar component
calcScore getter needed to be updated to return a number to make it more usable displayScoreAsPercent added to replicate original use of calcScore
1 parent 09cd93a commit d746cd3

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

src/components/ProgressBar.vue

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<template>
2+
<progress
3+
:max="max"
4+
:aria-valuemax="max"
5+
:aria-valuemin="min"
6+
:value="value"
7+
:aria-valuenow="value"
8+
:aria-labelledby="label"
9+
>
10+
<div
11+
class="progress-bar"
12+
:aria-valuemax="max"
13+
:aria-valuemin="min"
14+
:aria-valuenow="value"
15+
:aria-labelledby="label"
16+
>
17+
<div :style="styleObject"></div>
18+
</div>
19+
</progress>
20+
</template>
21+
22+
<script>
23+
export default {
24+
props: {
25+
value: {
26+
type: Number,
27+
required: true,
28+
},
29+
min: {
30+
type: Number,
31+
default: 0,
32+
},
33+
max: {
34+
type: Number,
35+
default: 100,
36+
},
37+
label: {
38+
type: String,
39+
default: '',
40+
},
41+
},
42+
data() {
43+
return {
44+
styleObject: {
45+
width: this.value + '%',
46+
},
47+
};
48+
},
49+
};
50+
</script>
51+
52+
<style lang="scss" scoped>
53+
@mixin default-bar-styles {
54+
background-color: $color-mystic;
55+
box-shadow: inset 0 1px 2px 0 $color-regent-gray;
56+
width: 100%;
57+
}
58+
$bar-color: $color-salem;
59+
60+
progress {
61+
@include default-bar-styles();
62+
appearance: none;
63+
border: none;
64+
color: $bar-color;
65+
}
66+
67+
progress::-webkit-progress-bar {
68+
@include default-bar-styles();
69+
}
70+
71+
progress::-webkit-progress-value {
72+
background-color: $bar-color;
73+
}
74+
75+
progress::-moz-progress-bar {
76+
background-color: $bar-color;
77+
}
78+
79+
.progress-bar {
80+
@include default-bar-styles();
81+
> div {
82+
background-color: $bar-color;
83+
height: 100%;
84+
}
85+
}
86+
87+
progress,
88+
.progress-bar {
89+
height: 24px;
90+
}
91+
</style>

src/components/SummaryStats.vue

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<h2>Summary</h2>
33
<div class="summary u-padding-horizontal-sm u-padding-vertical u-margin-bottom-lg">
44
<h3 class="u-margin-top-none u-margin-bottom-sm">Your Score</h3>
5-
<h4 class="u-margin-top-none u-margin-bottom-lg u-margin-left">{{ getScore }}</h4>
5+
<ProgressBar :value="getScore" label="quiz-score" />
6+
<span id="quiz-score" class="grade-details progress-bar-label u-margin-left-xs">{{
7+
displayScoreAsPercent
8+
}}</span>
69
<span class="meta meta--duration">Time Spent: {{ formattedDuration }}</span>
710
<SvgIconContainer width="24" height="24" icon-name="Success" aria-hidden>
811
<IconCheckmark />
@@ -18,11 +21,12 @@
1821
import { mapGetters } from 'vuex';
1922
import SvgIconContainer from './SvgIconContainer.vue';
2023
import IconCheckmark from './icons/IconCheckmark.vue';
21-
24+
import ProgressBar from './ProgressBar';
2225
export default {
2326
components: {
2427
SvgIconContainer,
2528
IconCheckmark,
29+
ProgressBar,
2630
},
2731
props: {
2832
data: {
@@ -37,6 +41,9 @@ export default {
3741
countCorrect: 'quiz/countCorrect',
3842
getScore: 'quiz/calcScore',
3943
}),
44+
displayScoreAsPercent() {
45+
return this.getScore + '%';
46+
},
4047
formattedDuration() {
4148
const durationArray = this.data.timeSpent.split(':');
4249
const duration = [];
@@ -93,6 +100,9 @@ h3 {
93100
.grade-details {
94101
font-size: $text-size-up-1;
95102
}
103+
.progress-bar-label {
104+
letter-spacing: 1px;
105+
}
96106
svg {
97107
color: $color-salem;
98108
}

src/store/modules/quiz.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Getters = {
2323
listQuestions(state: QuizStateInterface): Quiz['questions'];
2424
countQuestions(state: QuizStateInterface): number;
2525
countCorrect(state: QuizStateInterface): number;
26-
calcScore(state: QuizStateInterface): string;
26+
calcScore(state: QuizStateInterface): number;
2727
};
2828

2929
const getters: GetterTree<QuizStateInterface, StateInterface> & Getters = {
@@ -53,7 +53,7 @@ const getters: GetterTree<QuizStateInterface, StateInterface> & Getters = {
5353
const totalQ = getters.countQuestions(state);
5454
const correctQ = getters.countCorrect(state);
5555
const score = (correctQ / totalQ) * 100;
56-
return Math.floor(score) + '%';
56+
return Math.floor(score);
5757
},
5858
};
5959

0 commit comments

Comments
 (0)