Skip to content

Commit 5679898

Browse files
committed
feat: add ActivityState component with state management and usage documentation
1 parent 37093e9 commit 5679898

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

app/tab-sheet/tab-sheet.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<div id="tab1">Tab 1 content</div>
88
<div id="tab2">Tab 2 content</div>
99
<div id="tab3">Tab 3 content</div>
10+
11+
<button slot="suffix">Do Something</button>
12+
<button slot="suffix">Do</button>
1013
</tab-sheet>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ActivityState Component
2+
3+
The `ActivityState` component is a custom HTML element that represents the state of an activity. It can display different states such as `busy`, `success`, and `error`.
4+
5+
## Usage
6+
7+
### Importing the Component
8+
9+
To use the `ActivityState` component, you need to import it into your project:
10+
11+
```javascript
12+
import './components/activity-state/activity-state.js';
13+
```
14+
15+
### Adding the Component to Your HTML
16+
17+
You can add the `ActivityState` component to your HTML as follows:
18+
19+
```html
20+
<activity-state></activity-state>
21+
```
22+
23+
### Setting the State
24+
25+
You can set the state of the `ActivityState` component using JavaScript:
26+
27+
```javascript
28+
const activityStateElement = document.querySelector('activity-state');
29+
activityStateElement.setState('busy'); // Sets the state to 'busy'
30+
activityStateElement.setState('success'); // Sets the state to 'success'
31+
activityStateElement.setState('error'); // Sets the state to 'error'
32+
```
33+
34+
## States
35+
36+
The `ActivityState` component supports the following states:
37+
38+
- `busy`: Indicates that the activity is in progress.
39+
- `success`: Indicates that the activity was successful.
40+
- `error`: Indicates that there was an error in the activity.
41+
42+
## Example
43+
44+
Here is a complete example of how to use the `ActivityState` component:
45+
46+
```html
47+
<!DOCTYPE html>
48+
<html lang="en">
49+
<head>
50+
<meta charset="UTF-8">
51+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
52+
<title>ActivityState Example</title>
53+
<script type="module" src="./components/activity-state/activity-state.js"></script>
54+
</head>
55+
<body>
56+
<activity-state id="activityState"></activity-state>
57+
58+
<script>
59+
const activityStateElement = document.getElementById('activityState');
60+
61+
// Set the state to 'busy'
62+
activityStateElement.setState('busy');
63+
64+
// Simulate an activity completion
65+
setTimeout(() => {
66+
activityStateElement.setState('success');
67+
}, 3000);
68+
</script>
69+
</body>
70+
</html>
71+
```
72+
73+
In this example, the `ActivityState` component is initially set to the `busy` state. After 3 seconds, the state is changed to `success`.

components/activity-state/activity-state.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { ComponentModule } from "../../src/modules/component.js";
22
import { HTML } from "./activity-state.html.js";
33

4+
/**
5+
* Class representing the activity state component.
6+
* @extends HTMLElement
7+
*/
48
class ActivityState extends HTMLElement {
59
static name = Object.freeze("activity-state");
610

@@ -12,12 +16,19 @@ class ActivityState extends HTMLElement {
1216
this.shadowRoot.innerHTML = HTML;
1317
}
1418

19+
/**
20+
* Called when the element is connected to the document's DOM.
21+
*/
1522
async connectedCallback() {
1623
if (this.#state) {
1724
this.setState(this.#state);
1825
}
1926
}
2027

28+
/**
29+
* Sets the state of the activity.
30+
* @param {string} state - The state to set ('busy', 'success', 'error').
31+
*/
2132
setState(state) {
2233
const materialIcon = this.shadowRoot.querySelector("material-icon");
2334

0 commit comments

Comments
 (0)