Skip to content

Cookie Disclaimer

The Cookie Disclaimer component displays a notification at the bottom of the page informing users about cookie usage on the website. It allows users to accept or decline cookies, and stores their preference in a browser cookie.

  • Cookie component (automatically imported)
// Initialize with default options
Metro.cookieDisclaimer.init();
// Initialize with custom options
Metro.cookieDisclaimer.init({
name: "my_cookies_accepted",
title: "We use cookies",
message: "This website uses cookies to ensure you get the best experience on our website.",
duration: "30days",
onAccept: function() {
console.log("Cookies accepted");
},
onDecline: function() {
console.log("Cookies declined");
}
});
// With custom buttons
Metro.cookieDisclaimer.init({
duration: "1day",
clsAcceptButton: "success",
customButtons: [
{
text: `<span class="mif-info mr-2"></span>View details`,
cls: "info ml-auto",
onclick: () => {
alert("Details");
}
}
],
});
// Remove the cookie to show the disclaimer again
Metro.cookie.delCookie('cookies_accepted');
ParameterTypeDefaultDescription
namestring”cookies_accepted”The name of the cookie that will be set when user accepts cookies
templateUrlstringnullURL to a custom template for the disclaimer. If not provided, the default template will be used
titlestring""The title of the disclaimer. If empty, a localized default will be used
messagestring""The message of the disclaimer. If empty, a localized default will be used
durationstring”30days”The duration for which the cookie will be valid. Format: “Xdays”, “Xhours”, “Xmin”, “Xsec”
clsContainerstring""Additional CSS class(es) for the disclaimer container
clsMessagestring""Additional CSS class(es) for the message container
clsButtonsstring""Additional CSS class(es) for the buttons container
clsAcceptButtonstring""Additional CSS class(es) for the accept button
clsCancelButtonstring""Additional CSS class(es) for the cancel button
customButtonsarrayundefinedArray of custom button objects with properties: text, cls, onclick
onAcceptfunctionMetro.noopCallback function that is called when the user accepts cookies
onDeclinefunctionMetro.noopCallback function that is called when the user declines cookies
  • init(options) - Initializes the cookie disclaimer component with the specified options.
Metro.cookieDisclaimer.init({
name: "my_cookies_accepted",
duration: "7days"
});
  • create(html) - Creates the disclaimer UI. This method is called internally by the init method and typically doesn’t need to be called directly.
  • html (optional): Custom HTML content for the disclaimer
EventDescription
onAcceptTriggered when the user accepts cookies
onDeclineTriggered when the user declines cookies
VariableDefault (Light)Dark ModeDescription
--disclaimer-background#f5f5f5#343637Background color of the disclaimer
--disclaimer-color#191919#dbdfe7Text color of the disclaimer

The component also uses the --border-color variable for borders, which is defined in the global CSS variables.

:root {
--disclaimer-background: #e0f7fa;
--disclaimer-color: #006064;
}
/* For dark mode */
.dark-side {
--disclaimer-background: #263238;
--disclaimer-color: #b0bec5;
}
  • .cookie-disclaimer - Main container for the disclaimer
  • .disclaimer-message - Container for the title and text
  • .disclaimer-title - Title element
  • .disclaimer-text - Text content element
  • .disclaimer-actions - Container for buttons
  • .cookie-accept-button - Accept button
  • .cookie-cancel-button - Cancel button
  • .cookie-custom-button - Custom buttons

The component creates the following HTML structure:

<div class="cookie-disclaimer">
<div class="disclaimer-message">
<div class="disclaimer-title">...</div>
<div class="disclaimer-text">...</div>
</div>
<div class="disclaimer-actions">
<button class="button cookie-accept-button">Accept</button>
<button class="button cookie-cancel-button">Cancel</button>
<!-- Custom buttons if defined -->
</div>
</div>