Files
metabuilder/packages/dashboard/seed/scripts/stats.lua
JohnDoe6345789 bf1401fe34 Enhance module definitions and add type annotations across various packages
- Added type annotations and class definitions in the dashboard layout, stats, and data table modules for improved type safety and documentation.
- Introduced new classes for UI components, props, and configuration in the form builder, navigation menu, notification center, and UI dialogs packages.
- Implemented detailed type definitions for actions, fields, and pagination components to streamline usage and enhance clarity.
- Updated initialization functions in multiple packages to include versioning and installation context.
- Improved structure and readability of the codebase by organizing and documenting component properties and methods.
2025-12-30 10:21:33 +00:00

54 lines
1.3 KiB
Lua

---@class Stats
local M = {}
---@class UIComponent
---@field type string
---@field props? table
---@field children? table
---@class StatCardProps
---@field label string
---@field value number|string
---@field change? string
---@field positive? boolean
---@field className? string
---@param props StatCardProps
---@return UIComponent
function M.card(props)
return {
type = "Card",
props = { className = props.className },
children = {
{
type = "CardContent",
props = { className = "p-6" },
children = {
{ type = "Typography", props = { variant = "overline", text = props.label, className = "text-muted-foreground" } },
{ type = "Typography", props = { variant = "h4", text = tostring(props.value) } },
props.change and {
type = "Typography",
props = { variant = "caption", text = props.change, className = props.positive and "text-green-500" or "text-red-500" }
} or nil
}
}
}
}
end
---@param stats StatCardProps[]
---@return UIComponent
function M.grid(stats)
local items = {}
for _, s in ipairs(stats) do
items[#items + 1] = M.card(s)
end
return {
type = "Grid",
props = { cols = #stats > 4 and 4 or #stats, gap = 4 },
children = items
}
end
return M