--- /dev/null
+<span *ngIf="!key; else key_value"
+ class="badge badge-{{value}}"
+ ngClass="{{value | colorClassFromText}}">
+ {{ value }}
+</span>
+
+<ng-template #key_value>
+ <span class="badge badge-background-primary badge-{{key}}-{{value}}">
+ {{ key }}: {{ value }}
+ </span>
+</ng-template>
--- /dev/null
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { CdLabelComponent } from './cd-label.component';
+import { ColorClassFromTextPipe } from './color-class-from-text.pipe';
+
+describe('CdLabelComponent', () => {
+ let component: CdLabelComponent;
+ let fixture: ComponentFixture<CdLabelComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [CdLabelComponent, ColorClassFromTextPipe]
+ }).compileComponents();
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(CdLabelComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
--- /dev/null
+import { Component, Input } from '@angular/core';
+
+@Component({
+ selector: 'cd-label',
+ templateUrl: './cd-label.component.html',
+ styleUrls: ['./cd-label.component.scss']
+})
+export class CdLabelComponent {
+ @Input() key?: string;
+ @Input() value?: string;
+}
--- /dev/null
+import { Pipe, PipeTransform } from '@angular/core';
+
+@Pipe({
+ name: 'colorClassFromText'
+})
+export class ColorClassFromTextPipe implements PipeTransform {
+ readonly cssClasses: string[] = [
+ 'badge-cd-label-green',
+ 'badge-cd-label-cyan',
+ 'badge-cd-label-purple',
+ 'badge-cd-label-light-blue',
+ 'badge-cd-label-gold',
+ 'badge-cd-label-light-green'
+ ];
+
+ transform(text: string): string {
+ let hash = 0;
+ let charCode = 0;
+ if (text) {
+ for (let i = 0; i < text.length; i++) {
+ charCode = text.charCodeAt(i);
+ // tslint:disable-next-line:no-bitwise
+ hash = Math.abs((hash << 5) - hash + charCode);
+ }
+ }
+ return this.cssClasses[hash % this.cssClasses.length];
+ }
+}
import { PipesModule } from '../pipes/pipes.module';
import { AlertPanelComponent } from './alert-panel/alert-panel.component';
import { BackButtonComponent } from './back-button/back-button.component';
+import { CdLabelComponent } from './cd-label/cd-label.component';
+import { ColorClassFromTextPipe } from './cd-label/color-class-from-text.pipe';
import { ConfigOptionComponent } from './config-option/config-option.component';
import { ConfirmationModalComponent } from './confirmation-modal/confirmation-modal.component';
import { Copy2ClipboardButtonComponent } from './copy2clipboard-button/copy2clipboard-button.component';
FormButtonPanelComponent,
MotdComponent,
WizardComponent,
- CustomLoginBannerComponent
+ CustomLoginBannerComponent,
+ CdLabelComponent,
+ ColorClassFromTextPipe
],
providers: [],
exports: [
FormButtonPanelComponent,
MotdComponent,
WizardComponent,
- CustomLoginBannerComponent
+ CustomLoginBannerComponent,
+ CdLabelComponent
]
})
export class ComponentsModule {}
color: $gray-700;
}
+.badge-cd-label-green {
+ background-color: $green-300;
+ color: $white;
+}
+
+.badge-cd-label-cyan {
+ background-color: $cyan-300;
+ color: $white;
+}
+
+.badge-cd-label-purple {
+ background-color: $purple-300;
+ color: $white;
+}
+
+.badge-cd-label-light-blue {
+ background-color: $light-blue-300;
+ color: $white;
+}
+
+.badge-cd-label-gold {
+ background-color: $gold-300;
+ color: $white;
+}
+
+.badge-cd-label-light-green {
+ background-color: $light-green-300;
+ color: $white;
+}
+
// angular-tree-component
tree-root {
tree-viewport {
$light: $gray-100 !default;
$dark: #777 !default;
+//badges colors
+$green-300: #6ec664;
+$cyan-300: #009596;
+$purple-300: #a18fff;
+$light-blue-300: #35caed;
+$gold-300: #f4c145;
+$light-green-300: #ace12e;
+
// Extra theme colors.
$accent: $red !default;
$warning-dark: $orange !default;