Skip to content
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(design): update the way the nav height is calculated #2714

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import {
ChangeDetectionStrategy,
Component,
Injector,
} from '@angular/core';
import { faBars } from '@fortawesome/free-solid-svg-icons';
import { Store } from '@ngrx/store';

import { DaffSidebarViewportNavDirective } from '@daffodil/design/sidebar';

import { ToggleSidebar } from '../../../../core/sidebar/actions/sidebar.actions';

@Component({
selector: 'daffio-docs-header-container',
templateUrl: './docs-header.component.html',
styles: [`
:host {
display: block;
border-bottom: 1px solid black;
}`],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: DaffSidebarViewportNavDirective,
useValue: {},
},
],
})
export class DaffioDocsHeaderContainer {
faBars = faBars;
Expand All @@ -19,9 +33,13 @@ export class DaffioDocsHeaderContainer {
{ path: '/api', title: 'API Index' },
];

constructor(private store: Store<any>) { }
constructor(private store: Store<any>, private injector: Injector) { }

openDocsSidebar() {
this.store.dispatch(new ToggleSidebar());
}

get height() {
return 65;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import {
import { faBars } from '@fortawesome/free-solid-svg-icons';
import { Store } from '@ngrx/store';

import { DaffSidebarViewportNavDirective } from '@daffodil/design/sidebar';

import { ToggleSidebar } from '../../../../core/sidebar/actions/sidebar.actions';

@Component({
selector: 'daffio-marketing-header-container',
templateUrl: './marketing-header.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: DaffSidebarViewportNavDirective,
useValue: {},
},
],
})
export class DaffioMarketingHeaderContainer {
faBars = faBars;
Expand All @@ -25,4 +33,8 @@ export class DaffioMarketingHeaderContainer {
openSidebar() {
this.store.dispatch(new ToggleSidebar());
}

get height() {
return 64;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<a href="https://github.com/graycoreio/daffodil" rel="noopener noreferrer" target="_blank" class="daffio-sidebar-viewport__get-started">Get Started</a>
</daff-sidebar-footer>
</daff-sidebar>
<ng-container daff-sidebar-viewport-nav>
<ng-content select="[daff-sidebar-viewport-nav]"></ng-content>
<ng-container ngProjectAs="[daff-sidebar-viewport-nav]">
<ng-container [daffRouterNamedViewOutlet]="navNamedView"></ng-container>
</ng-container>
<ng-content></ng-content>
</daff-sidebar-viewport>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import * as fromDaffioSidebar from '../../reducers/index';
})
export class DaffioSidebarViewportContainer implements OnInit {
faTimes = faTimes;
readonly sidebarNamedView = DaffioRouterNamedViewsEnum.SIDEBAR;
readonly navNamedView = DaffioRouterNamedViewsEnum.NAV;

showSidebar$: Observable<boolean>;
sidebarContents$: Observable<DaffioGuideList>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<daffio-sidebar-viewport-container>
<ng-container [daffRouterNamedViewOutlet]="navNamedView" daff-sidebar-viewport-nav></ng-container>
<router-outlet></router-outlet>
<daffio-sub-footer></daffio-sub-footer>
<daffio-simple-footer></daffio-simple-footer>
Expand Down
1 change: 0 additions & 1 deletion apps/daffio/src/app/core/template/template.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ import { DaffioRouterNamedViewsEnum } from '../../named-views/models/named-views
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TemplateComponent {
readonly navNamedView = DaffioRouterNamedViewsEnum.NAV;
}
1 change: 1 addition & 0 deletions libs/design/sidebar/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './sidebar-header/sidebar-header.component';
export * from './sidebar-footer/sidebar-footer.component';
export * from './sidebar-header/sidebar-header-title/sidebar-header-title.directive';
export * from './sidebar-header/sidebar-header-action/sidebar-header-action.directive';
export * from './sidebar-viewport/nav/nav.directive';
export {
DaffSidebarMode,
DaffSidebarModeEnum,
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions libs/design/sidebar/src/sidebar-viewport/nav/nav.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
AfterViewInit,
Directive,
ElementRef,
} from '@angular/core';

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[daff-sidebar-viewport-nav]',
})
export class DaffSidebarViewportNavDirective implements AfterViewInit {
private _height = 64;

constructor(private elementRef: ElementRef) {}

ngAfterViewInit() {
this._height = this.elementRef.nativeElement.offsetHeight;
}

get height() {
return this._height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import {
Inject,
SkipSelf,
Optional,
ViewChild,
ViewContainerRef,
ContentChild,
} from '@angular/core';

import { hasParentViewport } from './helper/has-parent-viewport';
import { DaffSidebarViewportNavDirective } from './nav/nav.directive';
import {
DaffNavPlacement,
DaffNavPlacementEnum,
Expand Down Expand Up @@ -134,6 +138,8 @@ export class DaffSidebarViewportComponent implements AfterContentChecked {
*/
public _navPadRight = 0;

private _navHeight = 0;

/**
* Whether or not the backdrop is interactable
*/
Expand All @@ -144,6 +150,11 @@ export class DaffSidebarViewportComponent implements AfterContentChecked {
*/
_animationState: DaffSidebarViewportAnimationStateWithParams = { value: DaffSidebarAnimationStates.CLOSED, params: { shift: '0px' }};

/**
* @docs-private
*/
@ContentChild(DaffSidebarViewportNavDirective, { static: false, descendants: true }) nav: DaffSidebarViewportNavDirective;

/**
* Event fired when the backdrop is clicked. This is often used to close the sidebar.
*/
Expand All @@ -164,6 +175,12 @@ export class DaffSidebarViewportComponent implements AfterContentChecked {
this.cdRef.markForCheck();
}

const nextNavHeight = this.nav?.height;
if( nextNavHeight !== this._navHeight ) {
this._navHeight = nextNavHeight;
this._elementRef.nativeElement.style.setProperty('--daff-sidebar-side-fixed-top-shift', nextNavHeight + 'px');
}

const nextBackdropInteractable = sidebarViewportBackdropInteractable(this.sidebars);
if (this._backdropInteractable !== nextBackdropInteractable) {
this._backdropInteractable = nextBackdropInteractable;
Expand Down
3 changes: 3 additions & 0 deletions libs/design/sidebar/src/sidebar.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DaffSidebarFooterComponent } from './sidebar-footer/sidebar-footer.comp
import { DaffSidebarHeaderActionDirective } from './sidebar-header/sidebar-header-action/sidebar-header-action.directive';
import { DaffSidebarHeaderTitleDirective } from './sidebar-header/sidebar-header-title/sidebar-header-title.directive';
import { DaffSidebarHeaderComponent } from './sidebar-header/sidebar-header.component';
import { DaffSidebarViewportNavDirective } from './sidebar-viewport/nav/nav.directive';
import { DaffSidebarViewportComponent } from './sidebar-viewport/sidebar-viewport.component';

@NgModule({
Expand All @@ -24,6 +25,7 @@ import { DaffSidebarViewportComponent } from './sidebar-viewport/sidebar-viewpor
DaffSidebarFooterComponent,
DaffSidebarHeaderTitleDirective,
DaffSidebarHeaderActionDirective,
DaffSidebarViewportNavDirective,
],
exports: [
DaffSidebarComponent,
Expand All @@ -32,6 +34,7 @@ import { DaffSidebarViewportComponent } from './sidebar-viewport/sidebar-viewpor
DaffSidebarFooterComponent,
DaffSidebarHeaderTitleDirective,
DaffSidebarHeaderActionDirective,
DaffSidebarViewportNavDirective,
],
})
export class DaffSidebarModule { }
2 changes: 1 addition & 1 deletion libs/router/src/named-view/outlet/outlet.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class DaffRouterNamedViewOutletDirective implements OnInit, OnChanges, On
).subscribe((component) => {
this.viewRef.clear();
if (component) {
const ref = this.viewRef.createComponent(component);
const ref = this.viewRef.createComponent(component, { injector: this.viewRef.injector });
ref.changeDetectorRef.markForCheck();
}
});
Expand Down
Loading