Skip to content

Commit dc92344

Browse files
committed
refactor: restructure component
1 parent 8af4489 commit dc92344

4 files changed

Lines changed: 55 additions & 55 deletions

File tree

src/generators/web/ui/components/AnnouncementBanner/AnnouncementBanner.jsx

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { lazy, Suspense } from 'preact/compat';
2+
3+
import AnnouncementBanner from './index.jsx';
4+
import { loadBanners } from './loadBanners.mjs';
5+
6+
import { remoteConfig, version } from '#theme/config';
7+
8+
// TODO: Revisit SERVER global usage (https://github.com/nodejs/doc-kit/issues/353)
9+
const LazyBanners = SERVER
10+
? null
11+
: lazy(async () => {
12+
const active = await loadBanners(remoteConfig, version.major);
13+
14+
if (!active.length) {
15+
return { default: () => null };
16+
}
17+
18+
return { default: () => <AnnouncementBanner banners={active} /> };
19+
});
20+
21+
const RemoteLoadableBanner = SERVER
22+
? () => <div />
23+
: () => (
24+
<div>
25+
<Suspense fallback={null}>
26+
<LazyBanners />
27+
</Suspense>
28+
</div>
29+
);
30+
31+
export default RemoteLoadableBanner;
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
import { lazy, Suspense } from 'preact/compat';
1+
import { ArrowUpRightIcon } from '@heroicons/react/24/outline';
2+
import Banner from '@node-core/ui-components/Common/Banner';
23

3-
import AnnouncementBanner from './AnnouncementBanner.jsx';
4-
import { loadBanners } from './loadBanners.mjs';
4+
import styles from './index.module.css';
55

6-
import { remoteConfig, version } from '#theme/config';
6+
/**
7+
* @param {import('./types.d.ts').AnnouncementBannerProps} props
8+
*/
9+
const AnnouncementBanner = ({ banners }) => (
10+
<div role="region" aria-label="Announcements" className={styles.banners}>
11+
{banners.map(banner => (
12+
<Banner key={banner.text} type={banner.type}>
13+
{banner.link ? (
14+
<a href={banner.link} target="_blank" rel="noopener noreferrer">
15+
{banner.text}
16+
</a>
17+
) : (
18+
banner.text
19+
)}
20+
{banner.link && <ArrowUpRightIcon />}
21+
</Banner>
22+
))}
23+
</div>
24+
);
725

8-
// TODO: Revisit SERVER global usage (https://github.com/nodejs/doc-kit/issues/353)
9-
const LazyBanners = SERVER
10-
? null
11-
: lazy(async () => {
12-
const active = await loadBanners(remoteConfig, version.major);
13-
14-
if (!active.length) {
15-
return { default: () => null };
16-
}
17-
18-
return { default: () => <AnnouncementBanner banners={active} /> };
19-
});
20-
21-
const RemoteLoadableBanner = SERVER
22-
? () => <div />
23-
: () => (
24-
<div>
25-
<Suspense fallback={null}>
26-
<LazyBanners />
27-
</Suspense>
28-
</div>
29-
);
30-
31-
export default RemoteLoadableBanner;
26+
export default AnnouncementBanner;

src/generators/web/ui/components/Layout/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import TableOfContents from '@node-core/ui-components/Common/TableOfContents';
22
import Article from '@node-core/ui-components/Containers/Article';
33

4-
import RemoteLoadableBanner from '../AnnouncementBanner';
4+
import RemoteLoadableBanner from '../AnnouncementBanner/RemoteLoadableBanner';
55

66
import Footer from '#theme/Footer';
77
import MetaBar from '#theme/Metabar';

0 commit comments

Comments
 (0)