// {{{
var pStyle = {
margin: 0,
padding: 10,
backgroundColor: "white"
};
// }}}
return <Tooltip className="class-for-tooltip-contents"
horizontalPosition="left"
horizontalAlign="left"
verticalPosition="bottom"
arrowSize={10}
borderColor="#ccc"
show>
<div>reticulating splines!</div>
<p style={pStyle}>
<a href="/?originalUrl=https%3A%2F%2Fkhan.github.io%2F%26%2334%3Bhttp%3A%2F%2Fsims.wikia.com%2Fwiki%2FReticulating_splines%26%2334%3B%26gt%3Bmeaningless%2520phrase%26lt%3B%2Fa%26gt%3B%2520%2520%2520%2520%26lt%3B%2Fp%26gt%3B%26lt%3B%2FTooltip%26gt%3B%3B%253C%2Fdiv">
A very simple informational tooltip that displays on hover.
return <div>
reticulating splines
<InfoTip><p>
<a href="/?originalUrl=https%3A%2F%2Fkhan.github.io%2F%26%2334%3Bhttp%3A%2F%2Fsims.wikia.com%2Fwiki%2FReticulating_splines%26%2334%3B%26gt%3Bmeaningless%2520phrase%26lt%3B%2Fa%26gt%3B%2520%2520%2520%2520%26lt%3B%2Fp%26gt%3B%26lt%3B%2FInfoTip%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3B%253C%2Fdiv">
Sortable
Sort a list.
var Sorter = React.createClass({
render: function() {
return <Sortable components={this.state.components}
onReorder={this.handleReorder}
className="sidebar-list"
verify={() => true} />;
},
// {{{
handleReorder: function(components) {
this.setState({ components });
},
getInitialState: function() {
return { components: this.props.components };
}
// }}}
});
// {{{
var components = [
<div draggable={true} key="1">1</div>,
<div draggable={true} key="2">2</div>,
<div draggable={true} key="3">3</div>,
<div draggable={true} key="4">4</div>
];
return <Sorter components={components} />;
// }}}
Drag Target
Accept dragged content from the browser or the desktop.
var Target = React.createClass({
render: function() {
return <DragTarget onDrop={this.handleDrop}>
{this.state.message}
</DragTarget>;
},
handleDrop: function(event) {
this.setState({ message: "delicious. thank you!" });
},
getInitialState: function() {
return { message: "I haven't received any drags" };
}
});
return <Target />;
Window Drag
Detect drags into and out of the page.
var Indicator = React.createClass({
render: function() {
return <WindowDrag>
{/* modal? */}
<div>WINDOW DRAG!</div>
</WindowDrag>;
}
});
return <Indicator />;
Timeout Transition Group
A wrapper which applies CSS classes to children who are entering or leaving. It is very much like the CSSTransitionGroup provided in the React addons. Unfortunately, CSSTransitionGroup uses the transitionEnd event, which is not fired in a variety of conditions (including the transition not being visible or in another tab). This version of CSSTransitionGroup uses a manually set timeout, instead.
// {{{
var itemStyle = {
padding: 10,
borderColor: "black",
borderWidth: 1,
borderStyle: "solid",
overflow: "hidden",
cursor: "pointer"
};
// }}}
/**
* Already in the stylesheet of the page:
*
* .demo-enter {
* opacity: 0.01;
* height: 0px;
* padding: 0px 10px !important;
* transition: opacity 500ms ease-out,
* padding 500ms ease-out,
* height 500ms ease-out;
* }
* .demo-enter.demo-enter-active {
* opacity: 1;
* height: 16px;
* padding: 10px !important;
* }
* .demo-leave {
* opacity: 1;
* height: 16px;
* transition: opacity 500ms ease-out,
* padding 500ms ease-out,
* height 500ms ease-out;
* }
* .demo-leave.demo-leave-active {
* opacity: 0;
* height: 0px;
* padding: 0px 10px !important;
* }
*/
var List = React.createClass({
getInitialState: function() {
return {
items: [0, 1, 2, 3]
};
},
removeThenReadd: function(item) {
// {{{
var items = this.state.items.slice(0);
var found = false;
for(var i = 0; i < items.length; i++) {
if (items[i] === item) {
items.splice(i, 1);
found = true;
break;
}
}
this.setState({items: items}, function() {
if (found) {
setTimeout(function() {
var items = this.state.items.slice(0);
items.push(item);
this.setState({items: items});
}.bind(this), 5000);
}
}.bind(this));
// }}}
},
_makeDiv: function(index) {
// {{{
return <div onClick={this.removeThenReadd.bind(null, index)}
style={itemStyle}
key={index}>
{"Item " + index}
</div>;
// }}}
},
render: function() {
var items = this.state.items.map(this._makeDiv);
return <TimeoutTransitionGroup enterTimeout={500}
leaveTimeout={500}
transitionName="demo">
{items}
</TimeoutTransitionGroup>;
}
});
return <List />;
Backbone Mixin
Update this view every time a backbone model updates:
This mixin is deprecated. We do not recommend using it in production.
var SimpleModel = Backbone.Model.extend({
defaults: {
comment: "This is a comment!"
}
});
var Comment = React.createClass({
mixins: [BackboneMixin],
getBackboneModels: function() {
return [this.props.model];
},
render: function() {
return <div>{this.props.model.get("comment")}</div>;
}
});
var myModel = new SimpleModel();
return <div>
<Comment model={myModel} />
<button onClick={function() {myModel.set("comment", "This is an (edited) comment!");}}>
Edit
</button>
</div>;