Skip to content
Merged
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
Prev Previous commit
Next Next commit
Update components/Heading/index.tsx
Co-authored-by: Rafe Goldberg <[email protected]>
  • Loading branch information
kellyjosephprice and rafegoldberg authored Jun 3, 2024
commit 5e588227c73ea33e24f6603b6f9a990ada841d24
41 changes: 18 additions & 23 deletions components/Heading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@ import React from 'react';

export type Depth = 1 | 2 | 3 | 4 | 5 | 6;

const CreateHeading = (depth: Depth) => {
const Tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' = `h${depth}`;
const Heading = ({ tag: Tag = 'h3', depth = 3, id, children, ...attrs }: React.PropsWithChildren<HTMLHeadingElement>) => {
if (!children) return '';

const Heading = ({ id, children, ...attrs }: React.PropsWithChildren<HTMLHeadingElement>) => {
if (!children) return '';

return (
// @ts-expect-error
<Tag {...attrs} className={`heading heading-${depth} header-scroll`}>
<div key={`heading-anchor-${id}`} className="heading-anchor anchor waypoint" id={id} />
<div key={`heading-text-${id}`} className="heading-text">
{children}
</div>
<a
key={`heading-anchor-icon-${id}`}
aria-label={`Skip link to ${children[1]}`}
className="heading-anchor-icon fa fa-anchor"
href={`#${id}`}
/>
</Tag>
);
};

return Heading;
return (
<Tag {...attrs} className={`heading heading-${depth} header-scroll`}>
<div key={`heading-anchor-${id}`} className="heading-anchor anchor waypoint" id={id} />
<div key={`heading-text-${id}`} className="heading-text">
{children}
</div>
<a
key={`heading-anchor-icon-${id}`}
aria-label={`Skip link to ${children[1]}`}
className="heading-anchor-icon fa fa-anchor"
href={`#${id}`}
/>
</Tag>
);
};

const CreateHeading = (depth: Depth) => props => <Heading {...props} depth={depth} Tag={`h${depth}`} />;

export default CreateHeading;