From 0e4de968db009fcb2fa5462ce419f7565fb03523 Mon Sep 17 00:00:00 2001 From: Corban-Lee <77944149+Corban-Lee@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:32:20 +0100 Subject: [PATCH] Dynamic sidebar implementation --- src/static/css/custom.css | 12 ----- src/static/js/base.js | 17 ++++++ src/static/scss/base.scss | 105 ++++++++++++++++++++++++++++++++++++++ src/templates/base.html | 50 +++++++++++------- 4 files changed, 154 insertions(+), 30 deletions(-) create mode 100644 src/static/js/base.js create mode 100644 src/static/scss/base.scss diff --git a/src/static/css/custom.css b/src/static/css/custom.css index 7db4c8d..17864ee 100644 --- a/src/static/css/custom.css +++ b/src/static/css/custom.css @@ -124,22 +124,10 @@ input[type='radio']:checked { box-shadow: none; } -#sidebar { - width: 80px; -} - -#webContent { - margin-left: 80px; -} - .light-tooltip { --bs-tooltip-bg: #04385c; } -#sidebar .nav-item > a:hover { - background-color: rgba(0, 0, 0, 0.15); -} - html, body { overflow: hidden !important; max-width: 100vw; diff --git a/src/static/js/base.js b/src/static/js/base.js new file mode 100644 index 0000000..53852ad --- /dev/null +++ b/src/static/js/base.js @@ -0,0 +1,17 @@ +$(".sidebar-collapse-button").on("click", function () { + + const sidebar = $("#sidebar") + const content = $("#webContent") + const collapsed = !sidebar.hasClass("sidebar-enlarged"); + + if (collapsed) { + sidebar.addClass("sidebar-enlarged"); + sidebar.find(".nav-item").tooltip("disable"); + content.addClass("webcontent-collapsed") + } + else { + sidebar.removeClass("sidebar-enlarged"); + sidebar.find(".nav-item").tooltip("enable"); + content.removeClass("webcontent-collapsed") + } +}); diff --git a/src/static/scss/base.scss b/src/static/scss/base.scss new file mode 100644 index 0000000..5c0bc98 --- /dev/null +++ b/src/static/scss/base.scss @@ -0,0 +1,105 @@ +#webContent { + margin-left: 80px; + transition: margin 400ms ease-in-out; + + &.webcontent-collapsed { + margin-left: 280px !important; + } +} + +#sidebar { + + color: white; + background-color: #04385c; + + display: flex; + flex-direction: column; + flex-shrink: 0; + + position: fixed; + height: 100%; + z-index: 3; + padding: 1rem 0; + + transition: width 400ms ease-in-out; + overflow: hidden; + + .sidebar-collapse-button { + + display: inline-block; + color: white; + border: none; + background: none; + transition: transform 200ms ease-in-out; + + } + + &.sidebar-enlarged { + width: 280px !important; + + .sidebar-collapse-button > i { transform: rotate(-180deg); } + + a.nav-link { + text-align: start !important; + + i.bi { + margin: 0 1rem 0 .5rem !important; + } + + span.sidebar-item-text { + display: inline !important; + } + } + } + + &:not(.sidebar-enlarged) { + width: 80px; + } + + #sidebar-brand { + + max-width: 120px; + align-self: center; + display: flex; + align-items: center; + color: inherit; + text-decoration: none; + padding: 0 .5rem; + + } + + ul.sidebar-items { + + flex-direction: column; + margin-bottom: auto; + + li.nav-item { + + a.nav-link { + + color: inherit; + transition: all 200ms; + text-align: center; + white-space: nowrap; + + &:hover { background-color: rgba(0, 0, 0, 0.15); } + + i.bi { + // transition: all 200ms ease-in-out; + // margin: 0 auto; + } + + span.sidebar-item-text { + + display: none; + + } + + } + + } + + } + +} + diff --git a/src/templates/base.html b/src/templates/base.html index 783f39a..918328d 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -1,3 +1,4 @@ +{% load compress %}
@@ -6,10 +7,13 @@