Skip to content

Commit 434b2bb

Browse files
committed
docs: Added ui components section docs
Changelog: documentation
1 parent 0e207f1 commit 434b2bb

10 files changed

Lines changed: 589 additions & 98 deletions

File tree

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,49 @@
11
# Alert
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
5-
:::
3+
The `alert` component in Acode is a dialog box for displaying messages, warnings, or errors to users within a modal window. Similar to the traditional JavaScript `alert()`.
64

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!
5+
## Usage
86

9-
## Contribute to the Documentation
7+
To use the `alert` component in your Acode plugin, you can require it using the following code:
108

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.
9+
```javascript
10+
const alert = acode.require('alert');
11+
```
1212

13-
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
15-
:::
13+
Once you have the `alert` component, you can create an instance with the following syntax:
1614

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
15+
```js
16+
alert(
17+
'Title of Alert', // Title of the alert modal
18+
'The alert body message..', // Message to display in the body of the alert modal
19+
() => {
20+
// Optional function to call when the alert modal is closed
21+
window.toast('Alert modal closed', 4000);
22+
}
23+
);
24+
```
25+
26+
## Parameters
27+
28+
- **titleText (string):**
29+
- The text to display in the title of the alert modal.
30+
31+
- **message (string):**
32+
- The message to display in the body of the alert modal.
33+
34+
- **onhide (Function):**
35+
- An optional function to call when the alert modal is closed.
36+
37+
## Example
38+
39+
```javascript:line-numbers{1,7}
40+
const alert = acode.require('alert');
41+
42+
const handleOnHide = () => {
43+
window.toast('Alert modal closed', 4000);
44+
};
45+
46+
alert('Title of Alert', 'The alert body message..', handleOnHide);
47+
```
48+
49+
In this example, when the alert modal is closed, the `handleOnHide` function will be called, and a toast message **'Alert modal closed'** will be displayed for 4000 milliseconds. This allows you to perform additional actions or provide feedback when the user interacts with the alert dialog.
Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
# Color Picker
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
5-
:::
3+
The `colorPicker` dialog box in Acode offers a way for users to choose colors within your plugins. This feature-rich color picker opens a dialog box showcasing a spectrum of color options, providing users with an intuitive and visually pleasing experience.
64

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!
5+
## Usage
86

9-
## Contribute to the Documentation
7+
To integrate the `colorPicker` component into your Acode plugin, you can require it using the following code:
108

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.
9+
```javascript
10+
const colorPicker = acode.require('colorPicker');
11+
```
1212

13-
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
15-
:::
13+
Once you have the `colorPicker` component, you can utilize it by calling the function and passing in the desired default color as a string argument:
1614

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
15+
```javascript
16+
let selectedColor = await colorPicker('#ff0000');
17+
```
18+
19+
In this example, the color picker dialog box will open with the default color set to red (`#ff0000`).
20+
21+
## Parameters
22+
23+
- **`defaultColor (string):`**
24+
- The default color that the color picker will display initially. It should be a string representing a color in hexadecimal format or rgba or hsl.
25+
26+
- **`onhide (Function):`**
27+
- An optional callback function to be called when the color picker dialog box is closed.
28+
29+
## Returns
30+
31+
The `colorPicker` component returns a promise that resolves to a string representing the `selected color`. This color can then be used in your plugin based on user input.
32+
33+
## Example
34+
35+
```javascript:line-numbers{1,3}
36+
const colorPicker = acode.require('colorPicker');
37+
38+
let selectedColor = await colorPicker('#ff0000');
39+
console.log(`Selected Color: ${selectedColor}`);
40+
```
41+
42+
In this example, the `colorPicker` component is used to open a color picker dialog box with the default color set to red. The selected color is then logged to the console, demonstrating how to retrieve and utilize the user's color selection.
Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
# Confirm
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
5-
:::
3+
The `confirm` ui component in Acode is a dialog box for displaying confirmation message modals to users. Whether you're seeking user approval for a critical action or confirming a decision, this component is best suited for this process.
64

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!
5+
## Usage
86

9-
## Contribute to the Documentation
7+
To use the `confirm` component in your Acode plugin, you can require it using the following code:
108

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.
9+
```javascript
10+
const confirm = acode.require('confirm');
11+
```
1212

13-
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
15-
:::
13+
Once you have the `confirm` component, you can create an instance with the following syntax:
1614

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
15+
```javascript
16+
const confirmation = await confirm(
17+
'Warning', // Title of the confirmation message modal
18+
'Are you sure?' // Body of the confirmation message modal
19+
);
20+
```
21+
22+
## Parameters
23+
24+
- **titleText (string):**
25+
- A string representing the title of the confirmation message modal. This title will be displayed at the top of the message modal.
26+
27+
- **message (string):**
28+
- A string representing the body of the confirmation message modal.
29+
30+
## Returns
31+
32+
The `confirm` component returns a promise that resolves to a `boolean` value. The boolean value represents whether the user confirmed or denied the message. A value of `true` represents confirmation, while `false` represents denial.
33+
34+
## Example
35+
36+
```javascript:line-numbers{1,3}
37+
const confirm = acode.require('confirm');
38+
39+
let confirmation = await confirm('Warning', 'Are you sure?');
40+
if (confirmation) {
41+
window.toast('File deleted...', 4000);
42+
} else {
43+
window.toast('File not deleted...', 4000);
44+
}
45+
```
46+
47+
In this example, the `confirm` component is utilized to ask the user if they want to delete a file. If the user confirms, the message "File deleted." will be toasted. If the user denies, the message "File not deleted." will be toasted.
Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,104 @@
11
# Custom Dialog
22

3-
:::warning
4-
**Note:** Work is in progress 🚧
5-
:::
3+
The `dialogBox` API in Acode provides a way to create custom dialog boxes within your plugins. Basically it creates a dialog and gives you the freedom to display whatever you wish.
64

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!
5+
## Getting Started
86

9-
## Contribute to the Documentation
7+
To use the DialogBox ui component in your Acode plugin, you can require it using the following code:
108

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.
9+
```javascript
10+
const DialogBox = acode.require('dialogBox');
11+
```
1212

13-
:::tip
14-
You can suggest changes, add new content, or improve existing sections. Every bit of help is appreciated! 🤗
15-
:::
13+
Once you have the DialogBox component, you can create a new instance with the following syntax:
1614

17-
For more information, see official [Guide](https://acode.app/plugin-docs).
15+
```javascript
16+
const myDialogBox = DialogBox(
17+
'Title', // Title of the dialog box
18+
'<h1>Dialog content</h1>', // Content of the dialog box (HTML supported)
19+
'hideButtonText', // Text for the hide button
20+
'cancelButtonText' // Text for the cancel button
21+
);
22+
```
23+
24+
### Forming a Dialog Box Instance
25+
26+
```javascript
27+
/**
28+
* Dialog Box Instance
29+
* @param {string} titleText - Title text
30+
* @param {string} html - HTML string
31+
* @param {string} [hideButtonText] - Text for hide button
32+
* @param {string} [cancelButtonText] - Text for cancel button
33+
* @returns {PromiseLike} - A promise representing the Dialog Box instance
34+
*/
35+
```
36+
37+
## Methods
38+
39+
### 1. `hide()`
40+
41+
The `hide` method is used to hide the dialog box.
42+
43+
```javascript
44+
myDialogBox.hide();
45+
```
46+
47+
### 2. `wait(time: number)`
48+
49+
The `wait` method disables the OK button for the specified time (in milliseconds).
50+
51+
```javascript
52+
myDialogBox.wait(1000);
53+
```
54+
55+
### 3. `onhide(callback: Function)`
56+
57+
The `onhide` method sets a callback function to be called when the dialog box is hidden.
58+
59+
```javascript
60+
myDialogBox.onhide(() => {
61+
console.log('Dialog box is hidden');
62+
});
63+
```
64+
65+
### 4. `onclick(callback: Function)`
66+
67+
The `onclick` method sets a callback function to be called when the content is clicked.
68+
69+
```javascript
70+
myDialogBox.onclick((e) => {
71+
const target = e.target;
72+
console.log(target, 'is clicked');
73+
});
74+
```
75+
76+
### 5. `then(callback: Function)`
77+
78+
The `then` method sets a callback function to be called when the OK button is clicked.
79+
80+
```javascript
81+
myDialogBox.then(() => {
82+
console.log('OK button is clicked');
83+
});
84+
```
85+
86+
### 6. `ok(callback: Function)`
87+
88+
The `ok` method sets a callback function to be called when the OK button is clicked.
89+
90+
```javascript
91+
myDialogBox.ok(() => {
92+
console.log('OK button is clicked');
93+
});
94+
```
95+
96+
### 7. `cancel(callback: Function)`
97+
98+
The `cancel` method sets a callback function to be called when the Cancel button is clicked.
99+
100+
```javascript
101+
myDialogBox.cancel(() => {
102+
console.log('Cancel button is clicked');
103+
});
104+
```
Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,101 @@
11
# Loader
22

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()`
610

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.
812

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.
1022

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.
1223

1324
:::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()`.
1552
:::
1653

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

Comments
 (0)