[go: nahoru, domu]

Skip to content

Commit

Permalink
Update example for events
Browse files Browse the repository at this point in the history
  • Loading branch information
zesik committed Oct 5, 2017
1 parent f5107e7 commit cf21291
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/javascripts/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function App(props) {
<li><NavLink to="/percentage">Width in Percentage</NavLink></li>
<li><NavLink to="/nested">Nested Layout</NavLink></li>
<li><NavLink to="/sidebar">Sidebar</NavLink></li>
<li><NavLink to="/events">Events</NavLink></li>
</ul>
</nav>
<div className="child-content">
Expand Down
86 changes: 86 additions & 0 deletions example/javascripts/components/HorizontalLayoutWithEvents.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint no-void: [0] */
import React from 'react';
import SplitterLayout from '../../../index';

export default class HorizontalLayoutWithEvents extends React.Component {
constructor(props) {
super(props);
this.onDragStart = this.onDragStart.bind(this);
this.onDragEnd = this.onDragEnd.bind(this);
this.onSecondaryPaneSizeChange = this.onSecondaryPaneSizeChange.bind(this);
this.state = {
secondaryPaneSize: -1,
dragging: false
};
}

componentDidUpdate(prevProps, prevState) {
if (prevState.dragging !== this.state.dragging && this.draggingEl1 && this.draggingEl2) {
this.draggingEl1.classList.add('highlight');
this.draggingEl2.classList.add('highlight');
void this.draggingEl1.offsetWidth;
void this.draggingEl2.offsetWidth;
this.draggingEl1.classList.remove('highlight');
this.draggingEl2.classList.remove('highlight');
}
if (prevState.secondaryPaneSize !== this.state.secondaryPaneSize && this.sizeEl1 && this.sizeEl2) {
this.sizeEl1.classList.add('highlight');
this.sizeEl2.classList.add('highlight');
void this.sizeEl1.offsetWidth;
void this.sizeEl2.offsetWidth;
this.sizeEl1.classList.remove('highlight');
this.sizeEl2.classList.remove('highlight');
}
}

onDragStart() {
this.setState({ dragging: true });
}

onDragEnd() {
this.setState({ dragging: false });
}

onSecondaryPaneSizeChange(secondaryPaneSize) {
this.setState({ secondaryPaneSize });
}

render() {
return (
<SplitterLayout
onDragStart={this.onDragStart}
onDragEnd={this.onDragEnd}
onSecondaryPaneSizeChange={this.onSecondaryPaneSizeChange}
>
<div className="my-pane">
<h2>1st Pane</h2>
<p>This is the 1st pane, and this is the primary pane by default.</p>
<p>Dragging:
<span className="volatile" ref={(e) => { this.draggingEl1 = e; }}>
{this.state.dragging ? 'Yes' : 'No'}
</span>
</p>
<p>Size of the 2nd pane:
<span className="volatile" ref={(e) => { this.sizeEl1 = e; }}>
{this.state.secondaryPaneSize}
</span>
</p>
</div>
<div className="my-pane">
<h2>2nd Pane</h2>
<p>This is the 2nd pane, and this is the secondary pane by default.</p>
<p>Dragging:
<span className="volatile" ref={(e) => { this.draggingEl2 = e; }}>
{this.state.dragging ? 'Yes' : 'No'}
</span>
</p>
<p>Size of this pane:
<span className="volatile" ref={(e) => { this.sizeEl2 = e; }}>
{this.state.secondaryPaneSize}
</span>
</p>
</div>
</SplitterLayout>
);
}
}
4 changes: 2 additions & 2 deletions example/javascripts/components/NavLink.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint import/no-extraneous-dependencies: [0] */
import React from 'react';
import { Link } from 'react-router-dom';
import { NavLink } from 'react-router-dom';

export default function(props) {
return (
<Link {...props} activeClassName="active" />
<NavLink {...props} activeClassName="active" />
);
}
2 changes: 2 additions & 0 deletions example/javascripts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import LayoutWithMinimalSize from './components/LayoutWithMinimalSize';
import PercentageLayout from './components/PercentageLayout';
import NestedLayout from './components/NestedLayout';
import TogglableSidebarLayout from './components/TogglableSidebarLayout';
import HorizontalLayoutWithEvents from './components/HorizontalLayoutWithEvents';
import '../stylesheets/index.css';

function NoMatch() {
Expand All @@ -31,6 +32,7 @@ render(
<Route path="/percentage" component={PercentageLayout} />
<Route path="/nested" component={NestedLayout} />
<Route path="/sidebar" component={TogglableSidebarLayout} />
<Route path="/events" component={HorizontalLayoutWithEvents} />
<Route path="*" component={NoMatch} />
</Switch>
</App>
Expand Down
15 changes: 15 additions & 0 deletions example/stylesheets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@ pre {
.not-found {
margin: 20px;
}

.volatile {
transition: background-color 1s, border-color 1s;
transition-delay: 500ms;
padding: 2px 4px;
margin: 0 2px;
border: 1px solid white;
border-radius: 4px;
}

.volatile.highlight {
transition: none;
background: #fff176;
border-color: #ff8f00;
}
3 changes: 2 additions & 1 deletion example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = {
]
},
plugins: [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') })
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
new webpack.optimize.UglifyJsPlugin()
],
output: {
filename: 'bundle.js'
Expand Down

0 comments on commit cf21291

Please sign in to comment.