Skip to content

Commit 9217a02

Browse files
awolfdenAdam Wolfman
andauthored
Add snackbar to send event buttons (#26)
Co-authored-by: Adam Wolfman <[email protected]>
1 parent 55ba6b7 commit 9217a02

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

python-flask-audit-logs-example/static/login.css

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,49 @@ pre.prettyprint {
358358

359359
.org-button-div {
360360
min-width: 233px;
361-
}
361+
}
362+
363+
#snackbar {
364+
visibility: hidden; /* Hidden by default. Visible on click */
365+
min-width: 250px; /* Set a default minimum width */
366+
margin-left: -125px; /* Divide value of min-width by 2 */
367+
background-color: rgba(51, 51, 51, 0.786); /* Black background color */
368+
color: #fff; /* White text color */
369+
text-align: center; /* Centered text */
370+
border-radius: 2px; /* Rounded borders */
371+
padding: 16px; /* Padding */
372+
position: fixed; /* Sit on top of the screen */
373+
z-index: 1; /* Add a z-index if needed */
374+
left: 50%; /* Center the snackbar */
375+
bottom: 30px; /* 30px from the bottom */
376+
}
377+
378+
/* Show the snackbar when clicking on a button (class added with JavaScript) */
379+
#snackbar.show {
380+
visibility: visible; /* Show the snackbar */
381+
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
382+
However, delay the fade out process for 2.5 seconds */
383+
-webkit-animation: fadein 0.1s, fadeout 0.1s .5s;
384+
animation: fadein 0.1s, fadeout 0.1s 0.5s;
385+
}
386+
387+
/* Animations to fade the snackbar in and out */
388+
@-webkit-keyframes fadein {
389+
from {bottom: 0; opacity: 0;}
390+
to {bottom: 30px; opacity: 1;}
391+
}
392+
393+
@keyframes fadein {
394+
from {bottom: 0; opacity: 0;}
395+
to {bottom: 30px; opacity: 1;}
396+
}
397+
398+
@-webkit-keyframes fadeout {
399+
from {bottom: 30px; opacity: 1;}
400+
to {bottom: 0; opacity: 0;}
401+
}
402+
403+
@keyframes fadeout {
404+
from {bottom: 30px; opacity: 1;}
405+
to {bottom: 0; opacity: 0;}
406+
}

python-flask-audit-logs-example/templates/send_events.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ <h2 class="home-hero-gradient">Enterprise Ready</h2>
6565
<form action="{{ url_for('send_event') }}" method="POST">
6666
<div class="flex margin-y-15">
6767
<div>
68-
<button class="box" name="event" id="user_signed_in" value="0" type="submit">
68+
<button class="box" name="event" id="user_signed_in" value="0" type="submit" onclick="showSnackbar()">
6969
<div class="flex width-100p">
7070
<p>User Signed In</p>
7171
</div>
7272
</button>
73-
<button class="box" name="event" id="user_logged_out" value="1" type="submit">
73+
<button class="box" name="event" id="user_logged_out" value="1" type="submit" onclick="showSnackbar()">
7474
<div class="flex width-100p">
7575
<p>User Logged Out</p>
7676
</div>
7777
</button>
7878
</div>
7979
<div>
80-
<button class="box" name="event" id="user_org_deleted" value="2" type="submit">
80+
<button class="box" name="event" id="user_org_deleted" value="2" type="submit" onclick="showSnackbar()">
8181
<div class="flex width-100p">
8282
<p>User Organization Deleted</p>
8383
</div>
8484
</button>
85-
<button class="box" name="event" id="user_connection_deleted" value="3" type="submit">
85+
<button class="box" name="event" id="user_connection_deleted" value="3" type="submit" onclick="showSnackbar()">
8686
<div class="flex width-100p">
8787
<p>User Connection Deleted</p>
8888
</div>
@@ -91,11 +91,18 @@ <h2 class="home-hero-gradient">Enterprise Ready</h2>
9191
</div>
9292
</form>
9393
</div>
94-
94+
<div id="snackbar">Log Event Sent</div>
9595
</div>
9696
</div>
9797
</div>
9898
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
99+
<script>
100+
function showSnackbar() {
101+
var x = document.getElementById("snackbar");
102+
x.className = "show";
103+
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 500);
104+
}
105+
</script>
99106
</body>
100107

101108
</html>

0 commit comments

Comments
 (0)