Skip to content

Commit

Permalink
refactor: cleanup addon-doc (#7855)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Jun 20, 2024
1 parent 885fdc6 commit 160d80c
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 65 deletions.
8 changes: 4 additions & 4 deletions projects/addon-doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ npm i @taiga-ui/addon-doc
},
],
})
export class AppComponent {}
export class App {}
```

3. Configure documentation providers:
Expand Down Expand Up @@ -103,7 +103,7 @@ npm i @taiga-ui/addon-doc
standalone: true,
imports: [TuiAddonDoc, SuperComponent],
})
export class AppComponent {}
export class App {}
```

_Component:_
Expand All @@ -113,10 +113,10 @@ npm i @taiga-ui/addon-doc

@Component({
standalone: true,
selector: 'super-component',
selector: 'super',
templateUrl: './super.component.html',
})
export class SuperComponent {
export class Super {
// Keys would be used as tabs for code example
readonly example = {
// import a file as a string
Expand Down
33 changes: 0 additions & 33 deletions projects/addon-doc/addon-doc.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion projects/addon-doc/components/internal/header/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {TuiDocNavigation} from '../../navigation/navigation.component';
styleUrls: ['./index.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiDocHeaderComponent {
export class TuiDocHeader {
private readonly stream$ = new Subject<boolean>();
private readonly router = inject(Router);
protected readonly icons = inject(TUI_DOC_ICONS);
Expand Down
2 changes: 1 addition & 1 deletion projects/addon-doc/components/internal/see-also/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {TuiLink} from '@taiga-ui/core';
styleUrls: ['./index.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiDocSeeAlsoComponent {
export class TuiDocSeeAlso {
private readonly pages = inject(TUI_DOC_MAP_PAGES);
protected readonly text = inject(TUI_DOC_SEE_ALSO_TEXT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {PolymorpheusOutlet, PolymorpheusTemplate} from '@taiga-ui/polymorpheus';
templateUrl: './source-code.template.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiDocSourceCodeComponent {
export class TuiDocSourceCode {
protected readonly icons = inject(TUI_DOC_ICONS);
protected readonly sourceCode = inject(TUI_DOC_SOURCE_CODE);
protected readonly text = inject(TUI_DOC_SOURCE_CODE_TEXT);
Expand Down
6 changes: 3 additions & 3 deletions projects/addon-doc/components/language-switcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {TuiDataList, TuiFlagPipe} from '@taiga-ui/core';
import type {TuiCountryIsoCode, TuiLanguageName} from '@taiga-ui/i18n';
import {TuiLanguageSwitcher} from '@taiga-ui/i18n';
import {TuiLanguageSwitcherService} from '@taiga-ui/i18n';
import {TuiSelectModule} from '@taiga-ui/legacy';

@Component({
Expand All @@ -21,8 +21,8 @@ import {TuiSelectModule} from '@taiga-ui/legacy';
styleUrls: ['./index.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiLanguageSwitcherComponent {
protected readonly switcher = inject(TuiLanguageSwitcher);
export class TuiLanguageSwitcher {
protected readonly switcher = inject(TuiLanguageSwitcherService);
protected readonly language = new FormControl(capitalize(this.switcher.language));

public readonly flags = new Map<TuiLanguageName, TuiCountryIsoCode>([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {ReactiveFormsModule} from '@angular/forms';
import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc';
import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc';
import {TuiDataList, TuiFlagPipe} from '@taiga-ui/core';
import {TuiLanguageSwitcher} from '@taiga-ui/i18n';
import {TuiLanguageSwitcherService} from '@taiga-ui/i18n';
import {TuiSelectModule} from '@taiga-ui/legacy';

describe('TuiLanguageSwitcherComponent', () => {
let component: TuiLanguageSwitcherComponent;
let fixture: ComponentFixture<TuiLanguageSwitcherComponent>;
let component: TuiLanguageSwitcher;
let fixture: ComponentFixture<TuiLanguageSwitcher>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
TuiSelectModule,
TuiDataList,
TuiLanguageSwitcherComponent,
TuiLanguageSwitcher,
],
providers: [TuiLanguageSwitcher],
providers: [TuiLanguageSwitcherService],
}).compileComponents();

fixture = TestBed.createComponent(TuiLanguageSwitcherComponent);
fixture = TestBed.createComponent(TuiLanguageSwitcher);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
4 changes: 2 additions & 2 deletions projects/addon-doc/components/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TUI_DOC_ICONS} from '@taiga-ui/addon-doc/tokens';
import {TuiSwipeService} from '@taiga-ui/cdk';
import {TuiButton, TuiRoot} from '@taiga-ui/core';

import {TuiDocHeaderComponent} from '../internal/header';
import {TuiDocHeader} from '../internal/header';
import {TuiDocNavigation} from '../navigation/navigation.component';

@Component({
Expand All @@ -22,7 +22,7 @@ import {TuiDocNavigation} from '../navigation/navigation.component';
AsyncPipe,
RouterOutlet,
TuiButton,
TuiDocHeaderComponent,
TuiDocHeader,
TuiDocNavigation,
],
templateUrl: './main.template.html',
Expand Down
8 changes: 4 additions & 4 deletions projects/addon-doc/components/page/page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {EMPTY_QUERY, TuiItem, TuiReplacePipe} from '@taiga-ui/cdk';
import {TuiAutoColorPipe} from '@taiga-ui/core';
import {TuiChip, TuiTabDirective, TuiTabsWithMoreComponent} from '@taiga-ui/kit';

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

Expand All @@ -32,8 +32,8 @@ import {TuiDocPageTabConnector} from './page-tab.directive';
RouterLink,
RouterLinkActive,
TuiReplacePipe,
TuiDocSourceCodeComponent,
TuiDocSeeAlsoComponent,
TuiDocSourceCode,
TuiDocSeeAlso,
NgTemplateOutlet,
],
templateUrl: './page.template.html',
Expand Down
35 changes: 34 additions & 1 deletion projects/addon-doc/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
export * from './addon-doc.module';
import {
TuiDocCode,
TuiDocCopy,
TuiDocDemo,
TuiDocDocumentation,
TuiDocDocumentationPropertyConnector,
TuiDocExample,
TuiDocExampleGetTabsPipe,
TuiDocMain,
TuiDocNavigation,
TuiDocPage,
TuiDocPageTabConnector,
TuiDocTab,
TuiDocTypeReferencePipe,
} from '@taiga-ui/addon-doc/components';
import {TuiTextCode} from '@taiga-ui/addon-doc/directives';

export const TuiAddonDoc = [
TuiDocCopy,
TuiDocTab,
TuiDocDemo,
TuiDocCode,
TuiDocExample,
TuiDocExampleGetTabsPipe,
TuiDocTypeReferencePipe,
TuiDocDocumentation,
TuiDocDocumentationPropertyConnector,
TuiDocPage,
TuiDocPageTabConnector,
TuiDocNavigation,
TuiDocMain,
TuiTextCode,
] as const;

export * from '@taiga-ui/addon-doc/components';
export * from '@taiga-ui/addon-doc/directives';
export * from '@taiga-ui/addon-doc/pipes';
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/modules/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {DemoRoute} from '@demo/routes';
import {TuiDemo} from '@demo/utils';
import {LOCAL_STORAGE} from '@ng-web-apis/common';
import {ResizeObserverService} from '@ng-web-apis/resize-observer';
import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc';
import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc';
import {TuiSheetModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy';
import {distinctUntilChanged, filter, map} from 'rxjs';

Expand All @@ -22,7 +22,7 @@ import {TUI_VERSION_MANAGER_PROVIDERS} from './version-manager/version-manager.p
selector: 'app',
imports: [
TuiDemo,
TuiLanguageSwitcherComponent,
TuiLanguageSwitcher,
VersionManager,
CustomHost,
TuiTextfieldControllerModule,
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/modules/customization/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {TuiDemo} from '@demo/utils';
import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc';
import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc';
import {TuiLink} from '@taiga-ui/core';
import {from, map} from 'rxjs';

@Component({
standalone: true,
imports: [TuiDemo, TuiLink, TuiLanguageSwitcherComponent],
imports: [TuiDemo, TuiLink, TuiLanguageSwitcher],
templateUrl: './index.html',
changeDetection,
})
Expand Down
4 changes: 2 additions & 2 deletions projects/i18n/switch/language-switcher.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Provider} from '@angular/core';
import type {TuiLanguageLoader} from '@taiga-ui/i18n/interfaces';
import {TUI_LANGUAGE, TUI_LANGUAGE_LOADER} from '@taiga-ui/i18n/tokens';

import {TuiLanguageSwitcher} from './language-switcher.service';
import {TuiLanguageSwitcherService} from './language-switcher.service';

export function tuiLanguageSwitcher(loader: TuiLanguageLoader): Provider[] {
return [
Expand All @@ -12,7 +12,7 @@ export function tuiLanguageSwitcher(loader: TuiLanguageLoader): Provider[] {
},
{
provide: TUI_LANGUAGE,
useExisting: TuiLanguageSwitcher,
useExisting: TuiLanguageSwitcherService,
},
];
}
6 changes: 4 additions & 2 deletions projects/i18n/switch/language-switcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {BehaviorSubject, of} from 'rxjs';

import {tuiAsyncLoadLanguage} from './utils';

@Injectable({providedIn: 'root'})
export class TuiLanguageSwitcher extends BehaviorSubject<Observable<TuiLanguage>> {
@Injectable({
providedIn: 'root',
})
export class TuiLanguageSwitcherService extends BehaviorSubject<Observable<TuiLanguage>> {
private readonly fallback = inject(TUI_DEFAULT_LANGUAGE);
private readonly key = inject(TUI_LANGUAGE_STORAGE_KEY);
private readonly storage = inject(LOCAL_STORAGE);
Expand Down

0 comments on commit 160d80c

Please sign in to comment.