1-
2- import { Component } from '@angular/core' ;
3- import { ButtonComponent , HideOnEmptyTemplateDirective , SegmentComponent , TabComponent , TabGroupComponent , TemplateComponent , TemplateOutletComponent } from '@mantic-ui/angular' ;
1+ import { Component , signal } from '@angular/core' ;
2+ import { ButtonComponent , FlexComponent , HideOnEmptyTemplateDirective , SegmentComponent , TabComponent , TabGroupComponent , TemplateComponent , TemplateOutletComponent } from '@mantic-ui/angular' ;
43import { ExampleCodeComponent , ExampleComponent } from '@mantic-ui/angular-doc' ;
54import { HeaderComponent } from '../../components/header/header.component' ;
65
76@Component ( {
87 selector : 'app-template' ,
9- imports : [ ExampleCodeComponent , ExampleComponent , HeaderComponent , SegmentComponent , TabComponent , TabGroupComponent , TemplateComponent , TemplateOutletComponent , ButtonComponent , HideOnEmptyTemplateDirective ] ,
8+ imports : [ ExampleCodeComponent , ExampleComponent , HeaderComponent , SegmentComponent , TabComponent , TabGroupComponent , TemplateComponent , TemplateOutletComponent , ButtonComponent , HideOnEmptyTemplateDirective , FlexComponent ] ,
109 templateUrl : './template.component.html' ,
1110 styleUrl : './template.component.scss'
1211} )
1312export class TemplateExampleComponent {
14- protected showA = false ;
15- protected showB = false ;
16- protected showC = false ;
17- protected visible = false ;
13+ protected readonly showB = signal ( false ) ;
14+ protected readonly showC = signal ( false ) ;
1815
1916 protected readonly code1 = `<m-template name="my.template.id">
2017 This content is projected
@@ -24,24 +21,43 @@ export class TemplateExampleComponent {
2421 to here
2522</m-segment>` ;
2623
27- protected readonly code2 = `<m-button *ngIf="!showA" primary (click)="showA = true">Show A</m-button>
28- <m-button *ngIf="showA" primary (click)="showA = false">Hide A</m-button>
29- <m-template *ngIf="showA" name="stacked-templates">A is the best.</m-template>
30- <m-button *ngIf="!showB" secondary (click)="showB = true">Show B</m-button>
31- <m-button *ngIf="showB" secondary (click)="showB = false">Hide B</m-button>
32- <m-template *ngIf="showB" name="stacked-templates">B is even better!</m-template>
33- <m-button *ngIf="!showC" positive (click)="showC = true">Show C</m-button>
34- <m-button *ngIf="showC" positive (click)="showC = false">Hide C</m-button>
35- <m-template *ngIf="showC" name="stacked-templates">C is the is the bestestestest!!1!!</m-template>
24+ protected readonly code2 = `<!-- A uses template methods and is per default hidden. -->
25+ <!-- It gets hidden when other templates are shown. That allows bring A in front via button. -->
26+ <m-button primary (click)="templateA.toggle()">
27+ {{ templateA.visible() ? 'Hide' : 'Show' }} A
28+ </m-button>
29+ <m-template name="stacked-templates" hidden autoHide #templateA>A is the best.</m-template>
30+
31+ <!-- B uses a local signal bound to template's visible property -->
32+ <!-- It gets also hidden when other templates are shown. That allows bring B in front via button. -->
33+ @if (showB()) {
34+ <m-button secondary (click)="showB.set(false)">Hide B</m-button>
35+ } @else {
36+ <m-button secondary (click)="showB.set(true)">Show B</m-button>
37+ }
38+ <m-template name="stacked-templates" [(visible)]="showB" autoHide>B is even better!</m-template>
39+
40+ <!-- C uses a local signal and shows/hides the template via @if. -->
41+ <!-- But button state does not change when other templates are in front. -->
42+ <!-- So all other templates has to hide, to make C visible again. -->
43+ @if (showC()) {
44+ <m-button positive (click)="showC.set(false)">Hide C</m-button>
45+ <m-template name="stacked-templates">C is the bestestestest!!1!!</m-template>
46+ } @else {
47+ <m-button positive (click)="showC.set(true)">Show C</m-button>
48+ }
49+
50+ <!-- Fallback template is always visible. So it recovers its visible state when the outlet is empty -->
3651<m-template name="stacked-templates">No result available. Press a button</m-template>
52+
53+ <!-- Projection target -->
3754<m-segment>
3855 <div>Result:</div>
3956 <m-template-outlet name="stacked-templates" />
4057</m-segment>` ;
4158
42- protected readonly code3 = `<m-button *ngIf="!visible" primary (click)="visible = true">Show</m-button>
43- <m-button *ngIf="visible" primary (click)="visible = false">Hide</m-button>
44- <m-template *ngIf="visible" name="onlyFilledTemplates">
59+ protected readonly code3 = `<m-button primary (click)="onlyFilledTemplates.toggle()">Toggle</m-button>
60+ <m-template name="onlyFilledTemplates" #onlyFilledTemplates>
4561 This content is projected and also hides it wrapping m-segment
4662</m-template>
4763<m-segment *mHideOnEmptyTemplate="'onlyFilledTemplates'">
0 commit comments