Skip to content

Commit 4acbedf

Browse files
committed
feat: upd shuffle quiz button
1 parent 961f514 commit 4acbedf

4 files changed

Lines changed: 43 additions & 40 deletions

File tree

src/app/quiz/quiz.page.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
<ion-header class="quiz-header">
1+
<ion-header class="quiz-header" [translucent]="true">
22
<ion-toolbar>
3-
<div class="quiz-header__toggle">
4-
<span class="quiz-header__label">{{ 'QUIZ.RANDOMIZE' | translate }}</span>
5-
<ion-toggle [checked]="isRandomized" (ionChange)="toggleQuiz($event)"></ion-toggle>
6-
</div>
3+
<ion-title>{{ 'TABS.QUIZ' | translate }}</ion-title>
4+
<ion-buttons slot="end">
5+
<button
6+
type="button"
7+
class="quiz-header__shuffle"
8+
[class.quiz-header__shuffle--active]="isRandomized"
9+
[attr.aria-pressed]="isRandomized"
10+
[attr.aria-label]="'QUIZ.RANDOMIZE' | translate"
11+
[title]="'QUIZ.RANDOMIZE' | translate"
12+
(click)="toggleRandom()">
13+
<ion-icon name="shuffle-outline" aria-hidden="true"></ion-icon>
14+
</button>
15+
</ion-buttons>
716
</ion-toolbar>
817
</ion-header>
918

src/app/quiz/quiz.page.scss

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,31 @@
44

55
/* ---------- Header ---------- */
66
.quiz-header {
7-
ion-toolbar {
8-
--padding-start: 0;
9-
--padding-end: 0;
10-
}
11-
12-
.quiz-header__toggle {
13-
display: flex;
7+
.quiz-header__shuffle {
8+
display: inline-flex;
149
align-items: center;
15-
justify-content: space-between;
16-
gap: 0.75rem;
17-
width: 100%;
18-
padding-inline: var(--quiz-gutter);
19-
box-sizing: border-box;
20-
font-size: 0.95rem;
21-
font-weight: 600;
22-
letter-spacing: 0.01em;
23-
color: var(--ion-text-color);
24-
}
25-
26-
.quiz-header__label {
27-
min-width: 0;
28-
overflow: hidden;
29-
text-overflow: ellipsis;
30-
white-space: nowrap;
31-
}
32-
33-
ion-toggle {
34-
flex: 0 0 auto;
10+
justify-content: center;
11+
width: 2.3rem;
12+
height: 2.3rem;
13+
margin-inline-end: 0.4rem;
14+
padding: 0;
15+
border: 0;
16+
border-radius: 999px;
17+
font-size: 1.2rem;
18+
color: var(--ion-color-medium);
19+
background: rgba(var(--ion-color-medium-rgb), 0.12);
20+
cursor: pointer;
21+
-webkit-tap-highlight-color: transparent;
22+
transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
23+
24+
&:active {
25+
transform: scale(0.9);
26+
}
27+
28+
&--active {
29+
color: var(--ion-color-primary);
30+
background: rgba(var(--ion-color-primary-rgb), 0.14);
31+
}
3532
}
3633
}
3734

@@ -280,8 +277,4 @@
280277
.quiz__body {
281278
justify-content: center;
282279
}
283-
284-
.quiz-header__toggle {
285-
font-size: 0.8rem;
286-
}
287280
}

src/app/quiz/quiz.page.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ describe('QuizPage', () => {
139139
}));
140140
});
141141

142-
describe('toggleQuiz', () => {
142+
describe('toggleRandom', () => {
143143
it('should persist the randomize flag and load a new question', fakeAsync(() => {
144-
component.toggleQuiz({ detail: { checked: true } } as CustomEvent<{ checked: boolean }>);
144+
component.isRandomized = false;
145+
component.toggleRandom();
145146

146147
expect(component.isRandomized).toBeTrue();
147148
expect(localStorage.getItem('isRandomized')).toBe('true');

src/app/quiz/quiz.page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class QuizPage implements OnInit, OnDestroy {
8484
this.router.navigate(['tabs/quiz/answer-structure'], navigationExtras);
8585
}
8686

87-
public toggleQuiz(event: CustomEvent<{ checked: boolean }>): void {
88-
this.isRandomized = event.detail.checked;
87+
public toggleRandom(): void {
88+
this.isRandomized = !this.isRandomized;
8989
localStorage.setItem('isRandomized', JSON.stringify(this.isRandomized));
9090

9191
this.getNextQuestion();

0 commit comments

Comments
 (0)