Skip to content

Commit

Permalink
feat(ui): build Nav component
Browse files Browse the repository at this point in the history
  • Loading branch information
AliKdhim87 committed Jun 24, 2024
1 parent a58c75f commit 402086e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/ui/src/components/Nav/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Heading } from '@utrecht/component-library-react';
import type { HeadingProps } from '@utrecht/component-library-react';
import { DetailedHTMLProps, ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react';
import { forwardRef, useId } from 'react';

export interface NavProps extends DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> {
label?: string;
headingLevel?: number;
headingRestProps?: HeadingProps;
}

export const Nav = forwardRef(
(
{ children, label, headingLevel = 3, className, headingRestProps, ...restProps }: PropsWithChildren<NavProps>,
ref: ForwardedRef<HTMLElement>,
) => {
const headingId = label ? useId() : undefined;

return (
<nav ref={ref} className={className} aria-labelledby={headingId} {...restProps}>
{label && (
<Heading id={headingId} level={headingLevel} aria-hidden="true" hidden {...headingRestProps}>
{label}
</Heading>
)}
{children}
</nav>
);
},
);
Nav.displayName = 'SocialMediaNav';
1 change: 1 addition & 0 deletions packages/ui/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { Navigation } from './Navigation';
export { NavigationList } from './Navigation/NavigationList';
export { PreviewAlert } from './PreviewAlert';
export { ProductListItem, ProductListPaginationInfo, ProductsList } from './ProductList';
export { Nav } from './Nav';
export { ScrollToTopButton } from './ScrollToTopButton';
export { SearchIndexContent } from './SearchIndexContent';
export * from './AdvancedLink';
Expand Down

0 comments on commit 402086e

Please sign in to comment.