mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
feat(resource/interface): export notify
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
local contextMenus = {}
|
local contextMenus = {}
|
||||||
|
|
||||||
local function showContext(id)
|
function lib.showContext(id)
|
||||||
local data = contextMenus[id]
|
local data = contextMenus[id]
|
||||||
SetNuiFocus(true, true)
|
SetNuiFocus(true, true)
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
@@ -13,7 +13,7 @@ local function showContext(id)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function registerContext(context)
|
function lib.registerContext(context)
|
||||||
for k, v in pairs(context) do
|
for k, v in pairs(context) do
|
||||||
if type(k) == 'number' then
|
if type(k) == 'number' then
|
||||||
contextMenus[v.id] = v
|
contextMenus[v.id] = v
|
||||||
@@ -25,7 +25,7 @@ local function registerContext(context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
RegisterNUICallback('openContext', function(id)
|
RegisterNUICallback('openContext', function(id)
|
||||||
showContext(id)
|
lib.showContext(id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('clickContext', function(data)
|
RegisterNUICallback('clickContext', function(data)
|
||||||
19
resource/interface/client/notify.lua
Normal file
19
resource/interface/client/notify.lua
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
--[[```lua
|
||||||
|
{
|
||||||
|
id?: string
|
||||||
|
title?: string
|
||||||
|
description: string
|
||||||
|
duration?: number
|
||||||
|
position?: 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left'
|
||||||
|
style?: table
|
||||||
|
icon?: string
|
||||||
|
iconColor?: string
|
||||||
|
}
|
||||||
|
```]]
|
||||||
|
---@param data table
|
||||||
|
function lib.notify(data)
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'customNotify',
|
||||||
|
data = data
|
||||||
|
})
|
||||||
|
end
|
||||||
@@ -28,6 +28,7 @@ interface CustomProps {
|
|||||||
iconColor?: string;
|
iconColor?: string;
|
||||||
position?: ToastPositionWithLogical;
|
position?: ToastPositionWithLogical;
|
||||||
id?: number;
|
id?: number;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
debugData<Props>([
|
debugData<Props>([
|
||||||
@@ -59,23 +60,39 @@ debugData<CustomProps>([
|
|||||||
const Notifications: React.FC = () => {
|
const Notifications: React.FC = () => {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
// todo: figure out icon support
|
|
||||||
useNuiEvent<CustomProps>("customNotify", (data) => {
|
useNuiEvent<CustomProps>("customNotify", (data) => {
|
||||||
if (data.id && toast.isActive(data.id)) return;
|
if (data.id && toast.isActive(data.id)) return;
|
||||||
|
if (!data.icon) {
|
||||||
|
//@ts-expect-error because amazing types
|
||||||
|
data.icon =
|
||||||
|
data.type === "error"
|
||||||
|
? "fa-circle-xmark"
|
||||||
|
: data.type === "success"
|
||||||
|
? "fa-circle-check"
|
||||||
|
: "fa-circle-info";
|
||||||
|
}
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
duration: data.duration || 4000,
|
duration: data.duration || 3000,
|
||||||
position: data.position || "top-right",
|
position: data.position || "top-right",
|
||||||
render: () => (
|
render: () => (
|
||||||
<Box style={data.style} p={3} borderRadius="md" boxShadow="lg">
|
<Box
|
||||||
|
className={`toast-${data.type || "inform"}`}
|
||||||
|
style={data.style}
|
||||||
|
p={2}
|
||||||
|
borderRadius="sm"
|
||||||
|
boxShadow="md"
|
||||||
|
>
|
||||||
<HStack spacing={0}>
|
<HStack spacing={0}>
|
||||||
{data.icon && (
|
{
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
|
//@ts-expect-error because amazing types
|
||||||
icon={data.icon}
|
icon={data.icon}
|
||||||
fontSize="1.4rem"
|
fontSize="1.3em"
|
||||||
style={{ paddingRight: 11 }}
|
style={{ paddingRight: 8 }}
|
||||||
color={data.iconColor}
|
color={data.iconColor}
|
||||||
/>
|
/>
|
||||||
)}
|
}
|
||||||
<Box w="100%">
|
<Box w="100%">
|
||||||
{data.title && <Text as="b">{data.title}</Text>}
|
{data.title && <Text as="b">{data.title}</Text>}
|
||||||
{data.description && <Text>{data.description}</Text>}
|
{data.description && <Text>{data.description}</Text>}
|
||||||
|
|||||||
@@ -50,3 +50,15 @@ code {
|
|||||||
width: 0;
|
width: 0;
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toast-inform {
|
||||||
|
background-color: #2980b9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-success {
|
||||||
|
background-color: #27ae60;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-error {
|
||||||
|
background-color: #c0392b;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user