Skip to content

Commit 4551ef5

Browse files
authored
docs: fix transitions code playground and use Tooltip component (#42)
* fix(docs): transitions – example is not displayed due to JS error #41 injectCss is not defined * fix(docs): transitions – tooltip example is not working incorrect destructuring on children params * refactor(docs): use Tooltip component
1 parent 9222cee commit 4551ef5

File tree

3 files changed

+43
-61
lines changed

3 files changed

+43
-61
lines changed

www/docs/Overlay.mdx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ positioning engine.
1414
import clsx from "clsx";
1515
import { Overlay } from "@restart/ui";
1616
import Button from "../src/Button";
17+
import Tooltip from "../src/Tooltip";
1718

1819
const PLACEMENTS = ["left", "top", "right", "bottom"];
1920

@@ -70,24 +71,10 @@ function OverlayExample() {
7071
target={triggerRef}
7172
>
7273
{(props, { arrowProps, popper, show }) => (
73-
<div {...props} className="absolute">
74-
<div
75-
{...arrowProps}
76-
style={arrowProps.style}
77-
className={clsx(
78-
"absolute w-3 h-3 z-[-1]",
79-
"before:absolute before:rotate-45 before:bg-black before:top-0 before:left-0 before:w-3 before:h-3",
80-
popper.placement === "left" && "-right-1",
81-
popper.placement === "right" && "-left-1",
82-
popper.placement === "bottom" && "-top-1",
83-
popper.placement === "top" && "-bottom-1"
84-
)}
85-
/>
86-
<div className="py-1 px-2 text-center rounded bg-black text-white ">
87-
I&rsquo;m placed to the{" "}
88-
<strong>{popper.placement}</strong>
89-
</div>
90-
</div>
74+
<Tooltip {...props} arrowProps={arrowProps} popper={popper}>
75+
I&rsquo;m placed to the{" "}
76+
<strong>{popper.placement}</strong>
77+
</Tooltip>
9178
)}
9279
</Overlay>
9380
</div>

www/docs/transitions.mdx

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,12 @@ specifically, or roll your own like the below example.
1111
```js live
1212
import { Modal, Overlay } from "@restart/ui";
1313
import Transition from "react-transition-group/Transition";
14+
import Button from "../src/Button";
15+
import Tooltip from "../src/Tooltip";
16+
import '../src/css/transitions.css';
1417

1518
const FADE_DURATION = 200;
1619

17-
injectCss(`
18-
.fade {
19-
opacity: 0;
20-
transition: opacity ${FADE_DURATION}ms linear;
21-
}
22-
23-
.show {
24-
opacity: 1;
25-
}
26-
27-
28-
.backdrop.fade.show {
29-
opacity: 0.5;
30-
}
31-
32-
.dialog {
33-
position: absolute;
34-
width: 400;
35-
top: 50%; left: 50%;
36-
transform: translate(-50%, -50%);
37-
border: 1px solid #e5e5e5;
38-
background-color: white;
39-
box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
40-
padding: 20px;
41-
}
42-
`);
43-
4420
const fadeStyles = {
4521
entering: "show",
4622
entered: "show",
@@ -60,32 +36,33 @@ const Fade = ({ children, ...props }) => (
6036
function TransitionExample() {
6137
const [showModal, setShowModal] = useState(false);
6238
const [showTooltip, setShowTooltip] = useState(false);
63-
const [tooltipRef, attachRef] = useState(null);
39+
40+
const triggerRef = useRef(null);
6441

6542
return (
6643
<div className="flex flex-col items-center">
67-
<button
44+
<Button
6845
type="button"
6946
className="btn btn-primary mr-3"
7047
onClick={() => setShowModal((prev) => !prev)}
7148
>
7249
Show Animated Modal
73-
</button>
50+
</Button>
7451

75-
<button
52+
<Button
7653
type="button"
7754
className="btn btn-primary"
7855
onClick={() => setShowTooltip((prev) => !prev)}
79-
ref={attachRef}
56+
ref={triggerRef}
8057
>
8158
Show Tooltip
82-
</button>
59+
</Button>
8360

8461
<Overlay
8562
placement="top"
8663
transition={Fade}
8764
show={showTooltip}
88-
target={tooltipRef}
65+
target={triggerRef}
8966
popperConfig={{
9067
modifiers: [
9168
{
@@ -96,14 +73,10 @@ function TransitionExample() {
9673
],
9774
}}
9875
>
99-
{({ props: { ref, style } }) => (
100-
<div
101-
ref={ref}
102-
className="bg-primary-200 shadow rounded z-10 px-4"
103-
style={style}
104-
>
105-
Hello there
106-
</div>
76+
{(props, { arrowProps, popper, show }) => (
77+
<Tooltip {...props} arrowProps={arrowProps} popper={popper}>
78+
Tooltip content
79+
</Tooltip>
10780
)}
10881
</Overlay>
10982

@@ -123,7 +96,7 @@ function TransitionExample() {
12396
{...props}
12497
className="fixed inset-0 z-50 flex items-center justify-center pointer-events-none"
12598
>
126-
<div className="dialog bg-white shadow rounded-lg pointer-events-auto">
99+
<div className="dialog dialog-transitions-example bg-white shadow rounded-lg pointer-events-auto">
127100
<h4 id="modal-label">I&apos;m fading in!</h4>
128101
<p>
129102
Anim pariatur cliche reprehenderit, enim

www/src/css/transitions.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.fade {
2+
opacity: 0;
3+
transition: opacity 200ms linear;
4+
}
5+
6+
.show {
7+
opacity: 1;
8+
}
9+
10+
.backdrop.fade.show {
11+
opacity: 0.5;
12+
}
13+
14+
.dialog-transitions-example {
15+
position: absolute;
16+
top: 50%; left: 50%;
17+
transform: translate(-50%, -50%);
18+
border: 1px solid #e5e5e5;
19+
background-color: white;
20+
box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
21+
padding: 20px;
22+
}

0 commit comments

Comments
 (0)