Alerts

Basic dismissable and non-dismissable alerts that can be customized with variables globally or inline.

Examples

Basic alert

Dismissable alert!

Example HTML
<div class="alert">
<p>Basic alert</p>
</div>

<dialog class="alert" open>
<p>Dismissable alert!</p>
<form method="dialog">
<button><span>Close</span></button>
</form>
</dialog>

Using the module

Add the sassmods.scss to your custom styles as below, use the Sass variables from the module's source code (see below) to customize the default property values if required, then include the Sass mixin anywhere below.

@use "sassmods/scss/sassmods" as *;
$alert-padding-block: 0.25rem; // example
$alert-padding-inline: 0.5rem; // example

@include alerts-css;

Using the framework

Enable the module in the sassmods-system.scss document as below, if required customize the styles or the Sass variables for the default property values directly in the source code (see below).

$enable-alerts: true;

Source

The source code is a self-contained Sass document that compiles the style modules as Sass mixins using Sass variables provided for the core property values that can be customized as described above.

_alerts.scss

Use the property specific CSS variables to create root level variables for global styles and/or editing inline, or change all the values to suit your own parameters.

// ---------------------------------------------------------- 
// Alerts
// ----------------------------------------------------------
$alert-text-color:        var(--alert-text, inherit);
$alert-margin-bottom:     var(--alert-mb, 1rem);
$alert-padding-block:     var(--alert-py, 0.66rem);
$alert-padding-inline:    var(--alert-px, 1rem);
$alert-border-color:      var(--alert-bd-color, color-mix(in srgb, CanvasText 12%, Canvas));
$alert-radius:            var(--alert-radius); 
$alert-background-color:  var(--alert-bg, color-mix(in srgb, CanvasText 3%, Canvas));

@mixin alerts-css {

.alert {
  color: #{$alert-text-color};
  margin-block-end: #{$alert-margin-bottom};
  padding-block: #{$alert-padding-block};
  padding-inline: #{$alert-padding-inline};
  border: 1px solid #{$alert-border-color};
  border-radius: #{$alert-radius}; 
  background-color: #{$alert-background-color};
}

.alert * {
  margin-block-end: 0;
}

.alert[open] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  position: relative;
  inline-size: 100%;
  max-inline-size: 100%;  
  margin: initial;
  margin-block-end: #{$alert-margin-bottom};
  padding-block: #{$alert-padding-block};
  padding-inline-end: #{$alert-padding-inline};
  transition: none;
}

.alert [method="dialog"] {
  margin-inline-start: auto;
}

.alert [method="dialog"] button {
  background-color: transparent;
  border: none;
  padding-block: 0.1rem;
  padding-inline: 0.5rem;
  margin-inline-start: auto;
}

.alert [method="dialog"] button:before {
  --ico: var(--alert-txt, CanvasText);
  display: inline-block;
  content: "";
  block-size: 1em;
  inline-size: 1em;  
  vertical-align: -.115em;
  background-color: var(--ico);
  mask-image: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path d='m13 3-10 10zm-10 0 10 10z' fill='none' stroke='currentColor' stroke-width='1.5'/></svg>");
  mask-repeat: no-repeat;
}

.alert [method="dialog"] button span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

} // End alerts-css