mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 14:38:50 +00:00
wip js/ts examples
This commit is contained in:
1 parent
3aee4976c3
commit
d44c42104e
7 files changed
+602
-163
No files matched your search
@@ -10,34 +10,57 @@ by setting input fields.
|
||||
|
||||
### lib.inputDialog
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- heading: string
|
||||
-- rows: strings array or table
|
||||
-- type: "input" or "number" or "checkbox" or "select" or "slider"
|
||||
-- label: string
|
||||
-- options: table array (optional - used ONLY with "select" type)
|
||||
-- value: string
|
||||
-- label: string
|
||||
-- default: string (optional - any of the values)
|
||||
-- password: boolean (optional - used ONLY with "input" type)
|
||||
-- icon: string (optional - used ONLY with "input" type)
|
||||
-- placeholder: string (optional - used ONLY with "input" or "number" type)
|
||||
-- default: string or number (optional)
|
||||
-- checked: boolean (optional - used ONLY with "checkbox" type)
|
||||
-- min: number (optional - used ONLY with "slider" type)
|
||||
-- max: number (optional - used ONLY with "slider" type)
|
||||
-- step: number (optional - used ONLY with "slider" type)
|
||||
lib.inputDialog(heading, rows)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.inputDialog(heading, rows)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* heading: `string`
|
||||
* rows: `string[]` or `table` (`array`)
|
||||
* type: `'input'` or `'number'` or `'checkbox'` or `'select'` or `'slider'`
|
||||
* label: `string`
|
||||
* options?: `table` (`array`)
|
||||
* [ Only used with `'select'` type ]
|
||||
* value: `string`
|
||||
* label: `string`
|
||||
* default?: `string`
|
||||
* password?: `boolean`
|
||||
* Hides input characters with ability to toggle them on. Used only with `'input'` type.
|
||||
* icon?: `string`
|
||||
* Used only with `'input'` and `'number'` types.
|
||||
* placeholder?: `string`
|
||||
* Used only with `'input'` and `'number'` types.
|
||||
* default?: `string` or `number`
|
||||
* Default value for the field.
|
||||
* checked?: `boolean`
|
||||
* Whether the checkbox should be checked by default. Used only with `'checkbox'` type.
|
||||
* min?: `number`
|
||||
* Used only with `'slider'` and `'number'` types.
|
||||
* max?: `number`
|
||||
* Used only with `'slider'` and `'number'` types.
|
||||
* step?: `number`
|
||||
* Amount of change per slider step. Used only with `'slider'` type.
|
||||
|
||||
The callback data is promise based meaning that the thread will
|
||||
not continue executing until the user either sends the data
|
||||
or exits the popup.
|
||||
|
||||
The data returned will be a table, indexes represent the rows
|
||||
The data returned will be a table (array), indexes represent the rows
|
||||
sent to the dialog, so if we want data from the first field that
|
||||
would be index `1`, if we want data from the third field, that would
|
||||
be index `3`, etc...
|
||||
would be index `1` (`0`), if we want data from the third field, that would
|
||||
be index `3` (`2`), etc...
|
||||
|
||||
The standard input rows will always return a string, if you want a row to be of
|
||||
number data type, you can use set the `type` to `number`.
|
||||
@@ -49,31 +72,56 @@ Look at the *Advanced* example for it's usage.
|
||||
|
||||
:::caution
|
||||
|
||||
When using the advanced method you can define `icon` and `password` **ONLY** with type `"input"` and
|
||||
you can define `options` **ONLY** with type `"select"`.
|
||||
When using the advanced method you can define `icon` and `password` **ONLY** with type `'input'` and `'number'` and
|
||||
you can define `options` **ONLY** with type `'select'`.
|
||||
|
||||
|
||||
Doing so otherwise ***will*** result in errors.
|
||||
:::
|
||||
|
||||
**Example:**
|
||||
## Usage Example
|
||||
|
||||
### Basic
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="basic" label="Basic">
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'})
|
||||
|
||||
if input then
|
||||
local lockerNumber = tonumber(input[1])
|
||||
local lockerPasscode = input[2]
|
||||
if not input then return end
|
||||
local lockerNumber = tonumber(input[1])
|
||||
local lockerPasscode = input[2]
|
||||
|
||||
print(lockerNumber, lockerPasscode)
|
||||
end
|
||||
print(lockerNumber, lockerPasscode)
|
||||
```
|
||||

|
||||
</TabItem>
|
||||
<TabItem value='advanced' label='Advanced'>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
:::caution
|
||||
|
||||
This function is **asynchronous** requiring you to do a `.then` callback on the promise or make your function `async`.
|
||||
:::
|
||||
|
||||
|
||||
```ts
|
||||
const input = await lib.inputDialog('Police locker', ['Locker number', 'Locker passcode'])
|
||||
|
||||
if (!input) return
|
||||
const lockerNumber = input[0] as number
|
||||
const lockerPasscode = input[1] as number
|
||||
|
||||
console.log(lockerNumber, lockerPasscode)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||

|
||||
|
||||
### Advanced
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="Lua">
|
||||
|
||||
```lua
|
||||
local input = lib.inputDialog('Police locker', {
|
||||
@@ -90,6 +138,31 @@ local input = lib.inputDialog('Police locker', {
|
||||
})
|
||||
print(json.encode(input, {indent=true}))
|
||||
```
|
||||
 
|
||||
</TabItem>
|
||||
<TabItem value="JS/TS">
|
||||
|
||||
:::caution
|
||||
|
||||
This function is **asynchronous** requiring you to do a `.then` callback on the promise or make your function `async`.
|
||||
:::
|
||||
|
||||
```ts
|
||||
const input = await lib.inputDialog('Police locker', [
|
||||
{ type: 'input', label: 'Locker number', placeholder: '123' },
|
||||
{ type: 'checkbox', label: 'Some checkbox' },
|
||||
{ type: 'input', label: 'Locker PIN', password: true, icon: 'lock' },
|
||||
{ type: 'checkbox', label: 'Some other checkbox', checked: true },
|
||||
{ type: 'select', label: 'Value select', options: [
|
||||
{ value: 'option1', label: 'Option 1' },
|
||||
{ value: 'option2', label: 'Option 2' },
|
||||
{ value: 'option3', label: 'Option 3' },
|
||||
]},
|
||||
{ type: 'number', label: 'Number counter', default: 12 },
|
||||
]);
|
||||
|
||||
console.log(JSON.stringify(input, null, 2));
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
 
|
||||
Reference in new issue
Block a user