1- import { Component , Injector , PLATFORM_ID , inject } from '@angular/core' ;
1+ import {
2+ Component ,
3+ Injector ,
4+ PLATFORM_ID ,
5+ inject ,
6+ signal ,
7+ effect ,
8+ } from '@angular/core' ;
29import { RouterOutlet } from '@angular/router' ;
310import { isPlatformBrowser } from '@angular/common' ;
411import { MenuComponent } from './components/menu.component' ;
@@ -8,79 +15,121 @@ import { CodeExampleComponent } from './components/docs/code-example.component';
815import { CodeTabsComponent } from './components/docs/code-tabs.component' ;
916import { StackblitzComponent } from './components/docs/stackblitz.component' ;
1017import { FooterComponent } from './components/footer.component' ;
18+ import {
19+ TOP_BANNER_DISMISSED_STORAGE_KEY ,
20+ TopBannerComponent ,
21+ } from './components/top-banner.component' ;
1122
1223@Component ( {
1324 selector : 'ngrx-root' ,
1425 imports : [
1526 RouterOutlet ,
1627 MenuComponent ,
28+ TopBannerComponent ,
1729 MarkdownSymbolLinkComponent ,
1830 AlertComponent ,
1931 CodeExampleComponent ,
2032 StackblitzComponent ,
2133 FooterComponent ,
2234 ] ,
2335 template : `
24- <ngrx-menu></ngrx-menu>
25- <router-outlet></router-outlet>
26- <ngrx-footer></ngrx-footer>
36+ @if (isTopBannerVisible()) {
37+ <ngrx-top-banner (dismiss)="isTopBannerVisible.set(false)" />
38+ }
39+ <ngrx-menu />
40+ <div class="content">
41+ <router-outlet />
42+ <ngrx-footer />
43+ </div>
2744 ` ,
2845 styles : [
2946 `
3047 :host {
3148 display: block;
32- position: relative;
33- width: calc(100% - 270px);
34- left: 270px;
49+ }
50+
51+ :host.top-banner-visible {
52+ --top-banner-height: 44px;
53+
3554 @media only screen and (max-width: 1280px) {
36- width: 100%;
37- left: 0;
55+ --top-banner-height: 70px;
3856 }
3957 }
4058
4159 ngrx-menu {
4260 position: fixed;
43- top: 0;
4461 left: 0;
62+ top: 0;
63+ }
64+
65+ .content {
66+ position: relative;
67+ width: calc(100% - 270px);
68+ left: 270px;
69+
70+ @media only screen and (max-width: 1280px) {
71+ width: 100%;
72+ left: 0;
73+ padding-top: var(--top-banner-height, 0px);
74+ }
4575 }
4676 ` ,
4777 ] ,
78+ host : {
79+ '[class.top-banner-visible]' : 'isTopBannerVisible()' ,
80+ } ,
4881} )
4982export class AppComponent {
50- injector = inject ( Injector ) ;
51- platformId = inject ( PLATFORM_ID ) ;
83+ readonly #injector = inject ( Injector ) ;
84+ readonly #platformId = inject ( PLATFORM_ID ) ;
85+
86+ readonly isTopBannerVisible = signal ( false ) ;
5287
5388 constructor ( ) {
54- if ( isPlatformBrowser ( this . platformId ) ) {
89+ if ( isPlatformBrowser ( this . #platformId) ) {
90+ this . initTopBanner ( ) ;
5591 this . installCustomElements ( ) ;
5692 }
5793 }
5894
59- async installCustomElements ( ) {
95+ initTopBanner ( ) : void {
96+ if ( localStorage . getItem ( TOP_BANNER_DISMISSED_STORAGE_KEY ) !== 'true' ) {
97+ this . isTopBannerVisible . set ( true ) ;
98+ }
99+
100+ effect ( ( ) => {
101+ localStorage . setItem (
102+ TOP_BANNER_DISMISSED_STORAGE_KEY ,
103+ `${ ! this . isTopBannerVisible ( ) } `
104+ ) ;
105+ } ) ;
106+ }
107+
108+ async installCustomElements ( ) : Promise < void > {
60109 const { createCustomElement } = await import ( '@angular/elements' ) ;
61110
62111 const symbolLinkElement = createCustomElement ( MarkdownSymbolLinkComponent , {
63- injector : this . injector ,
112+ injector : this . # injector,
64113 } ) ;
65114 customElements . define ( 'ngrx-docs-symbol-link' , symbolLinkElement ) ;
66115
67116 const alertElement = createCustomElement ( AlertComponent , {
68- injector : this . injector ,
117+ injector : this . # injector,
69118 } ) ;
70119 customElements . define ( 'ngrx-docs-alert' , alertElement ) ;
71120
72121 const codeExampleElement = createCustomElement ( CodeExampleComponent , {
73- injector : this . injector ,
122+ injector : this . # injector,
74123 } ) ;
75124 customElements . define ( 'ngrx-code-example' , codeExampleElement ) ;
76125
77126 const codeTabsElement = createCustomElement ( CodeTabsComponent , {
78- injector : this . injector ,
127+ injector : this . # injector,
79128 } ) ;
80129 customElements . define ( 'ngrx-code-tabs' , codeTabsElement ) ;
81130
82131 const stackblitzElement = createCustomElement ( StackblitzComponent , {
83- injector : this . injector ,
132+ injector : this . # injector,
84133 } ) ;
85134 customElements . define ( 'ngrx-docs-stackblitz' , stackblitzElement ) ;
86135 }
0 commit comments