projects/core/src/lib/action-anchor/action-anchor.ts
ActionAnchor
used to create basic link
const button = new ActionAnchor({ title: 'Test', link: 'https://...' });
Or
const button = actionFactory.createButton({ title: 'Test', link: 'https://...' });
Or
const button = actionFactory.createButton().setTitle('Test');
Properties |
Methods |
constructor(options: ActionAnchorOptions, component?: Type<ActionAnchorComponentImpl>)
|
||||||||||||
Public
Parameters :
|
Readonly changes$ |
Type : Observable<ActionAnchorOptions>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:48
|
|
Readonly fire$ |
Default value : EMPTY
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:43
|
|
Readonly href$ |
Type : Observable<string | null>
|
|
Readonly routerLink$ |
Type : Observable<UrlTree | string | | null>
|
|
Readonly target$ |
Type : Observable<AnchorTarget | null>
|
|
Readonly ariaLabel$ |
Type : Observable<string>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:124
|
|
Readonly disabled$ |
Type : Observable<boolean>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:115
|
|
Readonly icon$ |
Type : Observable<string>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:106
|
|
Readonly state$ |
Type : Observable<ActionState>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:120
|
|
Readonly title$ |
Type : Observable<string>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:102
|
|
Readonly visible$ |
Type : Observable<boolean>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:111
|
|
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 :
Returns :
this
|
setTarget | ||||||
setTarget(target: AnchorTarget)
|
||||||
Set the target for the anchor element
Parameters :
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 |
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
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
Returns :
ActionGroup | undefined
|
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
Returns :
boolean
|
isDestroyed |
isDestroyed()
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:321
|
Returns boolean defining whether action has state
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
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 :
|
setIcon | ||||||||
setIcon(icon: string)
|
||||||||
Inherited from
ActionAbstract
|
||||||||
Defined in
ActionAbstract:364
|
||||||||
Will set the new icon and notify all icon subscriptions
Parameters :
|
setTitle | ||||||||
setTitle(title: string)
|
||||||||
Inherited from
ActionAbstract
|
||||||||
Defined in
ActionAbstract:330
|
||||||||
Will set the new title and notify all title subscriptions
Parameters :
|
setVisibility | ||||||||
setVisibility(visibility: boolean)
|
||||||||
Inherited from
ActionAbstract
|
||||||||
Defined in
ActionAbstract:397
|
||||||||
Will show or hide the action depending from the provided visibility boolean
Parameters :
|
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;
}
}