Skip to content

Commit b07e787

Browse files
authored
Migrate remaining demos to docs (#2984)
1 parent 713eaf3 commit b07e787

12 files changed

+742
-1614
lines changed

demo/ts/app.tsx

+1-163
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
11
import * as React from "react";
22
import * as ReactDOM from "react-dom";
33

4-
import AccessibilityDemo from "./components/accessibility-demo";
5-
import BrushLineDemo from "./components/victory-brush-line-demo";
6-
import DraggableDemo from "./components/draggable-demo";
7-
import StackedThemeDemos from "./components/stacked-theme-demo";
84
import ThemeBuilder from "./components/theme-builder";
95

10-
const DEMO_ROUTES = {
11-
"/demo/accessibility": {
12-
component: AccessibilityDemo,
13-
name: "AccessibilityDemo",
14-
},
15-
"/demo/brush-line": { component: BrushLineDemo, name: "BrushLineDemo" },
16-
"/demo/draggable": { component: DraggableDemo, name: "DraggableDemo" },
17-
"/demo/stacked-theme": {
18-
component: StackedThemeDemos,
19-
name: "StackedThemeDemos",
20-
},
21-
};
22-
23-
class Home extends React.Component {
24-
render() {
25-
return <h1>Pick A Demo</h1>;
26-
}
27-
}
28-
29-
const NAV_ROUTES = {
30-
"/demo": { component: Home, name: "Demos" },
31-
"/theme-builder": { component: ThemeBuilder, name: "ThemeBuilder" },
32-
};
33-
346
interface AppState {
357
route: string;
368
}
@@ -42,153 +14,19 @@ const containerStyle: React.CSSProperties = {
4214
fontFamily: "sans-serif",
4315
};
4416

45-
const navStyle: React.CSSProperties = {
46-
display: "flex",
47-
gap: "20px",
48-
padding: "20px",
49-
borderBottom: "1px solid #ddd",
50-
fontWeight: "bold",
51-
fontSize: "1.1em",
52-
width: "100%",
53-
height: 62,
54-
top: 0,
55-
background: "#fff",
56-
};
57-
58-
const sidebarStyle: React.CSSProperties = {
59-
flexShrink: "0",
60-
borderRight: "1px solid #ddd",
61-
overflow: "auto",
62-
padding: "5px",
63-
};
64-
6517
const contentStyle: React.CSSProperties = {
6618
display: "flex",
6719
gap: "20px",
6820
overflow: "hidden",
6921
flex: 1,
7022
};
7123

72-
const mainStyle: React.CSSProperties = {
73-
overflow: "auto",
74-
flex: 1,
75-
};
76-
77-
const listStyle: React.CSSProperties = {
78-
display: "flex",
79-
flexDirection: "column",
80-
listStyle: "none",
81-
padding: "0",
82-
margin: "0",
83-
color: "#666",
84-
};
85-
86-
const linkStyle: React.CSSProperties = {
87-
color: "currentcolor",
88-
textDecoration: "none",
89-
};
90-
91-
const activeLinkStyle: React.CSSProperties = {
92-
...linkStyle,
93-
color: "#2165E3",
94-
};
95-
96-
const listItemStyle: React.CSSProperties = {
97-
padding: "10px 15px",
98-
borderRadius: "5px",
99-
color: "#666",
100-
margin: "5px 0",
101-
};
102-
103-
const activeListItemStyle: React.CSSProperties = {
104-
...listItemStyle,
105-
backgroundColor: "#eee",
106-
};
107-
10824
class App extends React.Component<any, AppState> {
109-
constructor(props: any) {
110-
super(props);
111-
112-
this.state = {
113-
route: window.location.hash.slice(1),
114-
};
115-
116-
if (this.state.route === "") {
117-
window.location.hash = "#/demo";
118-
}
119-
}
120-
121-
componentDidMount() {
122-
window.addEventListener("hashchange", () => {
123-
this.setState({
124-
route: window.location.hash.substr(1),
125-
});
126-
});
127-
}
128-
129-
getChild() {
130-
const item =
131-
DEMO_ROUTES[this.state.route] || NAV_ROUTES[this.state.route] || {};
132-
return item.component || Home;
133-
}
134-
13525
render() {
136-
const Child = this.getChild();
137-
const demoRoutes = Object.keys(DEMO_ROUTES).sort();
138-
const navRoutes = Object.keys(NAV_ROUTES);
139-
140-
const isDemoRoute = this.state.route.startsWith("/demo");
141-
14226
return (
14327
<div style={containerStyle}>
144-
<nav style={navStyle}>
145-
{navRoutes.map((route, index) => {
146-
return (
147-
<a
148-
key={index}
149-
href={`#${route}`}
150-
style={
151-
this.state.route.startsWith(route)
152-
? activeLinkStyle
153-
: linkStyle
154-
}
155-
>
156-
{NAV_ROUTES[route]?.name}
157-
</a>
158-
);
159-
})}
160-
</nav>
16128
<div style={contentStyle}>
162-
{isDemoRoute ? (
163-
<>
164-
<aside style={sidebarStyle}>
165-
<ul style={listStyle}>
166-
{demoRoutes.map((route, index) => {
167-
const item = DEMO_ROUTES[route] || {};
168-
const isActive = this.state.route === route;
169-
return (
170-
<li
171-
key={index}
172-
style={isActive ? activeListItemStyle : listItemStyle}
173-
>
174-
<a
175-
href={`#${route}`}
176-
style={isActive ? activeLinkStyle : linkStyle}
177-
>
178-
{item.name}
179-
</a>
180-
</li>
181-
);
182-
})}
183-
</ul>
184-
</aside>
185-
<main style={mainStyle}>
186-
<Child />
187-
</main>
188-
</>
189-
) : (
190-
<Child />
191-
)}
29+
<ThemeBuilder />
19230
</div>
19331
</div>
19432
);

0 commit comments

Comments
 (0)