Components
The Components module allows you to define UI elements and their properties declaratively.
Components.New(class, props, self) -> Instance
Parameters
- class
- Type:
string
- Required:
Yes
- Description: The Roblox UI class to create (e.g.,
"Frame"
,"TextLabel"
).
- Type:
- props
- Type:
table
- Required:
Yes
- Description: A table containing properties, events, children, and lifecycle hooks for the component.
- Type:
- self
- Type:
table
- Required:
No
- Description: Optional table to store component references (usually the parent component’s
self
).
- Type:
Returns
- Instance
- Type:
Instance
- Always:
Yes
- Description: The newly created Roblox UI component instance.
- Type:
Description
Creates a new UI component of the specified class and applies the given properties.
lua
local myButton = Vuxel.Components.New("TextButton", {
Text = "Click Me!",
Size = UDim2.new(0, 100, 0, 50)
})
Components.Template(template, parentSelf) -> Instance
TIP
You can also use Vuxel.Template
instead!
Parameters
- template
- Type:
table
- Required:
Yes
- Description: A table-based component template describing the UI structure and properties.
- Type:
- parentSelf
- Type:
table
- Required:
No
- Description: Optional table from the parent component to store child component references.
- Type:
Returns
- Instance
- Type:
Instance
- Always:
Yes
- Description: The root instance created from the template, with all nested children.
- Type:
Description
Creates a nested UI component structure from a table-based template
.
lua
local template = {
Class = "Frame",
Size = UDim2.new(0, 200, 0, 200),
Children = {
{
Class = "TextLabel",
Text = "Hello, Vuxel!",
Size = UDim2.new(0, 100, 0, 50)
}
}
}
local frame = Vuxel.Components.Template(template)
Components.RegisterLifecycleHook(instance, hookName, callback) -> 'void'
TIP
You can also use Vuxel.RegisterLifecycleHook
instead!
Parameters
- instance
- Type:
Instance
- Required:
Yes
- Description: The component instance on which to register the lifecycle hook.
- Type:
- hookName
- Type:
string
- Required:
Yes
- Description: The name of the lifecycle hook (e.g.,
"onMounted"
, "onDestroyed"
).
- Type:
- callback
- Type:
function
- Required:
Yes
- Description: The function to call when the lifecycle hook is triggered.
- Type:
Returns
- void
- Type:
nil
- Always:
Yes
- Description: No return value; lifecycle hook is registered internally.
- Type:
Description
Registers a lifecycle hook (onMounted, onDestroyed, etc.) for a component.
lua
Vuxel.Components.RegisterLifecycleHook(myButton, "onMounted", function()
print("Button mounted!")
end)
Components.RemoveComponent(instance) -> 'void'
TIP
You can also use Vuxel.RemoveComponent
instead!
Parameters
- instance
- Type:
Instance
- Required:
Yes
- Description: The component instance to remove, triggering its
"onDestroyed"
lifecycle hook if it exists.
- Type:
Returns
- void
- Type:
nil
- Always:
Yes
- Description: No return value; lifecycle hook is registered internally.
- Type:
Description
Removes a component and calls its onDestroyed hook.
lua
Vuxel.Components.RemoveComponent(myButton)