-- Used to implement {{OOUI button}}
-- This is not the same as {{Clickable button 2}}, which uses mw-ui.
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
local finalCategories = {}
function p.main(frame)
local args = getArgs(frame, {
trim = true,
removeBlanks = false
})
return p._main(frame, args)
end
function p._main(frame, args)
-- aliases
args["label"] = args["1"] or args["label"]
return tostring(renderButtonWidget(args))
end
function renderButtonWidget(args)
local wrapper = mw.html.create("span")
:addClass("oo-ui-widget")
:addClass("oo-ui-buttonElement")
:addClass("oo-ui-buttonWidget")
-- <icon/label/indicator>Element
if args["icon"] and string.len(args["icon"]) > 0 then
wrapper:addClass("oo-ui-iconElement")
end
if args["label"] and string.len(args["label"]) > 0 then
wrapper:addClass("oo-ui-labelElement")
end
if args["indicator"] and string.len(args["indicator"]) > 0 then
wrapper:addClass("oo-ui-indicatorElement")
end
-- flags
if args["flags"] == "progressive" or yesno(args["progressive"]) then
wrapper:addClass("oo-ui-flaggedElement-progressive")
end
if args["flags"] == "destructive" or yesno(args["destructive"]) then
wrapper:addClass("oo-ui-flaggedElement-destructive")
end
-- frame
if yesno(args["framed"] or "yes") then
wrapper:addClass("oo-ui-buttonElement-framed")
else
wrapper:addClass("oo-ui-buttonElement-frameless")
end
-- disabled
if yesno(args["disabled"] or "no") then
wrapper:addClass("oo-ui-widget-disabled")
wrapper:attr("aria-diasbled", "true")
else
wrapper:addClass("oo-ui-widget-enabled")
wrapper:attr("aria-diasbled", "false")
end
wrapper:node(renderButton(args))
return wrapper
end
function renderButton(args)
return mw.html.create("span")
:addClass("oo-ui-buttonElement-button")
:attr("role", "button")
:attr("title", args["title"] or args["label"])
:attr("aria-disabled", yesno(args["disabled"] or "no") and "true" or "false")
:node(renderIcon(args["icon"]))
:node(renderLabel(args["label"]))
:node(renderIndicator(args["indicator"]))
end
function renderIcon(icon)
return mw.html.create("span")
:addClass("oo-ui-iconElement-icon")
:addClass((icon and string.len(icon) > 0)
and ("oo-ui-icon-" .. icon)
or "oo-ui-iconElement-noIcon")
end
function renderLabel(label)
return mw.html.create("span")
:addClass("oo-ui-labelElement-label")
:wikitext(label)
end
function renderIndicator(indicator)
if
indicator ~= "clear"
and indicator ~= "down"
and indicator ~= "required"
and indicator ~= "up"
and indicator ~= ""
and indicator ~= nil
then
mw.addWarning("Unrecognized indicator: ''" .. indicator .. "''")
indicator = ""
end
return mw.html.create("span")
:addClass("oo-ui-indicatorElement-indicator")
:addClass((indicator and string.len(indicator) > 0)
and ("oo-ui-indicator-" .. indicator)
or "oo-ui-indicatorElement-noIndicator")
end
return p