|
| 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`. |
0 commit comments