-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): shellbar redesign, add branding and additional context area #12694
Open
dpavlenishvili
wants to merge
13
commits into
main
Choose a base branch
from
12520-shellbar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c21beb0
feat(core): shellbar redesign, add branding and additional context area
dpavlenishvili fb0aa51
feat(core): enhanced context area overflow logic, add second options …
dpavlenishvili efd958d
feat(core): enhanced context area overflow logic, add second options …
dpavlenishvili 6221f97
feat(core): update
dpavlenishvili 7dd5f6d
fix(core): refactored shelbar-actions flow accroding actions-toolbar.
dpavlenishvili 9091efa
fix(core): removed additional, unnecessary search icon
dpavlenishvili 39a183b
Merge branch 'main' into 12520-shellbar
dpavlenishvili 2407be3
fix(core, docs): address branding updates, improvements
dpavlenishvili c781af9
fix(core): overflow wp
dpavlenishvili 9d3cab2
Merge remote-tracking branch 'origin/main' into 12520-shellbar
dpavlenishvili 2300f82
Merge branch 'main' into 12520-shellbar
dpavlenishvili a000645
Merge branch 'main' into 12520-shellbar
dpavlenishvili 0a31d70
fix(deps): fix merge conflicts
dpavlenishvili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
10 changes: 10 additions & 0 deletions
10
libs/core/shellbar/shellbar-branding/shellbar-branding.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="fd-shellbar__branding" role="link" tabindex="0" [attr.aria-label]="ariaLabel" (click)="callback?.($event)"> | ||
<ng-content select="fd-shellbar-logo"></ng-content> | ||
|
||
@if (titleContent || subtitleContent) { | ||
<div class="fd-shellbar__product"> | ||
<ng-content select="fd-shellbar-title"></ng-content> | ||
<ng-content select="fd-shellbar-subtitle"></ng-content> | ||
</div> | ||
} | ||
</div> |
21 changes: 21 additions & 0 deletions
21
libs/core/shellbar/shellbar-branding/shellbar-branding.component.spec.ts
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 { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ShellbarBrandingComponent } from './shellbar-branding.component'; | ||
|
||
describe('ShellbarBrandingComponent', () => { | ||
let component: ShellbarBrandingComponent; | ||
let fixture: ComponentFixture<ShellbarBrandingComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ShellbarBrandingComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ShellbarBrandingComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
libs/core/shellbar/shellbar-branding/shellbar-branding.component.ts
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,32 @@ | ||
import { ChangeDetectionStrategy, Component, ContentChild, Input, ViewEncapsulation } from '@angular/core'; | ||
import { Nullable } from '@fundamental-ngx/cdk/utils'; | ||
import { FD_SHELLBAR_BRANDING_COMPONENT, FD_SHELLBAR_SUBTITLE_COMPONENT, FD_SHELLBAR_TITLE_COMPONENT } from '../tokens'; | ||
|
||
@Component({ | ||
selector: 'fd-shellbar-branding', | ||
standalone: true, | ||
templateUrl: './shellbar-branding.component.html', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
providers: [ | ||
{ | ||
provide: FD_SHELLBAR_BRANDING_COMPONENT, | ||
useExisting: ShellbarBrandingComponent | ||
} | ||
] | ||
}) | ||
export class ShellbarBrandingComponent { | ||
/** Callback that hanldles the response to clicks on any of the actions. */ | ||
@Input() | ||
callback: Nullable<(event: MouseEvent) => void>; | ||
|
||
/** add aria label dynamically to add to the button */ | ||
@Input() | ||
ariaLabel: Nullable<string>; | ||
|
||
/** hidden */ | ||
@ContentChild(FD_SHELLBAR_TITLE_COMPONENT) titleContent?: HTMLElement; | ||
|
||
/** hidden */ | ||
@ContentChild(FD_SHELLBAR_SUBTITLE_COMPONENT) subtitleContent?: HTMLElement; | ||
} |
59 changes: 59 additions & 0 deletions
59
libs/core/shellbar/shellbar-context-area/shellbar-context-area.component.spec.ts
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,59 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ShellbarContextAreaComponent } from './shellbar-context-area.component'; | ||
import { ResizeObserverService } from '@fundamental-ngx/core/utils'; | ||
import { ElementRef } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
|
||
export class ResizeObservableServiceMock { | ||
private readonly _observerMap = new Map<Element | ElementRef<Element>, Subject<ResizeObserverEntry[]>>(); | ||
|
||
observe(elementOrRef: Element | ElementRef<Element>): Subject<ResizeObserverEntry[]> { | ||
const subj = new Subject<ResizeObserverEntry[]>(); | ||
this._observerMap.set(elementOrRef, subj); | ||
return subj; | ||
} | ||
|
||
trigger(elementOrRef: Element | ElementRef<Element>, data: ResizeObserverEntry[]): void { | ||
this._observerMap.get(elementOrRef)?.next(data); | ||
} | ||
} | ||
|
||
describe('ShellbarContextAreaComponent', () => { | ||
let component: ShellbarContextAreaComponent; | ||
let fixture: ComponentFixture<ShellbarContextAreaComponent>; | ||
let resizeObserverServiceMock: ResizeObservableServiceMock; | ||
|
||
beforeEach(async () => { | ||
resizeObserverServiceMock = new ResizeObservableServiceMock(); | ||
|
||
await TestBed.configureTestingModule({ | ||
imports: [ShellbarContextAreaComponent], | ||
providers: [ | ||
{ | ||
provide: ResizeObserverService, | ||
useValue: resizeObserverServiceMock | ||
} | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ShellbarContextAreaComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should call updateVisibility on resize event', async () => { | ||
const updateVisibilitySpy = jest.spyOn(component, 'updateVisibility'); | ||
|
||
await fixture.whenRenderingDone(); | ||
|
||
resizeObserverServiceMock.trigger(component.el.nativeElement, []); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(updateVisibilitySpy).toHaveBeenCalled(); | ||
}); | ||
}); |
155 changes: 155 additions & 0 deletions
155
libs/core/shellbar/shellbar-context-area/shellbar-context-area.component.ts
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,155 @@ | ||
import { AfterViewInit, ChangeDetectionStrategy, Component, DestroyRef, ElementRef } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { ResizeObserverService } from '@fundamental-ngx/cdk/utils'; | ||
|
||
/** | ||
* Component representing the context area of the shellbar. | ||
* It manages the visibility of its child elements based on the available width. | ||
*/ | ||
@Component({ | ||
selector: 'fd-shellbar-context-area', | ||
standalone: true, | ||
template: ` <ng-content></ng-content>`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
host: { | ||
'[class.fd-shellbar__group]': 'true', | ||
'[class.fd-shellbar__group--context-area]': 'true' | ||
}, | ||
styles: [ | ||
` | ||
:host { | ||
min-width: 0; | ||
} | ||
` | ||
] | ||
}) | ||
export class ShellbarContextAreaComponent implements AfterViewInit { | ||
/** @hidden */ | ||
constructor( | ||
public el: ElementRef, | ||
private _resizeObserverService: ResizeObserverService, | ||
private _destroyRef: DestroyRef | ||
) {} | ||
|
||
/** @hidden */ | ||
ngAfterViewInit(): void { | ||
this._resizeObserverService | ||
.observe(this.el) | ||
.pipe(takeUntilDestroyed(this._destroyRef)) | ||
.subscribe(() => this.updateVisibility()); | ||
requestAnimationFrame(() => this.updateVisibility()); | ||
} | ||
|
||
/** | ||
* Updates the visibility of the child elements based on the available width. | ||
* This method ensures that the elements with the highest priority are shown | ||
* while hiding the lower priority elements if there is not enough space. | ||
* | ||
* The method works by: | ||
* 1. Sorting the elements based on their priority. | ||
* 2. Calculating the total width of the currently shown elements. | ||
* 3. Comparing the total width with the available width. | ||
* 4. Iteratively hiding the last shown element if the total width exceeds the available width. | ||
* 5. Iteratively showing the first hidden element if there is enough space. | ||
* 6. Ensuring all elements fit within the available width without recursion. | ||
*/ | ||
updateVisibility(): void { | ||
const elements: { el: HTMLElement; priority: number }[] = this._getElementsWithPriority(); | ||
const availableWidth = this._getAvailableWidth(); | ||
const allItemsWidth = this._calculateShownElementsWidth(elements); | ||
|
||
this._hideElementsIfNeeded(elements, availableWidth, allItemsWidth); | ||
this._showElementsIfNeeded(elements, availableWidth, allItemsWidth); | ||
} | ||
|
||
/** | ||
* Retrieves the child elements with their respective priority values. | ||
* The elements are sorted based on their priority, with elements having | ||
* higher priority shown first. | ||
*/ | ||
private _getElementsWithPriority(): { el: HTMLElement; priority: number }[] { | ||
return [...this.el.nativeElement.childNodes] | ||
.map((element: HTMLElement, index) => { | ||
const hasPriorityAttribute = element.hasAttribute && element.hasAttribute('fdShellbarHidePriority'); | ||
const priority = hasPriorityAttribute | ||
? parseInt(element.getAttribute('fdShellbarHidePriority')!, 10) | ||
: index + 1; | ||
|
||
return { el: element, priority }; | ||
}) | ||
.sort((a, b) => a.priority - b.priority); | ||
} | ||
|
||
/** | ||
* Hides elements if the total width exceeds the available width. | ||
* This method will hide the last shown element iteratively until the total width | ||
* fits within the available width. | ||
*/ | ||
private _hideElementsIfNeeded( | ||
elements: { | ||
el: HTMLElement; | ||
priority: number; | ||
}[], | ||
availableWidth: number, | ||
allItemsWidth: number | ||
): void { | ||
while (allItemsWidth > availableWidth) { | ||
const shownElements = elements.filter((el) => el.el.style.display !== 'none'); | ||
if (shownElements.length === 0) { | ||
break; | ||
} | ||
shownElements[shownElements.length - 1].el.style.display = 'none'; | ||
allItemsWidth = this._calculateShownElementsWidth(elements); | ||
} | ||
} | ||
|
||
/** | ||
* Shows elements if there is enough space available. | ||
* This method will show the first hidden element iteratively as long as there | ||
* is sufficient space, and hide the element again if the space is exceeded. | ||
*/ | ||
private _showElementsIfNeeded( | ||
elements: { | ||
el: HTMLElement; | ||
priority: number; | ||
}[], | ||
availableWidth: number, | ||
allItemsWidth: number | ||
): void { | ||
let hiddenElements = elements.filter((el) => el.el.style.display === 'none'); | ||
while (hiddenElements.length > 0 && allItemsWidth <= availableWidth) { | ||
hiddenElements[0].el.style.display = ''; | ||
allItemsWidth = this._calculateShownElementsWidth(elements); | ||
if (allItemsWidth > availableWidth) { | ||
hiddenElements[0].el.style.display = 'none'; | ||
break; | ||
} | ||
hiddenElements = elements.filter((el) => el.el.style.display === 'none'); | ||
} | ||
} | ||
|
||
/** | ||
* Calculates the total gap between the visible elements. | ||
* Avoids negative gap for single or no elements. | ||
*/ | ||
private _calculateTotalGap(elementsLength: number): number { | ||
const gap = parseFloat(window.getComputedStyle(this.el.nativeElement).gap || '0'); | ||
return gap * Math.max(elementsLength - 1, 0); | ||
} | ||
|
||
/** | ||
* Calculates the total width of the shown elements, including the gaps. | ||
*/ | ||
private _calculateShownElementsWidth(elements: { el: HTMLElement; priority: number }[]): number { | ||
const shownElements = elements.filter((el) => el.el.style.display !== 'none'); | ||
const totalWidth = shownElements.reduce((acc, el) => acc + el.el.clientWidth, 0); | ||
return totalWidth + this._calculateTotalGap(shownElements.length); | ||
} | ||
|
||
/** | ||
* Gets the available width of the container. | ||
*/ | ||
private _getAvailableWidth(): number { | ||
return this.el.nativeElement.offsetWidth; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
libs/core/shellbar/shellbar-overflow-priority.directive.ts
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 { Directive, ElementRef, inject, Input } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[fdShellbarHidePriority]', | ||
standalone: true | ||
}) | ||
export class ShellbarHidePriorityDirective { | ||
/** @hidden */ | ||
@Input('fdShellbarHidePriority') priority: any; | ||
dpavlenishvili marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** @hidden */ | ||
el = inject(ElementRef); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signal inputs