From 30bbfaced1ccea38e62caefb24f2668fe2182827 Mon Sep 17 00:00:00 2001 From: droshev Date: Fri, 20 Sep 2024 15:26:14 -0400 Subject: [PATCH] fix(core): toolbar render spacer before overflow conditionally --- libs/core/toolbar/toolbar.component.html | 4 +- libs/core/toolbar/toolbar.component.ts | 25 ++++- .../examples/toolbar-example.component.ts | 11 +-- ...r-overflow-priority-example.component.html | 93 +++++++++++++++++++ .../toolbar-size-example.component.html | 9 -- .../toolbar-documentation.component.html | 20 ++-- .../toolbar-documentation.component.ts | 11 --- 7 files changed, 126 insertions(+), 47 deletions(-) delete mode 100644 libs/docs/core/toolbar/examples/toolbar-size-example.component.html diff --git a/libs/core/toolbar/toolbar.component.html b/libs/core/toolbar/toolbar.component.html index 6f5b7827da1..e9ebc25f161 100644 --- a/libs/core/toolbar/toolbar.component.html +++ b/libs/core/toolbar/toolbar.component.html @@ -3,7 +3,9 @@

{{ title }}< } @if (overflownItems.length > 0) { - + @if (!spacerUsed()) { + + } diff --git a/libs/core/toolbar/toolbar.component.ts b/libs/core/toolbar/toolbar.component.ts index 9c3888f3822..2ff83d719e5 100644 --- a/libs/core/toolbar/toolbar.component.ts +++ b/libs/core/toolbar/toolbar.component.ts @@ -7,6 +7,7 @@ import { Component, ContentChild, ContentChildren, + contentChildren, DestroyRef, ElementRef, forwardRef, @@ -16,6 +17,7 @@ import { Input, Optional, QueryList, + signal, SkipSelf, ViewChild, ViewEncapsulation @@ -46,7 +48,8 @@ import { ToolbarSeparatorComponent } from './toolbar-separator.component'; import { ToolbarSpacerDirective } from './toolbar-spacer.directive'; const ELEMENT_MARGIN = 8; -const OVERFLOW_SPACE = 50 + 2 * ELEMENT_MARGIN; +const OVERFLOW_BTN_COZY = 36; +const OVERFLOW_BTN_COMPACT = 32; const MAX_CONTENT_SIZE = 99999999; export type ToolbarType = 'solid' | 'transparent' | 'auto' | 'info'; @@ -178,6 +181,12 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla /** @hidden */ overflownItems: ToolbarItem[] = []; + /** @hidden */ + spacerUsed = signal(false); + + /** @hidden */ + spacerDirectives = contentChildren(ToolbarSpacerDirective); + /** HTML Element Reference. */ readonly elementRef = inject(ElementRef); @@ -189,7 +198,8 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla /** @hidden */ private get _toolbarWidth(): number { - return (this.elementRef.nativeElement as HTMLElement).clientWidth - OVERFLOW_SPACE; + const _overflow_btn_size = this._contentDensityObserver.isCompact ? OVERFLOW_BTN_COMPACT : OVERFLOW_BTN_COZY; + return (this.elementRef.nativeElement as HTMLElement).clientWidth - (_overflow_btn_size + 2 * ELEMENT_MARGIN); } /** @hidden */ @@ -224,6 +234,8 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla /** @hidden */ ngAfterViewInit(): void { + this._updateSpacerUsed(); + this.overflowItems$ = combineLatest([ this.resizeObserverService.observe(this.elementRef.nativeElement).pipe(map(() => this._toolbarWidth)), this.toolbarItems.changes.pipe( @@ -318,6 +330,15 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla this._refreshOverflow$.next(); } + /** hidden */ + private _updateSpacerUsed(): void { + // do not render extra spacer if there is at least one passed by the application + // and it is not fixed this.spacerUsed.set(this.spacer.length > 0 && this.spacer.some((spacer) => !spacer.fixed)); + this.spacerUsed.set( + this.spacerDirectives().length > 0 && this.spacerDirectives().some((spacer) => !spacer.fixed) + ); + } + /** @hidden Get group number with the lowest priority. * Uses for detecting a group of elements which would be hidden from the toolbar. * */ diff --git a/libs/docs/core/toolbar/examples/toolbar-example.component.ts b/libs/docs/core/toolbar/examples/toolbar-example.component.ts index 2f555be17f5..ed0a3beac6c 100644 --- a/libs/docs/core/toolbar/examples/toolbar-example.component.ts +++ b/libs/docs/core/toolbar/examples/toolbar-example.component.ts @@ -1,6 +1,5 @@ import { Component } from '@angular/core'; import { ButtonComponent } from '@fundamental-ngx/core/button'; -import { ContentDensityDirective } from '@fundamental-ngx/core/content-density'; import { IconComponent } from '@fundamental-ngx/core/icon'; import { TitleComponent } from '@fundamental-ngx/core/title'; import { @@ -47,7 +46,7 @@ export class ToolbarSeparatorExampleComponent {} selector: 'fd-toolbar-overflow-priority-example', templateUrl: './toolbar-overflow-priority-example.component.html', standalone: true, - imports: [ToolbarComponent, ButtonComponent, ToolbarItemDirective] + imports: [ToolbarComponent, ButtonComponent, ToolbarItemDirective, ToolbarSpacerDirective] }) export class ToolbarOverflowPriorityExampleComponent {} @@ -58,11 +57,3 @@ export class ToolbarOverflowPriorityExampleComponent {} imports: [ToolbarComponent, ButtonComponent, ToolbarItemDirective] }) export class ToolbarOverflowGroupingExampleComponent {} - -@Component({ - selector: 'fd-toolbar-size-example', - templateUrl: './toolbar-size-example.component.html', - standalone: true, - imports: [ToolbarComponent, ContentDensityDirective, ToolbarLabelDirective] -}) -export class ToolbarSizeExampleComponent {} diff --git a/libs/docs/core/toolbar/examples/toolbar-overflow-priority-example.component.html b/libs/docs/core/toolbar/examples/toolbar-overflow-priority-example.component.html index 7a90412e66f..57b2c569f1b 100644 --- a/libs/docs/core/toolbar/examples/toolbar-overflow-priority-example.component.html +++ b/libs/docs/core/toolbar/examples/toolbar-overflow-priority-example.component.html @@ -1,9 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/docs/core/toolbar/examples/toolbar-size-example.component.html b/libs/docs/core/toolbar/examples/toolbar-size-example.component.html deleted file mode 100644 index a76094a7cc7..00000000000 --- a/libs/docs/core/toolbar/examples/toolbar-size-example.component.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - -
- - - - diff --git a/libs/docs/core/toolbar/toolbar-documentation.component.html b/libs/docs/core/toolbar/toolbar-documentation.component.html index 7b9bc134a83..cd009d832ad 100644 --- a/libs/docs/core/toolbar/toolbar-documentation.component.html +++ b/libs/docs/core/toolbar/toolbar-documentation.component.html @@ -1,5 +1,5 @@ Toolbar Types - + - + @@ -85,15 +85,7 @@ - - Toolbar Size - The Toolbar size can be set to either compact(default) or cozy. T - - - - - - + diff --git a/libs/docs/core/toolbar/toolbar-documentation.component.ts b/libs/docs/core/toolbar/toolbar-documentation.component.ts index b32c8cc4032..a91025ea697 100644 --- a/libs/docs/core/toolbar/toolbar-documentation.component.ts +++ b/libs/docs/core/toolbar/toolbar-documentation.component.ts @@ -12,7 +12,6 @@ import { ToolbarOverflowGroupingExampleComponent, ToolbarOverflowPriorityExampleComponent, ToolbarSeparatorExampleComponent, - ToolbarSizeExampleComponent, ToolbarSpacerExampleComponent, ToolbarTitleExampleComponent, ToolbarTypeExampleComponent @@ -27,7 +26,6 @@ const toolbarOverflowExampleTs = 'toolbar-overflow-example.component.ts'; const toolbarOverflowExampleHtml = 'toolbar-overflow-example.component.html'; const toolbarOverflowPriorityExampleHtml = 'toolbar-overflow-priority-example.component.html'; const toolbarOverflowGroupingExampleHtml = 'toolbar-overflow-grouping-example.component.html'; -const toolbarSizeExampleHtml = 'toolbar-size-example.component.html'; @Component({ selector: 'fd-docs-toolbar', @@ -45,7 +43,6 @@ const toolbarSizeExampleHtml = 'toolbar-size-example.component.html'; ToolbarOverflowExampleComponent, ToolbarOverflowPriorityExampleComponent, ToolbarOverflowGroupingExampleComponent, - ToolbarSizeExampleComponent, ToolbarSpacerExampleComponent, ToolbarSeparatorExampleComponent ] @@ -112,12 +109,4 @@ export class ToolbarDocumentationComponent { fileName: 'toolbar-overflow-grouping-example' } ]; - - toolbarSizeExample: ExampleFile[] = [ - { - language: 'html', - code: getAssetFromModuleAssets(toolbarSizeExampleHtml), - fileName: 'toolbar-size-example' - } - ]; }