src/inline-loading/inline-loading.component.ts
Get started with importing the module:
Example :import { InlineLoadingModule } from 'carbon-components-angular';| selector | cds-inline-loading, ibm-inline-loading |
| template | |
Properties |
Inputs |
Outputs |
HostBindings |
Accessors |
| errorText | |
Type : string
|
|
|
Specify the text description for the error state. |
|
| iconDescription | |
Type : string
|
|
|
Accessible description applied to the loading/success/error SVG. |
|
| isActive | |
Type : boolean
|
|
|
set to |
|
| loadingText | |
Type : string
|
|
|
Specify the text description for the loading state. |
|
| state | |
Type : InlineLoadingState | string
|
|
Default value : InlineLoadingState.Active
|
|
|
Specify the text description for the loading state. |
|
| success | |
Type : boolean
|
|
|
Returns value |
|
| successDelay | |
Type : number
|
|
Default value : 1500
|
|
|
Provide a delay for the |
|
| successText | |
Type : string
|
|
|
Specify the text description for the success state. |
|
| onSuccess | |
Type : EventEmitter<any>
|
|
|
Emits event after the success state is active |
|
| attr.aria-live |
Type : string | null
|
|
|
| class.cds--inline-loading |
Type : boolean
|
Default value : true
|
| InlineLoadingState |
Default value : InlineLoadingState
|
| loadingClass |
Default value : true
|
Decorators :
@HostBinding('class.cds--inline-loading')
|
| hostAriaLive |
gethostAriaLive()
|
|
Returns :
string | null
|
| isActive | ||||||
getisActive()
|
||||||
|
set to |
||||||
setisActive(active: boolean)
|
||||||
|
Parameters :
Returns :
void
|
| success | ||||||
getsuccess()
|
||||||
|
Returns value |
||||||
setsuccess(success: boolean)
|
||||||
|
Set the component's state to match the parameter and emits onSuccess if it exits.
Parameters :
Returns :
void
|
import {
Component,
Input,
Output,
EventEmitter,
HostBinding
} from "@angular/core";
export enum InlineLoadingState {
/** It hides the whole component. */
Hidden = "hidden",
/** It shows the `loadingText` but no loading animation. */
Inactive = "inactive",
/** It shows the `loadingText` with loading animation. */
Active = "active",
/** It shows the `successText` with a success state. */
Finished = "finished",
/** It shows the `errorText` with an error state. */
Error = "error"
}
/**
* Get started with importing the module:
*
* ```typescript
* import { InlineLoadingModule } from 'carbon-components-angular';
* ```
*
* [See demo](../../?path=/story/components-inline-loading--basic)
*/
@Component({
selector: "cds-inline-loading, ibm-inline-loading",
template: `
<div *ngIf="state !== InlineLoadingState.Hidden"
class="cds--inline-loading__animation">
<div
*ngIf="state === InlineLoadingState.Inactive || state === InlineLoadingState.Active"
class="cds--loading cds--loading--small"
[ngClass]="{
'cds--loading--stop': state === InlineLoadingState.Inactive
}">
<svg class="cds--loading__svg" viewBox="0 0 100 100">
<title *ngIf="iconDescription">{{iconDescription}}</title>
<circle class="cds--loading__background" cx="50%" cy="50%" r="44" />
<circle class="cds--loading__stroke" cx="50%" cy="50%" r="44" />
</svg>
</div>
<svg
*ngIf="state === InlineLoadingState.Finished"
cdsIcon="checkmark--filled"
size="16"
class="cds--inline-loading__checkmark-container"
[attr.title]="iconDescription || null">
</svg>
<svg
*ngIf="state === InlineLoadingState.Error"
cdsIcon="error--filled"
size="16"
class="cds--inline-loading--error"
[attr.title]="iconDescription || null">
</svg>
</div>
<p
*ngIf="state === InlineLoadingState.Inactive || state === InlineLoadingState.Active"
class="cds--inline-loading__text">{{loadingText}}</p>
<p *ngIf="state === InlineLoadingState.Finished" class="cds--inline-loading__text">{{successText}}</p>
<p *ngIf="state === InlineLoadingState.Error" class="cds--inline-loading__text">{{errorText}}</p>
`
})
export class InlineLoading {
InlineLoadingState = InlineLoadingState;
/**
* Specify the text description for the loading state.
*/
@Input() state: InlineLoadingState | string = InlineLoadingState.Active;
/**
* Specify the text description for the loading state.
*/
@Input() loadingText: string;
/**
* Specify the text description for the success state.
*/
@Input() successText: string;
/**
* Provide a delay for the `setTimeout` for success.
*/
@Input() successDelay = 1500;
/**
* Specify the text description for the error state.
*/
@Input() errorText: string;
/**
* Accessible description applied to the loading/success/error SVG.
*/
@Input() iconDescription: string;
/**
* `aria-live` value applied to the host based on `state` (`'off'` for inactive states, `'assertive'`
* otherwise).
*/
@HostBinding("attr.aria-live") get hostAriaLive(): string | null {
if (this.state === InlineLoadingState.Hidden) {
return null;
}
return this.state === InlineLoadingState.Inactive ? "off" : "assertive";
}
/**
* set to `false` to stop the loading animation
*/
@Input() get isActive() {
return this.state === InlineLoadingState.Active;
}
set isActive(active: boolean) {
this.state = active ? InlineLoadingState.Active : InlineLoadingState.Inactive;
}
/**
* Returns value `true` if the component is in the success state.
*/
@Input() get success() {
return this.state === InlineLoadingState.Finished;
}
/**
* Set the component's state to match the parameter and emits onSuccess if it exits.
*/
set success(success: boolean) {
this.state = success ? InlineLoadingState.Finished : InlineLoadingState.Error;
if (this.state === InlineLoadingState.Finished) {
setTimeout(() => {
this.onSuccess.emit();
}, this.successDelay);
}
}
/**
* Emits event after the success state is active
*/
@Output() onSuccess: EventEmitter<any> = new EventEmitter();
@HostBinding("class.cds--inline-loading") loadingClass = true;
}