maille
Version:
Component library for MithrilJS
47 lines (46 loc) • 1.91 kB
JavaScript
;
// THIS FILE WAS AUTO-GENERATED FOR PACKAGING, DO NOT MODIFY
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
class Alert {
view(vnode) {
// Retrieve relevant attributes
const { title, closeOptions, description, footer, rounded } = vnode.attrs;
const alertType = vnode.attrs.type || types_1.AlertType.Default;
// Build list of classes, combine with vnode
const classes = new Set(["maille", "maille-alert"]);
// If outlined, add the outline class
if (rounded) {
classes.add("rounded");
}
// Add the alert type
classes.add(alertType);
// Add in className classes provided by vnode
if (vnode.attrs.className) {
vnode.attrs.className.split(" ").forEach(c => classes.add(c));
}
// Build classname
const className = [...classes].join(" ");
// Build header elements
const headerElements = [
m(".maille-alert-title", title),
description ? m(".maille-alert-description", description) : null,
];
// Add close options if configured
if (closeOptions) {
const closeHandler = () => {
if (closeOptions.fn) {
closeOptions.fn(closeOptions.key);
}
};
const closeElement = closeOptions.elements || m.trust("×");
headerElements.push(m("span.maille-alert-close-container", { onclick: closeHandler }, closeElement));
}
return m(".maille.maille-alert", Object.assign(Object.assign({}, vnode.attrs), { className }), [
m(".maille-alert-header", headerElements),
m(".maille-alert-body", vnode.children),
footer ? m(".maille-alert-footer", footer) : null,
]);
}
}
exports.default = Alert;