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(addon-doc): allow adding extra tabs with DI #9381

Merged
merged 3 commits into from
Oct 8, 2024
Merged
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
10 changes: 7 additions & 3 deletions projects/addon-doc/components/page/page.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgForOf, NgIf, NgTemplateOutlet} from '@angular/common';
import {KeyValuePipe, NgForOf, NgIf, NgTemplateOutlet} from '@angular/common';
import type {QueryList} from '@angular/core';
import {
ChangeDetectionStrategy,
Expand All @@ -7,27 +7,30 @@ import {
inject,
Input,
} from '@angular/core';
import {RouterLink, RouterLinkActive} from '@angular/router';
import {ActivatedRoute, RouterLink, RouterLinkActive} from '@angular/router';
import {TUI_DOC_DEFAULT_TABS, TUI_DOC_SUPPORT_LANGUAGE} from '@taiga-ui/addon-doc/tokens';
import {EMPTY_QUERY} from '@taiga-ui/cdk/constants';
import {TuiReplacePipe} from '@taiga-ui/cdk/pipes/replace';
import {TuiAutoColorPipe} from '@taiga-ui/core/pipes/auto-color';
import {TuiChip} from '@taiga-ui/kit/components/chip';
import {TuiTabs} from '@taiga-ui/kit/components/tabs';
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';

import {TuiDocSeeAlso} from '../internal/see-also';
import {TuiDocSourceCode} from '../internal/source-code/source-code.component';
import {TuiDocLanguageSwitcher} from '../language-switcher';
import {PAGE_PROVIDERS, PAGE_SEE_ALSO} from './page.providers';
import {PAGE_PROVIDERS, PAGE_SEE_ALSO, TUI_DOC_TABS} from './page.providers';
import {TuiDocPageTabConnector} from './page-tab.directive';

@Component({
standalone: true,
selector: 'tui-doc-page',
imports: [
KeyValuePipe,
NgForOf,
NgIf,
NgTemplateOutlet,
PolymorpheusOutlet,
RouterLink,
RouterLinkActive,
TuiAutoColorPipe,
Expand All @@ -44,6 +47,7 @@ import {TuiDocPageTabConnector} from './page-tab.directive';
providers: PAGE_PROVIDERS,
})
export class TuiDocPage {
protected readonly tabs = inject(TUI_DOC_TABS)(inject(ActivatedRoute).snapshot);
protected readonly supportLanguage = inject(TUI_DOC_SUPPORT_LANGUAGE);
waterplea marked this conversation as resolved.
Show resolved Hide resolved
protected readonly defaultTabs = inject(TUI_DOC_DEFAULT_TABS);
protected readonly from = / /g;
Expand Down
7 changes: 7 additions & 0 deletions projects/addon-doc/components/page/page.providers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type {Provider} from '@angular/core';
import {ElementRef} from '@angular/core';
import type {ActivatedRouteSnapshot} from '@angular/router';
import {TUI_DOC_SEE_ALSO} from '@taiga-ui/addon-doc/tokens';
import type {TuiHandler} from '@taiga-ui/cdk/types';
import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';

export const TUI_DOC_TABS = tuiCreateToken<
TuiHandler<ActivatedRouteSnapshot, Record<string, PolymorpheusContent>>
>(() => ({}));

/**
* Array if related page titles
Expand Down
15 changes: 15 additions & 0 deletions projects/addon-doc/components/page/page.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ <h1 class="t-title">
</a>
</ng-container>
</ng-container>
<ng-container *ngFor="let tab of tabs | keyvalue">
<a
*tuiItem
routerLinkActive
tuiTab
[routerLink]="tab.key"
>
{{ tab.key }}
</a>
</ng-container>
</tui-tabs-with-more>

<div
Expand Down Expand Up @@ -76,4 +86,9 @@ <h1 class="t-title">
[ngTemplateOutlet]="tab.template"
/>
</ng-container>
<ng-container *ngFor="let tab of tabs | keyvalue; index as index">
<ng-container *ngIf="index + tabConnectors.length === activeItemIndex">
<ng-container *polymorpheusOutlet="tab.value as text">{{ text }}</ng-container>
</ng-container>
</ng-container>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {ActivatedRoute} from '@angular/router';
import {PAGE_SEE_ALSO, TuiDocPage} from '@taiga-ui/addon-doc';
import {TUI_DOC_DEFAULT_TABS} from '@taiga-ui/addon-doc/tokens';
import {EMPTY_QUERY} from '@taiga-ui/cdk';
Expand All @@ -12,6 +13,10 @@ describe('TuiDocPageComponent', () => {
await TestBed.configureTestingModule({
imports: [TuiDocPage],
providers: [
{
provide: ActivatedRoute,
useValue: {},
},
{
provide: TUI_DOC_DEFAULT_TABS,
useValue: ['tab1', 'tab2'],
Expand Down
Loading