Skip to content

Commit 51594fd

Browse files
authored
Merge pull request #68 from ishythefishy/left-hand-config
Add a left hand configuration to the fretboard; remember user settings in local storage
2 parents 52c271a + fe1d666 commit 51594fd

File tree

7 files changed

+256
-39
lines changed

7 files changed

+256
-39
lines changed

angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
{
6363
"type": "anyComponentStyle",
6464
"maximumWarning": "6kb",
65-
"maximumError": "10kb"
65+
"maximumError": "12kb"
6666
}
6767
],
6868
"serviceWorker": true,

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.html

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,42 @@
2222
</ng-template>
2323

2424
<div class="fretboard__toggle">
25-
<button class="fretboard__toggleButton fretboard__toggleButton--twelve"
25+
<button class="fretboard__toggleButton fretboard__toggleButton--left"
2626
[class.fretboard__toggleButton--active]="fretMode === fretModes.twelve"
2727
(click)="setFretMode(fretModes.twelve)">12 frets
2828
</button>
29-
<button class="fretboard__toggleButton fretboard__toggleButton--twentyFour"
29+
<button class="fretboard__toggleButton fretboard__toggleButton--middle-left"
3030
[class.fretboard__toggleButton--active]="fretMode === fretModes.twentyFour"
3131
(click)="setFretMode(fretModes.twentyFour)">24 frets
3232
</button>
33+
<button class="fretboard__toggleButton fretboard__toggleButton--middle-right"
34+
[class.fretboard__toggleButton--active]="orientation === orientations.left"
35+
(click)="setOrientation(orientations.left)">
36+
<span class="toggle__shortLabel">LH</span>
37+
<span class="toggle__longLabel">Left handed</span>
38+
</button>
39+
<button class="fretboard__toggleButton fretboard__toggleButton--right"
40+
[class.fretboard__toggleButton--active]="orientation === orientations.right"
41+
(click)="setOrientation(orientations.right)">
42+
<span class="toggle__shortLabel">RH</span>
43+
<span class="toggle__longLabel">Right handed</span>
44+
</button>
3345
</div>
3446

3547
<div class="arrowHint">
36-
<span class="arrowHint__arrow"></span>
48+
<span class="arrowHint__arrow"
49+
[class.fretboard__flip]="orientation === orientations.left"></span>
3750
</div>
3851

3952
<div class="fretboard__container"
53+
[class.fretboard__flip]="orientation === orientations.left"
4054
[class.fretboard__wide]="fretMode === fretModes.twentyFour">
4155

56+
4257
<div class="fretboard"
58+
[class.fretboard__leftHanded]="orientation === orientations.left"
4359
[class.fretboard__24]="fretMode === fretModes.twentyFour">
60+
4461
<ng-container
4562
[ngTemplateOutlet]="string"
4663
[ngTemplateOutletContext]="{ stringName: 'e', string: 'E' }"
@@ -70,9 +87,12 @@
7087
[ngTemplateOutlet]="string"
7188
[ngTemplateOutletContext]="{ stringName: 'E', string: 'E' }"
7289
></ng-container>
90+
7391
</div>
7492

93+
7594
<div class="fretboard"
95+
[class.fretboard__leftHanded]="orientation === orientations.left"
7696
[class.fretboard__24]="fretMode === fretModes.twentyFour">
7797
<ng-container
7898
[ngTemplateOutlet]="fretboardHelp"

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.scss

Lines changed: 97 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
@import "../../../../styles/mixins";
44
@import "../../../../styles/typography";
55

6+
$note-height: 36;
7+
68
.fretboard__container {
79
margin-top: pxToRem($grid-unit * 1);
810
max-width: $fretonator_max_width;
911
margin-left: auto;
1012
margin-right: auto;
1113
padding-right: 0;
12-
padding-left: pxToRem($grid-unit * 4);
14+
padding-left: pxToRem($grid-unit * 5);
1315
padding-bottom: pxToRem($grid-unit * 4);
14-
padding-top: pxToRem($grid-unit * 9);
16+
padding-top: pxToRem($grid-unit * 7);
1517
overflow-x: auto;
1618
transition: max-width 0.09s ease-in-out;
1719

1820
&.fretboard__wide {
1921
max-width: $fretonator_max_width-wide;
2022
}
23+
24+
&.fretboard__flip {
25+
padding-left: 0;
26+
padding-right: pxToRem($grid-unit * 5);
27+
direction: rtl;
28+
}
2129
}
2230

2331
.fretboard__help {
@@ -138,11 +146,21 @@
138146
transform: translate(-50%, calc(50% - 1px));
139147
}
140148
}
149+
150+
&.fretboard__leftHanded {
151+
.fretboard__cell--string {
152+
&:nth-last-child(-n + 25):after {
153+
transform: translate(50%, calc(50% - 1px));
154+
}
155+
}
156+
}
141157
}
142158

143159
.fretboard {
144160
display: grid;
145161
grid-template-columns: 32px repeat(12, minmax(50px, 1fr));
162+
padding-top: pxToRem($grid-unit * 3);
163+
padding-bottom: pxToRem($grid-unit * 3);
146164

147165
&.fretboard__24 {
148166
grid-template-columns: 32px repeat(24, minmax(50px, 1fr));
@@ -235,9 +253,9 @@
235253

236254
&:after {
237255
content: attr(data-display-note);
238-
height: var(--note-height);
239-
width: var(--note-height);
240-
line-height: var(--note-height);
256+
height: pxToRem($note-height);
257+
width: pxToRem($note-height);
258+
line-height: pxToRem($note-height);
241259
left: 50%;
242260
right: unset;
243261
box-sizing: border-box;
@@ -252,13 +270,7 @@
252270
transition-duration: 0.1s;
253271
transition-property: line-height, height, width, opacity;
254272
transition-timing-function: ease-in-out;
255-
}
256-
257-
&:hover:after,
258-
&:active:after {
259-
height: var(--note-height-hover);
260-
width: var(--note-height-hover);
261-
line-height: var(--note-height-hover);
273+
direction: ltr;
262274
}
263275

264276
&:nth-child(-n + 13):after {
@@ -317,15 +329,15 @@
317329

318330
&:after {
319331
content: attr(data-string-name);
320-
height: var(--note-height);
321-
width: var(--note-height);
332+
height: pxToRem($note-height);
333+
width: pxToRem($note-height);
322334
left: 0;
323335
right: unset;
324336
box-sizing: border-box;
325337
border-radius: 50%;
326338
transform: translate(-50%, 50%);
327339
color: var(--string-color);
328-
line-height: var(--note-height);
340+
line-height: pxToRem($note-height);
329341
text-align: center;
330342
font-weight: var(--font-weight-bold);
331343
font-family: var(--font-family-main);
@@ -381,6 +393,11 @@
381393
.arrowHint {
382394
position: relative;
383395
display: block;
396+
margin-top: pxToRem($grid-unit * 4);
397+
398+
@media screen and (min-width: 712px) {
399+
display: none;
400+
}
384401
}
385402

386403
.arrowHint__arrow {
@@ -395,8 +412,11 @@
395412
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 512 512'%3E%3Cpath fill='%233993dd' d='M319.1 217c20.2 20.2 19.9 53.2-.6 73.7s-53.5 20.8-73.7.6l-190-190c-20.1-20.2-19.8-53.2.7-73.7S109 6.8 129.1 27l190 190z'/%3E%3Cpath fill='%233993dd' d='M319.1 290.5c20.2-20.2 19.9-53.2-.6-73.7s-53.5-20.8-73.7-.6l-190 190c-20.2 20.2-19.9 53.2.6 73.7s53.5 20.8 73.7.6l190-190z'/%3E%3C/svg%3E");
396413
}
397414

398-
@media screen and (min-width: 712px) {
399-
display: none;
415+
416+
&.fretboard__flip {
417+
right: unset;
418+
left: 0;
419+
transform: rotate(180deg);
400420
}
401421
}
402422

@@ -428,18 +448,50 @@
428448
height: pxToRem(44);
429449
}
430450

451+
.toggle__shortLabel {
452+
display: inline;
453+
font-weight: inherit;
454+
padding-left: pxToRem($grid_unit * 1.5);
455+
padding-right: pxToRem($grid_unit * 1.5);
456+
457+
@media screen and (min-width: $screen-med) {
458+
display: none;
459+
}
460+
}
461+
462+
.toggle__longLabel {
463+
display: none;
464+
font-weight: inherit;
465+
466+
@media screen and (min-width: $screen-med) {
467+
display: inline;
468+
}
469+
}
470+
431471
.fretboard__toggleButton--active {
432472
background-color: var(--black);
433473
color: var(--offwhite);
434474
}
435475

436-
.fretboard__toggleButton--twelve {
476+
.fretboard__toggleButton--left {
437477
border-top-right-radius: 0;
438478
border-bottom-right-radius: 0;
439479
border-right-width: calc(var(--border-width-button) / 2);
440480
}
441481

442-
.fretboard__toggleButton--twentyFour {
482+
.fretboard__toggleButton--middle-left {
483+
border-radius: 0;
484+
border-right-width: calc(var(--border-width-button) / 2);
485+
border-left-width: 0;
486+
}
487+
488+
.fretboard__toggleButton--middle-right {
489+
border-radius: 0;
490+
border-right-width: 0;
491+
border-left-width: calc(var(--border-width-button) / 2);
492+
}
493+
494+
.fretboard__toggleButton--right {
443495
border-top-left-radius: 0;
444496
border-bottom-left-radius: 0;
445497
border-left-width: calc(var(--border-width-button) / 2);
@@ -451,3 +503,29 @@
451503
width: pxToRem($grid-unit * 2);
452504
margin-right: pxToRem($grid-unit);
453505
}
506+
507+
.fretboard__leftHanded {
508+
.fretboard__cell {
509+
border-left: var(--fret-width-base) solid var(--fret-color);
510+
border-right: unset;
511+
}
512+
513+
.fretboard__cell--string {
514+
border-left: pxToRem(6) solid var(--nut-color);
515+
border-right: unset;
516+
517+
&:after {
518+
transform: translate(50%, 50%);
519+
}
520+
521+
&:nth-child(-n + 13):after {
522+
transform: translate(50%, 6px);
523+
}
524+
525+
&:nth-last-child(-n + 13):after {
526+
bottom: 0;
527+
top: unset;
528+
transform: translate(50%, calc(50% - 1px));
529+
}
530+
}
531+
}

apps/fretonator-web/src/app/common/fretonator/fretboard/fretboard.component.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { By } from '@angular/platform-browser';
77

88
describe('FretboardComponent', () => {
99
const selectors = {
10-
twelveButton: By.css('.fretboard__toggleButton--twelve'),
11-
twentyFourButton: By.css('.fretboard__toggleButton--twentyFour')
10+
twelveButton: By.css('.fretboard__toggleButton--left'),
11+
twentyFourButton: By.css('.fretboard__toggleButton--middle-left'),
12+
rightButton: By.css('.fretboard__toggleButton--right'),
13+
leftButton: By.css('.fretboard__toggleButton--middle-right')
1214
};
1315

1416
const classNames = {
@@ -68,4 +70,26 @@ describe('FretboardComponent', () => {
6870
expect(twelveButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
6971
});
7072
});
73+
74+
describe('setOrientation()', () => {
75+
let leftButton: DebugElement;
76+
let rightButton: DebugElement;
77+
78+
beforeEach(() => {
79+
leftButton = fixture.debugElement.query(selectors.leftButton);
80+
rightButton = fixture.debugElement.query(selectors.rightButton);
81+
});
82+
83+
it('changes the fret mode to left orientation when the button is clicked', () => {
84+
leftButton.nativeElement.click();
85+
fixture.detectChanges();
86+
expect(leftButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
87+
});
88+
89+
it('changes the fret mode to right orientation when the button is clicked', () => {
90+
rightButton.nativeElement.click();
91+
fixture.detectChanges();
92+
expect(rightButton.classes[classNames.toggleFretButtonSelected]).toBeTruthy();
93+
});
94+
})
7195
});

0 commit comments

Comments
 (0)