Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion src/main/resources/templates/fragments/layout.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html th:fragment="layout (template, menu)">
<html th:fragment="layout (template, menu)" data-bs-theme="light">

<head>

Expand Down Expand Up @@ -67,6 +67,15 @@
</li>

</ul>

<ul class="navbar-nav">
<li class="nav-item">
<button id="theme-toggle" class="btn btn-link nav-link">
<span class="fa fa-moon-o" id="dark-theme-icon"></span>
<span class="fa fa-sun-o" id="light-theme-icon" style="display: none;"></span>
</button>
</li>
</ul>
</div>
</div>
</nav>
Expand All @@ -89,6 +98,48 @@

<script th:src="@{/webjars/bootstrap/dist/js/bootstrap.bundle.min.js}"></script>

<script>
// Theme switcher functionality
document.addEventListener('DOMContentLoaded', function() {
const themeToggle = document.getElementById('theme-toggle');
const darkThemeIcon = document.getElementById('dark-theme-icon');
const lightThemeIcon = document.getElementById('light-theme-icon');

// Check for saved theme preference or use system preference
const savedTheme = localStorage.getItem('theme');
const systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;

// Set initial theme
if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) {
document.documentElement.setAttribute('data-bs-theme', 'dark');
darkThemeIcon.style.display = 'none';
lightThemeIcon.style.display = 'inline';
} else {
document.documentElement.setAttribute('data-bs-theme', 'light');
darkThemeIcon.style.display = 'inline';
lightThemeIcon.style.display = 'none';
}

// Handle theme toggle click
themeToggle.addEventListener('click', function() {
const currentTheme = document.documentElement.getAttribute('data-bs-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';

document.documentElement.setAttribute('data-bs-theme', newTheme);
localStorage.setItem('theme', newTheme);

// Toggle icons
if (newTheme === 'dark') {
darkThemeIcon.style.display = 'none';
lightThemeIcon.style.display = 'inline';
} else {
darkThemeIcon.style.display = 'inline';
lightThemeIcon.style.display = 'none';
}
});
});
</script>

</body>

</html>
113 changes: 113 additions & 0 deletions src/main/scss/dark-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
:root {
--primary-color: #6db33f;
--primary-dark-color: #5fa134;
--secondary-color: #34302d;
--text-color: #212529;
--background-color: #fff;
--light-background: #f1f1f1;
--border-color: #dee2e6;
--input-bg: #fff;
--input-border: #ced4da;
--card-bg: #fff;
--card-border: rgba(0, 0, 0, 0.125);
}

[data-bs-theme="dark"] {
--primary-color: #6db33f;
--primary-dark-color: #5fa134;
--secondary-color: #34302d;
--text-color: #f1f1f1;
--background-color: #212529;
--light-background: #343a40;
--border-color: #495057;
--input-bg: #2b3035;
--input-border: #495057;
--card-bg: #2b3035;
--card-border: rgba(255, 255, 255, 0.125);

background-color: var(--background-color);
color: var(--text-color);

.navbar {
background-color: var(--secondary-color);
}

.table {
color: var(--text-color);
border-color: var(--border-color);

> thead > tr > th {
background-color: var(--light-background);
color: var(--text-color);
}

> tbody > tr > td {
border-color: var(--border-color);
}
}

.table-filter {
background-color: var(--light-background);
}

.btn-primary {
color: var(--text-color);
background-color: var(--secondary-color);
border-color: var(--primary-color);

&:hover,
&:focus,
&:active,
&.active,
.open .dropdown-toggle {
background-color: var(--secondary-color);
border-color: var(--primary-dark-color);
}
}

.form-control, .form-select {
background-color: var(--input-bg);
border-color: var(--input-border);
color: var(--text-color);

&:focus {
background-color: var(--input-bg);
color: var(--text-color);
}
}

.card {
background-color: var(--card-bg);
border-color: var(--card-border);
}

hr {
border-top: 1px dotted var(--border-color);
}

.container-details-table th {
background-color: var(--light-background);
color: var(--text-color);
}

.status-help-content-table td {
color: var(--text-color);
}

a {
color: var(--primary-color);

&:hover {
color: var(--primary-dark-color);
}
}

.xd-container {
background-color: var(--background-color);
}

.help-block {
color: var(--text-color);
opacity: 0.7;
}
}
1 change: 1 addition & 0 deletions src/main/scss/petclinic.scss
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,4 @@ hr {
@import "typography.scss";
@import "header.scss";
@import "responsive.scss";
@import "dark-theme.scss";
Loading