Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 19:23, 27 January 2026 by Texyc (talk | contribs) (Created page with "local p = {} function p.render(frame) local args = frame:getParent().args -- 1. SETUP CONTAINER local root = mw.html.create('div') :addClass('citizen-infobox') -- Hook for CSS :css({ ['float'] = 'right', ['width'] = '300px', ['max-width'] = '100%', ['background'] = 'var(--color-surface-2)', ['border'] = '1px solid var(--border-color-base)', ['border-radius'] = 'var(-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Infobox/doc

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    
    -- 1. SETUP CONTAINER
    local root = mw.html.create('div')
        :addClass('citizen-infobox') -- Hook for CSS
        :css({
            ['float'] = 'right',
            ['width'] = '300px',
            ['max-width'] = '100%',
            ['background'] = 'var(--color-surface-2)',
            ['border'] = '1px solid var(--border-color-base)',
            ['border-radius'] = 'var(--border-radius-base, 8px)',
            ['box-shadow'] = 'var(--box-shadow-level-1)',
            ['margin'] = '0 0 1em 1em',
            ['padding'] = '0',
            ['display'] = 'flex',
            ['flex-direction'] = 'column',
            ['overflow'] = 'hidden'
        })

    -- 2. TITLE HEADER
    if args['name'] then
        root:tag('div')
            :css({
                ['background'] = 'var(--color-primary--hover)', -- Use theme accent color
                ['color'] = '#fff',
                ['padding'] = '12px',
                ['text-align'] = 'center',
                ['font-weight'] = 'bold',
                ['font-size'] = '1.2em'
            })
            :wikitext(args['name'])
    end

    -- 3. IMAGES & TABS LOGIC
    local images = {}
    local i = 1
    while args['image' .. i] do
        table.insert(images, {
            file    = args['image' .. i],
            tab     = args['tab' .. i] or ('View ' .. i),
            caption = args['caption' .. i] or ''
        })
        i = i + 1
    end

    if #images > 0 then
        local imageContainer = root:tag('div'):addClass('infobox-image-area')
            :css({['background'] = 'var(--color-surface-1)', ['text-align'] = 'center', ['border-bottom'] = '1px solid var(--border-color-base)'})

        -- A. Render the Tabs (only if > 1 image)
        if #images > 1 then
            local tabRow = imageContainer:tag('div'):addClass('infobox-tabs')
                :css({['display'] = 'flex', ['justify-content'] = 'center', ['gap'] = '5px', ['padding'] = '10px 10px 0 10px'})
            
            for idx, imgData in ipairs(images) do
                tabRow:tag('span')
                    :addClass('infobox-tab-btn')
                    :addClass(idx == 1 and 'active' or '') -- First one is active
                    :attr('data-target', 'infobox-img-' .. idx)
                    :wikitext(imgData.tab)
            end
        end

        -- B. Render the Images
        for idx, imgData in ipairs(images) do
            local imgWrapper = imageContainer:tag('div')
                :addClass('infobox-img-content')
                :addClass(idx == 1 and 'active' or '')
                :attr('id', 'infobox-img-' .. idx)
                :css({['padding'] = '15px'})

            -- Image
            imgWrapper:tag('div'):wikitext(string.format('[[File:%s|250px]]', imgData.file))
            
            -- Caption
            if imgData.caption ~= '' then
                imgWrapper:tag('div')
                    :css({['font-size'] = '0.9em', ['color'] = 'var(--color-subtle)', ['margin-top'] = '8px'})
                    :wikitext(imgData.caption)
            end
        end
    end

    -- 4. DATA ROWS
    local contentTable = root:tag('table')
        :css({['width'] = '100%', ['border-collapse'] = 'collapse', ['font-size'] = '0.95em'})
    
    local j = 1
    while args['label' .. j] or args['header' .. j] do
        -- A. Section Header (Optional)
        if args['header' .. j] then
            contentTable:tag('tr'):tag('th')
                :attr('colspan', '2')
                :css({
                    ['background'] = 'var(--color-surface-2)',
                    ['border-top'] = '1px solid var(--border-color-base)',
                    ['border-bottom'] = '1px solid var(--border-color-base)',
                    ['padding'] = '8px',
                    ['text-align'] = 'center',
                    ['color'] = 'var(--color-base)'
                })
                :wikitext(args['header' .. j])
        end

        -- B. Data Row (Label + Value)
        if args['label' .. j] and args['value' .. j] then
            local row = contentTable:tag('tr')
                :css({['border-bottom'] = '1px solid var(--border-color-subtle)'})
            
            -- Label
            row:tag('th')
                :css({['text-align'] = 'left', ['padding'] = '10px', ['width'] = '40%', ['color'] = 'var(--color-subtle)'})
                :wikitext(args['label' .. j])
            
            -- Value
            row:tag('td')
                :css({['text-align'] = 'right', ['padding'] = '10px', ['font-weight'] = '500'})
                :wikitext(args['value' .. j])
        end
        j = j + 1
    end

    return tostring(root)
end

return p