Module:Mbox

From CLFR.wiki
Jump to navigation Jump to search

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

local p = {}

local function getArgs(frame)
    return frame.args
end

local styles = {
    default = "border: 2px solid #FF9B00; background: linear-gradient(to bottom, #FFF6E5, #FFE3B8); padding: 1em; margin: 1em auto; max-width:800px; border-radius: 8px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;",
    uc = "border: 2px solid #d9534f; background: linear-gradient(to bottom, #fde9e7, #fdd4d0); padding: 1.5em; margin: 1em auto; max-width:800px; border-radius: 10px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; box-shadow: 0 4px 6px rgba(0,0,0,0.1);",
    stub = "border: 2px solid #f0ad4e; background: linear-gradient(to bottom, #fcf8e3, #faf2cc); padding: 1em; margin: 1em auto; max-width:800px; border-radius: 8px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;",
    editcount = "border: 2px solid #5bc0de; background: linear-gradient(to bottom, #d9edf7, #c4e3f3); padding: 1em; margin: 1em auto; max-width:800px; border-radius: 8px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;"
}

local innerStyles = {
    header = "text-align: center; font-size: 1.5em; margin-bottom: 0.5em; font-weight: bold;",
    text = "text-align: center; font-size: 1.2em; margin-bottom: 0.5em;",
    comment = "text-align: center; font-size: 1em; color: #555; margin-top: 1em;"
}

function p.render(frame)
    local args = getArgs(frame)
    local boxType = args.type or "default"
    local style = styles[boxType] or styles.default

    local container = mw.html.create("div")
        :cssText(style)

    if args.header and args.header ~= "" then
        container:tag("div")
            :cssText(innerStyles.header)
            :wikitext(args.header)
    end

    if args.text and args.text ~= "" then
        container:tag("div")
            :cssText(innerStyles.text)
            :wikitext(args.text)
    end

    if args.comment and args.comment ~= "" then
        container:tag("div")
            :cssText(innerStyles.comment)
            :wikitext(args.comment)
    end

    return tostring(container)
end

return p