Module:TableColors
De Nefald
Autres actions
La documentation pour ce module peut être créée à Module:TableColors/doc
local p = {}
-- Palette inspirée de Bootstrap 5 + Citizen
local colors = {
-- Variantes de succès (vert)
success = { bg = "#d1e7dd", fg = "#0f5132", label = "Succès" },
["success-light"] = { bg = "#e8f5e9", fg = "#1b5e20", label = "Succès clair" },
-- Variantes de danger (rouge)
danger = { bg = "#f8d7da", fg = "#842029", label = "Danger" },
["danger-light"] = { bg = "#ffebee", fg = "#c62828", label = "Danger clair" },
-- Variantes d'avertissement (jaune/orange)
warning = { bg = "#fff3cd", fg = "#664d03", label = "Avertissement" },
["warning-light"] = { bg = "#fffde7", fg = "#f57f17", label = "Avertissement clair" },
-- Variantes d'information (bleu)
info = { bg = "#cfe2ff", fg = "#084298", label = "Info" },
["info-light"] = { bg = "#e3f2fd", fg = "#01579b", label = "Info clair" },
-- Variantes neutres
primary = { bg = "#cfe2ff", fg = "#052c65", label = "Primaire" },
secondary = { bg = "#e2e3e5", fg = "#41464b", label = "Secondaire" },
light = { bg = "#f8f9fa", fg = "#495057", label = "Clair" },
dark = { bg = "#ced4da", fg = "#212529", label = "Foncé" },
-- Compatibilité anciens noms
vert = { bg = "#d1e7dd", fg = "#0f5132", label = "Vert" },
rouge = { bg = "#f8d7da", fg = "#842029", label = "Rouge" },
jaune = { bg = "#fff3cd", fg = "#664d03", label = "Jaune" },
rose = { bg = "#f8d7da", fg = "#842029", label = "Rose" },
gris = { bg = "#e2e3e5", fg = "#41464b", label = "Gris" },
bleu = { bg = "#cfe2ff", fg = "#084298", label = "Bleu" },
}
-- Fonction principale
function p.style(frame)
local args = frame:getParent().args
local colorName = mw.text.trim(args[1] or ""):lower()
local customLabel = args[2]
-- Gestion des alias
local aliases = {
["gris-"] = "info-light",
["gris+"] = "secondary",
["vert-clair"] = "success-light",
["rouge-clair"] = "danger-light",
}
colorName = aliases[colorName] or colorName
-- Récupération de la couleur
local color = colors[colorName] or colors.light
-- Construction du style avec classes CSS
local style = string.format(
'class="table-color-cell table-color-%s" style="background-color: %s; color: %s"',
colorName:gsub("%W", "-"),
color.bg,
color.fg
)
-- Traitement du label
if customLabel then
local labelTrimmed = mw.text.trim(customLabel)
-- Si le label existe et n'est pas vide
if labelTrimmed ~= "" then
return style .. ' | ' .. customLabel
end
end
-- Si pas de label ou label vide, retourner juste le style sans le séparateur
return style
end
-- Fonction pour lister les couleurs disponibles
function p.list(frame)
local output = '{| class="wikitable sortable"\n! Nom !! Aperçu !! Code\n'
local sorted = {}
for name, _ in pairs(colors) do
table.insert(sorted, name)
end
table.sort(sorted)
for _, name in ipairs(sorted) do
local color = colors[name]
output = output .. string.format(
'|-\n| %s || style="background:%s; color:%s; padding:5px 10px;" | %s || <code>{{Couleur|%s}}</code>\n',
color.label,
color.bg,
color.fg,
color.label,
name
)
end
return output .. '|}'
end
return p