Skip to content

Commit

Permalink
Added styling for flash messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JayGaba committed Oct 15, 2024
1 parent 287e6e9 commit 26c3e1d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
35 changes: 35 additions & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,41 @@ video {
color: rgba(229, 62, 62, var(--text-opacity));
}

.flash-message {
position: relative;
padding: 1rem 2.5rem 1rem 1rem;
border-radius: 0.375rem;
margin-bottom: 1rem;
font-weight: 500;
background-color: #eb7f325b;
border: 1px solid #aa4700;
color: #aa4700;
}

.flash-message .btn-close {
position: absolute;
top: 0;
right: 0;
padding: 1rem;
color: inherit;
background: transparent;
border: 0;
font-size: 1.5rem;
font-weight: 700;
line-height: 1;
opacity: 0.5;
cursor: pointer;
}

.flash-message .btn-close:hover,
.flash-message .btn-close:focus {
opacity: 1;
}

.flash-message .btn-close::after {
content: "×";
}

.space-y-0 > :not(template) ~ :not(template) {
--space-y-reverse: 0;
margin-top: calc(0px * calc(1 - var(--space-y-reverse)));
Expand Down
8 changes: 8 additions & 0 deletions assets/js/flash-messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.flash-message .btn-close').forEach(function(button) {
button.addEventListener('click', function(e) {
e.preventDefault();
this.closest('.flash-message').remove();
});
});
});
6 changes: 5 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,600,700&display=swap" rel="stylesheet">
<link href="/assets/css/app.css" rel="stylesheet">
<script src="https://cdn.usefathom.com/script.js" data-site="ICQJXHPJ" defer></script>
<script src="/assets/js/flash-messages.js" defer></script>
</head>
<body class="min-h-screen flex flex-col">
<header class="header-image relative text-center">
Expand All @@ -34,7 +35,10 @@
<main class="px-4 py-4 flex-1">
<div class="max-w-lg mx-auto">
{{ range .flashes }}
<p>{{ . }}</p>
<div class="flash-message">
{{ . }}
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
{{ end }}
{{ template "content" . }}
</div>
Expand Down

0 comments on commit 26c3e1d

Please sign in to comment.