Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:InfoboxLua/Components/Item

From Paracosm

Documentation for this module may be created at Module:InfoboxLua/Components/Item/doc

require( 'strict' )

local util = require( 'Module:InfoboxLua/Util' )
local types = require( 'Module:InfoboxLua/Types' )

local p = {}


--- Returns the mw.html object of the infobox item component.
---
--- @param data table
--- @return mw.html|nil
function p.getHtml( data )
	--- Sometimes modules short-circuit the infobox data and don't return a content string.
	--- If that's the case, we don't want to render anything.
	if not util.isNonEmptyString( data.content ) then
		return nil
	end

	--- @type ItemComponentData
	local item = util.validateAndConstruct( data, types.ItemComponentDataSchema )


	local root = mw.html.create( 'div' )
	root:addClass( 't-infobox-item' )

	if item.class then
		root:addClass( item.class )
	end

	if util.isNonEmptyString( item.label ) then
		root:tag( 'div' )
			:addClass( 't-infobox-item-label' )
			:wikitext( item.label )
			:done()
	end

	root:tag( 'div' )
		:addClass( 't-infobox-item-content' )
		:wikitext( item.content )
		:done()

	return root
end

return p
Last modified