Skip to content

Commit

Permalink
Use container-fluid with JS to expand toc's width
Browse files Browse the repository at this point in the history
  • Loading branch information
danirus committed Feb 19, 2024
1 parent 0a00d9e commit fb8c09d
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 136 deletions.
1 change: 1 addition & 0 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ window.addEventListener('DOMContentLoaded', (_) => {
//
updateScrollPaddingTop();
resizeAsides(); // Resize just after DOM content is loaded.

// And register the function for every height change of the body.
const resize_observer = new ResizeObserver(entries => resizeAsides());
resize_observer.observe(document.body);
Expand Down
21 changes: 20 additions & 1 deletion js/src/tocresize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export function resizeAsides() {
let height = "";

const nftt_layout = document.querySelector(".nftt-layout");
const nftt_content = document.querySelector(".nftt-content");
const nftt_sidebar = document.querySelector(".nftt-sidebar");
const nftt_sidebar_content = document.querySelector(".nftt-sidebar-content");
const nftt_toc = document.querySelector(".nftt-toc");

if (nftt_content != undefined) {
Expand All @@ -10,13 +13,15 @@ export function resizeAsides() {
: `height: ${nftt_content.clientHeight}px`;
}

// Height for nftt-sidebar.
// Apply style attribute to nftt-sidebar (when min-width >= 1200px).
if (window.matchMedia('(min-width: 1200px)').matches == false) {
nftt_sidebar?.setAttribute("style", "");
} else {
nftt_sidebar?.setAttribute("style", height);
}

// Height for nftt-toc.
// Apply style attribute to nftt-toc (when min-width >= 992px).
if (window.matchMedia('(min-width: 992px)').matches == false) {
nftt_toc?.setAttribute("style", "");
Expand All @@ -25,7 +30,21 @@ export function resizeAsides() {
nftt_toc?.setAttribute("style", height);
}

return height;
// Compute new 'grid-template-columns' for nftt-layout.
const max = (window.innerWidth - nftt_content.offsetWidth);
const newmax = nftt_toc
? Math.floor(max / 2)
: (
nftt_sidebar_content
? Math.floor((max + nftt_sidebar_content.offsetWidth) / 2)
: undefined
);
if (newmax) {
const newgtcols = `minmax(300px, ${newmax}px) 5fr`;
nftt_layout?.setAttribute("style", `grid-template-columns: ${newgtcols}`);
}

return [height, newmax];
}


Expand Down
8 changes: 4 additions & 4 deletions js/tests/unit/tocresize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ describe('resize', () => {
}
);

const resulting_height = resizeAsides();
expect(resulting_height).toEqual("height: calc(100vh - 7rem)");
const results = resizeAsides();
expect(results[0]).toEqual("height: calc(100vh - 7rem)");
});

it('checks resizeAsides when nftt_content shorter than body', () => {
Expand All @@ -90,7 +90,7 @@ describe('resize', () => {
}
);

const resulting_height = resizeAsides();
expect(resulting_height).toEqual(expected_height);
const results = resizeAsides();
expect(results[0]).toEqual(expected_height);
});
});
13 changes: 10 additions & 3 deletions scss/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ body {
@include media-breakpoint-up(xl) {
display: grid;
grid-template-areas: "sidebar main";
grid-template-columns: minmax(300px 2fr) 5fr;
gap: 1.5rem;
grid-template-columns: minmax(300px, 1.5fr) 5fr;
gap: 25px;
}
}

Expand Down Expand Up @@ -63,10 +63,12 @@ body {
display: grid;
grid-area: main;
grid-template-areas: "content";
grid-template-columns: minmax(570px, 860px);
padding-right: 48px;

@include media-breakpoint-down(xl) {
padding-right: 0;
grid-template-columns: none;
}
}

Expand All @@ -86,7 +88,7 @@ body {

@include media-breakpoint-up(lg) {
grid-template-areas: "content toc";
grid-template-columns: minmax(570px, 790px) minmax(190px, 1.3fr);
grid-template-columns: minmax(570px, 760px) minmax(190px, 1.3fr);
}
}

Expand All @@ -107,6 +109,11 @@ body {
font-family: var(--#{$prefix}documentation-font);
font-size: var(--#{$prefix}documentation-font-size);

@include media-breakpoint-down(xl) {
padding-left: 2rem;
padding-right: 2rem;
}

h1,
h2,
h3,
Expand Down
2 changes: 2 additions & 0 deletions scss/components/_toc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
z-index: 2;
padding-right: .25rem;
overflow-y: auto;
// overflow-x: auto;
// white-space: nowrap;

@include scrollbars();
}
Expand Down
173 changes: 88 additions & 85 deletions site/index.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions sphinx_nefertiti/colorsets-dropdown.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- colorssets-dropdown.html -->
<li class="nav-item dropdown">
<a class="nav-link d-flex py-2 px-0 px-lg-2 dropdown-toggle align-items-center" id="snftt-color" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false" aria-label="Toggle color set">
<a class="nav-link d-flex py-2 px-0 px-xl-2 dropdown-toggle align-items-center" id="snftt-color" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false" aria-label="Toggle color set">
<i class="bi bi-palette"></i>
<span id="snftt-color-text" class="d-lg-none small ms-2">{{ _('Change color set') }}</span>
<span id="snftt-color-text" class="d-xl-none small ms-2">{{ _('Change color set') }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="snftt-color-text">
<li>
Expand All @@ -22,7 +22,7 @@ <h6 class="dropdown-header">{{ _('Change color set') }}</h6>
</ul>
</li>

<li class="nav-item col-12 col-lg-auto h-100" aria-hidden="true">
<div class="vr d-none d-lg-flex h-100 mx-lg-2 text-white"></div>
<li class="nav-item col-12 col-xl-auto h-100" aria-hidden="true">
<div class="vr d-none d-xl-flex h-100 mx-xl-2 text-white"></div>
<hr class="d-lg-none text-white-50">
</li>
2 changes: 1 addition & 1 deletion sphinx_nefertiti/globaltoc.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="offcanvas-header border-bottom">
<h5 class="offcanvas-title" id="nfttSidebarOffcanvasLabel">
<h5 class="offcanvas-title fw-bold" id="nfttSidebarOffcanvasLabel">
{{ _('Table of contents') }}
</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close" data-bs-target="#sidebar"></button>
Expand Down
51 changes: 26 additions & 25 deletions sphinx_nefertiti/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
</style>
</head>
<body>
<header class="navbar navbar-expand-lg navbar-dark nftt-navbar flex-column fixed-top">
<header class="navbar navbar-expand-xl navbar-dark nftt-navbar flex-column fixed-top">
<div class="skip-links container-xxl visually-hidden-focusable overflow-hidden justify-content-start">
<div class="border-bottom mb-2 pb-2 w-100">
<a class="d-none d-md-inline-flex p-2 m-1" href="#sidebar-filter">{{ _('Skip to docs navigation') }}</a>
<a class="d-inline-flex p-2 m-1" href="#content">{{ _('Skip to main content') }}</a>
</div>
</div>
<nav class="container-xxl nftt-gutter flex-wrap flex-lg-nowrap" aria-label="Main navigation">
<nav class="container-xxl nftt-gutter flex-wrap flex-xl-nowrap" aria-label="Main navigation">
<div class="nftt-navbar-toggler">
<button class="navbar-toggler p-2" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar" aria-label="Toggle documentation navigation">
<i class="bi bi-list"></i>
Expand All @@ -129,7 +129,7 @@
class="navbar-brand p-0 me-0 md-lg-2"
><span class="brand-text">{{ project }}</span></a>
{% endif %}
<div class="d-flex d-lg-none">
<div class="d-flex d-xl-none">
<button class="navbar-toggler p-2" type="button" data-bs-toggle="offcanvas" data-bs-target="#nfttSearch" aria-controls="nfttSearch" aria-label="Search">
<i class="bi bi-search"></i>
</button>
Expand All @@ -138,17 +138,17 @@
</button>
</div>
{% include "searchbox.html" %}
<div class="offcanvas-lg offcanvas-end" tabindex="-1" id="nfttNavbar" aria-labelledby="nfttNavbarOffcanvasLabel" data-bs-scroll="true">
<div class="offcanvas-xl offcanvas-end flex-grow-1" tabindex="-1" id="nfttNavbar" aria-labelledby="nfttNavbarOffcanvasLabel" data-bs-scroll="true">
<div class="offcanvas-header px-4 pb-0">
<div class="offcanvas-title text-white fw-bold" id="nfttNavbarOffcanvasLabel"><span class="brand-text">Nefertiti for Sphinx</span></div>
<div class="offcanvas-title navbar-brand" id="nfttNavbarOffcanvasLabel"><span class="brand-text">Nefertiti for Sphinx</span></div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close" data-bs-target="#nfttNavbar"></button>
</div>
<div class="offcanvas-body p-4 pt-0 p-lg-0">
<hr class="d-lg-none text-white-50">
<ul class="navbar-nav flex-row align-items-center flex-wrap ms-md-auto">
<div class="offcanvas-body p-4 pt-0 p-xl-0 px-xl-3">
<hr class="d-xl-none text-white-50">
<ul class="navbar-nav flex-row align-items-center flex-wrap ms-lg-auto">
{% if theme_repository_url and theme_repository_name %}
<li class="nav-item col-12 col-lg-auto">
<a class="nav-link py-2 py-lg-0 px-0 px-lg-2" href="{{ theme_repository_url }}" target="_blank" rel="noopener">
<li class="nav-item col-12 col-xl-auto">
<a class="nav-link py-2 py-xl-0 px-0 px-xl-2" href="{{ theme_repository_url }}" target="_blank" rel="noopener">
<div class="d-flex align-items-center">
<div class="me-2">
<i class="bi bi-git size-24"></i>
Expand All @@ -173,9 +173,9 @@
</div>
</a>
</li>
<li class="nav-item col-12 col-lg-auto h-100" aria-hidden="true">
<div class="vr d-none d-lg-flex h-100 mx-lg-2 text-white"></div>
<hr class="d-lg-none text-white-50">
<li class="nav-item col-12 col-xl-auto h-100" aria-hidden="true">
<div class="vr d-none d-xl-flex h-100 mx-xl-2 text-white"></div>
<hr class="d-xl-none text-white-50">
</li>
{% endif %}
{% include "version-dropdown.html" %}
Expand All @@ -189,16 +189,18 @@
</nav>
</header>

<div class="container-xxl nftt-gutter nftt-layout">
<div class="container-fluid nftt-gutter nftt-layout">
<aside class="nftt-sidebar">
<div class="title d-none d-md-block">
<i class="bi bi-book"></i>&nbsp;&nbsp;<span>{{ _('Table of contents') }}</span>
</div>
<div id="sidebar" tabindex="-1" class="offcanvas-lg offcanvas-start" aria-labelledby="nfttSidebarOffcanvasLabel">
{%- for sidebartemplate in sidebars %}
<!-- danirus sidebartemplate: "{{ sidebartemplate }}" -->
{%- include sidebartemplate %}
{%- endfor %}
<div class="nftt-sidebar-content">
<div class="title d-none d-xl-block">
<i class="bi bi-book"></i>&nbsp;&nbsp;<span>{{ _('Index') }}</span>
</div>
<div id="sidebar" tabindex="-1" class="offcanvas-xl offcanvas-start" aria-labelledby="nfttSidebarOffcanvasLabel">
{%- for sidebartemplate in sidebars %}
<!-- danirus sidebartemplate: "{{ sidebartemplate }}" -->
{%- include sidebartemplate %}
{%- endfor %}
</div>
</div>
</aside>
<main class="{% if hidetoc %}nftt-main-wo-toc{% else %}nftt-main{% endif %}">
Expand All @@ -209,12 +211,11 @@
{% if display_toc and not hidetoc %}
<aside class="nftt-toc">
<div class="mt-3 mb-1 my-lg-0 ps-xl-3 text-muted">
<button class="btn btn-link link-dark p-md-0 mb-2 mb-md-0 text-decoration-none nftt-toc-toggle d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#tocContents" aria-expanded="false" aria-controls="tocContents"
<button class="btn btn-link link-dark p-lg-0 mb-2 mb-lg-0 text-decoration-none nftt-toc-toggle d-lg-none" type="button" data-bs-toggle="collapse" data-bs-target="#tocContents" aria-expanded="false" aria-controls="tocContents"
>On this page <i class="ms-2 bi bi-chevron-expand"></i></button>
<div class="title d-none d-md-block">
<div class="title d-none d-lg-block">
<i class="bi bi-file-earmark-text"></i>&nbsp;&nbsp;<span class="small">On this page</span>
</div>
<hr class="d-none d-md-block my-2">
<div class="collapse nftt-toc-collapse" id="tocContents">
<nav id="TableOfContents">
{{ toc }}
Expand Down
4 changes: 2 additions & 2 deletions sphinx_nefertiti/lightdark-dropdown.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- colorscheme_dropdown.html -->
<li class="nav-item dropdown">
<a class="nav-link d-flex py-2 px-0 px-lg-2 dropdown-toggle align-items-center" id="snftt-luz" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false" aria-label="Toggle light/dark">
<a class="nav-link d-flex py-2 px-0 px-xl-2 dropdown-toggle align-items-center" id="snftt-luz" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false" aria-label="Toggle light/dark">
<i class="bi bi-circle-half" data-snftt-luz-icon-active></i>
<span id="snftt-luz-text" class="d-lg-none small ms-2">{{ _('Toggle light/dark') }}</span>
<span id="snftt-luz-text" class="d-xl-none small ms-2">{{ _('Toggle light/dark') }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="snftt-luz-text">
<li>
Expand Down
8 changes: 4 additions & 4 deletions sphinx_nefertiti/searchbox.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{%- if pagename != "search" and builder != "singlehtml" %}
<div class="offcanvas-lg offcanvas-end flex-grow-1" tabindex="-1" id="nfttSearch" aria-labelledby="nfttSearchOffcanvasLabel" data-bs-scroll="true">
<div class="offcanvas-xl offcanvas-end flex-grow-1" tabindex="-1" id="nfttSearch" aria-labelledby="nfttSearchOffcanvasLabel" data-bs-scroll="true">
<div class="offcanvas-header px-4 pb-0">
<h5 class="offcanvas-title fw-bold" id="nfttSearchOffcanvasLabel">Search the documentation</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close" data-bs-target="#nfttSearch"></button>
</div>
<div class="offcanvas-body p-4 pt-0 p-lg-0 px-lg-3">
<hr class="d-lg-none text-white-50">
<div class="offcanvas-body p-4 pt-0 p-xl-0 px-xl-3">
<hr class="d-xl-none text-white-50">
<ul class="navbar-nav flex-row align-items-center flex-wrap ms-md-auto">
<li class="nav-item col-12 col-lg-auto">
<li class="nav-item col-12 col-xl-auto">
<form id="nftt-search-form" action="{{ pathto('search') }}" method="get">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="{{ _('Search docs') }}" aria-label="Search" aria-describedby="button-search">
Expand Down
14 changes: 7 additions & 7 deletions sphinx_nefertiti/version-dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{% if READTHEDOCS or theme_versions %}
{% if READTHEDOCS %}
<li class="nav-item dropdown">
<a class="nav-link d-flex py-2 px-0 px-lg-2 dropdown-toggle align-items-center" id="snftt-version" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-label="Select version">
<span id="snftt-version-text" class="d-lg-none small">{{ project|striptags|e }}</span>
<a class="nav-link d-flex py-2 px-0 px-xl-2 dropdown-toggle align-items-center" id="snftt-version" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-label="Select version">
<span id="snftt-version-text" class="d-xl-none small">{{ project|striptags|e }}</span>
<span class="small ms-2" data-snftt-version-active="{{ current_version }}">v: {{ current_version }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="snftt-version-text">
Expand Down Expand Up @@ -32,8 +32,8 @@ <h6 class="dropdown-header">On Read the Docs</h6>
</li>
{% elif theme_versions %}
<li class="nav-item dropdown">
<a class="nav-link d-flex py-2 px-0 px-lg-2 dropdown-toggle align-items-center" id="snftt-version" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-label="Select version">
<span id="snftt-version-text" class="d-lg-none small">{{ project|striptags|e }}</span>
<a class="nav-link d-flex py-2 px-0 px-xl-2 dropdown-toggle align-items-center" id="snftt-version" href="#" data-bs-toggle="dropdown" data-bs-display="static" aria-label="Select version">
<span id="snftt-version-text" class="d-xl-none small">{{ project|striptags|e }}</span>
<span class="small ms-2" data-snftt-version-active="{{ theme_current_version }}">{{ theme_current_version }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="snftt-version-text">
Expand All @@ -52,8 +52,8 @@ <h6 class="dropdown-header">{{ _('Versions') }}</h6>
</li>
{% endif %}

<li class="nav-item col-12 col-lg-auto h-100" aria-hidden="true">
<div class="vr d-none d-lg-flex h-100 mx-lg-2 text-white"></div>
<hr class="d-lg-none text-white-50">
<li class="nav-item col-12 col-xl-auto h-100" aria-hidden="true">
<div class="vr d-none d-xl-flex h-100 mx-xl-2 text-white"></div>
<hr class="d-xl-none text-white-50">
</li>
{% endif %}

0 comments on commit fb8c09d

Please sign in to comment.