Module:Infobox: Difference between revisions
Appearance
uses common colors |
padding 0.5em 1em |
||
| (31 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
:addClass('infobox') | |||
:css('border', '1px solid var(--vw-border)') | |||
:css('border-radius', '4px') | |||
:css('overflow', 'hidden') | |||
:css('font-size', '90%') | |||
:css('background', 'var(--vw-bg-subtle)') | |||
:css('padding-bottom', '4px') | |||
local light = (args['titlebg-light'] and args['titlebg-light'] ~= '') and args['titlebg-light'] or 'var(--vw-accent-subtle)' | |||
local dark = (args['titlebg-dark'] and args['titlebg-dark'] ~= '') and args['titlebg-dark'] or 'var(--vw-accent-subtle)' | |||
local titlebg = 'light-dark(' .. light .. ', ' .. dark .. ')' | |||
if args.title and args.title ~= '' then | if args.title and args.title ~= '' then | ||
root:tag('tr') | |||
:tag('th') | |||
:attr('colspan', '2') | |||
:css('width', '100%') | |||
:css('text-align', 'center') | |||
:css('font-size', '125%') | |||
:css('background', titlebg) | |||
:css('padding', '0.5em 1em') | |||
:wikitext(args.title) | |||
end | end | ||
-- Image | -- Image | ||
if args.image and args.image ~= '' then | if args.image and args.image ~= '' then | ||
local caption = args.caption or '' | |||
local imgBottomPad = caption ~= '' and '6px 6px 2px 6px' or '6px' | |||
root:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
:css('text-align', 'center') | |||
:css('padding', imgBottomPad) | |||
:wikitext('[[File:' .. args.image .. '|300px]]') | |||
if caption ~= '' then | |||
root:tag('tr') | |||
:tag('td') | |||
:attr('colspan', '2') | |||
:css('text-align', 'center') | |||
:css('padding', '0px 6px 4px 6px') | |||
:wikitext(caption) | |||
end | |||
end | end | ||
-- Data rows | -- Data rows | ||
local i = 1 | local i = 1 | ||
while args['label' .. i] or args['data' .. i] do | while args['label' .. i] or args['data' .. i] or args['header' .. i] do | ||
local label = args['label' .. i] | local header = args['header' .. i] | ||
local data | local label = args['label' .. i] | ||
if data and data ~= '' then | local data = args['data' .. i] | ||
if header and header ~= '' then | |||
root:tag('tr') | |||
:tag('th') | |||
:attr('colspan', '2') | |||
:css('width', '100%') | |||
:css('text-align', 'center') | |||
:css('background', 'var(--vw-bg-heading)') | |||
:css('padding', '4px 6px') | |||
:wikitext(header) | |||
elseif data and data ~= '' then | |||
local row = root:tag('tr') | local row = root:tag('tr') | ||
if label and label ~= '' then | if label and label ~= '' then | ||
row:tag('th') | row:tag('th') | ||
:css('text-align', 'left') | :css('text-align', 'left') | ||
:css('padding', ' | :css('padding', '2px 6px 2px 6px') | ||
:css('background', 'var(--vw- | :css('background', 'var(--vw-bg-subtle)') | ||
:css('width', '45%') | :css('width', '45%') | ||
:wikitext(label) | :wikitext(label) | ||
end | end | ||
row:tag('td') | row:tag('td') | ||
:css('padding', ' | :css('padding', '2px 6px 2px 6px') | ||
:attr('colspan', (label and label ~= '') and '1' or '2') | :attr('colspan', (label and label ~= '') and '1' or '2') | ||
:wikitext(data) | :wikitext(data) | ||
| Line 67: | Line 81: | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
return p | return p | ||
Latest revision as of 22:28, 30 May 2026
Documentation for this module may be created at Module:Infobox/doc
local p = {}
function p.render(frame)
local args = frame:getParent().args
local root = mw.html.create('table')
:addClass('infobox')
:css('border', '1px solid var(--vw-border)')
:css('border-radius', '4px')
:css('overflow', 'hidden')
:css('font-size', '90%')
:css('background', 'var(--vw-bg-subtle)')
:css('padding-bottom', '4px')
local light = (args['titlebg-light'] and args['titlebg-light'] ~= '') and args['titlebg-light'] or 'var(--vw-accent-subtle)'
local dark = (args['titlebg-dark'] and args['titlebg-dark'] ~= '') and args['titlebg-dark'] or 'var(--vw-accent-subtle)'
local titlebg = 'light-dark(' .. light .. ', ' .. dark .. ')'
if args.title and args.title ~= '' then
root:tag('tr')
:tag('th')
:attr('colspan', '2')
:css('width', '100%')
:css('text-align', 'center')
:css('font-size', '125%')
:css('background', titlebg)
:css('padding', '0.5em 1em')
:wikitext(args.title)
end
-- Image
if args.image and args.image ~= '' then
local caption = args.caption or ''
local imgBottomPad = caption ~= '' and '6px 6px 2px 6px' or '6px'
root:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:css('padding', imgBottomPad)
:wikitext('[[File:' .. args.image .. '|300px]]')
if caption ~= '' then
root:tag('tr')
:tag('td')
:attr('colspan', '2')
:css('text-align', 'center')
:css('padding', '0px 6px 4px 6px')
:wikitext(caption)
end
end
-- Data rows
local i = 1
while args['label' .. i] or args['data' .. i] or args['header' .. i] do
local header = args['header' .. i]
local label = args['label' .. i]
local data = args['data' .. i]
if header and header ~= '' then
root:tag('tr')
:tag('th')
:attr('colspan', '2')
:css('width', '100%')
:css('text-align', 'center')
:css('background', 'var(--vw-bg-heading)')
:css('padding', '4px 6px')
:wikitext(header)
elseif data and data ~= '' then
local row = root:tag('tr')
if label and label ~= '' then
row:tag('th')
:css('text-align', 'left')
:css('padding', '2px 6px 2px 6px')
:css('background', 'var(--vw-bg-subtle)')
:css('width', '45%')
:wikitext(label)
end
row:tag('td')
:css('padding', '2px 6px 2px 6px')
:attr('colspan', (label and label ~= '') and '1' or '2')
:wikitext(data)
end
i = i + 1
end
return tostring(root)
end
return p