Skip to content

Commit

Permalink
feat(daffio): split daffio nav into separate docs and marketing compo…
Browse files Browse the repository at this point in the history
…nents

---------

Co-authored-by: xelaint <xelaint@gmail.com>
  • Loading branch information
griest024 and xelaint committed Jan 15, 2025
1 parent 2017cc8 commit 560ff20
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 22 deletions.
4 changes: 2 additions & 2 deletions apps/daffio/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { DAFF_DOCS_PATH } from '@daffodil/docs-utils';

import { DaffioMarketingFooterComponent } from './core/footer/marketing-footer/marketing-footer.component';
import { DaffioNavHeaderContainer } from './core/nav/header/header.component';
import { DaffioMarketingNavContainer } from './core/nav/marketing/marketing.component';
import { DAFF_NAV_SIDEBAR_REGISTRATION } from './core/nav/sidebar.provider';
import { DaffioRouterNamedViewsEnum } from './core/router/named-views/models/named-views.enum';
import { DaffioRoute } from './core/router/route.type';
Expand All @@ -20,7 +20,7 @@ export const appRoutes: Routes = [
component: TemplateComponent,
data: {
daffNamedViews: {
[DaffioRouterNamedViewsEnum.NAV]: DaffioNavHeaderContainer,
[DaffioRouterNamedViewsEnum.NAV]: DaffioMarketingNavContainer,
},
daffioSidebars: {
[DAFF_NAV_SIDEBAR_REGISTRATION.id]: DAFF_NAV_SIDEBAR_REGISTRATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@

@mixin daffio-header-theme($theme) {
$primary: daff-theme.daff-map-get($theme, primary);
$neutral: daff-theme.daff-map-get($theme, 'core', 'neutral');
$base: daff-theme.daff-map-get($theme, 'core', 'base');

.daffio-header {
// stylelint-disable selector-class-pattern
&.bordered {
.daffio-header__navbar {
border-bottom: 1px solid daff-theme.daff-illuminate($base, $neutral, 2);
}
}
}
.daffio-header-item {
&.active {
color: daff-theme.daff-color($primary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:host {
$root: '.daffio-header';
display: block;
box-sizing: border-box;

::ng-deep {
.daffio-header-item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Component,
HostBinding,
ChangeDetectionStrategy,
Input,
} from '@angular/core';

@Component({
Expand All @@ -13,4 +14,5 @@ import {

export class DaffioHeaderComponent {
@HostBinding('class.daffio-header') class = true;
@Input() @HostBinding('class.bordered') bordered = false;
}
20 changes: 20 additions & 0 deletions apps/daffio/src/app/core/nav/docs/docs.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<daffio-header [bordered]="true">
<a routerLink="/" daffio-logo>
<daff-branding-logo type="full"></daff-branding-logo>
</a>
<daff-theme-switch-button theme-toggle></daff-theme-switch-button>
@for (link of links$ | async; track $index) {
<ng-container daffioHeaderItem>
@if (link.external) {
<a daffioHeaderItem [href]="link.url" target="_blank">{{link.title}}</a>
} @else {
<a daffioHeaderItem [routerLink]="link.url" [active]="rla.isActive" routerLinkActive #rla="routerLinkActive">{{ link.title }}</a>
}
</ng-container>
}
<button daff-icon-button color="theme-contrast" aria-label="Open Navigation Sidebar"
sidebar-button
(click)="openSidebar()">
<fa-icon [icon]="faBars"></fa-icon>
</button>
</daffio-header>
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import { BehaviorSubject } from 'rxjs';

import { DaffRouterDataService } from '@daffodil/router';

import { DaffioNavHeaderContainer } from './header.component';
import { DAFFIO_NAV_SIDEBAR_ID } from './sidebar-id';
import { DaffioDocsNavContainer } from './docs.component';
import { DaffioRoute } from '../../router/route.type';
import { DAFFIO_DOCS_NAV_SIDEBAR_ID } from '../../sidebar/docs-sidebar-id';
import { DaffioSidebarService } from '../../sidebar/services/sidebar.service';
import { DaffioNavLink } from '../link/type';

@Component({
template: '<daffio-nav-header-container></daffio-nav-header-container>',
template: '<daffio-docs-nav-container></daffio-docs-nav-container>',
standalone: true,
imports: [
DaffioNavHeaderContainer,
DaffioDocsNavContainer,
],
})
class WrapperComponent {}

describe('DaffioNavHeaderContainer', () => {
describe('DaffioDocsNavContainer', () => {
let component: WrapperComponent;
let fixture: ComponentFixture<WrapperComponent>;
let daffioHeaderContainer: DaffioNavHeaderContainer;
let docsNavContainer: DaffioDocsNavContainer;
let dataSpy: BehaviorSubject<DaffioRoute['data']>;
let sidebarServiceSpy: jasmine.SpyObj<DaffioSidebarService>;
let links: Array<DaffioNavLink>;
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('DaffioNavHeaderContainer', () => {
component = fixture.componentInstance;
fixture.detectChanges();

daffioHeaderContainer = fixture.debugElement.query(By.css('daffio-nav-header-container')).componentInstance;
docsNavContainer = fixture.debugElement.query(By.css('daffio-docs-nav-container')).componentInstance;
});

it('should create', () => {
Expand All @@ -88,7 +88,7 @@ describe('DaffioNavHeaderContainer', () => {
const sidebarButton = fixture.debugElement.query(By.css('[sidebar-button]')).nativeElement;
sidebarButton.click();

expect(sidebarServiceSpy.open).toHaveBeenCalledWith(DAFFIO_NAV_SIDEBAR_ID);
expect(sidebarServiceSpy.open).toHaveBeenCalledWith(DAFFIO_DOCS_NAV_SIDEBAR_ID);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import {
import { DaffRouterDataService } from '@daffodil/router';
import { DaffThemeSwitchButtonModule } from '@daffodil/theme-switch';

import { DAFFIO_NAV_SIDEBAR_ID } from './sidebar-id';
import { DaffioHeaderComponentModule } from '../../header/components/header.module';
import { DaffioRoute } from '../../router/route.type';
import { DaffioSidebarService } from '../../sidebar/services/sidebar.service';
import { DAFFIO_NAV_SIDEBAR_ID } from '../header/sidebar-id';
import { DaffioNavLink } from '../link/type';

@Component({
selector: 'daffio-nav-header-container',
templateUrl: './header.component.html',
selector: 'daffio-docs-nav-container',
templateUrl: './docs.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
Expand All @@ -50,7 +50,7 @@ import { DaffioNavLink } from '../link/type';
AsyncPipe,
],
})
export class DaffioNavHeaderContainer implements OnInit {
export class DaffioDocsNavContainer implements OnInit {
faBars = faBars;

links$: Observable<Array<DaffioNavLink>>;
Expand Down
94 changes: 94 additions & 0 deletions apps/daffio/src/app/core/nav/marketing/marketing.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Component } from '@angular/core';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { BehaviorSubject } from 'rxjs';

import { DaffRouterDataService } from '@daffodil/router';

import { DaffioMarketingNavContainer } from './marketing.component';
import { DaffioRoute } from '../../router/route.type';
import { DAFFIO_MARKETING_NAV_SIDEBAR_ID } from '../../sidebar/marketing-sidebar-id';
import { DaffioSidebarService } from '../../sidebar/services/sidebar.service';
import { DaffioNavLink } from '../link/type';

@Component({
template: '<daffio-nav-marketing-container></daffio-nav-marketing-container>',
standalone: true,
imports: [
DaffioMarketingNavContainer,
],
})
class WrapperComponent {}

describe('DaffioMarketingNavContainer', () => {
let component: WrapperComponent;
let fixture: ComponentFixture<WrapperComponent>;
let marketingNavContainer: DaffioMarketingNavContainer;
let dataSpy: BehaviorSubject<DaffioRoute['data']>;
let sidebarServiceSpy: jasmine.SpyObj<DaffioSidebarService>;
let links: Array<DaffioNavLink>;

beforeEach(waitForAsync(() => {
dataSpy = new BehaviorSubject({});
sidebarServiceSpy = jasmine.createSpyObj('DaffioSidebarService', ['open']);

TestBed.configureTestingModule({
imports: [
RouterTestingModule,
WrapperComponent,
],
providers: [
{
provide: DaffRouterDataService,
useValue: jasmine.createSpyObj('DaffRouterDataService', [], { data$: dataSpy }),
},
{
provide: DaffioSidebarService,
useValue: sidebarServiceSpy,
},
],
})
.compileComponents();

links = [
{ title: 'title1', url: 'url1' },
{ title: 'title2', url: 'url2' },
];
dataSpy.next({
daffioNavLinks: links,
});
}));

beforeEach(() => {
fixture = TestBed.createComponent(WrapperComponent);
component = fixture.componentInstance;
fixture.detectChanges();

marketingNavContainer = fixture.debugElement.query(By.css('daffio-nav-marketing-container')).componentInstance;
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should render the links', () => {
fixture.debugElement.queryAll(By.css('a[daffioHeaderItem]')).forEach((de, i) => {
expect(de.attributes['ng-reflect-router-link']).toEqual(links[i].url);
expect(de.nativeElement.innerText).toEqual(links[i].title);
});
});

describe('when [sidebar-button] is clicked', () => {
it('should open the nav sidebar', () => {
const sidebarButton = fixture.debugElement.query(By.css('[sidebar-button]')).nativeElement;
sidebarButton.click();

expect(sidebarServiceSpy.open).toHaveBeenCalledWith(DAFFIO_MARKETING_NAV_SIDEBAR_ID);
});
});
});
72 changes: 72 additions & 0 deletions apps/daffio/src/app/core/nav/marketing/marketing.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
AsyncPipe,
NgFor,
} from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
OnInit,
} from '@angular/core';
import {
RouterLink,
RouterLinkActive,
} from '@angular/router';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faBars } from '@fortawesome/free-solid-svg-icons';
import {
Observable,
map,
} from 'rxjs';

import { DaffLogoModule } from '@daffodil/branding';
import {
DaffButtonComponent,
DaffIconButtonComponent,
} from '@daffodil/design/button';
import { DaffRouterDataService } from '@daffodil/router';
import { DaffThemeSwitchButtonModule } from '@daffodil/theme-switch';

import { DaffioHeaderComponentModule } from '../../header/components/header.module';
import { DaffioRoute } from '../../router/route.type';
import { DaffioSidebarService } from '../../sidebar/services/sidebar.service';
import { DAFFIO_NAV_SIDEBAR_ID } from '../header/sidebar-id';
import { DaffioNavLink } from '../link/type';

@Component({
selector: 'daffio-nav-marketing-container',
templateUrl: './marketing.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffioHeaderComponentModule,
RouterLink,
RouterLinkActive,
DaffLogoModule,
DaffThemeSwitchButtonModule,
NgFor,
DaffButtonComponent,
DaffIconButtonComponent,
FaIconComponent,
AsyncPipe,
],
})
export class DaffioMarketingNavContainer implements OnInit {
faBars = faBars;

links$: Observable<Array<DaffioNavLink>>;

constructor(
private routerData: DaffRouterDataService<DaffioRoute['data']>,
private sidebarService: DaffioSidebarService,
) {}

ngOnInit(): void {
this.links$ = this.routerData.data$.pipe(
map((data) => data.daffioNavLinks),
);
}

openSidebar() {
this.sidebarService.open(DAFFIO_NAV_SIDEBAR_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
justify-content: center;
background: var(--daff-theme);
border: 0;
border-top: 1px solid rgb(var(--daff-theme-contrast-rgb), 0.1);
border-bottom: 1px solid rgb(var(--daff-theme-contrast-rgb), 0.1);
color: var(--daff-theme-contrast);
overflow: auto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
display: block;
padding: 1rem 0 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const visit = (guide: DaffDocsNavList): DaffTreeData<unknown> => ({
@Component({
selector: 'daffio-docs-list',
templateUrl: './docs-list.component.html',
styleUrl: './docs-list.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
Expand Down
2 changes: 0 additions & 2 deletions apps/daffio/src/app/docs/design/design-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { DAFFIO_DOCS_DESIGN_LIST_SIDEBAR_REGISTRATION } from './containers/docs-list/sidebar.provider';
import { DaffioDocsDesignComponentOverviewPageComponent } from './pages/components-overview/component-overview.component';
import { DaffioDocsDesignOverviewPageComponent } from './pages/overview/overview.component';
import { DAFF_NAV_SIDEBAR_REGISTRATION } from '../../core/nav/sidebar.provider';
import { DaffioRoute } from '../../core/router/route.type';
import { DaffioDocsPageComponent } from '../pages/docs-page/docs-page.component';
import { DocsResolver } from '../resolvers/docs-resolver.service';
Expand All @@ -30,7 +29,6 @@ export const docsDesignRoutes: Routes = [
data: {
docPrefix: `${DAFF_DOCS_PATH}/${DAFF_DOCS_DESIGN_PATH}`,
daffioSidebars: {
[DAFF_NAV_SIDEBAR_REGISTRATION.id]: DAFF_NAV_SIDEBAR_REGISTRATION,
[DAFFIO_DOCS_DESIGN_LIST_SIDEBAR_REGISTRATION.id]: DAFFIO_DOCS_DESIGN_LIST_SIDEBAR_REGISTRATION,
},
daffioDockedSidebar: DAFFIO_DOCS_DESIGN_LIST_SIDEBAR_REGISTRATION.id,
Expand Down
10 changes: 5 additions & 5 deletions apps/daffio/src/app/docs/docs-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ import {

import { DAFFIO_DOCS_LIST_SIDEBAR_REGISTRATION } from './containers/docs-list/sidebar.provider';
import { DaffioSimpleFooterComponent } from '../core/footer/simple-footer/simple-footer.component';
import { DAFF_NAV_SIDEBAR_REGISTRATION } from '../core/nav/sidebar.provider';
import { DaffioDocsNavContainer } from '../core/nav/docs/docs.component';
import { DaffioRouterNamedViewsEnum } from '../core/router/named-views/models/named-views.enum';
import { DaffioRoute } from '../core/router/route.type';

export const docsRoutes: Routes = [
<DaffioRoute>{
path: '',
data: {
daffNamedViews: {
[DaffioRouterNamedViewsEnum.NAV]: DaffioDocsNavContainer,
[DaffioRouterNamedViewsEnum.FOOTER]: DaffioSimpleFooterComponent,
},
daffioNavLinks: [
{ url: `/${DAFF_DOCS_PATH}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[DaffDocKind.GUIDE]}`, title: 'Guides' },
{ url: `/${DAFF_DOCS_PATH}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[DaffDocKind.PACKAGE]}`, title: 'Packages' },
{ url: `/${DAFF_DOCS_PATH}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[DaffDocKind.API]}`, title: 'API Reference' },
{ url: `/${DAFF_DOCS_PATH}/${DAFF_DOCS_DESIGN_PATH}`, title: 'Design' },
],
daffioSidebars: {
[DAFF_NAV_SIDEBAR_REGISTRATION.id]: DAFF_NAV_SIDEBAR_REGISTRATION,
[DAFFIO_DOCS_LIST_SIDEBAR_REGISTRATION.id]: DAFFIO_DOCS_LIST_SIDEBAR_REGISTRATION,
},
daffNamedViews: {
[DaffioRouterNamedViewsEnum.FOOTER]: DaffioSimpleFooterComponent,
},
},
children: [
{
Expand Down

0 comments on commit 560ff20

Please sign in to comment.