Skip to content

Commit fdbe627

Browse files
authored
Update place.mdx
Updated examples to include more placement types
1 parent 1afbb63 commit fdbe627

File tree

1 file changed

+58
-13
lines changed

1 file changed

+58
-13
lines changed

docs/docs/examples/place.mdx

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,76 @@ The `place` prop and the `data-tooltip-place` attribute accept the following val
4040

4141
```jsx
4242
import { Tooltip } from 'react-tooltip';
43+
const PLACES = ['top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end']
4344

4445
<a id="my-tooltip-anchor">◕‿‿◕</a>
45-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the top!" place="top" />
46-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the right!" place="right" />
47-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the bottom!" place="bottom" />
48-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the left!" place="left" />
46+
{PLACES.map(place => (
47+
<Tooltip
48+
key={place}
49+
anchorSelect="#my-tooltip-anchor"
50+
content={`Hello world from the ${place}!`}
51+
place={place}
52+
/>
53+
))}
4954
```
5055

51-
<TooltipAnchor id="my-tooltip-anchor">◕‿‿◕</TooltipAnchor>
52-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the top!" place="top" />
53-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the right!" place="right" />
54-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the bottom!" place="bottom" />
55-
<Tooltip anchorSelect="#my-tooltip-anchor" content="Hello world from the left!" place="left" />
56+
export const PlacementExampleAttributes = () => {
57+
const PLACES1 = ['top', 'right', 'bottom', 'left'];
58+
const PLACES2 = ['top-start', 'right-start', 'bottom-start', 'left-start'];
59+
const PLACES3 = ['top-end', 'right-end', 'bottom-end', 'left-end'];
60+
61+
return (
62+
<>
63+
<div style={{display: 'flex', gap: '16px'}}>
64+
<TooltipAnchor id="my-tooltip-anchor1">◕‿‿◕</TooltipAnchor>
65+
<TooltipAnchor id="my-tooltip-anchor2">◕‿‿◕</TooltipAnchor>
66+
<TooltipAnchor id="my-tooltip-anchor3">◕‿‿◕</TooltipAnchor>
67+
</div>
68+
<div>
69+
{PLACES1.map(place => (
70+
<Tooltip
71+
key={place}
72+
anchorSelect="#my-tooltip-anchor1"
73+
content={`Hello world from the ${place}!`}
74+
place={place}
75+
/>
76+
))}
77+
{PLACES2.map(place => (
78+
<Tooltip
79+
key={place}
80+
anchorSelect="#my-tooltip-anchor2"
81+
content={`Hello world from the ${place}!`}
82+
place={place}
83+
/>
84+
))}
85+
{PLACES3.map(place => (
86+
<Tooltip
87+
key={place}
88+
anchorSelect="#my-tooltip-anchor3"
89+
content={`Hello world from the ${place}!`}
90+
place={place}
91+
/>
92+
))}
93+
</div>
94+
</>
95+
)
96+
}
97+
98+
<PlacementExampleAttributes />
99+
100+
56101

57102
### Using `place` prop
58103

59104
```jsx
60105
import { Tooltip } from 'react-tooltip';
61106

62-
const PLACES = ['top', 'right', 'bottom', 'left']
107+
const PLACES = ['top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end']
63108
const [place, setPlace] = useState(0)
64109

65110
<a
66111
data-tooltip-id="my-tooltip"
67-
onClick={() => setPlace(p => (p + 1) % 4)}
112+
onClick={() => setPlace(p => (p + 1) % 12)}
68113
>
69114
◕‿‿◕
70115
</a>
@@ -76,14 +121,14 @@ const [place, setPlace] = useState(0)
76121
```
77122

78123
export const PlacementExample = () => {
79-
const PLACES = ['top', 'right', 'bottom', 'left']
124+
const PLACES = ['top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end'];
80125
const [place, setPlace] = useState(0)
81126

82127
return (
83128
<>
84129
<TooltipAnchor
85130
data-tooltip-id="my-tooltip"
86-
onClick={() => setPlace(p => (p + 1) % 4)}
131+
onClick={() => setPlace(p => (p + 1) % 12)}
87132
>
88133
◕‿‿◕
89134
</TooltipAnchor>

0 commit comments

Comments
 (0)