JCKSDocs
JCKS LibFunkcje

Panels

Build a complete admin window from a Lua table, with sidebar, pages, charts, tables, forms and live updates.

A panel is a full admin style window described as a Lua table: sidebar, pages, stat cards, charts, tables, forms, profiles and more. It looks like the JCKS Jobs and Vehicles admin windows and follows the server theme. No React, no NUI code and no build step are needed.

examples/panel_demo.lua in jcks_lib is a complete panel with every block type. Add it to your own resource as a client_script and run /mypanel.

Minimal panel

lua
RegisterCommand('mypanel', function()
    UI.OpenPanel({
        id = 'my_panel',
        title = 'Los Santos Customs',
        subtitle = 'Workshop',
        icon = 'wrench', color = '#FF9F0A',
        nav = {
            { section = 'Overview' },
            { id = 'home', label = 'Dashboard', icon = 'grid' },
            { id = 'orders', label = 'Orders', icon = 'receipt', count = 3 },
        },
        pages = {
            home = {
                title = 'Today',
                blocks = {
                    { type = 'stats', items = {
                        { label = 'Orders', value = 12, icon = 'receipt' },
                        { label = 'Revenue', value = 48200, format = 'money', trend = 8 },
                    } },
                },
            },
        },
        onNavigate = function(pageId)
            if pageId == 'orders' then
                local orders = jcks.callback.await('myshop:orders', 5000)
                return { title = 'Orders', blocks = { { type = 'table', columns = { { key = 'id', label = 'Order' } }, rows = orders or {} } } }
            end
        end,
    })
end, false)

Panel options

Key What it does
id Unique id. Required for RegisterPanel, optional for OpenPanel
title, subtitle Text in the sidebar
icon, color Logo icon and colour. Without them the JCKS logo is shown.
size sm, md, lg (default) or xl
search Sidebar search with Ctrl + K, default true
nav Sidebar items
footer Items pinned to the bottom of the sidebar
page Start page, default the first nav item
pages { [pageId] = page } known up front
onNavigate(pageId, ctx) Returns a page for ids missing from pages. It may yield, a skeleton shows meanwhile.
onAction(id, value, ctx) Catches clicks, changes and submits of elements without their own handler
onOpen(ctx), onClose(ctx) Lifecycle hooks
closable false keeps Esc and the X button from closing the panel
clear true removes the dimmed backdrop
lua
nav = {
    { section = 'Overview' },
    { id = 'dashboard', label = 'Dashboard', icon = 'grid' },
    { id = 'employees', label = 'Employees', icon = 'users', count = 23 },
    { id = 'alerts', label = 'Alerts', icon = 'bell', count = '!', alert = true },
    { section = 'Jobs', filter = 'Filter jobs' },
    { id = 'job:police', label = 'Los Santos Police', icon = 'shield', color = '#0A84FF', count = 6 },
    { id = 'logout', label = 'Log out', icon = 'right-from-bracket', onClick = function() end },
    { id = 'x', label = 'Alias', page = 'dashboard' },
}

section is a heading, filter adds a filter box for the items below it. With color the icon becomes a coloured tile, without it a line icon. onClick runs code instead of opening a page, page opens another page id.

Page

lua
{
    title = 'Employees',
    subtitle = '23 people',
    actions = {
        { id = 'hire', label = 'Hire', icon = 'user-plus', onClick = function() end },
        { id = 'export', label = 'Export', variant = 'secondary' },
    },
    blocks = {},
}

Blocks

Every block is { type = '...', ... }. Give an id to any block or item you want to change live with UpdatePanel. Ids only need to be unique within a page. Any item can carry its own onClick, onChange, onSubmit or onRow. Items with page = 'x' open that page. Add confirm = 'Text?' or confirm = { title, message, destructive } to any button or action to ask first.

Type What it shows Main fields
stats Stat cards with count up columns, items = { { label, value, icon, color, format, suffix, trend, spark, foot, page } }
chart Charts variant (bars default, line, area, donut, hbar), data, series for several lines, center and centerLabel for donut, title, format, height
gauge One value against a maximum value, max, format, label, color
heatmap Grid of values rows, columns (number or labels), values[row][column]
ranking Most active list or leaderboard items, numbered = true adds crowns for the top three
feed Activity feed items = { { icon, color, title, description, badge, time } }, action. A number in time is a unix timestamp.
list Rows with a switch, value, badge or button on the right items
table Sortable table with search and paging columns = { { key, label, format, align, mono, sortable } }, rows, pageSize, search, empty, onRow, actions
form Form with validation fields, columns, submit, submitIcon, reset, cancel, onSubmit(values, ctx)
settings Instant settings, each change is sent at once (text, number and slider debounced) items = { { id, type, label, value, onChange } }
progress Progress bars items = { { label, value, max, color, display } }
details Label and value pairs items = { { label, value, copy, mono, format, badge } }
timeline Steps items = { { title, description, time, done, active, icon } }
profile Person card name, subtitle, avatar, color, badges, stats, actions
cards Card grid columns, items = { { icon, image, title, description, badge, footer, onClick } }
buttons Button row align, items with variant
callout Notice with markdown tone, title, text, action
text Markdown text title, text
empty Empty state icon, title, text, action
divider Line
row Blocks side by side columns = { 1.5, 1 }, blocks
section Titled group title, description, action, blocks
tabs Tabs tabs = { { id, label, blocks } }

Table columns take every format below plus avatar, badge, bool, icon and ago. A table shows its search box past five rows and pages past pageSize. Form field types: text (default), select, segmented, number, slider, color, date, time, switch, checkbox, password, textarea (wide = true spans the row). Required fields are checked before onSubmit runs, and the submit button spins until the handler returns.

Tones are info, success, warning and danger. Button variants are primary, secondary, danger and plain.

Live updates

lua
UI.UpdatePanel('my_panel', 'online', { value = 71 })
UI.UpdatePanel('my_panel', 'staff', { rows = newRows })
UI.UpdatePanelNav('my_panel', 'orders', { count = 5, alert = true })
UI.SetPanelPage('my_panel', 'home', buildHome())
UI.ShowPanelPage('orders')
UI.ClosePanel()
local panelId, pageId = UI.GetOpenPanel()

A handler can also return what happens next:

lua
onClick = function(value, ctx)
    return {
        notify = { title = 'Saved', type = 'success' },
        update = { online = { value = 72 } },
        page = 'home',
        content = buildPage(),
        nav = newNav,
        close = true,
    }
end

ctx holds { panel, page, element }, plus row and action for table rows and their actions, and nav for sidebar items with onClick.

Formats

The format option on stats, charts, table columns, details, progress, gauges and ranking values:

Format 1234.5 shows as
none or number 1,234.5
money $1,235
compact $1,235, from 10,000 on shortened: $12.3K, $4.5M
percent 1,235%, pass 0 to 100
duration seconds as 20 min, from one hour on 1 h 5 min
hours seconds as 0.3 h
date, datetime unix timestamp as a date

Good to know

  • Panels run on the client. Anything that changes money, jobs or items must be checked again on the server, like any other NUI.
  • A closed panel costs nothing. While it is open only your own code runs, and every update carries only the changed block.
  • Pages from pages open at once. onNavigate pages show a skeleton while your callback runs.
  • When your resource stops, its panels close and are unregistered.