-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathIssues.stories.tsx
205 lines (187 loc) · 4.2 KB
/
Issues.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useState } from "react";
import {
Sandpack,
SandpackCodeEditor,
SandpackFileExplorer,
SandpackLayout,
SandpackProvider,
} from "./index";
export default {
title: "Bug reports/Issues",
};
export const FlushServerVsClient = (): JSX.Element => {
return (
<SandpackProvider>
<div style={{ border: "1px solid black" }}>
<SandpackCodeEditor />
</div>
</SandpackProvider>
);
};
export const Issue663 = (): JSX.Element => (
<Sandpack
options={{
showTabs: true,
activeFile: "/index.tsx",
}}
template="react-ts"
/>
);
export const Issue482 = (): JSX.Element => {
const [hidden, setHidden] = useState(false);
const toggleHidden = (): void => {
setHidden((prevHidden) => !prevHidden);
};
return (
<>
<button onClick={toggleHidden}>toggle hidden</button>
<SandpackProvider
customSetup={{
entry: "/index.js",
}}
files={{
"/index.js": {
code: "// index.js",
active: true,
},
"/index2.js": {
code: "// index2.js",
},
"/src/index.js": {
code: "// this file is generated by vanilla template, but it is not needed",
hidden: true,
},
"/hidden.js": {
code: "// hidden.js",
hidden: true,
},
}}
options={{
visibleFiles: ["/index.js", "/hidden.js"],
activeFile: "/index.js",
}}
template={"vanilla"}
>
<SandpackLayout>
<SandpackFileExplorer autoHiddenFiles={hidden} />
<SandpackCodeEditor />
</SandpackLayout>
</SandpackProvider>
</>
);
};
export const Issue454 = (): JSX.Element => {
const [readOnly, setReadOnly] = useState(false);
return (
<>
<button
className="trigger"
onClick={(): any => setReadOnly((prev) => !prev)}
>
click
</button>
<Sandpack options={{ readOnly }} />
</>
);
};
export const FileTab = (): JSX.Element => {
return (
<Sandpack
options={{ visibleFiles: ["/App.js", "/styles.css"] }}
template="react"
/>
);
};
export const ReactRouter = (): JSX.Element => {
return (
<Sandpack
customSetup={{
dependencies: {
"react-router-dom": "^5.3.0",
},
}}
files={{
"/App.js": `import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
// This site has 3 pages, all of which are rendered
// dynamically in the browser (not server rendered).
//
// Although the page does not ever refresh, notice how
// React Router keeps the URL up to date as you navigate
// through the site. This preserves the browser history,
// making sure things like the back button and bookmarks
// work properly.
export default function BasicExample() {
return (
<Router>
<div>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/dashboard">Dashboard</Link>
</li>
</ul>
<hr />
{/*
A <Switch> looks through all its children <Route>
elements and renders the first one whose path
matches the current URL. Use a <Switch> any time
you have multiple routes, but you want only one
of them to render at a time
*/}
<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/about">
<About />
</Route>
<Route path="/dashboard">
<Dashboard />
</Route>
</Switch>
</div>
</Router>
);
}
// You can think of these components as "pages"
// in your app.
function Home() {
return (
<div>
<h2>Home</h2>
</div>
);
}
function About() {
return (
<div>
<h2>About</h2>
</div>
);
}
function Dashboard() {
return (
<div>
<h2>Dashboard</h2>
</div>
);
}
`,
}}
options={{ showNavigator: true }}
template="react"
/>
);
};