Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion apps/site/components/withBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ArrowUpRightIcon } from '@heroicons/react/24/outline';
import Banner from '@node-core/ui-components/Common/Banner';
import { useTranslations } from 'next-intl';

import Link from '#site/components/Link';
import { siteConfig } from '#site/next.json.mjs';
Expand All @@ -9,10 +10,20 @@ import type { FC } from 'react';

const WithBanner: FC<{ section: string }> = ({ section }) => {
const banner = siteConfig.websiteBanners[section];
const t = useTranslations();

if (banner && dateIsBetween(banner.startDate, banner.endDate)) {
const ariaLabels = {
default: t('components.banner.announcement'),
warning: t('components.banner.warning'),
error: t('components.banner.error'),
} as const;

// Fallback to 'default' if no type is specified
const bannerType = banner.type || 'default';

return (
<Banner type={banner.type}>
<Banner type={banner.type} aria-label={ariaLabels[bannerType]}>
{banner.link ? (
<Link href={banner.link}>{banner.text}</Link>
) : (
Expand Down
1 change: 1 addition & 0 deletions apps/site/components/withMetaBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const WithMetaBar: FC = () => {
<MetaBar
heading={t('components.metabar.tableOfContents')}
as={Link}
aria-label={t('components.metabar.metadata')}
items={{
[t('components.metabar.lastUpdated')]: lastUpdated,
[t('components.metabar.readingTime')]: readingTimeText,
Expand Down
8 changes: 7 additions & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,13 @@
"contribute": "Contribute",
"contributeText": "Edit this page",
"viewAs": "View as",
"tableOfContents": "Table of Contents"
"tableOfContents": "Table of Contents",
"metadata": "Article metadata"
},
"banner": {
"announcement": "Announcement",
"warning": "Warning notification",
"error": "Error notification"
},
"search": {
"searchPlaceholder": "Start typing...",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-core/ui-components",
"version": "1.5.4",
"version": "1.5.5",
"type": "module",
"exports": {
"./*": [
Expand Down
12 changes: 8 additions & 4 deletions packages/ui-components/src/Common/Banner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import type { FC, PropsWithChildren } from 'react';
import type { FC, HTMLAttributes, PropsWithChildren } from 'react';

import styles from './index.module.css';

export type BannerProps = {
type?: 'default' | 'warning' | 'error';
};
} & HTMLAttributes<HTMLElement>;

const Banner: FC<PropsWithChildren<BannerProps>> = ({
type = 'default',
children,
...props
}) => (
<div className={`${styles.banner} ${styles[type] || styles.default}`}>
<section
className={`${styles.banner} ${styles[type] || styles.default}`}
{...props}
>
{children}
</div>
</section>
);

export default Banner;
9 changes: 5 additions & 4 deletions packages/ui-components/src/Containers/MetaBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fragment, useMemo } from 'react';

import type { LinkLike } from '#ui/types';
import type { Heading } from '@vcarl/remark-headings';
import type { FC } from 'react';
import type { FC, HTMLAttributes } from 'react';

import styles from './index.module.css';

Expand All @@ -14,13 +14,14 @@ type MetaBarProps = {
};
as?: LinkLike;
heading: string;
};
} & HTMLAttributes<HTMLElement>;

const MetaBar: FC<MetaBarProps> = ({
items,
headings,
as: Component = 'a',
heading,
...props
}) => {
// The default depth of headings to display in the table of contents.
const { minDepth = 2, items: headingItems = [] } = headings || {};
Expand All @@ -31,7 +32,7 @@ const MetaBar: FC<MetaBarProps> = ({
);

return (
<div className={styles.wrapper}>
<aside className={styles.wrapper} {...props}>
<dl>
{Object.entries(items)
.filter(([, value]) => !!value)
Expand Down Expand Up @@ -65,7 +66,7 @@ const MetaBar: FC<MetaBarProps> = ({
</>
)}
</dl>
</div>
</aside>
);
};

Expand Down