-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reactive-controller): new pending state controller (#4605)
* feat: added a pending state controller --------- Co-authored-by: TaraT <ttomar@adobe.com> Co-authored-by: Rajdeep Chandra <rajrock38@gmail.com> Co-authored-by: Rúben Carvalho <rubcar@sapo.pt>
- Loading branch information
1 parent
685d764
commit 68baf94
Showing
9 changed files
with
404 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
## Description | ||
|
||
The `PendingStateController` is a class that helps manage the pending state of a reactive element. It provides a standardized way to indicate when an element is in a pending state, such as during an asynchronous operation. | ||
When the components is in a pending state it supplies the pending state UI `sp-progress-circle` which gets rendered in the component. | ||
It also updates the value of ARIA label of the host element to its pending-label based on the pending state. | ||
|
||
The `HostWithPendingState` interface defines the properties that a host element must implement to work with the `PendingStateController`. | ||
|
||
## Usage | ||
|
||
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/reactive-controllers?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/reactive-controllers) | ||
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/reactive-controllers?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/reactive-controllers) | ||
|
||
``` | ||
yarn add @spectrum-web-components/reactive-controllers | ||
``` | ||
|
||
Import the `PendingStateController` via: | ||
|
||
``` | ||
import { PendingStateController } from '@spectrum-web-components/reactive-controllers/src/PendingState.js'; | ||
``` | ||
|
||
## Example | ||
|
||
```js | ||
import { LitElement } from 'lit'; | ||
import { PendingStateController } from '@spectrum-web-components/reactive-controllers/src/PendingState.js'; | ||
class Host extends LitElement{ | ||
|
||
/** Whether the items are currently loading. */ | ||
@property({ type: Boolean, reflect: true }) | ||
public pending = false; | ||
|
||
/** Defines a string value that labels the Picker while it is in pending state. */ | ||
@property({ type: String, attribute: 'pending-label' }) | ||
public pendingLabel = 'Pending'; | ||
public pendingStateController: PendingStateController<this>; | ||
|
||
/** | ||
* Initializes the `PendingStateController` for the Picker component. | ||
* The `PendingStateController` manages the pending state of the Component. | ||
*/ | ||
constructor() { | ||
super(); | ||
this.pendingStateController = new PendingStateController(this); | ||
} | ||
render(){ | ||
return html` | ||
<host-element></host-element> | ||
${when( | ||
this.pending, | ||
() => { | ||
return this.pendingStateController.renderPendingState(); | ||
} | ||
)} | ||
` | ||
} | ||
|
||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.