-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(admin-ui): Move stringToColor into a pipe
- Loading branch information
1 parent
894ea7b
commit 743998d
Showing
7 changed files
with
76 additions
and
27 deletions.
There are no files selected for viewing
12 changes: 9 additions & 3 deletions
12
admin-ui/src/app/shared/components/chip/chip.component.html
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,13 +1,19 @@ | ||
<div | ||
class="wrapper" | ||
[class.with-background]="colorFrom" | ||
[vdrBackgroundColorFrom]="colorFrom" | ||
[class.with-background]="!invert && colorFrom" | ||
[style.backgroundColor]="!invert && (colorFrom | stringToColor)" | ||
[style.color]="invert && (colorFrom | stringToColor)" | ||
[style.borderColor]="invert && (colorFrom | stringToColor)" | ||
[ngClass]="colorType" | ||
> | ||
<div class="chip-label"><ng-content></ng-content></div> | ||
<div class="chip-icon" *ngIf="icon"> | ||
<button (click)="iconClick.emit($event)"> | ||
<clr-icon [attr.shape]="icon" [class.is-inverse]="colorFrom"></clr-icon> | ||
<clr-icon | ||
[attr.shape]="icon" | ||
[style.color]="invert && (colorFrom | stringToColor)" | ||
[class.is-inverse]="!invert && colorFrom" | ||
></clr-icon> | ||
</button> | ||
</div> | ||
</div> |
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
22 changes: 0 additions & 22 deletions
22
admin-ui/src/app/shared/directives/background-color-from.directive.ts
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
import { SortPipe } from './sort.pipe'; | ||
|
||
describe('SortPipe', () => { | ||
const sortPipe = new SortPipe(); | ||
|
||
it('sorts a primitive array', () => { | ||
const input = [5, 4, 2, 3, 2, 7, 1]; | ||
expect(sortPipe.transform(input)).toEqual([1, 2, 2, 3, 4, 5, 7]); | ||
}); | ||
|
||
it('sorts an array of objects', () => { | ||
const input = [{ id: 3 }, { id: 1 }, { id: 9 }, { id: 2 }, { id: 4 }]; | ||
expect(sortPipe.transform(input, 'id')).toEqual([ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
{ id: 9 }, | ||
]); | ||
}); | ||
}); |
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,28 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
/** | ||
* A pipe for sorting elements of an array. Should be used with caution due to the | ||
* potential for perf degredation. Ideally should only be used on small arrays (< 10s of items) | ||
* and in components using OnPush change detection. | ||
*/ | ||
@Pipe({ | ||
name: 'sort', | ||
}) | ||
export class SortPipe implements PipeTransform { | ||
transform<T>(value: T[], orderByProp?: keyof T) { | ||
return value.sort((a, b) => { | ||
const aProp = orderByProp ? a[orderByProp] : a; | ||
const bProp = orderByProp ? b[orderByProp] : b; | ||
if (aProp === bProp) { | ||
return 0; | ||
} | ||
if (aProp == null) { | ||
return 1; | ||
} | ||
if (bProp == null) { | ||
return -1; | ||
} | ||
return aProp > bProp ? 1 : -1; | ||
}); | ||
} | ||
} |
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,13 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
import { stringToColor } from '../../common/utilities/string-to-color'; | ||
|
||
@Pipe({ | ||
name: 'stringToColor', | ||
pure: true, | ||
}) | ||
export class StringToColorPipe implements PipeTransform { | ||
transform(value: any): string { | ||
return stringToColor(value); | ||
} | ||
} |
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