File

projects/core/src/lib/action-button/action-button.ts

Description

ActionButton used to create basic button action

Example

const button = new ActionButton({ title: 'Test' });

Or

const button = actionFactory.createButton({ title: 'Test' });

Or

const button = actionFactory.createButton().setTitle('Test');

Extends

ActionAbstract

Index

Properties
Methods

Constructor

constructor(options: ActionButtonOptions, component?: Type<ActionButtonComponentImpl>)

Public constructor used to instantiate ActionButton

Parameters :
Name Type Optional Description
options ActionButtonOptions No

Options for ActionButton

component Type<ActionButtonComponentImpl> Yes

Optional custom Component

Properties

Readonly changes$
Type : Observable<ActionButtonOptions>
Inherited from ActionAbstract
Defined in ActionAbstract:47

Observable notifies subscriptions on following changes: title, icon, visibility, disabled

Readonly fire$
Type : Observable<ActionButtonEvent>
Inherited from ActionAbstract
Defined in ActionAbstract:42

Observable notifying subscriptions whenever button is triggered

Readonly ariaLabel$
Type : Observable<string>
Inherited from ActionAbstract
Defined in ActionAbstract:124

Observable that notifies subscribers when the ariaLabel changes.

Readonly disabled$
Type : Observable<boolean>
Inherited from ActionAbstract
Defined in ActionAbstract:115

Observable that notifies subscriptions when disabled state changes

Readonly icon$
Type : Observable<string>
Inherited from ActionAbstract
Defined in ActionAbstract:106

Observable that notifies subscriptions when icon changes

Readonly state$
Type : Observable<ActionState>
Inherited from ActionAbstract
Defined in ActionAbstract:120

Observable that notifies subscriptions when action state changes e.g. Active, Inactive, Destroyed

Readonly title$
Type : Observable<string>
Inherited from ActionAbstract
Defined in ActionAbstract:102

Observable that notifies subscriptions when title changes

Readonly visible$
Type : Observable<boolean>
Inherited from ActionAbstract
Defined in ActionAbstract:111

Observable that notifies subscriptions when visibility state changes (visible or hidden)

Methods

trigger
trigger()
Inherited from ActionAbstract
Defined in ActionAbstract:91

Will trigger fire$ subscribers Should be called in view component on click

Example:

button.trigger();
activate
activate()
Inherited from ActionAbstract
Defined in ActionAbstract:272

Will activate all observables in current action, unless action is already destroyed

deactivate
deactivate()
Inherited from ActionAbstract
Defined in ActionAbstract:285

Will deactivate all observables in current action, unless action is already destroyed

destroy
destroy()
Inherited from ActionAbstract
Defined in ActionAbstract:298

Will set action state to Destroyed, which will complete all observables

disable
disable()
Inherited from ActionAbstract
Defined in ActionAbstract:427

Will disable action, if prevously enabled

enable
enable()
Inherited from ActionAbstract
Defined in ActionAbstract:419

Will enable action, if prevously disabled

getAriaLabel
getAriaLabel()
Inherited from ActionAbstract
Defined in ActionAbstract:355

Returns current action ariaLabel

Returns : string
getForcedComponent
getForcedComponent()
Inherited from ActionAbstract
Defined in ActionAbstract:451

Returns a Component, that is provided as forced component via action constructor This component should be used by ActionOutletDirective, to represent the action in DOM, instead the component, provided via Angular Injector

Returns : Type | undefined
getIcon
getIcon()
Inherited from ActionAbstract
Defined in ActionAbstract:372

Returns current action icon

Returns : string
getParent
getParent()
Inherited from ActionAbstract
Defined in ActionAbstract:458

Returns current parent of the action

getTitle
getTitle()
Inherited from ActionAbstract
Defined in ActionAbstract:338

Returns current action title

Returns : string
hide
hide()
Inherited from ActionAbstract
Defined in ActionAbstract:387

Will nide the action, if previously visible

isActive
isActive()
Inherited from ActionAbstract
Defined in ActionAbstract:307

Returns boolean defining whether action has state ActionState.Active

Returns : boolean
isDestroyed
isDestroyed()
Inherited from ActionAbstract
Defined in ActionAbstract:321

Returns boolean defining whether action has state ActionState.Destroyed

Returns : boolean
isDisabled
isDisabled()
Inherited from ActionAbstract
Defined in ActionAbstract:435

Returns boolean defining whether action is disabled

Returns : boolean
isEnabled
isEnabled()
Inherited from ActionAbstract
Defined in ActionAbstract:442

Returns boolean defining whether action is enabled

Returns : boolean
isHidden
isHidden()
Inherited from ActionAbstract
Defined in ActionAbstract:412

Returns boolean defining whether action is hidden

Returns : boolean
isInactive
isInactive()
Inherited from ActionAbstract
Defined in ActionAbstract:314

Returns boolean defining whether action has state ActionState.Inactive

Returns : boolean
isVisible
isVisible()
Inherited from ActionAbstract
Defined in ActionAbstract:405

Returns boolean defining whether action is visible

Returns : boolean
setAriaLabel
setAriaLabel(ariaLabel: string)
Inherited from ActionAbstract
Defined in ActionAbstract:347

Will set the new ariaLabel and notify all ariaLabel subscribers

Parameters :
Name Type Optional Description
ariaLabel string No

The new action title

setIcon
setIcon(icon: string)
Inherited from ActionAbstract
Defined in ActionAbstract:364

Will set the new icon and notify all icon subscriptions

Parameters :
Name Type Optional Description
icon string No

The new action icon

setTitle
setTitle(title: string)
Inherited from ActionAbstract
Defined in ActionAbstract:330

Will set the new title and notify all title subscriptions

Parameters :
Name Type Optional Description
title string No

The new action title

setVisibility
setVisibility(visibility: boolean)
Inherited from ActionAbstract
Defined in ActionAbstract:397

Will show or hide the action depending from the provided visibility boolean

Parameters :
Name Type Optional Description
visibility boolean No

The new visibility

show
show()
Inherited from ActionAbstract
Defined in ActionAbstract:379

Will show the action, if previously hidden

import { Type } from '@angular/core';
import { Observable, Subject, merge } from 'rxjs';
import { map } from 'rxjs/operators';

import { ActionAbstract } from '../action-abstract/action-abstract';
import { ActionButtonComponentImpl, ActionButtonEvent, ActionButtonOptions } from './action-button.model';

/**
 * Default options for `ActionButton`
 * Extended by provided options in action `constructor`
 */
const defaultButtonOptions: ActionButtonOptions = {};

/**
 * `ActionButton` used to create basic button action
 *
 * ## Example
 *
 *
 *
```typescript
const button = new ActionButton({ title: 'Test' });
```
 *
 * **Or**
 *
 *
```typescript
const button = actionFactory.createButton({ title: 'Test' });
```
 *
 * **Or**
 *
```typescript
const button = actionFactory.createButton().setTitle('Test');
```
 */
export class ActionButton extends ActionAbstract<ActionButtonOptions, ActionButtonEvent> {
  /**
   * `Observable` notifying subscriptions whenever button is triggered
   */
  readonly fire$: Observable<ActionButtonEvent>;
  /**
   * `Observable` notifies subscriptions on following changes:
   * *title, icon, visibility, disabled*
   */
  readonly changes$: Observable<ActionButtonOptions>;

  /**
   * `Subject`, used to notify subscribers on action trigger
   */
  protected fire: Subject<ActionButtonEvent>;

  /**
   * Public `constructor` used to instantiate `ActionButton`
   *
   * @param options Options for `ActionButton`
   * @param component Optional custom `Component`
   */
  constructor(options: ActionButtonOptions = defaultButtonOptions, component?: Type<ActionButtonComponentImpl>) {
    super({ ...defaultButtonOptions, ...options }, component);

    this.fire = new Subject();

    this.fire$ = this.handleLivecycle(this.fire.asObservable(), false);
    this.changes$ = this.handleLivecycle(
      merge(
        this.title$.pipe(map(title => <ActionButtonOptions>{ title })),
        this.icon$.pipe(map(icon => <ActionButtonOptions>{ icon })),
        this.visible$.pipe(map(visible => <ActionButtonOptions>{ visible })),
        this.disabled$.pipe(map(disabled => <ActionButtonOptions>{ disabled })),
      ),
    );

    if (this.options.callback) {
      this.fire$.subscribe(this.options.callback);
    }
  }

  /**
     * Will trigger `fire$` subscribers
     * Should be called in view component on click
     *
     * #### Example:
```typescript
button.trigger();
```
     *
     * @method trigger
     */
  trigger(): this {
    this.fire.next({ action: this });
    return this;
  }
}

results matching ""

    No results matching ""