Skip to content

Commit

Permalink
alerts: refactor alerts and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hom3mad3 committed Dec 17, 2024
1 parent e2ea9f4 commit 5344acd
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
{% block title %}Component Library — {{ block.super }}{% endblock %}

{% block content %}
{% include 'meinberlin_contrib/components/breadcrumb.html' %}
<div id="layout-grid__area--leftcolumn">
<!-- LEFT COLUMN not used -->
</div>
<div id="layout-grid__area--maincontent">
{% include 'meinberlin_contrib/components/breadcrumb.html' %}
<main id="layout-grid__area--maincontent">
<h1>Component Library</h1>
{% include 'meinberlin_contrib/components/card.html' %}
</div>

<section id="alerts">
<h2>Alerts</h2>
{% include 'meinberlin_contrib/components/alert.html' with alert_headline='Info' alert_message='Error during validation. Please check your entries.' alert_type='info' %}
{% include 'meinberlin_contrib/components/alert.html' with alert_headline='Success' alert_message='Error during validation. Please check your entries.' alert_type='success' %}
{% include 'meinberlin_contrib/components/alert.html' with alert_headline='Warning' alert_message='Error during validation. Please check your entries.' alert_type='warning' %}
{% include 'meinberlin_contrib/components/alert.html' with alert_headline='Error' alert_message='Error during validation. Please check your entries.' alert_type='danger' %}
</section>
</main>
<!-- Component list and links -->
<div id="layout-grid__area--marginal" role="complementary" class="marginal">
<ul>
Expand All @@ -20,6 +29,9 @@
<li>
<a href="#card" class="">Card</a>
</li>
<li>
<a href="#alerts" class="">Alerts</a>
</li>
</ul>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{% load i18n %}

<div class="alert alert--{{ alert_type }}"
role="alert"
aria-live="{% if alert_type == 'danger' %}assertive{% else %}polite{% endif %}"
aria-describedby="{% if alert_headline %}alert__headline{% endif %} alert__text"
aria-atomic="true"
>
<div class="a4-alert__container">
<div class="a4-alert__content">
{% if alert_headline %}
<h3 class="alert__headline">
<div class="alert alert--{{ alert_type }}" role="alert" aria-live="{% if alert_type == 'danger' %}assertive{% else %}polite{% endif %}" aria-atomic="true">
<div class="alert__content">
{% if alert_headline %}
<h3 class="alert__headline">
{% translate alert_headline %}
</h3>
{% endif %}
<p class="alert__text">
{% translate alert_message %}
</p>
</div>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="{% translate 'Close' %}"><i class="fa fa-times" aria-hidden="true"></i></button>
</h3>
{% endif %}
<p class="alert__text">
{% translate alert_message %}
</p>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="{% translate 'Close' %}">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -367,37 +367,62 @@ <h2 id="cl-alerts">Alerts</h2>

<div class="cl-example">
<span title="`messages` behaves differently if it is the first child in a block"></span>
<ul class="messages">
<li class="alert alert--success" role="alert">
<div class="container">
Success
<button class="alert__close">X</button>
</div>
</li>
<li class="alert alert--info" role="alert">
<div class="container">

<div class="alert" role="alert" aria-live="polite" aria-atomic="true">
<div class="alert__content">
<h3 class="alert__headline">
Info
<button class="alert__close">X</button>
</div>
</li>
<li class="alert alert--warning" role="alert">
<div class="container">
</h3>
<p class="alert__text">
This is an informational alert
</p>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="Close">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>

<div class="alert alert--warning" role="alert" aria-live="polite" aria-atomic="true">
<div class="alert__content">
<h3 class="alert__headline">
Warning
<button class="alert__close">X</button>
</div>
</li>
<li class="alert alert--danger" role="alert">
<div class="container">
Danger
<button class="alert__close">X</button>
</div>
</li>
</ul>
</h3>
<p class="alert__text">
This is a warning message
</p>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="Close">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>

<p class="alert alert--small" role="alert">
Small
<button class="alert__close">X</button>
</p>
<div class="alert alert--success" role="alert" aria-live="polite" aria-atomic="true">
<div class="alert__content">
<h3 class="alert__headline">
Success
</h3>
<p class="alert__text">
This is a success message
</p>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="Close">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>

<div class="alert alert--danger" role="alert" aria-live="assertive" aria-atomic="true">
<div class="alert__content">
<h3 class="alert__headline">
Danger
</h3>
<p class="alert__text">
This is a danger message!!
</p>
<button type="button" class="alert__close" data-bs-dismiss="alert" aria-label="Close">
<i class="fa fa-times" aria-hidden="true"></i>
</button>
</div>
</div>
</div>

<h2 id="cl-blocks">Blocks</h2>
Expand Down
75 changes: 39 additions & 36 deletions meinberlin/assets/scss/components_dashboard/_alert.scss
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
@use "sass:color";

$messages-margin-bottom: 25px;

.messages {
margin: 0 0 $messages-margin-bottom;
padding: 0;
.alert {
position: relative;
color: $info;
background-color: $info-bg;
animation: slide-in 0.2s ease-in-out;
}

li {
display: block;
}
.alert__content {
padding: 1.5rem 2rem 1.5rem 1.5rem;
margin: 0 auto;
max-width: 81rem; // reproduces the old container max-width in bootstrap
}

+ .messages {
margin-top: -$messages-margin-bottom;
}
.alert__headline {
margin-top: 0;
}

.alert {
.alert__text {
margin: 0;
padding: $padding * 1.2 0;
background-color: color.adjust($info, $lightness: 60%);
color: $info;
text-align: center;
line-height: 1.5;
}

/* Alert types */
.alert--success {
background-color: color.adjust($success, $lightness: 70%);
color: $success;
background-color: $success-bg;
}

.alert--error,
.alert--danger {
background-color: color.adjust($danger, $lightness: 50%);
color: $danger;
background-color: $danger-bg;
}

.alert--warning {
background-color: color.adjust($warning, $lightness: 48%);
color: $warning;
}

.alert__close {
float: right;
color: inherit;
background-color: $warning-bg;
}

.alert--small {
padding: 0.5em;
}

// If this directly follows the dialog box (see header.scss), add 16px
// additional padding to the default value (see above).
.messages:first-child > :first-child {
padding-top: calc(16px + #{$padding * 1.2});
/* Close button */
.alert__close {
position: absolute;
top: 0.5rem;
right: 0.5rem;
padding: 0.25rem;
border: 0;
color: inherit;
cursor: pointer;
}

// compensate for margin-bottom on messages
.project-header,
.hero-unit {
.messages + & {
margin-top: -$messages-margin-bottom;
/* Animation */
@keyframes slide-in {
from {
opacity: 0;
transform: translateY(-10px);
}
}

to {
opacity: 1;
transform: translateY(0);
}
}
33 changes: 13 additions & 20 deletions meinberlin/assets/scss/components_user_facing/_alert.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
.alert {
position: relative;
margin: $padding 0;
background-color: $message-light-blue;
}

.a4-alert__container {
display: flex;
justify-content: space-between;
}

.a4-alert__content {
padding: $padding * 1.375 $padding * 1.125;
.alert__content {
padding: 1.125rem 2rem 1.125rem 1.125rem;
margin: 0 auto;
max-width: 81rem;
}

.alert__headline {
margin: 0;
margin: 0 0 .4em;
line-height: 1.353em;
padding: 0;
color: inherit;
}
Expand All @@ -24,9 +23,13 @@
}

.alert__close {
padding: $padding * 0.625;
height: fit-content;
position: absolute;
top: 0.5rem;
right: 0.5rem;
padding: 0.25rem;
border: 0;
color: inherit;
cursor: pointer;
}

.alert--success {
Expand All @@ -47,14 +50,4 @@

.alert--small {
padding: 0.5em;
}

.alert:first-child {
margin: 0;
margin-bottom: $padding;
}

.alert:last-child {
margin: 0;
margin-top: $padding;
}
13 changes: 10 additions & 3 deletions meinberlin/assets/scss/styles_dashboard/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ $primary: #00a982 !default;
$primary-tint: #f5ccdd !default;
$secondary: #253276 !default;
$secondary-darker: #1c2659 !default;
$success: #0a820a !default;
$info: $secondary !default;
$warning: #f49e00 !default;

// Alerts and Messages
$info: #1c2659 !default;
$success: #0f5132 !default;
$warning: #664d03 !default;
$danger: #a72b1e !default;

$info-bg: #ebf1f7 !default;
$success-bg: #e2f1eb !default;
$danger-bg: #fdecee !default;
$warning-bg: #f9f4e4 !default;

$body-bg: #fff !default;
$bg-secondary: #f2f2f2 !default;
$bg-tertiary: #e6e6e6 !default;
Expand Down
4 changes: 1 addition & 3 deletions meinberlin/templates/a4images/image_upload_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
>
</div>
<div class="col-12">
<div class="alert alert--info upload-wrapper__alert" aria-live="polite">
{% include 'meinberlin_contrib/components/alert.html' with alert_message='Your image will be uploaded/removed once you save your changes at the end of this page.' alert_type='info' %}
</div>
{% include 'meinberlin_contrib/components/alert.html' with alert_message='Your image will be uploaded/removed once you save your changes at the end of this page.' alert_type='info' %}
</div>
</div>

0 comments on commit 5344acd

Please sign in to comment.