nereo-material
Version:
This project contains [Material Design](https://material.io/design/) components built with Angular and Angular Material. Its goal is to provide components that are not yet implemented in [Angular Material](https://material.angular.io/).
672 lines (638 loc) • 22.4 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { EventEmitter, Input, Output, Component, NgModule } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { CommonModule } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatMenuModule } from '@angular/material/menu';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatCardModule } from '@angular/material/card';
import { MatListModule } from '@angular/material/list';
import { trigger, state, style, transition, animate, query, stagger, keyframes } from '@angular/animations';
var ContextualToolbarDisplayMode;
(function (ContextualToolbarDisplayMode) {
ContextualToolbarDisplayMode["icons"] = "icons";
ContextualToolbarDisplayMode["text"] = "text";
ContextualToolbarDisplayMode["all"] = "all";
})(ContextualToolbarDisplayMode || (ContextualToolbarDisplayMode = {}));
let ContextualToolbarComponent = class ContextualToolbarComponent {
constructor() {
this.displayMode = ContextualToolbarDisplayMode.icons;
this.selectedAction = new EventEmitter();
this.clearSelection = new EventEmitter();
this.classesToApply = {};
this.progressMessage = new BehaviorSubject(null);
}
ngOnInit() {
this.setContextualization();
}
showButtonIcon() {
console.log("Display Mode", this.displayMode);
return this.displayMode != ContextualToolbarDisplayMode.text;
}
showButtonText() {
return this.displayMode != ContextualToolbarDisplayMode.icons;
}
setContextualization() {
this.classesToApply = {
'page-contextual-toolbar': this.contextualizeTo != 'card',
'card-contextual-toolbar': this.contextualizeTo == 'card'
};
}
setProgress(progressMessage) {
this.progressMessage.next(progressMessage);
}
stopProgress() {
this.progressMessage.next(null);
}
actionSelected(action) {
this.selectedAction.emit(action);
}
clear() {
this.clearSelection.emit();
}
};
__decorate([
Input(),
__metadata("design:type", Number)
], ContextualToolbarComponent.prototype, "count", void 0);
__decorate([
Input(),
__metadata("design:type", Array)
], ContextualToolbarComponent.prototype, "actions", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], ContextualToolbarComponent.prototype, "displayMode", void 0);
__decorate([
Input(),
__metadata("design:type", Array)
], ContextualToolbarComponent.prototype, "moreActions", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], ContextualToolbarComponent.prototype, "contextualizeTo", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], ContextualToolbarComponent.prototype, "selectedAction", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], ContextualToolbarComponent.prototype, "clearSelection", void 0);
ContextualToolbarComponent = __decorate([
Component({
selector: 'nm-contextual-toolbar',
template: "<mat-toolbar *ngIf=\"count > 0\" [ngClass]=\"classesToApply\">\n <ng-container *ngIf=\"progressMessage | async; then progressMode; else defaultMode\">\n </ng-container>\n <ng-template #defaultMode>\n <button mat-icon-button (click)=\"clear()\">\n <mat-icon>clear</mat-icon>\n </button>\n <span i18n=\"@@contextualSelectedItems\">{{count}} selected</span>\n\n <span class=\"spacer\"></span>\n \n <button mat-icon-button \n *ngFor=\"let action of actions\" \n (click)=\"actionSelected(action)\"\n [class.textButton]=\"showButtonText()\">\n <mat-icon [matTooltip]=\"action.tooltip ? action.tooltip : action.name\"\n *ngIf=\"showButtonIcon()\">{{action.icon}}</mat-icon>\n <span *ngIf=\"showButtonText()\">{{action.text}}</span>\n </button>\n \n <button mat-icon-button *ngIf=\"moreActions\" [matMenuTriggerFor]=\"menu\">\n <mat-icon matTooltip=\"more\" i18n-matTooltip=\"@@moreActions\">more_vert</mat-icon>\n </button>\n <mat-menu #menu=\"matMenu\" yPosition=\"below\">\n <button mat-menu-item \n *ngFor=\"let moreAction of moreActions\" \n (click)=\"actionSelected(moreAction.name)\">{{moreAction.tooltip ? moreAction.tooltip: moreAction.name}}</button>\n </mat-menu>\n </ng-template>\n <ng-template #progressMode>\n <mat-spinner [diameter]='24'></mat-spinner>\n {{ progressMessage | async }}\n <span class=\"spacer\"></span>\n </ng-template>\n</mat-toolbar>",
styles: [":host mat-toolbar{background-color:var(--primary-lighter,#f5f5f5)!important;color:var(--primary,#000);left:0;top:0;width:100%;z-index:999}:host mat-toolbar>div{align-items:center;display:flex;width:100%}:host .page-contextual-toolbar{position:fixed}:host .textButton{margin-right:16px;text-transform:uppercase;width:auto}:host .textButton ::ng-deep .mat-button-wrapper{align-items:center;display:flex;gap:4px}:host mat-spinner{margin-left:8px;margin-right:8px}:host .card-contextual-toolbar{position:absolute}:host .spacer{flex:1 1 auto}"]
}),
__metadata("design:paramtypes", [])
], ContextualToolbarComponent);
let ContextualToolbarModule = class ContextualToolbarModule {
};
ContextualToolbarModule = __decorate([
NgModule({
imports: [
CommonModule,
MatToolbarModule,
MatButtonModule,
MatIconModule,
MatTooltipModule,
MatMenuModule,
MatProgressSpinnerModule
],
declarations: [ContextualToolbarComponent],
exports: [ContextualToolbarComponent]
})
], ContextualToolbarModule);
let BannerComponent = class BannerComponent {
constructor() {
this.mainActionClick = new EventEmitter();
this.secondaryActionClick = new EventEmitter();
}
ngOnInit() {
}
mainActionClicked() {
this.mainActionClick.emit();
}
secondaryActionClicked() {
this.secondaryActionClick.emit();
}
};
__decorate([
Input(),
__metadata("design:type", Boolean)
], BannerComponent.prototype, "show", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], BannerComponent.prototype, "icon", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], BannerComponent.prototype, "firstSentence", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], BannerComponent.prototype, "secondSentence", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], BannerComponent.prototype, "mainActionText", void 0);
__decorate([
Input(),
__metadata("design:type", String)
], BannerComponent.prototype, "secondaryActionText", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], BannerComponent.prototype, "mainActionClick", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], BannerComponent.prototype, "secondaryActionClick", void 0);
BannerComponent = __decorate([
Component({
selector: 'nm-banner',
template: `
<mat-card *ngIf="show">
<mat-card-content>
<mat-list>
<mat-list-item>
<mat-icon matListIcon color="primary" *ngIf="icon">{{icon}}</mat-icon>
<div id="banner-text-container">
<p matLine>{{firstSentence}}</p>
<p matLine *ngIf="secondSentence">{{secondSentence}}</p>
</div>
</mat-list-item>
</mat-list>
<div id="banner-actions">
<button mat-button color="primary" (click)="secondaryActionClicked()" *ngIf="secondaryActionText">{{secondaryActionText}}</button>
<button mat-button color="primary" (click)="mainActionClicked()">{{mainActionText}}</button>
</div>
</mat-card-content>
</mat-card>
`,
styles: [`
mat-card {
height: 52px;
padding: 0;
}
mat-card-content{
align-items: center;
display: flex;
justify-content: space-between;
margin: 0 auto;
max-width: 90%;
flex-wrap: wrap;
}
#banner-text-container {
margin-left: 24px;
}
#banner-text-container p{
font-size: 14px;
margin: 3px 0;
}
#banner-actions button{
text-transform: uppercase !important;
}
mat-card-content,
mat-list,
mat-list-item {
height: 100% !important;
padding: 0;
}
.mat-list, .mat-list-item, .mat-list-text{
flex-direction: row !important;
}
{
mat-card {
height: 112px;
}
mat-card-content,
mat-list,
mat-list-item {
height: auto !important;
max-width: 100% !important;
width: 100% !important;
}
mat-list-item {
margin: 12px 0 !important;
}
#banner-text-container {
margin-left: 16px !important;
}
#banner-actions {
justify-content: flex-end;
display: flex;
width: 100%;
}
}
`]
}),
__metadata("design:paramtypes", [])
], BannerComponent);
let BannerModule = class BannerModule {
};
BannerModule = __decorate([
NgModule({
imports: [
CommonModule,
MatCardModule,
MatListModule,
MatIconModule,
MatButtonModule
],
declarations: [BannerComponent],
exports: [BannerComponent]
})
], BannerModule);
let BackdropComponent = class BackdropComponent {
constructor() {
this.backLayerMinHeight = 56;
this.frontLayerMinHeight = 42;
}
reveal() {
let backLayer = this.getBackLayer();
let frontLayer = this.getFrontLayer();
let toolbar = this.getToolbar();
let from = frontLayer.offsetTop;
let to = toolbar.offsetHeight + backLayer.offsetHeight;
this.animateFrontLayerDown(frontLayer, from, to);
}
conceal() {
let frontLayer = this.getFrontLayer();
let from = frontLayer.offsetTop;
let to = this.backLayerMinHeight;
this.animateFrontLayerUp(frontLayer, from, to);
}
getBackLayer() {
return document.querySelector('nm-backdrop-back-layer-content');
}
getFrontLayer() {
return document.querySelector('nm-backdrop-front-layer');
}
getToolbar() {
return document.querySelector('mat-toolbar');
}
getWindowHeight() {
return document.documentElement.clientHeight;
}
// TODO Refactor animations to single function
animateFrontLayerDown(frontLayer, from, to) {
let pos = from;
let maxPos = this.getWindowHeight() - this.frontLayerMinHeight;
let interval = setInterval(frame, 3);
function frame() {
if (pos >= to || pos >= maxPos) {
if (to >= maxPos) {
frontLayer.style.top = maxPos + 'px';
}
else {
frontLayer.style.top = to + 'px';
}
clearInterval(interval);
}
else {
pos = to > from ? pos + 10 : pos - 10;
frontLayer.style.top = pos + 'px';
}
}
}
animateFrontLayerUp(frontLayer, from, to) {
let pos = from;
let interval = setInterval(frame, 3);
function frame() {
if (pos <= to) {
frontLayer.style.top = to + 'px';
clearInterval(interval);
}
else {
pos = to > from ? pos + 10 : pos - 10;
frontLayer.style.top = pos + 'px';
}
}
}
};
BackdropComponent = __decorate([
Component({
selector: 'nm-backdrop',
template: `
<ng-content select="nm-backdrop-back-layer"></ng-content>
<ng-content select="nm-backdrop-front-layer"></ng-content>
`,
styles: [`
:host {
width: 100%;
}
`]
}),
__metadata("design:paramtypes", [])
], BackdropComponent);
let BackdropBackLayerComponent = class BackdropBackLayerComponent {
};
BackdropBackLayerComponent = __decorate([
Component({
selector: 'nm-backdrop-back-layer',
template: `
<ng-content select="nm-backdrop-back-layer-toolbar"></ng-content>
<ng-content select="nm-backdrop-back-layer-content"></ng-content>
`,
styles: [`
:host {
display: flex;
flex-direction: column;
height: 100%;
min-height: 56px;
width: 100%;
}
`]
})
], BackdropBackLayerComponent);
let BackdropBackLayerContentComponent = class BackdropBackLayerContentComponent {
};
BackdropBackLayerContentComponent = __decorate([
Component({
selector: 'nm-backdrop-back-layer-content',
template: `
<ng-content></ng-content>
`,
styles: [`
:host{
overflow-y: auto;
}
`]
})
], BackdropBackLayerContentComponent);
let BackdropBackLayerToolbarComponent = class BackdropBackLayerToolbarComponent {
};
BackdropBackLayerToolbarComponent = __decorate([
Component({
selector: 'nm-backdrop-back-layer-toolbar',
template: `<ng-content></ng-content>`,
styles: [``]
})
], BackdropBackLayerToolbarComponent);
let BackdropFrontLayerComponent = class BackdropFrontLayerComponent {
};
BackdropFrontLayerComponent = __decorate([
Component({
selector: 'nm-backdrop-front-layer',
template: `
<ng-content select="nm-backdrop-front-layer-subtitle"></ng-content>
<ng-content select="nm-backdrop-front-layer-content"></ng-content>
`,
styles: [`
:host{
border-top-left-radius: 16px;
border-top-right-radius: 16px;
bottom: 0;
height: 100%;
overflow: hidden;
position: fixed;
top: 56px;
width: 100%;
}
`]
})
], BackdropFrontLayerComponent);
let BackdropFrontLayerSubtitleComponent = class BackdropFrontLayerSubtitleComponent {
};
BackdropFrontLayerSubtitleComponent = __decorate([
Component({
selector: 'nm-backdrop-front-layer-subtitle',
template: `<ng-container>
<ng-content select="mat-icon" class="subtitle-icon"></ng-content>
<ng-content select="span"></ng-content>
<span class="spacer"></span>
<ng-content select="button"></ng-content>
</ng-container>`,
styles: [`
:host{
align-items: center;
display: flex;
flex-direction: row;
margin: 12px 16px;
width: auto;
}
:host ::ng-deep mat-icon{
margin-right: 8px;
}
:host ::ng-deep span {
font-size: 1.2rem;
}
:host ::ng-deep .spacer {
flex: 1 1 auto;
}
`]
})
], BackdropFrontLayerSubtitleComponent);
let BackdropFrontLayerContentComponent = class BackdropFrontLayerContentComponent {
};
BackdropFrontLayerContentComponent = __decorate([
Component({
selector: 'nm-backdrop-front-layer-content',
template: `<ng-content></ng-content>`,
styles: [`
:host{
display: flex;
height: 100%;
overflow-y: auto;
width: 100%;
}
`]
})
], BackdropFrontLayerContentComponent);
let BackdropModule = class BackdropModule {
};
BackdropModule = __decorate([
NgModule({
imports: [
CommonModule,
],
declarations: [
BackdropComponent,
BackdropBackLayerComponent,
BackdropBackLayerContentComponent,
BackdropBackLayerToolbarComponent,
BackdropFrontLayerComponent,
BackdropFrontLayerSubtitleComponent,
BackdropFrontLayerContentComponent,
],
exports: [
BackdropComponent,
BackdropBackLayerComponent,
BackdropBackLayerContentComponent,
BackdropBackLayerToolbarComponent,
BackdropFrontLayerComponent,
BackdropFrontLayerSubtitleComponent,
BackdropFrontLayerContentComponent,
]
})
], BackdropModule);
const FabSpeedDialAnimation = [
trigger('fabButtonAnimation', [
state('inactive', style({
transform: 'rotate(0deg)'
})),
state('active', style({
transform: 'rotate(180deg)'
})),
transition('* <=> *', animate('200ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
]),
trigger('speedDialStagger', [
transition('* => *', [
query(':enter', style({ opacity: 0 }), { optional: true }),
query(':enter', stagger('40ms', [
animate('200ms cubic-bezier(0.4, 0.0, 0.2, 1)', keyframes([
style({ opacity: 0, transform: 'translateY(10px)' }),
style({ opacity: 1, transform: 'translateY(0)' }),
]))
]), { optional: true }),
query(':leave', animate('200ms cubic-bezier(0.4, 0.0, 0.2, 1)', keyframes([
style({ opacity: 1 }),
style({ opacity: 0 }),
])), { optional: true })
])
])
];
let FabSpeedDialComponent = class FabSpeedDialComponent {
constructor() {
this.selectedAction = new EventEmitter();
this.showActions = false;
this.displayedIcon = '';
this.fabSpeedDialState = '';
this.isCorrectActionsNumber = true;
}
ngOnInit() {
this.displayedIcon = this.mainIcon;
this.checkActions();
}
checkActions() {
if (this.actions.length < 3) {
console.error('A speed dial should include at least three options.');
this.isCorrectActionsNumber = false;
}
else if (this.actions.length > 6) {
console.error('A speed dial should include no more than six options.');
this.isCorrectActionsNumber = false;
}
}
toggleSpeedDial() {
this.showActions = !this.showActions;
if (this.showActions) {
this.fabSpeedDialState = 'active';
this.displayedIcon = 'close';
document.getElementById('nm-fab-speed-dial-button-overlay').classList.add('nm-fab-speed-dial-overlay');
}
else {
this.fabSpeedDialState = 'inactive';
this.displayedIcon = this.mainIcon;
document.getElementById('nm-fab-speed-dial-button-overlay').classList.remove('nm-fab-speed-dial-overlay');
}
}
actionSelected(action) {
this.selectedAction.emit(action);
this.toggleSpeedDial();
}
};
__decorate([
Input(),
__metadata("design:type", String)
], FabSpeedDialComponent.prototype, "mainIcon", void 0);
__decorate([
Input(),
__metadata("design:type", Array)
], FabSpeedDialComponent.prototype, "actions", void 0);
__decorate([
Output(),
__metadata("design:type", Object)
], FabSpeedDialComponent.prototype, "selectedAction", void 0);
FabSpeedDialComponent = __decorate([
Component({
selector: 'nm-fab-speed-dial',
template: `
<div *ngIf="isCorrectActionsNumber">
<div id="nm-fab-speed-dial-button-overlay"></div>
<div class="nm-fab-speed-dial-button-component">
<div *ngIf="showActions" []="actions.length" class="nm-fab-speed-dial-menu-actions">
<div *ngFor="let action of actions" class="nm-fab-speed-dial-mini-button">
<mat-card class="nm-fab-speed-dial-card-action" *ngIf="action.name">
{{ action.name }}
</mat-card>
<button mat-mini-fab color="primary" (click)="actionSelected(action)">
<mat-icon>{{ action.icon }}</mat-icon>
</button>
</div>
</div>
<button mat-fab color="primary" (click)="toggleSpeedDial()">
<mat-icon []="{value: fabSpeedDialState}">{{ displayedIcon }}</mat-icon>
</button>
</div>
</div>
`,
animations: FabSpeedDialAnimation,
styles: [`
.nm-fab-speed-dial-button-component {
position: fixed;
bottom: 16px;
right: 16px;
text-align: right;
}
.nm-fab-speed-dial-mini-button {
display: flex;
align-items: flex-end;
margin-bottom: 16px;
}
.nm-fab-speed-dial-card-action {
margin-right: 16px;
padding: 12px;
text-align: center;
padding-right: 16px;
padding-left: 16px;
}
.nm-fab-speed-dial-menu-actions {
flex-direction: column-reverse;
display: flex;
align-items: flex-end;
margin-right: 8px;
position: relative;
bottom: 56px;
}
.nm-fab-speed-dial-overlay {
width: 100%;
height: 100%;
position: fixed;
left: 0;
top: 0;
z-index: 0;
background: rgba(0, 0, 0, 0.32);
}
`]
}),
__metadata("design:paramtypes", [])
], FabSpeedDialComponent);
let FabSpeedDialModule = class FabSpeedDialModule {
};
FabSpeedDialModule = __decorate([
NgModule({
imports: [
CommonModule,
MatButtonModule,
MatIconModule,
MatCardModule
],
declarations: [FabSpeedDialComponent],
exports: [FabSpeedDialComponent]
})
], FabSpeedDialModule);
/*
* Public API Surface of nm
*/
/**
* Generated bundle index. Do not edit.
*/
export { BackdropBackLayerComponent, BackdropBackLayerContentComponent, BackdropBackLayerToolbarComponent, BackdropComponent, BackdropFrontLayerComponent, BackdropFrontLayerContentComponent, BackdropFrontLayerSubtitleComponent, BackdropModule, BannerComponent, BannerModule, ContextualToolbarComponent, ContextualToolbarDisplayMode, ContextualToolbarModule, FabSpeedDialComponent, FabSpeedDialModule, FabSpeedDialAnimation as ɵa };
//# sourceMappingURL=nereo-material.js.map