-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daffio): dynamically render doc views (#3415)
- Loading branch information
Showing
34 changed files
with
396 additions
and
320 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<daffio-doc-article [breadcrumbs]="doc().breadcrumbs"> | ||
@if (isApiPackage()) { | ||
<daffio-api-package [doc]="doc()"></daffio-api-package> | ||
} @else { | ||
<div [innerHTML]="doc().contents | safe"></div> | ||
} | ||
</daffio-doc-article> |
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,35 @@ | ||
import { | ||
Component, | ||
ChangeDetectionStrategy, | ||
input, | ||
computed, | ||
} from '@angular/core'; | ||
import { DaffioSafeHtmlPipe } from 'apps/daffio/src/app/core/html-sanitizer/safe.pipe'; | ||
|
||
import { | ||
DaffApiDoc, | ||
DaffDocKind, | ||
} from '@daffodil/docs-utils'; | ||
|
||
import { DaffioDocArticleModule } from '../../../components/doc-article/module'; | ||
import { DaffioDocComponent } from '../../../components/doc-renderer/component.type'; | ||
import { DaffioApiPackageComponent } from '../api-package/api-package.component'; | ||
|
||
@Component({ | ||
selector: 'daffio-api-doc', | ||
templateUrl: './component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
DaffioDocArticleModule, | ||
DaffioApiPackageComponent, | ||
DaffioSafeHtmlPipe, | ||
], | ||
}) | ||
export class DaffioDocApiComponent implements DaffioDocComponent<DaffApiDoc> { | ||
static readonly kind = DaffDocKind.API; | ||
|
||
readonly isApiPackage = computed(() => this.doc().docType === 'package'); | ||
|
||
doc = input<DaffApiDoc>(); | ||
} |
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,4 @@ | ||
import { DaffioDocApiComponent } from './component'; | ||
import { provideDaffioDocRendererComponents } from '../../../components/doc-renderer/token'; | ||
|
||
export const daffioDocsApiComponentProvider = () => provideDaffioDocRendererComponents(DaffioDocApiComponent); |
1 change: 0 additions & 1 deletion
1
apps/daffio/src/app/docs/api/pages/api-page/api-page.component.html
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
apps/daffio/src/app/docs/api/pages/api-page/api-page.component.spec.ts
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
apps/daffio/src/app/docs/api/pages/api-page/api-page.component.ts
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
apps/daffio/src/app/docs/components/doc-article/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,33 @@ | ||
<button class="daffio-doc-article__menu-button" (click)="open()"> | ||
<fa-icon [icon]="faBars"></fa-icon> | ||
<div>Menu</div> | ||
</button> | ||
<div class="daffio-doc-article__grid"> | ||
<div class="daffio-doc-article__content"> | ||
<daff-article> | ||
@if (breadcrumbs.length > 0) { | ||
<nav aria-label="Breadcrumb"> | ||
<ol daff-breadcrumb> | ||
@for (breadcrumb of breadcrumbs(); track $index) { | ||
<li daffBreadcrumbItem [active]="$last"> | ||
@if ($last) { | ||
{{breadcrumb.label}} | ||
} @else { | ||
<a [routerLink]="breadcrumb.path">{{breadcrumb.label}}</a> | ||
} | ||
</li> | ||
} | ||
</ol> | ||
</nav> | ||
} | ||
|
||
<ng-content></ng-content> | ||
</daff-article> | ||
</div> | ||
@if (toc) { | ||
<daffio-docs-table-of-contents | ||
class="daffio-doc-article__table-of-contents" | ||
[tableOfContents]="toc"> | ||
</daffio-docs-table-of-contents> | ||
} | ||
</div> |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
margin: 0 auto; | ||
} | ||
|
||
.daffio-doc-viewer { | ||
.daffio-doc-article { | ||
&__grid { | ||
padding: 24px; | ||
|
||
|
80 changes: 80 additions & 0 deletions
80
apps/daffio/src/app/docs/components/doc-article/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,80 @@ | ||
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 { provideMockStore } from '@ngrx/store/testing'; | ||
|
||
import { DAFF_ARTICLE_COMPONENTS } from '@daffodil/design/article'; | ||
import { | ||
DaffApiPackageDoc, | ||
DaffBreadcrumb, | ||
DaffDocTableOfContents, | ||
} from '@daffodil/docs-utils'; | ||
|
||
import { DaffioDocArticleComponent } from './component'; | ||
import { DaffioApiPackageComponent } from '../../api/components/api-package/api-package.component'; | ||
import { DaffioDocsFactory } from '../../testing/factories/docs.factory'; | ||
import { DaffioDocsTableOfContentsModule } from '../table-of-contents/table-of-contents.module'; | ||
|
||
@Component({ | ||
template: `<daffio-doc-article | ||
[toc]="tocValue" | ||
[breadcrumbs]="breadcrumbsValue" | ||
></daffio-doc-article>`, | ||
}) | ||
class WrapperComponent { | ||
tocValue: DaffDocTableOfContents; | ||
breadcrumbsValue: Array<DaffBreadcrumb>; | ||
} | ||
|
||
describe('DaffioDocArticleComponent', () => { | ||
let component: DaffioDocArticleComponent; | ||
let fixture: ComponentFixture<WrapperComponent>; | ||
let wrapper: WrapperComponent; | ||
const docFactory = new DaffioDocsFactory(); | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule, | ||
DAFF_ARTICLE_COMPONENTS, | ||
DaffioDocsTableOfContentsModule, | ||
DaffioApiPackageComponent, | ||
], | ||
declarations: [ | ||
WrapperComponent, | ||
DaffioDocArticleComponent, | ||
], | ||
providers: [ | ||
provideMockStore(), | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WrapperComponent); | ||
wrapper = fixture.componentInstance; | ||
wrapper.tocValue = []; | ||
wrapper.breadcrumbsValue = []; | ||
fixture.detectChanges(); | ||
|
||
component = fixture.debugElement.query(By.directive(DaffioDocArticleComponent)).componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('should take toc as an input', () => { | ||
expect(component.toc).toEqual(wrapper.tocValue); | ||
}); | ||
|
||
it('should take breadcrumbs as an input', () => { | ||
expect(component.breadcrumbs).toEqual(wrapper.breadcrumbsValue); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
apps/daffio/src/app/docs/components/doc-article/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,35 @@ | ||
import { | ||
Component, | ||
ChangeDetectionStrategy, | ||
Input, | ||
} from '@angular/core'; | ||
import { faBars } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
import { | ||
DaffBreadcrumb, | ||
DaffDocTableOfContents, | ||
} from '@daffodil/docs-utils'; | ||
|
||
import { DaffioSidebarService } from '../../../core/sidebar/services/sidebar.service'; | ||
import { DAFFIO_DOCS_LIST_SIDEBAR_ID } from '../../containers/docs-list/sidebar.provider'; | ||
|
||
@Component({ | ||
selector: 'daffio-doc-article', | ||
templateUrl: './component.html', | ||
styleUrls: ['./component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DaffioDocArticleComponent { | ||
faBars = faBars; | ||
|
||
constructor( | ||
private sidebarService: DaffioSidebarService, | ||
) {} | ||
|
||
@Input() toc?: DaffDocTableOfContents; | ||
@Input() breadcrumbs: Array<DaffBreadcrumb> = []; | ||
|
||
open() { | ||
this.sidebarService.open(DAFFIO_DOCS_LIST_SIDEBAR_ID); | ||
} | ||
} |
Oops, something went wrong.