projects/core/src/lib/action-button/action-button.ts
ActionButton
used to create basic button action
const button = new ActionButton({ title: 'Test' });
Or
const button = actionFactory.createButton({ title: 'Test' });
Or
const button = actionFactory.createButton().setTitle('Test');
Properties |
Methods |
constructor(options: ActionButtonOptions, component?: Type<ActionButtonComponentImpl>)
|
||||||||||||
Public
Parameters :
|
Readonly changes$ |
Type : Observable<ActionButtonOptions>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:47
|
|
Readonly fire$ |
Type : Observable<ActionButtonEvent>
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:42
|
|
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
|
|
trigger |
trigger()
|
Inherited from
ActionAbstract
|
Defined in
ActionAbstract:91
|
Will trigger Example:
|
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 |
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
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 { 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;
}
}