-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daffio): only render root api nav items (#3354)
- Loading branch information
Showing
11 changed files
with
199 additions
and
94 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
5 changes: 5 additions & 0 deletions
5
apps/daffio/src/app/docs/api/components/nav-list/nav-list.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,5 @@ | ||
<daff-nav-list> | ||
@for (doc of navList.children; track $index) { | ||
<a daff-list-item [active]="rla.isActive" routerLinkActive [routerLinkActiveOptions]="ROUTER_LINK_ACTIVE_CONFIG" #rla="routerLinkActive" [node]="doc" [routerLink]="doc.path">{{ doc.title }}</a> | ||
} | ||
</daff-nav-list> |
70 changes: 70 additions & 0 deletions
70
apps/daffio/src/app/docs/api/components/nav-list/nav-list.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,70 @@ | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { DaffTreeModule } from '@daffodil/design/tree'; | ||
import { DaffDocsApiNavList } from '@daffodil/docs-utils'; | ||
|
||
import { DaffioApiNavListComponent } from './nav-list.component'; | ||
|
||
describe('DaffioApiNavListComponent', () => { | ||
let component: DaffioApiNavListComponent; | ||
let fixture: ComponentFixture<DaffioApiNavListComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
DaffioApiNavListComponent, | ||
RouterTestingModule, | ||
NoopAnimationsModule, | ||
DaffTreeModule, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DaffioApiNavListComponent); | ||
component = fixture.componentInstance; | ||
const guideWithoutChildren = { | ||
id: 'id2', | ||
title: 'title2', | ||
children: [], | ||
}; | ||
const guideWithChildren = { | ||
id: 'id3', | ||
title: 'title3', | ||
children: [ | ||
{ | ||
id: 'id4', | ||
title: 'title4', | ||
children: [], | ||
}, | ||
], | ||
}; | ||
|
||
component.navList = <DaffDocsApiNavList>{ | ||
id: 'root', | ||
title: 'root', | ||
children: [ | ||
guideWithoutChildren, | ||
guideWithChildren, | ||
], | ||
}; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should render an anchor tag for each of the direct children', () => { | ||
const anchorTags = fixture.debugElement.queryAll(By.css('a')); | ||
expect(anchorTags.length).toEqual(2); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
apps/daffio/src/app/docs/api/components/nav-list/nav-list.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,33 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
} from '@angular/core'; | ||
import { | ||
RouterLink, | ||
RouterLinkActive, | ||
} from '@angular/router'; | ||
|
||
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list'; | ||
import { DaffDocsApiNavList } from '@daffodil/docs-utils'; | ||
|
||
const DEFAULT_ROUTER_LINK_ACTIVE_CONFIG: RouterLinkActive['routerLinkActiveOptions'] = { | ||
exact: true, | ||
}; | ||
|
||
@Component({ | ||
selector: 'daffio-api-nav-list', | ||
templateUrl: './nav-list.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
RouterLink, | ||
DAFF_LIST_COMPONENTS, | ||
RouterLinkActive, | ||
], | ||
}) | ||
export class DaffioApiNavListComponent { | ||
@Input() navList: DaffDocsApiNavList; | ||
|
||
readonly ROUTER_LINK_ACTIVE_CONFIG = DEFAULT_ROUTER_LINK_ACTIVE_CONFIG; | ||
} |
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,25 @@ | ||
import { AsyncPipe } from '@angular/common'; | ||
import { | ||
Component, | ||
ChangeDetectionStrategy, | ||
} from '@angular/core'; | ||
|
||
import { DaffDocsApiNavList } from '@daffodil/docs-utils'; | ||
|
||
import { useDaffioNavList } from '../../composables/nav-index'; | ||
import { DaffioApiNavListComponent } from '../components/nav-list/nav-list.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<daffio-api-nav-list [navList]="list$ | async"></daffio-api-nav-list> | ||
`, | ||
standalone: true, | ||
imports: [ | ||
DaffioApiNavListComponent, | ||
AsyncPipe, | ||
], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class DaffioApiNavListSidebarContainer { | ||
list$ = useDaffioNavList<DaffDocsApiNavList>().list; | ||
} |
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,11 @@ | ||
import { DaffioApiNavListSidebarContainer } from './component'; | ||
import { DaffioSidebarFooterComponent } from '../../../core/sidebar/components/sidebar-footer/sidebar-footer.component'; | ||
import { DaffioSidebarHeaderComponent } from '../../../core/sidebar/components/sidebar-header/sidebar-header.component'; | ||
import { DAFFIO_DOCS_LIST_SIDEBAR_ID } from '../../containers/docs-list/sidebar.provider'; | ||
|
||
export const DAFFIO_API_NAV_LIST_SIDEBAR_REGISTRATION = { | ||
id: DAFFIO_DOCS_LIST_SIDEBAR_ID, | ||
header: DaffioSidebarHeaderComponent, | ||
body: DaffioApiNavListSidebarContainer, | ||
footer: DaffioSidebarFooterComponent, | ||
}; |
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,23 @@ | ||
import { inject } from '@angular/core'; | ||
import { | ||
switchMap, | ||
filter, | ||
map, | ||
Observable, | ||
} from 'rxjs'; | ||
|
||
import { DaffDocsNavList } from '@daffodil/docs-utils'; | ||
import { DaffRouterActivatedRoute } from '@daffodil/router'; | ||
|
||
export const useDaffioNavList = <T extends DaffDocsNavList = DaffDocsNavList>() => { | ||
const route = inject(DaffRouterActivatedRoute); | ||
const list: Observable<T> = route.route$.pipe( | ||
switchMap((r) => r.data), | ||
filter(Boolean), | ||
map((data) => data.index), | ||
); | ||
|
||
return { | ||
list, | ||
}; | ||
}; |
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