<html>
<head>
<meta name="description" content="Morearty Portal Demo Trois">
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//fb.me/react-with-addons-0.12.0.js"></script>
<script src="https://rawgit.com/facebook/immutable-js/master/dist/immutable.js"></script>
<script src="https://rawgit.com/moreartyjs/moreartyjs/master/dist/morearty.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
.DialogGroup{ position:relative; }
.Dialog {
position:absolute;
top: 0;
left: 0;
border: 1px solid red;
height: 300px;
width: 100%;
backround: #ffdfef;
padding: 15px;
}
.Dialog-anim-enter {
transform: translateX(-100%);
transition: all 1s;
}
.Dialog-anim-enter-active {
transform: translateX(0%);
}
.Dialog-anim-leave {
transform: translateX(0%);
transition: all 1s;
}
.Dialog-anim-leave-active {
transform: translateX(100%);
opacity: 0;
}
.Main {
border: 1px solid blue;
}
var ctx = Morearty.createContext({
initialState: {
hello: 'hello dialog world',
activeDialog: 0,
foo: ''
}
});
window.rootBinding = ctx.getBinding();
// note: need to safeguard for server-side render
// note: doesn't support changing portalId
var Portal = React.createClass({
render: () => null,
portalElement: null,
componentDidMount() {
var p = this.props.portalId && document.getElementById(this.props.portalId);
if (!p) {
var p = document.createElement('div');
p.id = this.props.portalId;
document.body.appendChild(p);
}
this.portalElement = p;
this.componentDidUpdate();
},
componentWillUnmount() {
document.body.removeChild(this.portalElement);
},
componentDidUpdate() {
React.render(<div {this.props}>{this.props.children}</div>, this.portalElement);
}
});
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var App = React.createClass({
mixins: [Morearty.Mixin],
showOne() { this.getDefaultBinding().set('activeDialog', 1) },
showTwo() { this.getDefaultBinding().set('activeDialog', 2) },
foo() { this.getDefaultBinding().set('foo', 'bar') },
hide() { this.getDefaultBinding().set('activeDialog', 0) },
render(){
var binding = this.getDefaultBinding();
var activeDialog = binding.get('activeDialog');
var foo = binding.get('foo');
return (
<div>
<div className="Main">
<h1>Portalicious</h1>
<p>{binding.get('hello')}</p>
<button onClick={this.showOne}>show one</button>
<button onClick={this.showTwo}>show two</button>
<button onClick={this.hide}>hide</button>
{ /* Note: it's also possible to use just 1 portal for both dialogs */ }
<Portal className="DialogGroup">
<ReactCSSTransitionGroup transitionName="Dialog-anim">
{ activeDialog === 1 &&
<div key="0" className="Dialog"><button onClick={this.hide}>X</button>
<button onClick={this.foo}>foo</button>
ONE ONE <strong>{foo}</strong> ONE ONE!!!</div> }
</ReactCSSTransitionGroup>
</Portal>
<Portal className="DialogGroup">
<ReactCSSTransitionGroup transitionName="Dialog-anim">
{ activeDialog === 2 &&
<div key="1" className="Dialog"><button onClick={this.hide}>X</button>
TWO TWO <strong>TWO</strong> TWO TWO!!!</div> }
</ReactCSSTransitionGroup>
</Portal>
</div>
</div>
);
}
});
var Bootstrap = ctx.bootstrap(App);
React.render(<Bootstrap />, document.getElementById('app'));
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |