Skip to content

Commit

Permalink
update bootstrap lib to 5.3.0, add theme selector and correct templat…
Browse files Browse the repository at this point in the history
…e for dark mode support
  • Loading branch information
vsimakhin committed Jun 3, 2023
1 parent fba535c commit 6428e9a
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- New: Dark mode.
- New: A popup with airport infromation once you click on the marker on the `Map` page.
- Update: The Openlayers library upgraded to the version 7.3.0

Expand Down
7 changes: 3 additions & 4 deletions cmd/web/static/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/web/static/css/bootstrap.min.css.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions cmd/web/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ body {

.sidebar .nav-link {
font-weight: 500;
color: #333;
color: var(--bs-heading-color,inherit);
}

.sidebar .nav-link .feather {
Expand All @@ -58,7 +58,6 @@ body {
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/web/static/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/web/static/js/bootstrap.bundle.min.js.map

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions cmd/web/static/js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
(() => {
'use strict'

const storedTheme = localStorage.getItem('theme')

const getPreferredTheme = () => {
if (storedTheme) {
return storedTheme
}

return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

const setTheme = function (theme) {
if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark')
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}

setTheme(getPreferredTheme())

const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')

if (!themeSwitcher) {
return
}

const themeSwitcherText = document.querySelector('#bd-theme-text')
const activeThemeIcon = document.querySelector('#active-theme-i')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const iconOfActiveBtn = btnToActive.querySelector('i a').getAttribute('href')

document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
element.setAttribute('aria-pressed', 'false')
})

btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('class', `bi ${iconOfActiveBtn.replace('#','')}`)
const themeSwitcherLabel = `${themeSwitcherText.textContent}`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)

if (focus) {
themeSwitcher.focus()
}
}

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (storedTheme !== 'light' || storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})

window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())

document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
localStorage.setItem('theme', theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()
29 changes: 28 additions & 1 deletion cmd/web/templates/base.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-icons.css">
<link rel="stylesheet" type="text/css" href="/static/css/daterangepicker.css" />
</head>
<script type="text/javascript" src="/static/js/theme.js"></script>
<body>
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-3 col-lg-1 me-0 px-3 fs-6" href="/">Web Logbook</a>
Expand All @@ -28,7 +29,7 @@

<div class="container-fluid">
<div class="row">
<nav id="sidebarMenu" class="col-md-3 col-lg-1 d-md-block bg-light sidebar collapse">
<nav id="sidebarMenu" class="col-md-3 col-lg-1 d-md-block sidebar collapse">
<div class="position-sticky pt-3">
<ul class="nav flex-column">
<li class="nav-item">
Expand Down Expand Up @@ -68,6 +69,32 @@
<a class="nav-link" href="https://github.com/vsimakhin/web-logbook"><i class="bi bi-github"></i> v{{.Version}}
{{if .NewVersion}}<span class="badge rounded-pill text-bg-info">New</span>{{ end }}</a>
</li>

<!--theme selector -->
<div class="dropdown position-fixed bottom-0 start-0 mb-3 me-3 bd-mode-toggle">
<button class="btn btn-bd-primary py-2 dropdown-toggle d-flex align-items-center"
id="bd-theme" type="button" aria-expanded="false" data-bs-toggle="dropdown" aria-label="Toggle theme (auto)">
<i class="bi bi-circle-half" id="active-theme-i"></i><span class="visually-hidden" id="bd-theme-text">Toggle theme</span>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="bd-theme-text">
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false">
<i class="bi bi-sun-fill"><a href=#bi-sun-fill></a></i>&nbsp;Light
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark" aria-pressed="false">
<i class="bi bi-moon-stars-fill"><a href=#bi-moon-stars-fill></a></i>&nbsp;Dark
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto" aria-pressed="true">
<i class="bi bi-circle-half"><a href=#bi-circle-half></a></i>&nbsp;Auto
</button>
</li>
</ul>
</div>

</ul>
</div>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion cmd/web/templates/export-a4.partials.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div class="row"><strong>Logbook Columns Header <a onclick="wlbExport.restoreDefaults('a4headers')" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Restore header defaults"><i class="bi bi-arrow-counterclockwise"></i></a></strong></div>
<hr>
<div class="row">
<table id="logbook" class="table-editable table-responsive-md table table-sm table-bordered table-secondary nowrap table-fixed">
<table id="logbook" class="table-editable table-responsive-md table table-sm table-bordered table-active nowrap table-fixed">
<thead>
<tr class="align-top text-center">
<th rowspan=2 class="text-center" id="header_date_a4" contenteditable>{{$settings.ExportA4.Headers.Date}}</th>
Expand Down
2 changes: 1 addition & 1 deletion cmd/web/templates/export-a5.partials.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<div class="row"><strong>Logbook Columns Header <a onclick="wlbExport.restoreDefaults('a5headers')" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Restore header defaults"><i class="bi bi-arrow-counterclockwise"></i></a></strong></div>
<hr>
<div class="row">
<table id="logbook" class="table-editable table-responsive-md table table-sm table-bordered table-secondary nowrap table-fixed">
<table id="logbook" class="table-editable table-responsive-md table table-sm table-bordered table-active nowrap table-fixed">
<thead>
<tr class="align-top text-center">
<th rowspan=2 class="text-center" id="header_date_a5" contenteditable>{{$settings.ExportA5.Headers.Date}}</th>
Expand Down
2 changes: 1 addition & 1 deletion cmd/web/templates/licensing-js.partials.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ wlbLicensing = function () {
api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
if ( last !== group ) {
$(rows).eq( i ).before(
'<tr class="group"><td colspan="8" class="table-secondary">'+group+'</td></tr>'
'<tr class="group"><td colspan="8" class="table-active">'+group+'</td></tr>'
);
last = group;
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/web/templates/map.page.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
.ol-popup {
position: absolute;
background-color: white;
background-color: var(--bs-body-bg);
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
padding: 15px;
border-radius: 10px;
Expand All @@ -30,7 +30,7 @@
pointer-events: none;
}
.ol-popup:after {
border-top-color: white;
border-top-color: var(--bs-body-bg);
border-width: 10px;
left: 48px;
margin-left: -10px;
Expand Down

0 comments on commit 6428e9a

Please sign in to comment.