Update docs

This commit is contained in:
Aaron Smith 2023-08-10 15:42:58 +01:00
parent cc10c80a90
commit a4f59ee62b
5 changed files with 112 additions and 20 deletions

View file

@ -6,7 +6,7 @@
Creates a new UI element, applying any given properties.
- ### Type
- **Type**
```lua
function create(class: string): (Properties) -> Instance
@ -15,7 +15,7 @@ Creates a new UI element, applying any given properties.
type Properties = Map<string|number, any>
```
- ### Details
- **Details**
The function can take either a `string` or an `Instance` as its first argument.
@ -26,22 +26,22 @@ Creates a new UI element, applying any given properties.
This returns another function that is used to apply any properties to the new
instance.
- ### Property setting rules
- **Property setting rules**
- If a table value is another table, that nested table is processed so that
any properties inside that table are also applied to the instance just
like the outer table.
- If a table index is a string:
- If its value is a function then it will either bind that property to
a state or connect it if the property type is a `RBXScriptSignal`.
the function or connect it if the property type is a `RBXScriptSignal`.
- If the value is not a function then the property will be set to that
value.
- If a table index is a number:
- If its value is a function then it will parent any instances returned by
that function as children.
- If its value is a function then it will parent and bind any instances
returned by that function as children.
- If its value is an instance then it will be parented to the instance.
- ### Example
- **Example**
Basic element creation.
@ -77,3 +77,44 @@ Creates a new UI element, applying any given properties.
}
end
```
## action()
Creates a callback that can be passed to `create()` to invoke custom actions on
instances.
- **Type**
```lua
function action((Instance) -> (), priority: number = 1): Action
```
- **Details**
When passed to `create()`, the given callback is called with the instance
being created as the only argument. Actions take precedence over property
and child assignments.
A priority can be optionally specified to ensure certain actions run after
other actions. Higher priority numbers are ran after lower priority numbers.
- **Example**
An action to listen to changed properties:
```lua
local function changed(property: string, callback: (new) -> ())
return action(function(instance)
instance:GetPropertyChangedSignal("property"):Connect(function()
callback(instance[property])
end)
end)
end
local output = source ""
create "TextBox" {
-- will update the `output` source anytime the text property is changed
changed("Text", output)
}
```