Skip to content

Commit

Permalink
Infra: update canonical banners to not stick on small screens (#3559)
Browse files Browse the repository at this point in the history
Updates small media sizes to not have a sticky banner
Adds a helper close button to optionally close banner

Closes #3536
  • Loading branch information
JacobCoffee authored Dec 3, 2023
1 parent 2d1bdc5 commit ff0702e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def run(self) -> list[nodes.admonition]:
else:
pre_text = self.admonition_pre_text

close_button_node = nodes.paragraph('', '', nodes.Text('×'), classes=['close-button'])
close_button_node['classes'].append('close-button')

pre_text_node = nodes.paragraph(pre_text)
pre_text_node.line = self.lineno
pre_node, pre_msg = self.state.inline_text(pre_text, self.lineno)
Expand All @@ -50,6 +53,7 @@ def run(self) -> list[nodes.admonition]:
"\n".join(source_lines), classes=["pep-banner"] + self.css_classes)

admonition_node.append(pre_text_node)
admonition_node.append(close_button_node)
if self.content:
self.state.nested_parse(
self.content, self.content_offset, admonition_node)
Expand Down
10 changes: 10 additions & 0 deletions pep_sphinx_extensions/pep_theme/static/sticky_banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ document.addEventListener("DOMContentLoaded", () => {
node.replaceChildren(text);
}

const closeButton = document.querySelector('.close-button');
if (closeButton) {
closeButton.addEventListener('click', () => {
const stickyBanner = document.querySelector('.sticky-banner');
if (stickyBanner) {
stickyBanner.style.display = 'none';
}
});
}

adjustBannerMargin();
document.addEventListener("resize", adjustBannerMargin);
document.addEventListener("load", adjustBannerMargin);
Expand Down
23 changes: 23 additions & 0 deletions pep_sphinx_extensions/pep_theme/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,31 @@ dl.footnote > dd {
}

/* Sticky banners */
/* Default styles, sticky for larger screens */
.sticky-banner {
top: 0;
position: sticky;
z-index: 1;
}

/* Override for smaller screens, non-sticky */
@media (max-width: 600px) {
.sticky-banner {
position: static;
padding: 5px;
font-size: 12px;
}
}

.close-button {
cursor: pointer;
position: absolute;
top: 0;
right: 0;
padding: 0.5em;
font-size: 1.5em;
border: none;
background: transparent;
color: inherit;
margin-top: 0;
}

0 comments on commit ff0702e

Please sign in to comment.