react-headings 4.0.2 → 4.0.4
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 +40 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,47 +31,74 @@ npm install react-headings
|
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
### Basics
|
|
35
|
+
|
|
36
|
+
`HeadingLevel` moves headings inside one level deeper:
|
|
35
37
|
|
|
36
38
|
```tsx
|
|
37
39
|
import { Heading, HeadingLevel } from "react-headings";
|
|
38
40
|
|
|
39
|
-
function
|
|
41
|
+
function MyPage() {
|
|
40
42
|
return (
|
|
41
|
-
|
|
42
|
-
<Heading>Star Wars</Heading>
|
|
43
|
+
<main>
|
|
44
|
+
<Heading>Star Wars</Heading> {/* <h1> */}
|
|
43
45
|
<HeadingLevel>
|
|
44
46
|
<Heading>Characters</Heading> {/* <h2> */}
|
|
45
47
|
<HeadingLevel>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
Luke, Leia, Han Solo...
|
|
49
|
+
</HeadingLevel>
|
|
50
|
+
<Heading>Planets</Heading> {/* <h2> */}
|
|
51
|
+
<HeadingLevel>
|
|
52
|
+
Tatooine, Coruscant...
|
|
49
53
|
</HeadingLevel>
|
|
50
54
|
</HeadingLevel>
|
|
51
|
-
|
|
55
|
+
</main>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Reusability
|
|
61
|
+
|
|
62
|
+
Headings inside a component adapt to wherever it's used:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
function MyPage() {
|
|
66
|
+
return (
|
|
67
|
+
<main>
|
|
68
|
+
<MySection title="Star Wars"> {/* <h1> */}
|
|
69
|
+
<MySection title="Characters"> {/* <h2> */}
|
|
70
|
+
Luke, Leia, Han Solo...
|
|
71
|
+
</MySection>
|
|
72
|
+
<MySection title="Planets"> {/* <h2> */}
|
|
73
|
+
Tatooine, Coruscant...
|
|
74
|
+
</MySection>
|
|
75
|
+
</MySection>
|
|
76
|
+
</main>
|
|
52
77
|
);
|
|
53
78
|
}
|
|
54
79
|
|
|
55
|
-
function
|
|
80
|
+
function MySection({ title, children }) {
|
|
56
81
|
return (
|
|
57
82
|
<section>
|
|
58
|
-
<Heading>{title}</Heading>
|
|
83
|
+
<Heading>{title}</Heading> {/* <h1>, <h2>, etc. depending on where MySection is used */}
|
|
59
84
|
<HeadingLevel>{children}</HeadingLevel>
|
|
60
85
|
</section>
|
|
61
86
|
);
|
|
62
87
|
}
|
|
63
88
|
```
|
|
64
89
|
|
|
65
|
-
`Section` doesn't know its level: it renders `<h3>` here.
|
|
66
|
-
|
|
67
90
|
### Dialogs
|
|
68
91
|
|
|
69
|
-
Portaled elements, like dialogs, aren't part of the page outline. Use `level` to
|
|
92
|
+
Portaled elements, like dialogs, aren't part of the page outline. Use `level` to reset their headings to `<h1>`:
|
|
70
93
|
|
|
71
94
|
```tsx
|
|
72
95
|
<Dialog>
|
|
73
96
|
<HeadingLevel level={1}>
|
|
74
97
|
<Heading>Delete file?</Heading> {/* <h1> */}
|
|
98
|
+
<HeadingLevel>
|
|
99
|
+
<button>Delete</button>
|
|
100
|
+
<button>Cancel</button>
|
|
101
|
+
</HeadingLevel>
|
|
75
102
|
</HeadingLevel>
|
|
76
103
|
</Dialog>
|
|
77
104
|
```
|