JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div id="example"></div>
body {
padding: 20px;
}
[aria-hidden="true"] {
display: none;
}
[role="tablist"],
[role="tabpanel"] {
width: 80%;
}
[role="tablist"] {
list-style-type: none;
margin: 0;
padding: 0;
> * {
display: inline-block;
margin-right: 10px;
}
[role="tab"] {
position: relative;
top: 2px;
border: 2px solid #000;
border-top-right-radius: 7px;
border-top-left-radius: 7px;
color: #555;
background: #fff;
padding: 10px 30px;
&[aria-selected="true"] {
border-bottom: 2px solid #fff;
color: red;
}
}
}
[role="tabpanel"] {
padding: 30px 50px;
color: #333;
border: 2px solid #000;
background-color: #fff;
}
const KEYCODE_LEFT = 37;
const KEYCODE_RIGHT = 39;
class Tabs extends React.Component {
state = {
index: 0
};
updateIndex(i, fn) {
this.setState({index: i}, () => {
React.findDOMNode(this.refs['tab' + i]).focus();
});
}
onClickTab(i) {
this.updateIndex(i);
}
onMoveFocus(e) {
let curtIndex = this.state.index;
switch(e.keyCode) {
case KEYCODE_LEFT:
if (curtIndex !== 0) {
this.updateIndex(curtIndex - 1);
}
break;
case KEYCODE_RIGHT:
if (curtIndex !== this.props.children.length - 1) {
this.updateIndex(curtIndex + 1);
}
break;
}
}
render() {
let curtIndex = this.state.index;
let tabs = this.props.children.map((child, i) => {
return (
<li role="presentation" key={i}>
<button role="tab"
ref={'tab' + i}
tabIndex={curtIndex === i ? '0' : '-1'}
aria-selected={curtIndex === i ? 'true' : 'false'}
aria-controls={child.props.id}
onKeyUp={this.onMoveFocus.bind(this)}
onClick={this.onClickTab.bind(this, i)}>
{child.props.label}
</button>
</li>
);
});
let panels = this.props.children.map((child, i) => {
return (
<div role="tabpanel"
key={i}
id={child.props.id}
aria-hidden={curtIndex === i ? 'false' : 'true'}>
{child}
</div>
);
});
return (
<div>
<ul role="tablist"
className={this.props.className}>
{tabs}
</ul>
{panels}
</div>
);
}
}
class Container extends React.Component {
render() {
return (
<div>
<h1>Hello, world!</h1>
<Tabs>
<div id="tabset1" label="1st Panel">
<h2>1st Panel</h2>
<ul>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
</ul>
</div>
<div id="tabset2" label="2nd Panel">
<h2>2nd Panel</h2>
<ul>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
</ul>
</div>
<div id="tabset3" label="3rd Panel">
<h2>3rd Panel</h2>
<ul>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
<li><a href="http://example.com" target="_blank">example.com</a></li>
</ul>
</div>
</Tabs>
</div>
);
}
}
React.render(<Container />, document.getElementById('example'));
Also see: Tab Triggers