Module:LinkGrid: Difference between revisions
From Jules RNG Wiki
More actions
No edit summary |
No edit summary |
||
| Line 6: | Line 6: | ||
local i = 1 | local i = 1 | ||
-- Loop to gather data | |||
while args['title' .. i] do | while args['title' .. i] do | ||
table.insert(cards, { | table.insert(cards, { | ||
| Line 16: | Line 17: | ||
end | end | ||
-- CONTAINER STYLE | |||
local containerStyle = { | local containerStyle = { | ||
['display'] = 'flex', | ['display'] = 'flex', | ||
| Line 23: | Line 25: | ||
} | } | ||
-- | -- CARD STYLE | ||
-- Note: 'max-width' here is for Desktop. Mobile is handled by Common.css class .jule-grid-card | |||
local cardStyle = { | local cardStyle = { | ||
['flex'] = '1 1 300px', | ['flex'] = '1 1 300px', | ||
| Line 40: | Line 43: | ||
for _, card in ipairs(cards) do | for _, card in ipairs(cards) do | ||
local cardDiv = root:tag('div') | local cardDiv = root:tag('div') | ||
:addClass('jule-grid-card') -- | :addClass('jule-grid-card') -- CRITICAL: Uses Common.css for mobile width | ||
:css(cardStyle) | :css(cardStyle) | ||
-- Image Area | -- Image Area (Icon Style) | ||
cardDiv:tag('div') | cardDiv:tag('div') | ||
:css({['background']='var(--color-surface-2)', ['padding']='20px', ['text-align']='center', ['border-bottom']='1px solid var(--border-color-base)'}) | :css({ | ||
['background'] = 'var(--color-surface-2)', | |||
['padding'] = '20px', | |||
['text-align'] = 'center', | |||
['border-bottom'] = '1px solid var(--border-color-base)' | |||
}) | |||
:wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link)) | :wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link)) | ||
-- Content Area | -- Content Area | ||
local bodyDiv = cardDiv:tag('div'):css({['padding']='15px'}) | local bodyDiv = cardDiv:tag('div'):css({['padding'] = '15px'}) | ||
-- Title | -- Title | ||
bodyDiv:tag('div') | bodyDiv:tag('div') | ||
:css({['font-weight']='bold', ['font-size']='1.2em', ['margin-bottom']='8px', ['color']='var(--color-base)'}) | :css({ | ||
['font-weight'] = 'bold', | |||
['font-size'] = '1.2em', | |||
['margin-bottom'] = '8px', | |||
['color'] = 'var(--color-base)' | |||
}) | |||
:wikitext(string.format('[[%s|%s]]', card.link, card.title)) | :wikitext(string.format('[[%s|%s]]', card.link, card.title)) | ||
-- Description | -- Description | ||
bodyDiv:tag('div') | bodyDiv:tag('div') | ||
:css({['color']='var(--color-subtle)', ['font-size']='0.95em', ['line-height']='1.4'}) | :css({ | ||
['color'] = 'var(--color-subtle)', | |||
['font-size'] = '0.95em', | |||
['line-height'] = '1.4' | |||
}) | |||
:wikitext(card.body) | :wikitext(card.body) | ||
end | end | ||
return tostring(root) | |||
return | |||
end | end | ||
return p | return p | ||
Revision as of 05:14, 27 January 2026
Documentation for this module may be created at Module:LinkGrid/doc
local p = {}
function p.render(frame)
local args = frame:getParent().args
local cards = {}
local i = 1
-- Loop to gather data
while args['title' .. i] do
table.insert(cards, {
link = args['link' .. i] or args['title' .. i],
title = args['title' .. i],
image = args['image' .. i] or 'Default.png',
body = args['body' .. i] or ''
})
i = i + 1
end
-- CONTAINER STYLE
local containerStyle = {
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '1rem',
['justify-content'] = 'center'
}
-- CARD STYLE
-- Note: 'max-width' here is for Desktop. Mobile is handled by Common.css class .jule-grid-card
local cardStyle = {
['flex'] = '1 1 300px',
['max-width'] = '32%',
['border'] = '1px solid var(--border-color-base)',
['border-radius'] = 'var(--border-radius-base, 12px)',
['box-shadow'] = 'var(--box-shadow-level-1)',
['overflow'] = 'hidden',
['background'] = 'var(--color-surface-1)',
['transition'] = 'transform 0.2s ease',
['box-sizing'] = 'border-box'
}
local root = mw.html.create('div'):css(containerStyle)
for _, card in ipairs(cards) do
local cardDiv = root:tag('div')
:addClass('jule-grid-card') -- CRITICAL: Uses Common.css for mobile width
:css(cardStyle)
-- Image Area (Icon Style)
cardDiv:tag('div')
:css({
['background'] = 'var(--color-surface-2)',
['padding'] = '20px',
['text-align'] = 'center',
['border-bottom'] = '1px solid var(--border-color-base)'
})
:wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link))
-- Content Area
local bodyDiv = cardDiv:tag('div'):css({['padding'] = '15px'})
-- Title
bodyDiv:tag('div')
:css({
['font-weight'] = 'bold',
['font-size'] = '1.2em',
['margin-bottom'] = '8px',
['color'] = 'var(--color-base)'
})
:wikitext(string.format('[[%s|%s]]', card.link, card.title))
-- Description
bodyDiv:tag('div')
:css({
['color'] = 'var(--color-subtle)',
['font-size'] = '0.95em',
['line-height'] = '1.4'
})
:wikitext(card.body)
end
return tostring(root)
end
return p