|
1 | 1 | # Loader |
2 | 2 |
|
3 | | -:::warning |
4 | | -**Note:** Work is in progress 🚧 |
5 | | -::: |
| 3 | +The `loader` ui component in Acode is utility that help you to display loading dialogs with customizable titles and messages. These loading dialogs offer an informative and engaging experience for users while waiting for various processes to complete. The component also provides options for setting timeouts and callback functions for handling loading process cancellations. |
| 4 | + |
| 5 | +## Methods and Usage |
| 6 | + |
| 7 | +The `loader` component offers a variety of methods to control and manage the loading dialog: |
| 8 | + |
| 9 | +### `showTitleLoader()` |
6 | 10 |
|
7 | | -We are currently working on this section to provide you with detailed and comprehensive information about how Acode plugins work. Please check back soon for updates! |
| 11 | +- **Usage:** Shows the title loader. |
8 | 12 |
|
9 | | -## Contribute to the Documentation |
| 13 | +- **Parameters:** |
| 14 | + - `immortal {boolean}` If true, the loader will not be removed automatically |
| 15 | + |
| 16 | +### `removeTitleLoader()` |
| 17 | + |
| 18 | +- **Usage:** Hides the title loader. |
| 19 | + |
| 20 | +- **Parameters:** |
| 21 | + - `immortal {boolean}` If not true, the loader will not remove when immortal was true when it was created. |
10 | 22 |
|
11 | | -We welcome contributions from the community! If you would like to help improve this documentation, please visit our [GitHub repository](https://github.com/bajrangCoder/acode-plugin-docs) and follow the contribution guidelines. |
12 | 23 |
|
13 | 24 | :::tip |
14 | | -You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗 |
| 25 | +`showTitleLoader()` & `removeTitleLoader()` are loader methods to create and destroy a small spinner from title. Its good while opening any file in editor or working inside editor |
| 26 | +::: |
| 27 | + |
| 28 | +### `create(options: LoaderOptions)` |
| 29 | + |
| 30 | +- **Usage:** Creates a new loading dialog with the specified options. |
| 31 | +- **Parameters:** |
| 32 | + - `titleText (string)`: The title text to display on the loading dialog. |
| 33 | + - `message (string)`: The message to display on the loading dialog. |
| 34 | + - `cancel (object)`: An object containing the following properties: |
| 35 | + - `timeout (number)`: The time (in milliseconds) after which the loading process will automatically be cancelled. |
| 36 | + - `callback (Function)`: A function that will be called when the loading process is cancelled. |
| 37 | + |
| 38 | +### `destroy()` |
| 39 | + |
| 40 | +- **Usage:** Removes the loading dialog from the DOM permanently. |
| 41 | + |
| 42 | +### `hide()` |
| 43 | + |
| 44 | +- **Usage:** Hides the loading dialog temporarily. The dialog can be restored using the `show()` method. |
| 45 | + |
| 46 | +### `show()` |
| 47 | + |
| 48 | +- **Usage:** Shows a previously hidden loading dialog. |
| 49 | + |
| 50 | +:::info |
| 51 | +The `create()` method should be called before using other methods except `showTitleLoader()` & `removeTitleLoader()`. |
15 | 52 | ::: |
16 | 53 |
|
17 | | -For more information, see official [Guide](https://acode.app/plugin-docs). |
| 54 | +## Example |
| 55 | + |
| 56 | +```javascript:line-numbers{1,4-7,11,16,21,25,29} |
| 57 | +const loader = acode.require("loader"); |
| 58 | +
|
| 59 | +// Create the loader with specified options |
| 60 | +loader.create("Title Text", "Message...", { |
| 61 | + timeout: 5000, |
| 62 | + callback: () => window.toast("Loading cancelled", 4000), |
| 63 | +}); |
| 64 | +
|
| 65 | +// Hide the loader after 2 seconds |
| 66 | +setTimeout(() => { |
| 67 | + loader.hide(); |
| 68 | +}, 2000); |
| 69 | +
|
| 70 | +// Show the loader after 4 seconds |
| 71 | +setTimeout(() => { |
| 72 | + loader.show(); |
| 73 | +}, 4000); |
| 74 | +
|
| 75 | +// Destroy the loader after 6 seconds |
| 76 | +setTimeout(() => { |
| 77 | + loader.destroy(); |
| 78 | +}, 6000); |
| 79 | +
|
| 80 | +// example of `showTitleLoader()` & `removeTitleLoader()` |
| 81 | +loader.showTitleLoader(); |
| 82 | +
|
| 83 | +// remove the title loader after 4 seconds |
| 84 | +setTimeout(() => { |
| 85 | + loader.removeTitleLoader(); |
| 86 | +}, 4000); |
| 87 | +``` |
| 88 | + |
| 89 | +In this example, the `create()` method is called with the specified options to create a loading dialog. The loader is then hidden after 2 seconds, shown after 4 seconds, and finally destroyed after 6 seconds. |
| 90 | + |
| 91 | +:::tip |
| 92 | + |
| 93 | +- Use the `loader` component to provide informative loading dialogs during time-consuming operations. |
| 94 | +- Utilize the `timeout` and `callback` options to handle cancellations gracefully. |
| 95 | +- Show and hide the loader as needed to keep users informed about the process. |
| 96 | + ::: |
| 97 | + |
| 98 | +:::danger |
| 99 | + |
| 100 | +- Be cautious with long timeouts, as it may affect the user experience. |
| 101 | + ::: |
0 commit comments