Skip to content

Commit

Permalink
feat(): Add API JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnault committed Jan 4, 2021
1 parent 3405e35 commit f82d690
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ type Heading = `h${HeadingLevel}`;

const LevelContext = React.createContext<HeadingLevel>(1);

/**
* Returns the current level
*/
export function useLevel() {
return React.useContext(LevelContext);
}
Expand All @@ -14,6 +17,10 @@ type LevelProps = {
children: React.ReactNode;
};

/**
* Creates a new context 1 level down from current level.
* Any H component rendered within this context will use its level.
*/
export function Level({ children }: LevelProps) {
const level = useLevel();

Expand All @@ -37,6 +44,9 @@ type HProps = React.DetailedHTMLProps<
}) => React.ReactElement;
};

/**
* Renders a HTML heading (h1, h2, etc.) or a custom component according to the current level.
*/
export function H({ render, ...props }: HProps) {
const level = useLevel();

Expand Down

0 comments on commit f82d690

Please sign in to comment.