react-headings 4.0.0-next.2 → 4.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.development.js +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Hardcoded heading levels break accessibility and SEO when components are reused.
|
|
|
18
18
|
## Features
|
|
19
19
|
|
|
20
20
|
- Supports server-side rendering
|
|
21
|
-
-
|
|
21
|
+
- Only 369 bytes minified & brotlied
|
|
22
22
|
- Typed with TypeScript
|
|
23
23
|
- Works with any CSS solution (Tailwind, CSS-in-JS, etc.)
|
|
24
24
|
- Plays nicely with component libraries
|
|
@@ -31,37 +31,38 @@ npm install react-headings
|
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
|
-
Use `
|
|
34
|
+
Use `Heading` for every heading. Wrap the content that belongs under a heading in `HeadingLevel`: headings inside render one level deeper.
|
|
35
35
|
|
|
36
36
|
```tsx
|
|
37
|
-
import {
|
|
37
|
+
import { Heading, HeadingLevel } from "react-headings";
|
|
38
38
|
|
|
39
39
|
function Page() {
|
|
40
40
|
return (
|
|
41
41
|
<>
|
|
42
|
-
<
|
|
42
|
+
<Heading>Star Wars</Heading> {/* h1 */}
|
|
43
43
|
<HeadingLevel>
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
44
|
+
<Heading>Characters</Heading> {/* h2 */}
|
|
45
|
+
<HeadingLevel>
|
|
46
|
+
<Section title="Luke" /> {/* h3 */}
|
|
47
|
+
<Section title="Leia" /> {/* h3 */}
|
|
48
|
+
<Section title="Han Solo" /> {/* h3 */}
|
|
49
|
+
</HeadingLevel>
|
|
49
50
|
</HeadingLevel>
|
|
50
51
|
</>
|
|
51
52
|
);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
function
|
|
55
|
+
function Section({ title, children }) {
|
|
55
56
|
return (
|
|
56
|
-
<
|
|
57
|
-
<
|
|
57
|
+
<section>
|
|
58
|
+
<Heading>{title}</Heading>
|
|
58
59
|
<HeadingLevel>{children}</HeadingLevel>
|
|
59
|
-
</
|
|
60
|
+
</section>
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
63
|
```
|
|
63
64
|
|
|
64
|
-
`
|
|
65
|
+
`Section` doesn't know its level: it renders `h3` here.
|
|
65
66
|
|
|
66
67
|
### Dialogs
|
|
67
68
|
|
|
@@ -70,7 +71,7 @@ Portaled elements, like dialogs, aren't part of the page outline. Use `level` to
|
|
|
70
71
|
```tsx
|
|
71
72
|
<Dialog>
|
|
72
73
|
<HeadingLevel level={1}>
|
|
73
|
-
<
|
|
74
|
+
<Heading>Delete file?</Heading> {/* h1 */}
|
|
74
75
|
</HeadingLevel>
|
|
75
76
|
</Dialog>
|
|
76
77
|
```
|
|
@@ -80,14 +81,14 @@ Portaled elements, like dialogs, aren't part of the page outline. Use `level` to
|
|
|
80
81
|
React Headings only picks the tag. Style headings however you like, or use `render` for your own component:
|
|
81
82
|
|
|
82
83
|
```tsx
|
|
83
|
-
<
|
|
84
|
+
<Heading render={(props, { tag }) => <Text as={tag} size="lg" {...props} />}>
|
|
84
85
|
Title
|
|
85
|
-
</
|
|
86
|
+
</Heading>
|
|
86
87
|
```
|
|
87
88
|
|
|
88
89
|
## API
|
|
89
90
|
|
|
90
|
-
### `Heading`
|
|
91
|
+
### `Heading`
|
|
91
92
|
|
|
92
93
|
Renders `h1`–`h6` based on the current level: `h1` by default, and never deeper than `h6`.
|
|
93
94
|
|
|
@@ -97,8 +98,6 @@ Accepts every `h1` prop and a `ref`, plus:
|
|
|
97
98
|
| -------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
98
99
|
| `render` | `(props, { level, tag }) => ReactElement` | Renders your own element. Spread `props` on it (includes `children` and `ref`). |
|
|
99
100
|
|
|
100
|
-
`H` is the same component as `Heading`. Pick one name per project.
|
|
101
|
-
|
|
102
101
|
### `HeadingLevel`
|
|
103
102
|
|
|
104
103
|
| Prop | Type | Default | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,6 @@ export declare const Heading: import("react").ForwardRefExoticComponent<Omit<imp
|
|
|
25
25
|
tag: Tag;
|
|
26
26
|
}) => ReactElement;
|
|
27
27
|
} & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
28
|
-
export { Heading as H };
|
|
29
28
|
/**
|
|
30
29
|
* Renders headings inside `offset` levels deeper (default 1), or at `level`
|
|
31
30
|
* regardless of ancestors.
|
|
@@ -38,3 +37,4 @@ export declare function useHeadingLevel(): {
|
|
|
38
37
|
level: Level;
|
|
39
38
|
tag: Tag;
|
|
40
39
|
};
|
|
40
|
+
export {};
|
package/dist/index.js
CHANGED