File

src/app/component/speed-dial/speed-dial.component.ts

Implements

AfterContentInit

Metadata

encapsulation ViewEncapsulation.None
exportAs stbuiSpeedDial
host {
}
moduleId module.id
selector stbui-speed-dial
styleUrls ./speed-dial.component.scss
templateUrl ./speed-dial.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(renderer: Renderer2)
Parameters :
Name Type Optional
renderer Renderer2 No

Inputs

open
Type : boolean
Default value : false
position
Type : Position
Default value : 'up'

Methods

_getOrigin
_getOrigin(value)
Parameters :
Name Optional
value No
Returns : string
hide
hide()
Returns : void
ngAfterContentInit
ngAfterContentInit()
Returns : void
show
show()
Returns : void
toggle
toggle()
Returns : void

Properties

_actions
Type : ElementRef
Decorators :
@ViewChild('actions', {static: false})
_buttons
Type : QueryList<MatButton>
Decorators :
@ContentChildren(MatButton)
import {
  Component,
  Input,
  ContentChildren,
  QueryList,
  ViewChild,
  ElementRef,
  Renderer2,
  AfterContentInit,
  ViewEncapsulation
} from '@angular/core';
import { MatButton } from '@angular/material/button';

export type Position = 'up' | 'down' | 'left' | 'right';

@Component({
  moduleId: module.id,
  selector: 'stbui-speed-dial',
  templateUrl: './speed-dial.component.html',
  styleUrls: ['./speed-dial.component.scss'],
  encapsulation: ViewEncapsulation.None,
  exportAs: 'stbuiSpeedDial',
  host: {
    class: 'speed-dial'
  }
})
export class SpeedDialComponent implements AfterContentInit {
  @Input() position: Position = 'up';
  @Input() open: boolean = false;

  @ContentChildren(MatButton) _buttons: QueryList<MatButton>;
  @ViewChild('actions', { static: false }) _actions: ElementRef;

  constructor(private renderer: Renderer2) { }

  ngAfterContentInit() {
    this.toggle();
    this._buttons.toArray().forEach(button => {
      this.renderer.addClass(button._getHostElement(), 'spped-dial-action');
    });
  }

  toggle(): void {
    this.open = !this.open;

    if (this.open) {
      this.hide();
    } else {
      this.show();
    }
  }

  show() {
    this._buttons.toArray().forEach(button => {
      const transform = this._getOrigin('0');
      this.renderer.setStyle(button._getHostElement(), 'transform', transform);
    });
  }

  hide() {
    this._buttons.toArray().forEach((button, index) => {
      const pos = 55 * (index + 1) - index * 5;
      const transform = this._getOrigin(pos + 'px');
      this.renderer.setStyle(button._getHostElement(), 'transform', transform);
    });
  }

  _getOrigin(value) {
    let position = this.position;
    let translateFn =
      position === 'up' || position === 'down' ? 'translateY' : 'translateX';
    let sign = position === 'down' || position === 'right' ? '-' : '';
    return translateFn + '(' + sign + value + ')';
  }
}
<div class="speed-dial-container" [ngClass]="position">

  <div class="speed-dial-trigger" (click)="toggle()">
    <button mat-fab>
      <mat-icon>add</mat-icon>
    </button>
  </div>

  <div class="speed-dial-actions" #actions>
    <ng-content></ng-content>
  </div>
</div>

./speed-dial.component.scss

.speed-dial {
  display: inline-block;
  &-container {
    position: relative;
    display: flex;
    align-items: center;
  }
  &-trigger {
    z-index: 20;
    order: 2;
  }
  &-actions {
    display: flex;
    order: 1;
  }
  &-action,
  button {
    transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
  }
}

.speed-dial-container.up {
  flex-direction: column;
  .speed-dial-actions {
    flex-direction: column-reverse;
    .spped-dial-action {
      margin-bottom: 10px;
    }
  }
}

.speed-dial-container.down {
  flex-direction: column;
  .speed-dial-trigger {
    order: 1;
  }
  .speed-dial-actions {
    flex-direction: column;
    .spped-dial-action {
      margin-top: 10px;
    }
  }
  .speed-dial-actions button {
    margin-top: 10px;
  }
}

.speed-dial-container.left {
  flex-direction: row;
  .speed-dial-trigger {
    order: 2;
  }
  .speed-dial-actions {
    flex-direction: row-reverse;
    order: 1;
    .spped-dial-action {
      margin-right: 10px;
    }
  }
}

.speed-dial-container.right {
  flex-direction: row;
  .speed-dial-trigger {
    order: 1;
  }
  .speed-dial-actions {
    order: 2;
    .spped-dial-action {
      margin-left: 10px;
    }
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""