diff --git a/.changeset/banner-reduced-motion.md b/.changeset/banner-reduced-motion.md
new file mode 100644
index 0000000000000..cd413a0645b71
--- /dev/null
+++ b/.changeset/banner-reduced-motion.md
@@ -0,0 +1,5 @@
+---
+'@node-core/ui-components': patch
+---
+
+Skip the `Banner` animation for visitors who prefer reduced motion.
diff --git a/.changeset/fade-and-slide-down-spacing.md b/.changeset/fade-and-slide-down-spacing.md
new file mode 100644
index 0000000000000..86f2df9b4cb5c
--- /dev/null
+++ b/.changeset/fade-and-slide-down-spacing.md
@@ -0,0 +1,5 @@
+---
+'@node-core/ui-components': patch
+---
+
+`animate-fade-and-slide-down` now ends at the element's own padding, and also collapses its minimum height and bottom margin.
diff --git a/.changeset/main-gap-variable.md b/.changeset/main-gap-variable.md
new file mode 100644
index 0000000000000..2087ea7ca9cdb
--- /dev/null
+++ b/.changeset/main-gap-variable.md
@@ -0,0 +1,5 @@
+---
+'@node-core/ui-components': patch
+---
+
+Expose the `main` gap as `--main-gap`, and let `animate-fade-and-slide-down` collapse surrounding space via `--fade-and-slide-down-offset`.
diff --git a/apps/site/components/CarbonAds/TopBar.tsx b/apps/site/components/CarbonAds/TopBar.tsx
index b6d06d65b4dc5..9e3ce9eda68fd 100644
--- a/apps/site/components/CarbonAds/TopBar.tsx
+++ b/apps/site/components/CarbonAds/TopBar.tsx
@@ -7,12 +7,10 @@ import type { FC } from 'react';
import styles from './index.module.css';
const CarbonTopBar: FC = () => {
- const { ad, loading, ref } = useCarbonAd('CWBI6KJY');
+ const { ad, ref } = useCarbonAd('CWBI6KJY');
if (!ad) {
- return loading ? (
-
- ) : null;
+ return null;
}
return (
@@ -22,21 +20,23 @@ const CarbonTopBar: FC = () => {
style={adColors(ad)}
aria-label="Advertisement"
>
-
- {/* eslint-disable-next-line @next/next/no-img-element */}
-
- {ad.description}
- {ad.callToAction}
-
-
-
- Ad
-
+
);
};
diff --git a/apps/site/components/CarbonAds/index.module.css b/apps/site/components/CarbonAds/index.module.css
index 15d5d5bca4cb1..0814a3d01595a 100644
--- a/apps/site/components/CarbonAds/index.module.css
+++ b/apps/site/components/CarbonAds/index.module.css
@@ -27,30 +27,32 @@
}
.topBar {
- @apply mb-4
- flex
- items-center
- gap-3
+ @apply animate-fade-and-slide-down
+ mb-4
+ grid
+ grid-rows-1
+ overflow-hidden
rounded-md
px-4
py-2
text-sm
+ [--fade-and-slide-down-offset:var(--main-gap)]
+ motion-reduce:animate-none
lg:min-h-14;
-}
-/* Matches the banner's minimum height, so that it doesn't shift the page when it loads */
-.topBarPlaceholder {
- @apply mb-4
- hidden
- lg:block
- lg:h-14;
-
- /* While hidden, it still stops the next heading from matching `first:mt-0` in markdown.css */
- & + :is(h1, h2, h3, h4, h5, h6) {
- @apply max-lg:mt-0;
+ /* Until it animates in, it also cancels the parent's gap, and the margin it adds to a following heading */
+ &:first-child:has(+ :is(h1, h2, h3, h4, h5, h6)) {
+ @apply [--fade-and-slide-down-offset:calc(var(--main-gap)+--spacing(4))];
}
}
+.topBarContent {
+ @apply flex
+ min-h-0
+ items-center
+ gap-3;
+}
+
.topBarLink {
@apply flex
flex-1
diff --git a/apps/site/layouts/layouts.module.css b/apps/site/layouts/layouts.module.css
index a2b8a89315dea..25b7b23695776 100644
--- a/apps/site/layouts/layouts.module.css
+++ b/apps/site/layouts/layouts.module.css
@@ -105,9 +105,9 @@
main {
@apply max-w-7xl
- gap-4
px-4
py-12
+ [--main-gap:--spacing(4)]
md:px-14
lg:px-28;
}
@@ -166,8 +166,8 @@
dark:border-l-neutral-900;
main {
- @apply gap-4
- wrap-anywhere;
+ @apply wrap-anywhere
+ [--main-gap:--spacing(4)];
}
}
diff --git a/apps/site/tests/e2e/carbon-ads.spec.ts b/apps/site/tests/e2e/carbon-ads.spec.ts
index 0bfba1c6ba8d5..2c813348d1b84 100644
--- a/apps/site/tests/e2e/carbon-ads.spec.ts
+++ b/apps/site/tests/e2e/carbon-ads.spec.ts
@@ -129,7 +129,7 @@ test.describe('Carbon Ads', () => {
'/en/about',
'/en/blog/announcements/diving-into-the-nodejs-website-redesign',
]) {
- test(`should not shift ${path} when the Top Bar loads`, async ({
+ test(`should only render the Top Bar on ${path} once an ad is available`, async ({
page,
}) => {
await mockAds(page);
@@ -147,17 +147,14 @@ test.describe('Carbon Ads', () => {
await page.goto(path);
- // Only the position matters: the heading's size can change as fonts load
- const heading = page.locator('main h1').first();
- const before = await heading.boundingBox();
+ const topBar = page.locator('main > aside');
+ await expect(topBar).toHaveCount(0);
respond();
await expect(adLinks(page)).toHaveCount(2);
- const after = await heading.boundingBox();
-
- expect(after?.y).toBe(before?.y);
+ await expect(topBar).toHaveCount(1);
});
}
});
diff --git a/docs/carbon-ads.md b/docs/carbon-ads.md
index b740cc34fde03..8300acfcd4f1f 100644
--- a/docs/carbon-ads.md
+++ b/docs/carbon-ads.md
@@ -28,9 +28,11 @@ Learn (`/learn`) and the API docs (`/api`, `/docs`) are separate applications an
## How it works
- `apps/site/hooks/useCarbonAd.ts` requests the ad for the current page view and sends its view beacon. A page view changes with the pathname or locale (not with hashes or query strings), so a revisited page always gets a fresh ad.
-- `apps/site/components/CarbonAds/TopBar.tsx` and `apps/site/components/CarbonAds/Sidebar.tsx` render each format. From the `lg` breakpoint, the Top Bar reserves its minimum height while loading, so one- and two-line creatives don't shift the page; longer ones can still shift it slightly. Narrower screens reserve no space, because the height varies too much with the creative's length, and neither does the Sidebar, because it is the last item in its column. When there is no ad (empty response, invalid data, network error or ad blocker) nothing is shown, and any reserved space collapses.
+- `apps/site/components/CarbonAds/TopBar.tsx` and `apps/site/components/CarbonAds/Sidebar.tsx` render each format. Neither reserves space while loading. When there is no ad (empty response, invalid data, network error or ad blocker) nothing is shown.
- The ad request itself records the impression. The `statview` beacon is sent once per page view after at least 50% of the ad was visible for one continuous second. Clicks go through `statlink`.
+Once an ad is available, the Top Bar uses the announcement banner's `animate-fade-and-slide-down` animation to expand, fade and slide in. It takes up no space until then, including the parent's gap (from the `--main-gap` variable on `main`) and the margin it adds to a following heading. Visitors who prefer reduced motion see it immediately, without the animation.
+
## Staging and production
By default, every request is sent with `ignore=yes`, which returns a real ad **without counting the impression**. This applies to local development, tests and all preview deployments (which are production builds too).
diff --git a/packages/ui-components/src/Common/Banner/index.module.css b/packages/ui-components/src/Common/Banner/index.module.css
index d9bf2cc94b981..6a2401bba7c5b 100644
--- a/packages/ui-components/src/Common/Banner/index.module.css
+++ b/packages/ui-components/src/Common/Banner/index.module.css
@@ -8,7 +8,8 @@
grid-rows-1
px-8
py-3
- text-sm;
+ text-sm
+ motion-reduce:animate-none;
&,
a {
diff --git a/packages/ui-components/src/styles/animations.css b/packages/ui-components/src/styles/animations.css
index c16c21240ad67..5149103c21584 100644
--- a/packages/ui-components/src/styles/animations.css
+++ b/packages/ui-components/src/styles/animations.css
@@ -89,9 +89,13 @@
}
}
+ /* Expands a grid with a single `min-h-0` row from nothing, ending at the element's own spacing.
+ * `--fade-and-slide-down-offset` also collapses any space around it, such as the parent's gap */
@keyframes fade-and-slide-down {
from {
grid-template-rows: 0fr;
+ margin-bottom: calc(-1 * var(--fade-and-slide-down-offset, 0px));
+ min-height: 0;
opacity: 0;
padding-block: 0;
transform: translateY(-100%);
@@ -99,9 +103,6 @@
to {
grid-template-rows: 1fr;
- opacity: 1;
- padding-block: calc(var(--spacing, 0.25rem) * 3);
- transform: translateY(0);
}
}
}
diff --git a/packages/ui-components/src/styles/markdown.css b/packages/ui-components/src/styles/markdown.css
index 40e76dc283b6c..0a30ba05b2f57 100644
--- a/packages/ui-components/src/styles/markdown.css
+++ b/packages/ui-components/src/styles/markdown.css
@@ -1,9 +1,11 @@
+/* The gap is a variable, so that children can account for it */
main {
- @apply max-ml:gap-4
+ @apply max-ml:[--main-gap:--spacing(4)]
flex
w-full
flex-col
- gap-6;
+ gap-(--main-gap)
+ [--main-gap:--spacing(6)];
hr {
@apply w-full