Toggle menu
45
232
3
1.3K
EmrysSMP Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:DeclarativeUI/doc: Difference between revisions

From EmrysSMP Wiki
No edit summary
(No difference)

Revision as of 13:01, 22 February 2024

DeclarativeUI is an alternative to the existing Scribunto HTML library in the style of React's createElement.

createElement

Parameter Description Type Status
type Element tag string required
attributes Dictionary of attributes table<string, any> optional
...children Children element or table<element> or string optional
local createElement = require( 'Module:DeclarativeUI' )

-- You can create a simple element like this
createElement( 'div' ):render() -- <div/>

-- Add some attributes
createElement( 'div', { a = 'b' } ):render() -- <div a="b"/>

-- What about some text?
createElement( 'h1', nil, 'Scream!' ):render() -- <h1>Scream!</h1>

-- What about other elements?
local someElement = createElement( 'span', { style = 'color: red' }, 'Hello World' )
createElement( 'div', nil, 'This goes first', someElement ) -- <div>This goes first<span style="color: red">Hello World</span></div>

-- You can have as much children as you want
createElement( 'div', nil, 'a', 'b', 'c' ) -- <div>abc</div>