react-headings
Version:
HTML headings with auto-incrementing levels for WCAG compliance.
30 lines (29 loc) • 1.14 kB
TypeScript
import React from "react";
declare type Level = 1 | 2 | 3 | 4 | 5 | 6;
declare type Heading = `h${Level}`;
declare type LevelContextValue = {
level: Level;
Component: Heading;
};
/**
* Returns the current heading and level.
*/
export declare function useLevel(): LevelContextValue;
declare type HProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement> & {
render?: (context: LevelContextValue) => React.ReactElement;
};
/**
* Renders a dynamic HTML heading (h1, h2, etc.) or custom component according to the current level.
*/
export declare const H: React.ForwardRefExoticComponent<Pick<HProps, "render" | "key" | keyof React.HTMLAttributes<HTMLHeadingElement>> & React.RefAttributes<HTMLHeadingElement>>;
declare type SectionProps = {
component: React.ReactNode;
children?: React.ReactNode;
};
/**
* Renders `component` in the current level and `children` in the next level.
* @param component A component containing a heading
* @param children The children in the next level
*/
export declare function Section({ component, children }: SectionProps): JSX.Element;
export {};