Browse Source

Various improvements

pull/6575/head
Thomas Kaul 1 day ago
parent
commit
31a308416b
  1. 6
      libs/ui/src/lib/value/value.component.stories.ts
  2. 15
      libs/ui/src/lib/value/value.component.ts

6
libs/ui/src/lib/value/value.component.stories.ts

@ -14,13 +14,13 @@ export default {
}) })
], ],
argTypes: { argTypes: {
enableCopyToClipboardButton: {
control: 'boolean'
},
deviceType: { deviceType: {
control: 'select', control: 'select',
options: ['desktop', 'mobile'] options: ['desktop', 'mobile']
}, },
enableCopyToClipboardButton: {
control: 'boolean'
},
size: { size: {
control: 'select', control: 'select',
options: ['small', 'medium', 'large'] options: ['small', 'medium', 'large']

15
libs/ui/src/lib/value/value.component.ts

@ -5,6 +5,7 @@ import { CommonModule } from '@angular/common';
import { import {
AfterViewInit, AfterViewInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef,
Component, Component,
computed, computed,
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
@ -47,7 +48,8 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
@Input() unit = ''; @Input() unit = '';
@Input() value: number | string = ''; @Input() value: number | string = '';
@ViewChild('labelContent', { static: false }) labelContent!: ElementRef; @ViewChild('labelContent', { static: false })
labelContent!: ElementRef<HTMLSpanElement>;
public absoluteValue = 0; public absoluteValue = 0;
public formattedValue = ''; public formattedValue = '';
@ -57,6 +59,7 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
public useAbsoluteValue = false; public useAbsoluteValue = false;
public constructor( public constructor(
private changeDetectorRef: ChangeDetectorRef,
private clipboard: Clipboard, private clipboard: Clipboard,
private snackBar: MatSnackBar private snackBar: MatSnackBar
) { ) {
@ -82,8 +85,14 @@ export class GfValueComponent implements AfterViewInit, OnChanges {
} }
public ngAfterViewInit() { public ngAfterViewInit() {
const el = this.labelContent.nativeElement; if (this.labelContent) {
this.hasLabel = el.textContent.trim().length > 0 || el.children.length > 0; const element = this.labelContent.nativeElement;
this.hasLabel =
element.children.length > 0 || element.textContent.trim().length > 0;
this.changeDetectorRef.markForCheck();
}
} }
public ngOnChanges() { public ngOnChanges() {

Loading…
Cancel
Save