diff --git a/projects/addon-doc/src/internal/header/header.template.html b/projects/addon-doc/src/internal/header/header.template.html index 4c7231444e37..aa99fe2d70a8 100644 --- a/projects/addon-doc/src/internal/header/header.template.html +++ b/projects/addon-doc/src/internal/header/header.template.html @@ -4,14 +4,13 @@ icon="tuiIconMenuLarge" appearance="icon" [title]="menu" - [tuiSidebar]="sidebar" - [tuiSidebarOpen]="open$ | async" (click)="onClick()" (tuiActiveZoneChange)="onActiveZone($event)" > - - - + diff --git a/projects/addon-mobile/directives/sidebar/sidebar.directive.ts b/projects/addon-mobile/directives/sidebar/sidebar.directive.ts index d3001a9040e2..9d3fab59dbdd 100644 --- a/projects/addon-mobile/directives/sidebar/sidebar.directive.ts +++ b/projects/addon-mobile/directives/sidebar/sidebar.directive.ts @@ -6,24 +6,21 @@ import { Injector, Input, OnDestroy, + TemplateRef, } from '@angular/core'; import {TuiPortalService} from '@taiga-ui/cdk'; import {TuiHorizontalDirection} from '@taiga-ui/core'; -import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; import {TuiSidebarComponent} from './sidebar.component'; @Directive({ selector: '[tuiSidebar]', }) export class TuiSidebarDirective implements OnDestroy { - @Input('tuiSidebar') - content: PolymorpheusContent = ''; - @Input('tuiSidebarDirection') direction: TuiHorizontalDirection = 'left'; @Input() - set tuiSidebarOpen(open: boolean) { + set tuiSidebar(open: boolean) { if (open) { this.show(); } else { @@ -34,6 +31,7 @@ export class TuiSidebarDirective implements OnDestroy { private sidebarRef: ComponentRef | null = null; constructor( + @Inject(TemplateRef) readonly content: TemplateRef<{}>, @Inject(Injector) private readonly injector: Injector, @Inject(ComponentFactoryResolver) private readonly componentFactoryResolver: ComponentFactoryResolver, diff --git a/projects/demo/src/modules/app/app.routes.ts b/projects/demo/src/modules/app/app.routes.ts index d7d2dd52bce4..b599ae4727e2 100644 --- a/projects/demo/src/modules/app/app.routes.ts +++ b/projects/demo/src/modules/app/app.routes.ts @@ -1129,6 +1129,16 @@ export const ROUTES = [ title: 'Ripple', }, }, + { + path: 'tui-sidebar', + loadChildren: () => + import(`../directives/sidebar/sidebar.module`).then( + m => m.ExampleTuiSidebarModule, + ), + data: { + title: 'Sidebar', + }, + }, { path: 'tui-touchable', loadChildren: () => diff --git a/projects/demo/src/modules/app/pages.ts b/projects/demo/src/modules/app/pages.ts index 41be09cf89cb..cf5ca976fea1 100644 --- a/projects/demo/src/modules/app/pages.ts +++ b/projects/demo/src/modules/app/pages.ts @@ -888,6 +888,13 @@ export const pages: TuiDocPages = [ keywords: 'touch, mobile, смартфон, pwa, native, hybrid, android', route: '/tui-ripple', }, + { + section: $localize`Tools`, + title: 'Sidebar', + keywords: + 'sidebar, hamburger, drawer menu, mobile, смартфон, pwa, native, hybrid, сайдбар, меню', + route: '/tui-sidebar', + }, { section: $localize`Tools`, title: 'DropdownController', diff --git a/projects/demo/src/modules/directives/sidebar/examples/1/index.html b/projects/demo/src/modules/directives/sidebar/examples/1/index.html new file mode 100644 index 000000000000..7544d826ec3b --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/1/index.html @@ -0,0 +1,41 @@ + diff --git a/projects/demo/src/modules/directives/sidebar/examples/1/index.less b/projects/demo/src/modules/directives/sidebar/examples/1/index.less new file mode 100644 index 000000000000..1727f7637c3d --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/1/index.less @@ -0,0 +1,4 @@ +.link { + display: block; + margin: 12px 0; +} diff --git a/projects/demo/src/modules/directives/sidebar/examples/1/index.ts b/projects/demo/src/modules/directives/sidebar/examples/1/index.ts new file mode 100644 index 000000000000..5dee4652d71c --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/1/index.ts @@ -0,0 +1,34 @@ +import {Component} from '@angular/core'; +import {changeDetection} from '../../../../../change-detection-strategy'; +import {encapsulation} from '../../../../../view-encapsulation'; + +@Component({ + selector: 'tui-sidebar-example-1', + templateUrl: './index.html', + styleUrls: ['./index.less'], + changeDetection, + encapsulation, +}) +export class TuiSidebarExample1 { + open = false; + + readonly webApis = [ + 'Common', + 'Audio', + 'Canvas', + 'Geolocation', + 'MIDI', + 'Workers', + ]; + + readonly tinkoff = [ + 'Taiga-UI', + 'ng-event-plugins', + 'ng-polymorpheus', + 'ng-dompurify', + ]; + + toggle(open: boolean) { + this.open = open; + } +} diff --git a/projects/demo/src/modules/directives/sidebar/examples/import/component.txt b/projects/demo/src/modules/directives/sidebar/examples/import/component.txt new file mode 100644 index 000000000000..e788aeefdb04 --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/import/component.txt @@ -0,0 +1,5 @@ +open = false; + +toggle(open: boolean) { + this.open = open; +} diff --git a/projects/demo/src/modules/directives/sidebar/examples/import/import-module.txt b/projects/demo/src/modules/directives/sidebar/examples/import/import-module.txt new file mode 100644 index 000000000000..788459afb406 --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/import/import-module.txt @@ -0,0 +1,12 @@ +import {TuiSidebarModule} from '@taiga-ui/addon-mobile'; +import {TuiActiveZoneModule} from '@taiga-ui/cdk'; + +... + +@NgModule({ + imports: [ + ... + TuiSidebarModule, + TuiActiveZoneModule, + ], +... diff --git a/projects/demo/src/modules/directives/sidebar/examples/import/insert-template.txt b/projects/demo/src/modules/directives/sidebar/examples/import/insert-template.txt new file mode 100644 index 000000000000..ee3e0507b401 --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/examples/import/insert-template.txt @@ -0,0 +1,11 @@ + diff --git a/projects/demo/src/modules/directives/sidebar/sidebar.component.ts b/projects/demo/src/modules/directives/sidebar/sidebar.component.ts new file mode 100644 index 000000000000..978f126bfacc --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/sidebar.component.ts @@ -0,0 +1,27 @@ +import {default as example1Html} from '!!raw-loader!./examples/1/index.html'; +import {default as example1Less} from '!!raw-loader!./examples/1/index.less'; +import {default as example1Ts} from '!!raw-loader!./examples/1/index.ts'; +import {default as exampleComponent} from '!!raw-loader!./examples/import/component.txt'; +import {default as exampleImportModule} from '!!raw-loader!./examples/import/import-module.txt'; +import {default as exampleInsertTemplate} from '!!raw-loader!./examples/import/insert-template.txt'; + +import {Component} from '@angular/core'; +import {changeDetection} from '../../../change-detection-strategy'; +import {FrontEndExample} from '../../interfaces/front-end-example'; + +@Component({ + selector: 'example-tui-sidebar', + templateUrl: './sidebar.template.html', + changeDetection, +}) +export class ExampleTuiSidebarComponent { + readonly example1: FrontEndExample = { + TypeScript: example1Ts, + HTML: example1Html, + LESS: example1Less, + }; + + readonly exampleImportModule = exampleImportModule; + readonly exampleInsertTemplate = exampleInsertTemplate; + readonly exampleComponent = exampleComponent; +} diff --git a/projects/demo/src/modules/directives/sidebar/sidebar.module.ts b/projects/demo/src/modules/directives/sidebar/sidebar.module.ts new file mode 100644 index 000000000000..85bf882ccd7d --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/sidebar.module.ts @@ -0,0 +1,26 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {generateRoutes, TUI_DOC_PAGE_MODULES} from '@taiga-ui/addon-doc'; +import {TuiSidebarModule} from '@taiga-ui/addon-mobile'; +import {TuiActiveZoneModule} from '@taiga-ui/cdk'; +import {TuiButtonModule, TuiLinkModule} from '@taiga-ui/core'; +import {TuiAccordionModule} from '@taiga-ui/kit'; +import {TuiSidebarExample1} from './examples/1'; +import {ExampleTuiSidebarComponent} from './sidebar.component'; + +@NgModule({ + imports: [ + CommonModule, + TuiSidebarModule, + TuiActiveZoneModule, + TuiButtonModule, + TuiAccordionModule, + TuiLinkModule, + ...TUI_DOC_PAGE_MODULES, + RouterModule.forChild(generateRoutes(ExampleTuiSidebarComponent)), + ], + declarations: [ExampleTuiSidebarComponent, TuiSidebarExample1], + exports: [ExampleTuiSidebarComponent], +}) +export class ExampleTuiSidebarModule {} diff --git a/projects/demo/src/modules/directives/sidebar/sidebar.template.html b/projects/demo/src/modules/directives/sidebar/sidebar.template.html new file mode 100644 index 000000000000..89cb99f27139 --- /dev/null +++ b/projects/demo/src/modules/directives/sidebar/sidebar.template.html @@ -0,0 +1,52 @@ + + +

+ Directive allows to show arbitrary content in a sidebar above all content. + A darkening overlay is shown under the sidebar. +

+ + + + +
+ + +
    +
  1. +

    + Import TuiSidevarModule into your component + module. Also add TuiActiveZoneModule if you want + to close sidebar when user clicked outside: +

    + + +
  2. + +
  3. +

    Add to the template:

    + + +
  4. + +
  5. +

    Control sidebar in component

    + + +
  6. +
+
+