Skip to content

Feature/react hooks #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/.env.analyse
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANALYSE_BUNDLE=true
5 changes: 5 additions & 0 deletions demo/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpack
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const postcssNormalize = require('postcss-normalize');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack-plugin");

// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
Expand Down Expand Up @@ -272,6 +274,7 @@ module.exports = function(webpackEnv) {
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
'react-native': 'react-native-web',
'react': path.resolve('./node_modules/react')
},
plugins: [
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
Expand Down Expand Up @@ -475,6 +478,8 @@ module.exports = function(webpackEnv) {
],
},
plugins: [
new DuplicatePackageCheckerPlugin(),
process.env.ANALYSE_BUNDLE === 'true' && new BundleAnalyzerPlugin(),
new MonacoWebpackPlugin({
// available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
languages: ['typescript']
Expand Down
13,177 changes: 8,332 additions & 4,845 deletions demo/package-lock.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"css-loader": "2.1.1",
"dotenv": "6.2.0",
"dotenv-expand": "4.2.0",
"env-cmd": "^9.0.3",
"eslint": "^5.16.0",
"eslint-config-react-app": "^4.0.1",
"eslint-loader": "2.1.2",
Expand Down Expand Up @@ -53,7 +54,7 @@
"postcss-normalize": "7.0.1",
"postcss-preset-env": "6.6.0",
"postcss-safe-parser": "4.0.1",
"react": "^16.8.6",
"react": "^16.9.0",
"react-app-polyfill": "^1.0.1",
"react-dev-utils": "^9.0.1",
"react-dom": "^16.8.6",
Expand All @@ -70,14 +71,17 @@
"typescript": "^3.5.3",
"url-loader": "1.1.2",
"webpack": "4.29.6",
"webpack-bundle-analyser": "^1.4.0",
"webpack-bundle-analyzer": "^3.4.1",
"webpack-dev-server": "3.2.1",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "4.2.0"
},
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
"test": "node scripts/test.js",
"analyse": "env-cmd -f .env.analyse node scripts/build.js"
},
"eslintConfig": {
"extends": "react-app"
Expand Down Expand Up @@ -144,5 +148,8 @@
"presets": [
"react-app"
]
},
"devDependencies": {
"duplicate-package-checker-webpack-plugin": "^3.0.0"
}
}
36 changes: 17 additions & 19 deletions demo/src/docs/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@ import { Button, Icon } from 'antd';
export const Intro = () => {
return (
<>
<p id="intro" style={{ fontWeight: 400, paddingTop: 30, paddingBottom: 0, fontSize: 28, color: '#777' }}>
<p id="intro" style={{ fontWeight: 400, paddingTop: 30, paddingBottom: 0, fontSize: 28, color: '#777' }}>
React Spaces allow you to divide a page or container into nestable, anchored, scrollable and resizable spaces.
</p>
</p>

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

<p>
<h2>Features</h2>
<h2>Features</h2>

<ul>
<li>
No styling to achieve simple or complex layouts.
</li>
<li>
Spaces know how to behave in relation to each other and resize accordingly.
</li>
<li>
Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
</li>
</ul>
</p>
<ul>
<li>
No styling to achieve simple or complex layouts.
</li>
<li>
Spaces know how to behave in relation to each other and resize accordingly.
</li>
<li>
Spaces don't have any visual element to them (even padding or margins). You can fill them with whatever you want.
</li>
</ul>

<p>
<img src="https://www.allaneagle.com/react-spaces/react-spaces-demo.gif" alt="Screen demo" width="100%" style={{ maxWidth: 1000 }} />
</p>
<p>
<img src="https://www.allaneagle.com/react-spaces/react-spaces-demo.gif" alt="Screen demo" width="100%" style={{ maxWidth: 1000 }} />
</p>
</>
)
}
10 changes: 10 additions & 0 deletions demo/src/docs/KnownIssues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ export const KnownIssues = () => {
<h2 id="issues">Known issues / limitations</h2>

<ul>
<li>
The components in <strong>v0.1.13</strong> have been changed to use React Hooks. This can cause problems if there are
multiple versions of React loaded. If you are using webpack you can add to your webpack config:

<pre style={{ marginTop: 15 }}>
{`alias: { 'react': path.resolve('./node_modules/react') }`}
</pre>

This will ensure that all references to React resolve to the same version.
</li>
<li>
Rendering an anchored horizontal space and an anchored vertical space within the same parent space will cause a gap
to appear in the corner where the two anchored spaces meet. You can workaround this by using nested <strong>&lt;Fill /&gt;</strong>
Expand Down
2 changes: 1 addition & 1 deletion demo/src/docs/Try.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const Try: React.FC = () => {
<>
<h2 id="try">Try for yourself</h2>

<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>
{/* <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> */}
</>
)
}
15 changes: 13 additions & 2 deletions demo/src/docs/VersionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ export const VersionHistory = () => {
<>
<h2 id="changes">Version history</h2>

<div>
<h3>0.1.13</h3>
<ul>
<li>
Refactored spaces as functional component using hooks.
</li>
<li>
Fixed className type on &lt;ViewPort /&gt; component.
</li>
</ul>
</div>
<div>
<h3>0.1.11 - 0.1.12</h3>
<ul>
Expand All @@ -19,8 +30,8 @@ export const VersionHistory = () => {
<ul>
<li>
Added 'as' property to allow rendered DOM element to be specified (thanks to{" "}
<a href="https://www.reddit.com/user/MahNonAnon/" target="_blank">u/MahNonAnon</a> and{" "}
<a href="https://www.reddit.com/user/trevoreyre/" target="_blank">u/trevoreyre</a> on Reddit
<a href="https://www.reddit.com/user/MahNonAnon/" rel="noopener noreferrer" target="_blank">u/MahNonAnon</a> and{" "}
<a href="https://www.reddit.com/user/trevoreyre/" rel="noopener noreferrer" target="_blank">u/trevoreyre</a> on Reddit
for suggestion of this).
</li>
<li>
Expand Down
8 changes: 8 additions & 0 deletions demo/src/ui-demo/UI.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
.spaces-resize-handle {
background-color: #333 !important;
}

button {
margin-right: 10px;
border: none;
background-color: #555;
color: white;
padding: 5px 15px;
}
}

.side-bar-container {
Expand Down
29 changes: 17 additions & 12 deletions demo/src/ui-demo/UI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { CenterType } from 'react-spaces';

export const UI = () => {
return (
<div className="ui-demo">
<Space.ViewPort>
<Space.ViewPort className="ui-demo">
<Header />
<Main />
</Space.ViewPort>
</div>
)
}

Expand All @@ -28,18 +26,21 @@ const Header = () => {
}

const Main = () => {
const [ sidebarVisible, setSidebarVisible ] = React.useState(true);
const [ sidebarWide, setSidebarWide ] = React.useState(false);

return (
<Space.Fill style={{ backgroundColor: '#1E1E1E' }}>
<Space.Fill>
<IconPane />
<SideBar />
<Editor />
<SideBar wide={sidebarWide} visible={sidebarVisible} />
<Editor toggleSize={() => setSidebarWide(!sidebarWide)} toggleVisibility={() => setSidebarVisible(!sidebarVisible)} />
</Space.Fill>
</Space.Fill>
)
}

const Editor = () => {
const Editor : React.FC<{ toggleVisibility: () => void, toggleSize: () => void }> = (props) => {
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}');

const options = {
Expand All @@ -61,7 +62,7 @@ const Editor = () => {
theme="vs-dark" />
</Space.Fill>
</Space.Fill>
<BottomPane />
<BottomPane toggleSize={props.toggleSize} toggleVisibility={props.toggleVisibility} />
</Space.Fill>
)
}
Expand All @@ -73,9 +74,10 @@ const IconPane = () => {
)
}

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

</SideBarPane>
Expand All @@ -85,7 +87,8 @@ const SideBar = () => {
<SideBarPane fill={true} title="Outline">

</SideBarPane>
</Space.LeftResizable>
</Space.LeftResizable> :
null
)
}

Expand Down Expand Up @@ -117,9 +120,11 @@ const SideBarPaneInner: React.FC<{ title: string }> = (props) => {
)
}

const BottomPane = () => {
const BottomPane : React.FC<{ toggleVisibility: () => void, toggleSize: () => void }> = (props) => {
return (
<Space.BottomResizable className="bottom-pane" size="25%" handleSize={2}>
<Space.BottomResizable className="bottom-pane" size="25%" handleSize={2} centerContent={Space.CenterType.HorizontalVertical}>
<button onClick={props.toggleVisibility}>Toggle sidebar visibility</button>
<button onClick={props.toggleSize}>Toggle sidebar size</button>
</Space.BottomResizable>
)
}
Loading