Module:WDS Button

--

-- @todo

local p = {} local getArgs = require("Dev:Arguments").getArgs local userError = require("Dev:User error")

-- @todo Move to subpage and import with `mw.loadData`.

local data = (function    local colorSchemes = {}

local function ColorScheme(fields) for _, alias in ipairs(fields.aliases) do           if colorSchemes[alias] then error("duplicate alias `" .. alias .. "`") end

colorSchemes[alias] = fields end end

ColorScheme { aliases = {"stable", "pass"}, backgroundColor = "#32cd32", textColor = "white", }

ColorScheme { aliases = {"beta", "warn"}, backgroundColor = "#ffba01", textColor = "white", }

ColorScheme { aliases = {"experimental"}, backgroundColor = "#ff4500", textColor = "white", }

ColorScheme { aliases = {"unstable"}, backgroundColor = "#900", textColor = "yellow", }

ColorScheme { aliases = {"fail"}, backgroundColor = "#900", textColor = "white", }

ColorScheme { aliases = {"archive"}, backgroundColor = "#0d47a1", textColor = "white", }

ColorScheme { aliases = {"unmaintained"}, backgroundColor = "#8b4513", textColor = "white", }

ColorScheme { aliases = {"unknown", "nil", "default"}, backgroundColor = "#aaa", textColor = "white", }

return colorSchemes end)

-- @todo -- -- @param {string} text --    @todo -- @param {string} colorSchemeName --    @todo -- @returns {string} --    @todo

function p._badge(text, colorSchemeName) local colorScheme = data[colorSchemeName] or data.default local badge = mw.html.create("span") :addClass("wds-button") :css("background-color", colorScheme.backgroundColor) :css("border-color", colorScheme.backgroundColor) :css("color", colorScheme.textColor) :css("cursor", "inherit") :css("font-weight", "bold") :wikitext(text)

return tostring(badge) end

-- @todo -- -- @param {table} frame --    @todo -- @returns {string} --    @todo

function p.badge(frame) local args = getArgs(frame)

return p._badge(args[1], args[2]) end

-- @todo -- -- @param {string} text --    @todo -- @param {string} colorSchemeName --    @todo -- @returns {string} --    @todo

function p._bubblde(text, colorSchemeName) local colorScheme = data[colorSchemeName] or data.default local badge = mw.html.create("span") :addClass("wds-button") :addClass("wds-font-size-xxs") :css("background-color", colorScheme.backgroundColor) :css("border-color", colorScheme.backgroundColor) :css("color", colorScheme.textColor) :css("border-radius", "0.5em") :css("padding", "0 0.4em") :css("vertical-align", "middle") :wikitext(text)

return tostring(badge) end

-- @todo -- -- @param {table} frame --    @todo -- @returns {string} --    @todo

function p.bubble(frame) local args = getArgs(frame)

return p._bubble(args[1], args[2]) end

return p