<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>
<!-- The core React library -->
<script src="https://fb.me/react-0.14.7.js"></script>
<!-- The ReactDOM Library -->
<script src="https://fb.me/react-dom-0.14.7.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.30.7/react-bootstrap.js"></script>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
<title>React JSBin</title>
</head>
<body>
<div id="react_root"></div>
</body>
</html>
/* jshint esnext: true, asi: true */
const debounce = _.debounce
const Component = React.Component
const Tabs = ReactBootstrap.Tabs
const Tab = ReactBootstrap.Tab
/////////////////////////
// Equalizer
// From: https://github.com/patrickgalbraith/react-equalizer
// Version 1.0.5
// Note: This version may not be the latest see Github for latest
// Scroll down for example usage code
class Equalizer extends Component {
constructor(){
super()
this.handleResize = debounce(this.handleResize.bind(this), 50)
this.updateChildrenHeights = this.updateChildrenHeights.bind(this)
}
componentDidMount() {
this.handleResize()
addEventListener('resize', this.handleResize)
}
componentWillUnmount() {
removeEventListener('resize', this.handleResize)
}
componentDidUpdate() {
this.handleResize()
}
handleResize() {
setTimeout(this.updateChildrenHeights, 0)
}
static getHeights(nodes, byRow = true) {
let lastElTopOffset = 0,
groups = [],
row = 0
groups[row] = []
for(let i = 0; i < nodes.length; i++){
let node = nodes[i]
node.style.height = 'auto'
node.style.maxHeight = ''
node.style.minHeight = ''
const elOffsetTop = node.offsetTop
const elHeight = node.offsetHeight
if(i === 0) {
lastElTopOffset = elOffsetTop
}
if (elOffsetTop != lastElTopOffset && byRow) {
row++
groups[row] = []
lastElTopOffset = elOffsetTop
}
groups[row].push([node, elHeight])
}
for (let j = 0; j < groups.length; j++) {
const heights = groups[j].map((item) => item[1])
const max = Math.max.apply(null, heights)
groups[j].push(max)
}
return groups
}
updateChildrenHeights() {
const { property, byRow, enabled } = this.props
const node = ReactDOM.findDOMNode(this)
if (!enabled(this, node)) {
return
}
if (node !== undefined) {
const children = this.props.nodes(this, node)
const heights = this.constructor.getHeights(children, byRow)
for (let row = 0; row < heights.length; row++) {
const max = heights[row][heights[row].length-1]
for (let i = 0; i < (heights[row].length - 1); i++) {
heights[row][i][0].style[property] = max + 'px'
}
}
}
}
render() {
const {children, property, byRow, enabled, nodes, otherProps} = this.props
return (
<div onLoad={this.handleResize} {otherProps}>
{children}
</div>
)
}
}
Equalizer.defaultProps = {
property: 'height',
byRow: true,
enabled: () => true,
nodes: (component, node) => node.children
}
Equalizer.propTypes = {
children: React.PropTypes.node.isRequired,
property: React.PropTypes.string,
byRow: React.PropTypes.bool,
enabled: React.PropTypes.func,
nodes: React.PropTypes.func
}
////////////////////////
// Example Component
class MyComponent extends React.Component {
render() {
let colStyles = {
float: 'left',
width: '50%',
padding: '10px',
background: '#ddd',
border: '4px solid white',
boxSizing: 'border-box'
}
return (
<div>
<Tabs defaultActiveKey={2}>
<Tab eventKey={1} title="Tab 1">
<Equalizer byRow={false}>
<div style={colStyles}>
<img src="http://placehold.it/200x300" />
</div>
<div style={colStyles}>
Test content
</div>
</Equalizer>
</Tab>
<Tab eventKey={2} title="Tab 2">
<Equalizer byRow={false}>
<div style={colStyles}>
<img src="http://placehold.it/200x300" />
</div>
<div style={colStyles}>
Test content
</div>
</Equalizer>
</Tab>
<Tab eventKey={3} title="Tab 3">
<Equalizer byRow={false}>
<div style={colStyles}>
<img src="http://placehold.it/200x300" />
</div>
<div style={colStyles}>
Test content
</div>
</Equalizer>
</Tab>
</Tabs>
</div>
)
}
}
ReactDOM.render(
<MyComponent />,
document.getElementById('react_root')
)
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. |