Files
ox_lib/resource/interface/client/input.lua
Linden fb2225e373 chore: add copyright notices to each file
Some people accidentally, mistakenly, and without any malicious intent forget to attribute code from this resource to its source. This change will hopefully assist people, so that they do not make that mistake again.
2025-03-18 18:46:09 +11:00

86 lines
2.1 KiB
Lua

--[[
https://github.com/overextended/ox_lib
This file is licensed under LGPL-3.0 or higher <https://www.gnu.org/licenses/lgpl-3.0.en.html>
Copyright (c) 2025 Linden <https://github.com/thelindat/fivem>
]]
local input
---@class InputDialogRowProps
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider' | 'multi-select' | 'date' | 'date-range' | 'time' | 'textarea' | 'color'
---@field label string
---@field options? { value: string, label: string, default?: string }[]
---@field password? boolean
---@field icon? string | {[1]: IconProp, [2]: string};
---@field iconColor? string
---@field placeholder? string
---@field default? string | number
---@field disabled? boolean
---@field checked? boolean
---@field min? number
---@field max? number
---@field step? number
---@field autosize? boolean
---@field required? boolean
---@field format? string
---@field returnString? boolean
---@field clearable? boolean
---@field searchable? boolean
---@field description? string
---@field maxSelectedValues? number
---@class InputDialogOptionsProps
---@field allowCancel? boolean
---@param heading string
---@param rows string[] | InputDialogRowProps[]
---@param options InputDialogOptionsProps[]?
---@return string[] | number[] | boolean[] | nil
function lib.inputDialog(heading, rows, options)
if input then return end
input = promise.new()
-- Backwards compat with string tables
for i = 1, #rows do
if type(rows[i]) == 'string' then
rows[i] = { type = 'input', label = rows[i] --[[@as string]] }
end
end
lib.setNuiFocus(false)
SendNUIMessage({
action = 'openDialog',
data = {
heading = heading,
rows = rows,
options = options
}
})
return Citizen.Await(input)
end
function lib.closeInputDialog()
if not input then return end
lib.resetNuiFocus()
SendNUIMessage({
action = 'closeInputDialog'
})
input:resolve(nil)
input = nil
end
RegisterNUICallback('inputData', function(data, cb)
cb(1)
lib.resetNuiFocus()
local promise = input
input = nil
promise:resolve(data)
end)