diff --git a/projects/components/src/public-api.ts b/projects/components/src/public-api.ts index 3d030055d..b1811f15a 100644 --- a/projects/components/src/public-api.ts +++ b/projects/components/src/public-api.ts @@ -284,6 +284,10 @@ export * from './summary-value/summary-value.module'; export * from './summary-values/summary-values.component'; export * from './summary-values/summary-values.module'; +// X More +export * from './x-more/x-more.component'; +export * from './x-more/x-more.module'; + // Table export * from './table/controls/table-controls-api'; export * from './table/data/table-data-source'; diff --git a/projects/components/src/x-more/x-more.component.scss b/projects/components/src/x-more/x-more.component.scss new file mode 100644 index 000000000..b7a71984b --- /dev/null +++ b/projects/components/src/x-more/x-more.component.scss @@ -0,0 +1,19 @@ +@import 'color-palette'; + +.ht-x-more { + .summary-text { + padding: 0 6px; + margin-left: 8px; + border-radius: 4px; + } + + .plain { + color: $gray-7; + margin-left: 0px; + background-color: white; + } + + .gray { + background-color: $gray-2; + } +} diff --git a/projects/components/src/x-more/x-more.component.test.ts b/projects/components/src/x-more/x-more.component.test.ts new file mode 100644 index 000000000..e0487c8d9 --- /dev/null +++ b/projects/components/src/x-more/x-more.component.test.ts @@ -0,0 +1,70 @@ +import { TooltipDirective } from '@hypertrace/components'; +import { createHostFactory, SpectatorHost } from '@ngneat/spectator/jest'; +import { MockDirective } from 'ng-mocks'; + +import { XMoreComponent, XMoreDisplay } from './x-more.component'; + +describe('X-More Component', () => { + let spectator: SpectatorHost; + + const createHost = createHostFactory({ + component: XMoreComponent, + shallow: true, + declarations: [MockDirective(TooltipDirective)] + }); + + test('should not display if count is 0', () => { + spectator = createHost( + ` + `, + { + hostProps: { + count: 0, + value: 'tooltip value', + displayStyle: XMoreDisplay.Plain + } + } + ); + + expect(spectator.query('.summary-text')).not.toExist(); + expect(spectator.query(TooltipDirective)).not.toExist(); + }); + + test('should display if count greater than 0', () => { + spectator = createHost( + ` + `, + { + hostProps: { + count: 1, + value: 'tooltip value', + displayStyle: XMoreDisplay.Plain + } + } + ); + + expect(spectator.query('.summary-text')).toExist(); + expect(spectator.query('.summary-text')).toHaveText('+1'); + expect(spectator.query(TooltipDirective)).toExist(); + }); + + test('should contain suffix if provided', () => { + spectator = createHost( + ` + `, + { + hostProps: { + count: 1, + value: 'tooltip value', + displayStyle: XMoreDisplay.Plain, + suffix: 'more' + } + } + ); + + expect(spectator.query('.summary-text')).toExist(); + expect(spectator.query('.summary-text')).toHaveText('+1'); + expect(spectator.query('.summary-text')).toHaveText('more'); + expect(spectator.query(TooltipDirective)).toExist(); + }); +}); diff --git a/projects/components/src/x-more/x-more.component.ts b/projects/components/src/x-more/x-more.component.ts new file mode 100644 index 000000000..6aa8a0f5f --- /dev/null +++ b/projects/components/src/x-more/x-more.component.ts @@ -0,0 +1,40 @@ +import { ChangeDetectionStrategy, Component, Input, OnChanges, TemplateRef } from '@angular/core'; +import { TypedSimpleChanges } from '@hypertrace/common'; + +@Component({ + selector: 'ht-x-more', + changeDetection: ChangeDetectionStrategy.OnPush, + template: `
+ {{ + this.summaryText + }} +
`, + styleUrls: ['./x-more.component.scss'] +}) +export class XMoreComponent implements OnChanges { + @Input() + public count!: number; + + @Input() + public suffix?: string = ''; + + @Input() + public displayStyle: XMoreDisplay = XMoreDisplay.Plain; + + @Input() + public tooltip!: string | number | TemplateRef; + + public summaryText!: string; + + public ngOnChanges(changes: TypedSimpleChanges): void { + if (changes.count || changes.suffix) { + this.summaryText = + this.suffix !== undefined && this.suffix !== '' ? `+${this.count} ${this.suffix}` : `+${this.count}`; + } + } +} + +export const enum XMoreDisplay { + Plain = 'plain', + Gray = 'gray' +} diff --git a/projects/components/src/x-more/x-more.module.ts b/projects/components/src/x-more/x-more.module.ts new file mode 100644 index 000000000..71eb69033 --- /dev/null +++ b/projects/components/src/x-more/x-more.module.ts @@ -0,0 +1,11 @@ +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; +import { TooltipModule } from '../tooltip/tooltip.module'; +import { XMoreComponent } from './x-more.component'; + +@NgModule({ + imports: [CommonModule, TooltipModule], + declarations: [XMoreComponent], + exports: [XMoreComponent] +}) +export class XMoreModule {}