2019-09-19 20:10:52 +03:00
|
|
|
///
|
2021-01-11 13:42:16 +02:00
|
|
|
/// Copyright © 2016-2021 The Thingsboard Authors
|
2019-09-19 20:10:52 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import {
|
2020-04-21 11:53:26 +03:00
|
|
|
AfterViewInit,
|
2019-09-19 20:10:52 +03:00
|
|
|
Component,
|
2020-04-21 11:53:26 +03:00
|
|
|
Directive,
|
2019-09-19 20:10:52 +03:00
|
|
|
ElementRef,
|
2020-04-21 11:53:26 +03:00
|
|
|
Inject,
|
2019-09-19 20:10:52 +03:00
|
|
|
Input,
|
|
|
|
|
OnChanges,
|
2020-04-21 11:53:26 +03:00
|
|
|
OnDestroy,
|
2019-09-19 20:10:52 +03:00
|
|
|
OnInit,
|
|
|
|
|
SimpleChanges,
|
2020-04-21 11:53:26 +03:00
|
|
|
ViewEncapsulation
|
2019-09-19 20:10:52 +03:00
|
|
|
} from '@angular/core';
|
|
|
|
|
import { WINDOW } from '@core/services/window.service';
|
2020-04-21 11:53:26 +03:00
|
|
|
import { CanColorCtor, mixinColor } from '@angular/material/core';
|
2020-04-22 13:21:14 +03:00
|
|
|
import { ResizeObserver } from '@juggle/resize-observer';
|
2019-09-19 20:10:52 +03:00
|
|
|
|
|
|
|
|
export declare type FabToolbarDirection = 'left' | 'right';
|
|
|
|
|
|
|
|
|
|
class MatFabToolbarBase {
|
|
|
|
|
// tslint:disable-next-line:variable-name
|
|
|
|
|
constructor(public _elementRef: ElementRef) {}
|
|
|
|
|
}
|
|
|
|
|
const MatFabToolbarMixinBase: CanColorCtor & typeof MatFabToolbarBase = mixinColor(MatFabToolbarBase);
|
|
|
|
|
|
|
|
|
|
@Directive({
|
2020-02-04 15:14:17 +02:00
|
|
|
// tslint:disable-next-line:directive-selector
|
2019-09-19 20:10:52 +03:00
|
|
|
selector: 'mat-fab-trigger'
|
|
|
|
|
})
|
|
|
|
|
export class FabTriggerDirective {
|
|
|
|
|
|
|
|
|
|
constructor(private el: ElementRef<HTMLElement>) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Directive({
|
2020-02-04 15:14:17 +02:00
|
|
|
// tslint:disable-next-line:directive-selector
|
2019-09-19 20:10:52 +03:00
|
|
|
selector: 'mat-fab-actions'
|
|
|
|
|
})
|
|
|
|
|
export class FabActionsDirective implements OnInit {
|
|
|
|
|
|
|
|
|
|
constructor(private el: ElementRef<HTMLElement>) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
const element = $(this.el.nativeElement);
|
|
|
|
|
const children = element.children();
|
|
|
|
|
children.wrap('<div class="mat-fab-action-item">');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 14:36:44 +02:00
|
|
|
// @dynamic
|
2019-09-19 20:10:52 +03:00
|
|
|
@Component({
|
2020-02-04 15:14:17 +02:00
|
|
|
// tslint:disable-next-line:component-selector
|
2019-09-19 20:10:52 +03:00
|
|
|
selector: 'mat-fab-toolbar',
|
|
|
|
|
templateUrl: './fab-toolbar.component.html',
|
|
|
|
|
styleUrls: ['./fab-toolbar.component.scss'],
|
|
|
|
|
inputs: ['color'],
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
|
})
|
|
|
|
|
export class FabToolbarComponent extends MatFabToolbarMixinBase implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
|
|
|
|
|
2020-04-22 13:21:14 +03:00
|
|
|
private fabToolbarResize$: ResizeObserver;
|
|
|
|
|
|
2019-09-19 20:10:52 +03:00
|
|
|
@Input()
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
direction: FabToolbarDirection;
|
|
|
|
|
|
|
|
|
|
constructor(private el: ElementRef<HTMLElement>,
|
|
|
|
|
@Inject(WINDOW) private window: Window) {
|
|
|
|
|
super(el);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
const element = $(this.el.nativeElement);
|
|
|
|
|
element.addClass('mat-fab-toolbar');
|
|
|
|
|
element.find('mat-fab-trigger').find('button')
|
|
|
|
|
.prepend('<div class="mat-fab-toolbar-background"></div>');
|
|
|
|
|
element.addClass(`mat-${this.direction}`);
|
2020-04-22 13:21:14 +03:00
|
|
|
this.fabToolbarResize$ = new ResizeObserver(() => {
|
|
|
|
|
this.onFabToolbarResize();
|
|
|
|
|
});
|
|
|
|
|
this.fabToolbarResize$.observe(this.el.nativeElement);
|
2019-09-19 20:10:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
2020-04-22 13:21:14 +03:00
|
|
|
this.fabToolbarResize$.disconnect();
|
2019-09-19 20:10:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
this.triggerOpenClose(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
for (const propName of Object.keys(changes)) {
|
|
|
|
|
const change = changes[propName];
|
|
|
|
|
if (!change.firstChange && change.currentValue !== change.previousValue) {
|
|
|
|
|
if (propName === 'isOpen') {
|
|
|
|
|
this.triggerOpenClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private onFabToolbarResize() {
|
|
|
|
|
if (this.isOpen) {
|
|
|
|
|
this.triggerOpenClose(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private triggerOpenClose(disableAnimation?: boolean): void {
|
|
|
|
|
const el = this.el.nativeElement;
|
|
|
|
|
const element = $(this.el.nativeElement);
|
|
|
|
|
if (disableAnimation) {
|
|
|
|
|
element.removeClass('mat-animation');
|
|
|
|
|
} else {
|
|
|
|
|
element.addClass('mat-animation');
|
|
|
|
|
}
|
|
|
|
|
const backgroundElement: HTMLElement = el.querySelector('.mat-fab-toolbar-background');
|
|
|
|
|
const triggerElement: HTMLElement = el.querySelector('mat-fab-trigger button');
|
|
|
|
|
const toolbarElement: HTMLElement = el.querySelector('mat-toolbar');
|
|
|
|
|
const iconElement: HTMLElement = el.querySelector('mat-fab-trigger button mat-icon');
|
2020-04-28 14:44:48 +03:00
|
|
|
const actions = element.find<HTMLElement>('mat-fab-actions').children();
|
2019-09-19 20:10:52 +03:00
|
|
|
if (triggerElement && backgroundElement) {
|
|
|
|
|
const width = el.offsetWidth;
|
|
|
|
|
const scale = 2 * (width / triggerElement.offsetWidth);
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.borderRadius = width + 'px';
|
|
|
|
|
|
|
|
|
|
if (this.isOpen) {
|
|
|
|
|
element.addClass('mat-is-open');
|
|
|
|
|
toolbarElement.style.pointerEvents = 'inherit';
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.width = triggerElement.offsetWidth + 'px';
|
|
|
|
|
backgroundElement.style.height = triggerElement.offsetHeight + 'px';
|
|
|
|
|
backgroundElement.style.transform = 'scale(' + scale + ')';
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.transitionDelay = '0ms';
|
|
|
|
|
if (iconElement) {
|
|
|
|
|
iconElement.style.transitionDelay = disableAnimation ? '0ms' : '.3s';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actions.each((index, action) => {
|
|
|
|
|
action.style.transitionDelay = disableAnimation ? '0ms' : ((actions.length - index) * 25 + 'ms');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
element.removeClass('mat-is-open');
|
|
|
|
|
toolbarElement.style.pointerEvents = 'none';
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.transform = 'scale(1)';
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.top = '0';
|
|
|
|
|
|
|
|
|
|
if (element.hasClass('mat-right')) {
|
|
|
|
|
backgroundElement.style.left = '0';
|
|
|
|
|
backgroundElement.style.right = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (element.hasClass('mat-left')) {
|
|
|
|
|
backgroundElement.style.right = '0';
|
|
|
|
|
backgroundElement.style.left = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backgroundElement.style.transitionDelay = disableAnimation ? '0ms' : '200ms';
|
|
|
|
|
|
|
|
|
|
actions.each((index, action) => {
|
|
|
|
|
action.style.transitionDelay = (disableAnimation ? 0 : 200) + (index * 25) + 'ms';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|