File

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

Description

ActionAnchor used to create basic link

Example

const button = new ActionAnchor({ title: 'Test', link: 'https://...' });

Or

const button = actionFactory.createButton({ title: 'Test', link: 'https://...' });

Or

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

Extends

ActionAbstract

Index

Properties
Methods

Constructor

constructor(options: ActionAnchorOptions, component?: Type<ActionAnchorComponentImpl>)

Public constructor used to instantiate ActionAnchor

Parameters :
Name Type Optional Description
options ActionAnchorOptions No

Options for ActionAnchor

component Type<ActionAnchorComponentImpl> Yes

Optional custom Component

Properties

Readonly changes$
Type : Observable<ActionAnchorOptions>
Inherited from ActionAbstract
Defined in ActionAbstract:48

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

Readonly fire$
Default value : EMPTY
Inherited from ActionAbstract
Defined in ActionAbstract:43

EMPTY Observable as link is handled by the browser

Readonly href$
Type : Observable<string | null>

Observable notifying subscribers of the change to the href

Readonly routerLink$
Type : Observable<UrlTree | string | | null>

Observable notifying subscribers of the change to the routerLink

Readonly target$
Type : Observable<AnchorTarget | null>

Observable notifying subscribers of the change to the target

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

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

Noop: cannot disable the anchor

Returns : this
enable
enable()
Inherited from ActionAbstract
Defined in ActionAbstract:149

Noop: cannot disable the anchor

Returns : this
isExternalLink
isExternalLink()

Determines if the link is external

Returns : boolean
setHref
setHref(href: string | null)

Set the url for the anchor element

Parameters :
Name Type Optional
href string | null No
Returns : this
setRouterLink
setRouterLink(routerLink: UrlTree | string | | null)

Set the routerLink binding for router link directive

Parameters :
Name Type Optional
routerLink UrlTree | string | | null No
Returns : this
setTarget
setTarget(target: AnchorTarget)

Set the target for the anchor element

Parameters :
Name Type Optional
target AnchorTarget No
Returns : this
trigger
trigger()
Inherited from ActionAbstract
Defined in ActionAbstract:108

Noop: cannot manually trigger the anchor

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

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 { UrlTree } from '@angular/router';
import { Observable, merge, EMPTY, BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';

import { ActionAbstract } from '../action-abstract/action-abstract';
import { ActionAnchorComponentImpl, ActionAnchorOptions, AnchorTarget } from './action-anchor.model';

/**
 * Default options for `ActionAnchor`
 * Extended by provided options in action `constructor`
 */
const defaultButtonOptions = <ActionAnchorOptions>{};

/**
 * `ActionAnchor` used to create basic link
 *
 * ## Example
 *
 *
 *
```typescript
const button = new ActionAnchor({ title: 'Test', link: 'https://...' });
```
 *
 * **Or**
 *
 *
```typescript
const button = actionFactory.createButton({ title: 'Test', link: 'https://...' });
```
 *
 * **Or**
 *
```typescript
const button = actionFactory.createButton().setTitle('Test');
```
 */
export class ActionAnchor extends ActionAbstract<ActionAnchorOptions, null> {
  /**
   * `EMPTY Observable` as link is handled by the browser
   */
  readonly fire$ = EMPTY;
  /**
   * `Observable` notifies subscriptions on following changes:
   * *title, icon, visibility, disabled*
   */
  readonly changes$: Observable<ActionAnchorOptions>;

  /**
   * `Observable` notifying subscribers of the change to the href
   */
  readonly href$: Observable<string | null>;
  /**
   * `Observable` notifying subscribers of the change to the routerLink
   */
  readonly routerLink$: Observable<UrlTree | string | readonly string[] | null>;
  /**
   * `Observable` notifying subscribers of the change to the target
   */
  readonly target$: Observable<AnchorTarget | null>;

  /**
   * Subject storing the link/href
   */
  protected href: BehaviorSubject<string | null>;
  /**
   * Subject storing the routerLink
   */
  protected routerLink: BehaviorSubject<UrlTree | string | readonly string[] | null>;
  /**
   * Subject storing the target
   */
  protected target: BehaviorSubject<AnchorTarget | null>;

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

    this.href = new BehaviorSubject('href' in options ? options.href : null);
    this.routerLink = new BehaviorSubject('routerLink' in options ? options.routerLink : null);
    this.target = new BehaviorSubject(options.target ?? null);

    this.href$ = this.handleLivecycleDistinct(this.href.asObservable(), false);
    this.routerLink$ = this.handleLivecycleDistinct(this.routerLink.asObservable(), false);
    this.target$ = this.handleLivecycleDistinct(this.target.asObservable(), false);
    this.changes$ = this.handleLivecycle(
      merge(
        this.title$.pipe(map(title => <ActionAnchorOptions>{ title })),
        this.icon$.pipe(map(icon => <ActionAnchorOptions>{ icon })),
        this.visible$.pipe(map(visible => <ActionAnchorOptions>{ visible })),
        this.disabled$.pipe(map(disabled => <ActionAnchorOptions>{ disabled })),
        this.href$.pipe(map(href => <ActionAnchorOptions>{ href })),
        this.routerLink$.pipe(map(routerLink => <ActionAnchorOptions>{ routerLink })),
        this.target$.pipe(map(target => <ActionAnchorOptions>{ target })),
      ),
    );
  }

  /**
   * Noop: cannot manually trigger the anchor
   */
  trigger(): this {
    return this;
  }

  /**
   * Set the url for the anchor element
   */
  setHref(href: string | null) {
    this.href.next(href);
    this.routerLink.next(null);
    return this;
  }

  /**
   * Set the routerLink binding for router link directive
   */
  setRouterLink(routerLink: UrlTree | string | readonly string[] | null) {
    this.routerLink.next(routerLink);
    this.href.next(null);
    return this;
  }

  /**
   * Set the target for the anchor element
   */
  setTarget(target: AnchorTarget) {
    this.target.next(target);
    return this;
  }

  /**
   * Noop: cannot disable the anchor
   */
  disable() {
    // HTML Anchors cannot be disabled
    return this;
  }

  /**
   * Noop: cannot disable the anchor
   */
  enable() {
    // HTML Anchors cannot be disabled
    return this;
  }

  /**
   * Determines if the link is external
   */
  isExternalLink() {
    return this.href.getValue() !== null;
  }
}

results matching ""

    No results matching ""