Skip to content

Commit f60d143

Browse files
committed
Refactored space component into functional component using hooks
1 parent b55a67d commit f60d143

File tree

23 files changed

+2101
-17564
lines changed

23 files changed

+2101
-17564
lines changed

demo/config/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ module.exports = function(webpackEnv) {
272272
// Support React Native Web
273273
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
274274
'react-native': 'react-native-web',
275+
react: path.resolve( '__dirname', '..', 'node_modules', 'react')
275276
},
276277
plugins: [
277278
// Adds support for installing with Plug'n'Play, leading to faster installs and adding

demo/package-lock.json

Lines changed: 1541 additions & 1487 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"postcss-normalize": "7.0.1",
5454
"postcss-preset-env": "6.6.0",
5555
"postcss-safe-parser": "4.0.1",
56-
"react": "^16.8.6",
56+
"react": "16.8.6",
5757
"react-app-polyfill": "^1.0.1",
5858
"react-dev-utils": "^9.0.1",
59-
"react-dom": "^16.8.6",
59+
"react-dom": "16.8.6",
6060
"react-ga": "^2.6.0",
6161
"react-monaco-editor": "^0.28.0",
6262
"react-spaces": "file:../react-spaces",

demo/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Suspense } from 'react';
22
import './App.scss';
33
import ReactGA from 'react-ga';
44
import { Docs } from './docs/Docs';
5+
import { Test } from './Test';
56

67
ReactGA.initialize("UA-144490437-1");
78
ReactGA.pageview(window.location.pathname + window.location.search);
@@ -12,6 +13,10 @@ const App: React.FC = () => {
1213
const UI = React.lazy(() => import('./ui-demo/UI').then(({ UI }) => ({ default: UI })));
1314
return <Suspense fallback={<Loading />}><UI /></Suspense>
1415
}
16+
else if (window.location.hash === "#test")
17+
{
18+
return <Test />
19+
}
1520

1621
return <Docs />
1722
}

demo/src/Test.tsx

Lines changed: 52 additions & 0 deletions
Large diffs are not rendered by default.

demo/src/docs/Intro.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,33 @@ import { Button, Icon } from 'antd';
44
export const Intro = () => {
55
return (
66
<>
7-
<p id="intro" style={{ fontWeight: 400, paddingTop: 30, paddingBottom: 0, fontSize: 28, color: '#777' }}>
7+
<p id="intro" style={{ fontWeight: 400, paddingTop: 30, paddingBottom: 0, fontSize: 28, color: '#777' }}>
88
React Spaces allow you to divide a page or container into nestable, anchored, scrollable and resizable spaces.
9-
</p>
9+
</p>
1010

1111
<div className="mobile" style={{ marginBottom: 15 }}>
1212
<Button type="primary" onClick={() => window.location.href = 'https://github.com/aeagle/react-spaces'}><Icon type="github" /> View on GitHub</Button>
1313
&nbsp; &nbsp;
1414
<img style={{ position: 'relative', top: -2 }} alt="NPM version" src="https://img.shields.io/npm/v/react-spaces.svg" />
1515
</div>
1616

17-
<p>
18-
<h2>Features</h2>
17+
<h2>Features</h2>
1918

20-
<ul>
21-
<li>
22-
No styling to achieve simple or complex layouts.
23-
</li>
24-
<li>
25-
Spaces know how to behave in relation to each other and resize accordingly.
26-
</li>
27-
<li>
28-
Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
29-
</li>
30-
</ul>
31-
</p>
19+
<ul>
20+
<li>
21+
No styling to achieve simple or complex layouts.
22+
</li>
23+
<li>
24+
Spaces know how to behave in relation to each other and resize accordingly.
25+
</li>
26+
<li>
27+
Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
28+
</li>
29+
</ul>
3230

33-
<p>
34-
<img src="https://www.allaneagle.com/react-spaces/react-spaces-demo.gif" alt="Screen demo" width="100%" style={{ maxWidth: 1000 }} />
35-
</p>
31+
<p>
32+
<img src="https://www.allaneagle.com/react-spaces/react-spaces-demo.gif" alt="Screen demo" width="100%" style={{ maxWidth: 1000 }} />
33+
</p>
3634
</>
3735
)
3836
}

demo/src/docs/Try.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const Try: React.FC = () => {
55
<>
66
<h2 id="try">Try for yourself</h2>
77

8-
<iframe src="https://codesandbox.io/embed/react-shapes-ml4kl?fontsize=14" title="react-shapes" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media" style={{ width:'100%', maxWidth: 1000, height: 500, border: 0, borderRadius: 4, overflow: 'hidden' }} sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
8+
{/* <iframe src="https://codesandbox.io/embed/react-shapes-ml4kl?fontsize=14" title="react-shapes" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media" style={{ width:'100%', maxWidth: 1000, height: 500, border: 0, borderRadius: 4, overflow: 'hidden' }} sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe> */}
99
</>
1010
)
1111
}

demo/src/docs/VersionHistory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const VersionHistory = () => {
1919
<ul>
2020
<li>
2121
Added 'as' property to allow rendered DOM element to be specified (thanks to{" "}
22-
<a href="https://www.reddit.com/user/MahNonAnon/" target="_blank">u/MahNonAnon</a> and{" "}
23-
<a href="https://www.reddit.com/user/trevoreyre/" target="_blank">u/trevoreyre</a> on Reddit
22+
<a href="https://www.reddit.com/user/MahNonAnon/" rel="noopener noreferrer" target="_blank">u/MahNonAnon</a> and{" "}
23+
<a href="https://www.reddit.com/user/trevoreyre/" rel="noopener noreferrer" target="_blank">u/trevoreyre</a> on Reddit
2424
for suggestion of this).
2525
</li>
2626
<li>

demo/src/ui-demo/UI.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
.spaces-resize-handle {
2323
background-color: #333 !important;
2424
}
25+
26+
button {
27+
margin-right: 10px;
28+
border: none;
29+
background-color: #555;
30+
color: white;
31+
padding: 5px 15px;
32+
}
2533
}
2634

2735
.side-bar-container {

demo/src/ui-demo/UI.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ const Header = () => {
2828
}
2929

3030
const Main = () => {
31+
const [ sidebarVisible, setSidebarVisible ] = React.useState(true);
32+
const [ sidebarWide, setSidebarWide ] = React.useState(false);
33+
3134
return (
3235
<Space.Fill style={{ backgroundColor: '#1E1E1E' }}>
3336
<Space.Fill>
3437
<IconPane />
35-
<SideBar />
36-
<Editor />
38+
<SideBar wide={sidebarWide} visible={sidebarVisible} />
39+
<Editor toggleSize={() => setSidebarWide(!sidebarWide)} toggleVisibility={() => setSidebarVisible(!sidebarVisible)} />
3740
</Space.Fill>
3841
</Space.Fill>
3942
)
4043
}
4144

42-
const Editor = () => {
45+
const Editor : React.FC<{ toggleVisibility: () => void, toggleSize: () => void }> = (props) => {
4346
const [ code, setCode ] = React.useState('import * as React from \'react\';\r\nimport * as Space from \'react-spaces\';\r\n\r\nexport const App = () => {\r\n <Space.ViewPort>\r\n <Space.Top size={30}>\r\n Hello!\r\n </Space.Top>\r\n <Space.Fill>\r\n World!\r\n </Space.Fill>\r\n </Space.ViewPort>\r\n}');
4447

4548
const options = {
@@ -61,7 +64,7 @@ const Editor = () => {
6164
theme="vs-dark" />
6265
</Space.Fill>
6366
</Space.Fill>
64-
<BottomPane />
67+
<BottomPane toggleSize={props.toggleSize} toggleVisibility={props.toggleVisibility} />
6568
</Space.Fill>
6669
)
6770
}
@@ -73,9 +76,10 @@ const IconPane = () => {
7376
)
7477
}
7578

76-
const SideBar = () => {
79+
const SideBar : React.FC<{ wide: boolean, visible: boolean }> = (props) => {
7780
return (
78-
<Space.LeftResizable order={2} className="side-bar" size={300} handleSize={2} overlayHandle={false} style={{ backgroundColor: '#252526' }}>
81+
props.visible ?
82+
<Space.LeftResizable order={2} className="side-bar" size={props.wide ? 500 : 300} handleSize={2} overlayHandle={false} style={{ backgroundColor: '#252526' }}>
7983
<SideBarPane order={1} title="Open editors" height={200}>
8084

8185
</SideBarPane>
@@ -85,7 +89,8 @@ const SideBar = () => {
8589
<SideBarPane fill={true} title="Outline">
8690

8791
</SideBarPane>
88-
</Space.LeftResizable>
92+
</Space.LeftResizable> :
93+
null
8994
)
9095
}
9196

@@ -117,9 +122,11 @@ const SideBarPaneInner: React.FC<{ title: string }> = (props) => {
117122
)
118123
}
119124

120-
const BottomPane = () => {
125+
const BottomPane : React.FC<{ toggleVisibility: () => void, toggleSize: () => void }> = (props) => {
121126
return (
122-
<Space.BottomResizable className="bottom-pane" size="25%" handleSize={2}>
127+
<Space.BottomResizable className="bottom-pane" size="25%" handleSize={2} centerContent={Space.CenterType.HorizontalVertical}>
128+
<button onClick={props.toggleVisibility}>Toggle sidebar visibility</button>
129+
<button onClick={props.toggleSize}>Toggle sidebar size</button>
123130
</Space.BottomResizable>
124131
)
125132
}

0 commit comments

Comments
 (0)