Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH animation for the top banner #1693

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 9 additions & 17 deletions src/pydata_sphinx_theme/assets/styles/sections/_announcement.scss
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
.bd-header-version-warning,
.bd-header-announcement {
min-height: 3rem;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be the one thing about the final appearance that still differs between current main and this PR... can we change the definition of autoHeight to be the maximum of 3rem and outer.offsetHeight?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or is there a better approach you can think of?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested solution is clean enough, but I'm thinking perhaps we need still need to add the min-height property for safety. If 3rem > offsetHeight then when we remove the height property it is likely that the height drops back to offsetHeight. I will experiment a bit on that.

Copy link
Contributor Author

@Charlie-XIAO Charlie-XIAO Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so experimenting with min-height 10rem we can see that min-height is still needed.

(Only the last 3 seconds of the video is meaningful... something's wrong with my screen recording)

The.PyData.Sphinx.Theme.PyData.Theme.0.15.3dev0.documentation.7.-.-.Microsoft.Edge.2024-02-02.02-50-43.mp4

width: 100%;
display: flex;
position: relative;
align-items: center;
justify-content: center;
text-align: center;
transition: height 150ms ease-in-out;
overflow-y: hidden;
padding: 0.5rem 12.5%; // Horizontal padding so the width is 75%
// One breakpoint less than $breakpoint-sidebar-primary. See variables/_layout.scss for more info.
@include media-breakpoint-down(lg) {
// Announcements can take a bit more width on mobile
padding: 0.5rem 2%;
}

&.init {
position: fixed;
visibility: hidden;
}

p {
font-weight: bold;
margin: 0;
}

&:after {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
content: "";
z-index: -1; // So it doesn't hover over the content
}

&:empty {
display: none;
}
Expand All @@ -41,13 +37,9 @@

// Bg color is now defined in the theme color palette - using our secondary color
.bd-header-announcement {
&:after {
background-color: var(--pst-color-secondary-bg);
}
background-color: var(--pst-color-secondary-bg);
}

.bd-header-version-warning {
&:after {
background-color: var(--pst-color-danger-bg);
}
background-color: var(--pst-color-danger-bg);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set header_classes = ["bd-header-announcement", "container-fluid"] %}
{% set header_classes = ["bd-header-announcement", "container-fluid", "init"] %}
{% set is_remote=theme_announcement.startswith("http") %}
{# If we are remote, add a script to make an HTTP request for the value on page load #}
{%- if is_remote %}
Expand All @@ -10,6 +10,19 @@
div = document.querySelector(".bd-header-announcement");
div.classList.add(...{{ header_classes | tojson }});
div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`;
const autoHeight = div.offsetHeight;
// Set height and padding to 0 to prepare the height transition
div.style.height = 0;
div.style.padding = 0;
div.classList.remove("init");
// Set height to the computed height with a small timeout to activate the transition
setTimeout(() => {
div.style.height = `${autoHeight}px`;
// Remove the padding style after 150ms, i.e., the transition time
setTimeout(() => {
div.style.padding = "";
}, 150);
}, 10);
})
.catch(error => {
console.log("[PST]: Failed to load announcement at: {{ theme_announcement }}");
Expand Down
Loading