sample.layout.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { Component, OnDestroy } from '@angular/core';
  2. import { delay, withLatestFrom, takeWhile } from 'rxjs/operators';
  3. import {
  4. NbMediaBreakpoint,
  5. NbMediaBreakpointsService,
  6. NbMenuItem,
  7. NbMenuService,
  8. NbSidebarService,
  9. NbThemeService,
  10. } from '@nebular/theme';
  11. import { StateService } from '../../../@core/utils';
  12. // TODO: move layouts into the framework
  13. @Component({
  14. selector: 'ngx-sample-layout',
  15. styleUrls: ['./sample.layout.scss'],
  16. template: `
  17. <nb-layout [center]="layout.id === 'center-column'" windowMode>
  18. <nb-layout-header fixed>
  19. <ngx-header [position]="sidebar.id === 'start' ? 'normal': 'inverse'"></ngx-header>
  20. </nb-layout-header>
  21. <nb-sidebar class="menu-sidebar"
  22. tag="menu-sidebar"
  23. responsive
  24. [end]="sidebar.id === 'end'">
  25. <nb-sidebar-header *ngIf="currentTheme !== 'corporate'">
  26. </nb-sidebar-header>
  27. <ng-content select="nb-menu"></ng-content>
  28. </nb-sidebar>
  29. <nb-layout-column class="main-content">
  30. <ng-content select="router-outlet"></ng-content>
  31. </nb-layout-column>
  32. <nb-layout-column start class="small" *ngIf="layout.id === 'two-column' || layout.id === 'three-column'">
  33. <nb-menu [items]="subMenu"></nb-menu>
  34. </nb-layout-column>
  35. <nb-layout-column class="small" *ngIf="layout.id === 'three-column'">
  36. <nb-menu [items]="subMenu"></nb-menu>
  37. </nb-layout-column>
  38. <nb-layout-footer fixed>
  39. <ngx-footer></ngx-footer>
  40. </nb-layout-footer>
  41. <nb-sidebar class="settings-sidebar"
  42. tag="settings-sidebar"
  43. state="collapsed"
  44. fixed
  45. [end]="sidebar.id !== 'end'">
  46. <ngx-theme-settings></ngx-theme-settings>
  47. </nb-sidebar>
  48. </nb-layout>
  49. <ngx-toggle-settings-button></ngx-toggle-settings-button>
  50. `,
  51. })
  52. export class SampleLayoutComponent implements OnDestroy {
  53. subMenu: NbMenuItem[] = [
  54. {
  55. title: 'PAGE LEVEL MENU',
  56. group: true,
  57. },
  58. {
  59. title: 'Buttons',
  60. icon: 'ion ion-android-radio-button-off',
  61. link: '/pages/ui-features/buttons',
  62. },
  63. {
  64. title: 'Grid',
  65. icon: 'ion ion-android-radio-button-off',
  66. link: '/pages/ui-features/grid',
  67. },
  68. {
  69. title: 'Icons',
  70. icon: 'ion ion-android-radio-button-off',
  71. link: '/pages/ui-features/icons',
  72. },
  73. {
  74. title: 'Modals',
  75. icon: 'ion ion-android-radio-button-off',
  76. link: '/pages/ui-features/modals',
  77. },
  78. {
  79. title: 'Typography',
  80. icon: 'ion ion-android-radio-button-off',
  81. link: '/pages/ui-features/typography',
  82. },
  83. {
  84. title: 'Animated Searches',
  85. icon: 'ion ion-android-radio-button-off',
  86. link: '/pages/ui-features/search-fields',
  87. },
  88. {
  89. title: 'Tabs',
  90. icon: 'ion ion-android-radio-button-off',
  91. link: '/pages/ui-features/tabs',
  92. },
  93. ];
  94. layout: any = {};
  95. sidebar: any = {};
  96. private alive = true;
  97. currentTheme: string;
  98. constructor(protected stateService: StateService,
  99. protected menuService: NbMenuService,
  100. protected themeService: NbThemeService,
  101. protected bpService: NbMediaBreakpointsService,
  102. protected sidebarService: NbSidebarService) {
  103. this.stateService.onLayoutState()
  104. .pipe(takeWhile(() => this.alive))
  105. .subscribe((layout: string) => this.layout = layout);
  106. this.stateService.onSidebarState()
  107. .pipe(takeWhile(() => this.alive))
  108. .subscribe((sidebar: string) => {
  109. this.sidebar = sidebar;
  110. });
  111. const isBp = this.bpService.getByName('is');
  112. this.menuService.onItemSelect()
  113. .pipe(
  114. takeWhile(() => this.alive),
  115. withLatestFrom(this.themeService.onMediaQueryChange()),
  116. delay(20),
  117. )
  118. .subscribe(([item, [bpFrom, bpTo]]: [any, [NbMediaBreakpoint, NbMediaBreakpoint]]) => {
  119. if (bpTo.width <= isBp.width) {
  120. this.sidebarService.collapse('menu-sidebar');
  121. }
  122. });
  123. this.themeService.getJsTheme()
  124. .pipe(takeWhile(() => this.alive))
  125. .subscribe(theme => {
  126. this.currentTheme = theme.name;
  127. });
  128. }
  129. ngOnDestroy() {
  130. this.alive = false;
  131. }
  132. }