Skip to content

Commit a38fefc

Browse files
authored
Merge pull request #150 from zlepper/master
Make the format arrow buttons switch up and down as indicated
2 parents 2efdbaa + 3b79545 commit a38fefc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/lib/color-picker.component.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@
318318
background-position: center;
319319
}
320320

321+
.color-picker .type-policy .type-policy-arrow {
322+
display: block;
323+
324+
width: 100%;
325+
height: 50%;
326+
}
327+
321328
.color-picker .selected-color {
322329
position: absolute;
323330
top: 16px;

src/lib/color-picker.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
</div>
8484
</div>
8585

86-
<div *ngIf="!cpDisableInput && (cpColorMode || 1) === 1" class="type-policy" (click)="onFormatToggle()"></div>
86+
<div *ngIf="!cpDisableInput && (cpColorMode || 1) === 1" class="type-policy">
87+
<span class="type-policy-arrow" (click)="onFormatToggle(1)"></span>
88+
<span class="type-policy-arrow" (click)="onFormatToggle(-1)"></span>
89+
</div>
8790

8891
<div *ngIf="cpPresetColors?.length || cpAddColorButton" class="preset-area">
8992
<hr>

src/lib/color-picker.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,13 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
381381
this.directiveInstance.colorCanceled();
382382
}
383383

384-
public onFormatToggle(): void {
385-
const nextFormat = (this.dialogInputFields.indexOf(this.format) + 1) % this.dialogInputFields.length;
384+
public onFormatToggle(change: number): void {
385+
386+
const availableFormats = this.dialogInputFields.length;
387+
// Javascript modulo operation doesn't work that well with negative numbers, so we have to take
388+
// things a bit further to get the proper behavior for negative wrap around.
389+
const nextFormat = (((this.dialogInputFields.indexOf(this.format) + change) % availableFormats)
390+
+ availableFormats) % availableFormats;
386391

387392
this.format = this.dialogInputFields[nextFormat];
388393
}

0 commit comments

Comments
 (0)