File
Implements
Metadata
| selector |
stbui-dialog |
| styleUrls |
./dialog.component.scss |
| templateUrl |
./dialog.component.html |
Methods
|
ngAfterContentInit
|
ngAfterContentInit()
|
|
|
|
|
import {
Component,
Directive,
ContentChildren,
QueryList,
AfterContentInit
} from '@angular/core';
@Directive({ selector: 'stbui-dialog-title' })
export class DialogTitleDirective {}
@Directive({ selector: 'stbui-dialog-content' })
export class DialogContentDirective {}
@Directive({ selector: 'stbui-dialog-actions' })
export class DialogActionsDirective {}
@Component({
selector: 'stbui-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.scss']
})
export class DialogComponent implements AfterContentInit {
@ContentChildren(DialogTitleDirective)
dialogTitle: QueryList<DialogTitleDirective>;
@ContentChildren(DialogContentDirective)
dialogContent: QueryList<DialogContentDirective>;
@ContentChildren(DialogActionsDirective)
dialogActions: QueryList<DialogActionsDirective>;
ngAfterContentInit(): void {
if (this.dialogTitle.length > 1) {
throw new Error(
'Duplicate stbui-dialog-title component at in stbui-dialog.'
);
}
if (this.dialogContent.length > 1) {
throw new Error(
'Duplicate stbui-dialog-content component at in stbui-dialog.'
);
}
if (this.dialogActions.length > 1) {
throw new Error(
'Duplicate stbui-dialog-actions component at in stbui-dialog.'
);
}
}
}
<div class="stbui-dialog-wrapper">
<h3 class="stbui-dialog-title" *ngIf="dialogTitle.length > 0">
<ng-content select="stbui-dialog-title"></ng-content>
</h3>
<div class="stbui-dialog-content" *ngIf="dialogContent.length > 0">
<ng-content select="stbui-dialog-content"></ng-content>
</div>
<div class="stbui-dialog-actions" *ngIf="dialogActions.length > 0">
<span class="stbui-dialog-spacer"></span>
<ng-content select="stbui-dialog-actions"></ng-content>
</div>
</div>
:host {
display: block;
.stbui-dialog-actions {
flex-direction: row;
box-sizing: border-box;
display: flex;
.stbui-dialog-spacer {
flex: 1;
}
::ng-deep button {
text-transform: uppercase;
margin-left: 8px;
[dir='rtl'] & {
margin-right: 8px;
margin-left: inherit;
}
padding-left: 8px;
padding-right: 8px;
min-width: 64px;
}
}
}
.stbui-dialog-title {
margin-top: 0;
margin-bottom: 20px;
}
.stbui-dialog-content {
margin-bottom: 16px;
}
.stbui-dialog-actions {
position: relative;
top: 16px;
left: 16px;
::ng-deep [dir='rtl'] & {
right: 16px;
left: auto;
}
}
Legend
Html element with directive