Skip to content

Commit b3c7094

Browse files
committed
feat: Upgrade bootstrap to 5.3.0 and enable dark mode
Fixes ietf-tools#3365
1 parent f711c83 commit b3c7094

12 files changed

Lines changed: 129 additions & 18 deletions

.pnp.cjs

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-1.7 MB
Binary file not shown.
1.73 MB
Binary file not shown.

ietf/static/css/datepicker.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
@import "vanillajs-datepicker/sass/index-bs5";
1+
@import "bootstrap/scss/functions";
2+
@import "bootstrap/scss/variables";
3+
@import "bootstrap/scss/variables-dark";
4+
@import "bootstrap/scss/maps";
5+
@import "bootstrap/scss/mixins";
6+
@import "bootstrap/scss/root";
7+
8+
// FIXME: color.scale doesn't seem to work with CSS variables, so avoid those:`
9+
$dp-cell-focus-background-color: $dropdown-link-hover-bg !default;
10+
211
@import "vanillajs-datepicker/sass/datepicker-bs5";

ietf/static/css/document_html.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $font-family-monospace: "Noto Sans Mono", SFMono-Regular, Menlo, Monaco, Consola
1111

1212
@import "bootstrap/scss/functions";
1313
@import "bootstrap/scss/variables";
14+
@import "bootstrap/scss/variables-dark";
1415
@import "bootstrap/scss/maps";
1516
@import "bootstrap/scss/mixins";
1617
@import "bootstrap/scss/utilities";

ietf/static/css/ietf.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ $popover-max-width: 100%;
1515
$font-family-sans-serif: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
1616
$font-family-monospace: "Noto Sans Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
1717

18+
// Allow color modes
19+
20+
$color-mode-type: media-query;
21+
1822
// Only import what we need:
1923

2024
@import "bootstrap/scss/variables";
25+
@import "bootstrap/scss/variables-dark";
2126

2227
$h1-font-size: $font-size-base * 2.2;
2328
$h2-font-size: $font-size-base * 1.8;
@@ -334,7 +339,7 @@ th,
334339
}
335340

336341
.ballot-icon table .my {
337-
border: 2 * $table-border-width solid #000;
342+
border: calc(2 * $table-border-width) solid #000;
338343
}
339344

340345
// See https://getbootstrap.com/docs/5.1/customize/color/#all-colors

ietf/static/css/list.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Import bootstrap helpers
22
@import "bootstrap/scss/functions";
33
@import "bootstrap/scss/variables";
4+
@import "bootstrap/scss/variables-dark";
45

56
table .sort {
67
cursor: pointer;

ietf/static/css/select2.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@import "bootstrap/scss/functions";
22
@import "bootstrap/scss/variables";
3+
@import "bootstrap/scss/variables-dark";
4+
@import "bootstrap/scss/maps";
35
@import "bootstrap/scss/mixins";
6+
@import "bootstrap/scss/root";
7+
8+
// FIXME: bs-5.3.0 workaround from https://github.com/apalfrey/select2-bootstrap-5-theme/issues/75s
9+
$s2bs5-clear-icon: str-replace($btn-close-bg, #{$btn-close-color}, #{shade-color(red, 50%)}) !default;
410
@import "select2/src/scss/core";
511
@import "select2-bootstrap-5-theme/src/include-all";

ietf/static/js/theme.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*!
2+
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
3+
* Copyright 2011-2023 The Bootstrap Authors
4+
* Licensed under the Creative Commons Attribution 3.0 Unported License.
5+
*/
6+
7+
(() => {
8+
"use strict";
9+
10+
const storedTheme = localStorage.getItem("theme");
11+
12+
const getPreferredTheme = () => {
13+
if (storedTheme) {
14+
return storedTheme;
15+
}
16+
17+
return window.matchMedia("(prefers-color-scheme: dark)").matches
18+
? "dark"
19+
: "light";
20+
};
21+
22+
const setTheme = function (theme) {
23+
if (
24+
theme === "auto" &&
25+
window.matchMedia("(prefers-color-scheme: dark)").matches
26+
) {
27+
document.documentElement.setAttribute("data-bs-theme", "dark");
28+
} else {
29+
document.documentElement.setAttribute("data-bs-theme", theme);
30+
}
31+
};
32+
33+
setTheme(getPreferredTheme());
34+
35+
const showActiveTheme = (theme, focus = false) => {
36+
const themeSwitcher = document.querySelector("#bd-theme");
37+
38+
if (!themeSwitcher) {
39+
return;
40+
}
41+
42+
const themeSwitcherText = document.querySelector("#bd-theme-text");
43+
const activeThemeIcon = document.querySelector(".theme-icon-active use");
44+
const btnToActive = document.querySelector(
45+
`[data-bs-theme-value="${theme}"]`
46+
);
47+
const svgOfActiveBtn = btnToActive
48+
.querySelector("svg use")
49+
.getAttribute("href");
50+
51+
document.querySelectorAll("[data-bs-theme-value]").forEach((element) => {
52+
element.classList.remove("active");
53+
element.setAttribute("aria-pressed", "false");
54+
});
55+
56+
btnToActive.classList.add("active");
57+
btnToActive.setAttribute("aria-pressed", "true");
58+
activeThemeIcon.setAttribute("href", svgOfActiveBtn);
59+
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`;
60+
themeSwitcher.setAttribute("aria-label", themeSwitcherLabel);
61+
62+
if (focus) {
63+
themeSwitcher.focus();
64+
}
65+
};
66+
67+
window
68+
.matchMedia("(prefers-color-scheme: dark)")
69+
.addEventListener("change", () => {
70+
if (storedTheme !== "light" || storedTheme !== "dark") {
71+
setTheme(getPreferredTheme());
72+
}
73+
});
74+
75+
window.addEventListener("DOMContentLoaded", () => {
76+
showActiveTheme(getPreferredTheme());
77+
78+
document.querySelectorAll("[data-bs-theme-value]").forEach((toggle) => {
79+
toggle.addEventListener("click", () => {
80+
const theme = toggle.getAttribute("data-bs-theme-value");
81+
localStorage.setItem("theme", theme);
82+
setTheme(theme);
83+
showActiveTheme(theme, true);
84+
});
85+
});
86+
});
87+
})();

ietf/templates/base.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% origin %}
77
{% load django_bootstrap5 %}
88
{% load django_vite %}
9-
<html lang="en" {% block html_attrs %}{% endblock %}>
9+
<html data-bs-theme="auto" lang="en" {% block html_attrs %}{% endblock %}>
1010
<head>
1111
{% analytical_head_top %}
1212
<meta charset="utf-8">
@@ -160,6 +160,7 @@
160160
{% endblock %}
161161
{% block js %}
162162
{% endblock %}
163+
<script src="{% static 'ietf/js/theme.js' %}"></script>
163164
<script src="{% static 'ietf/js/select2.js' %}"></script>
164165
<script>
165166
$('#navbar-doc-search').on('select2:select', function (e) {

0 commit comments

Comments
 (0)