Module:Sandbox/0x99/Box

From Puella Magi Wiki
Jump to navigation Jump to search

This is a generic box.

Plain box

{{#invoke:Sandbox/0x99/Box|main}}
{{#invoke:Sandbox/0x99/Box|main|tintColor=#f8f2fb}}
{{#invoke:Sandbox/0x99/Box|main|tintColor=#e4efff}}

Plain box with title

{{#invoke:Sandbox/0x99/Box|main|title=Hello}}
Hello
{{#invoke:Sandbox/0x99/Box|main|title=Hello|tintColor=#f8f2fb}}
Hello
{{#invoke:Sandbox/0x99/Box|main|title=Hello|tintColor=#e4efff}}
Hello

Plain box with title and body

{{#invoke:Sandbox/0x99/Box|main|title=Hello|body=World}}
Hello
World
{{#invoke:Sandbox/0x99/Box|main|title=Hello|body=World|tintColor=#f8f2fb}}
Hello
World
{{#invoke:Sandbox/0x99/Box|main|title=Hello|body=World|tintColor=#e4efff}}
Hello
World

Plain box with body

{{#invoke:Sandbox/0x99/Box|main|body=World}}
World
{{#invoke:Sandbox/0x99/Box|main|body=World|tintColor=#f8f2fb}}
World
{{#invoke:Sandbox/0x99/Box|main|body=World|tintColor=#e4efff}}
World

local getArgs = require('Module:Arguments').getArgs
local color = require('Module:Color')
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	local root = mw.html.create('div')
	root:addClass("pm-box")
	root:wikitext(frame:extensionTag{
		name = 'templatestyles',
		args = { src = 'Module:Sandbox/0x99/Box/base.css' }
	})

	local tintColor = args.tintColor or ""
	local borderColor = ""
	if tintColor ~= "" then
		borderColor = color.darken(tintColor)
	end

	local outer = root:tag("div"):addClass("pm-box__outer")
	if tintColor ~= "" then
		outer:css("background-color", tintColor)
	end

	local inner = outer:tag("div"):addClass("pm-box__inner")
	if tintColor ~= "" then
		inner:css("border-color", borderColor)
	end

	if args.title and args.title ~= "" then
		local title = inner:tag("div"):addClass("pm-box__title")
		title:wikitext(args.title or "")
		if tintColor ~= "" then
			title:css("background-color", tintColor)
			title:css("border-color", borderColor)
		end
	end

	if args.body and args.body ~= "" then
		local body = inner:tag("div"):addClass("pm-box__body")
		body:wikitext(args.body or "")
	end

	return tostring(root)
end

return p