made with esnextbin
Last active
December 7, 2016 03:47
-
-
Save sgilligan/9e389ce9ef672543348eb7fa4d0a774b to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
<style> | |
#stateless-demo {margin:20px;} | |
#buttons {padding-bottom: 40px} | |
button {display:block;} | |
.Tabs-tablist { | |
list-style-type: none; | |
margin: 0; | |
padding: 0; | |
} | |
.Tabs-tablistItem { | |
display: inline-block; | |
} | |
.Tabs-tablistItem + .Tabs-tablistItem { | |
margin-left: 0.3em; | |
} | |
.Tabs-panel { | |
border: 1px solid #ccc; | |
padding: 1em; | |
} | |
.Tabs-tab { | |
cursor: pointer; | |
} | |
.Tabs-tab:focus { | |
box-shadow: 0 0 3px 3px #09f; | |
} | |
.Tabs-tabInner { | |
border: 1px solid transparent; | |
border-bottom: 0; | |
position: relative; | |
padding: 5px 20px; | |
background: #ccc; | |
position: relative; | |
} | |
.Tabs-tabInner.is-active { | |
background: #fff; | |
border-color: #ccc; | |
} | |
.Tabs-tabInner.is-active::after { | |
content: ""; | |
background: #fff; | |
height: 1px; | |
position: absolute; | |
bottom: -1px; | |
left: 0; | |
right: 0; | |
} | |
</style> | |
<script src="https://fb.me/react-with-addons-15.1.0.js"></script> | |
<script src="https://fb.me/react-dom-15.1.0.js"></script> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div id='stateless-demo'></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AriaTabPanel from 'react-aria-tabpanel'; | |
const tabDescriptions = [ | |
{ | |
title: 'one', | |
id: 't1', | |
content: ( | |
<div> | |
Lorem <a href='#'>ipsum</a> dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | |
</div> | |
), | |
}, | |
{ | |
title: 'two', | |
id: 't2', | |
content: ( | |
<div> | |
Ut <a href='#'>enim</a> ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | |
</div> | |
), | |
}, | |
{ | |
title: 'three', | |
id: 't3', | |
content: ( | |
<div> | |
Duis <a href='#'>aute</a> irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</div> | |
), | |
}, | |
]; | |
class StatelessDemo extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
activeTab: 't1', | |
tabset: 'all' | |
}; | |
this.reduceTabCount.bind(this); | |
this.restoreTabCount.bind(this); | |
} | |
setTab(newActiveTabId) { | |
this.setState({ activeTab: newActiveTabId }); | |
} | |
reduceTabCount() {this.setState({tabset:'reduce'})} | |
restoreTabCount() {console.log('restore'); this.setState({tabset:'restore'})} | |
render() { | |
const { activeTab } = this.state; | |
const tabs = tabDescriptions.map((tabDescription, i) => { | |
let innerCl = 'Tabs-tabInner'; | |
if (tabDescription.id === activeTab) innerCl += ' is-active'; | |
if (this.state.tabset === 'reduce' && i === 1) { | |
return undefined; | |
} | |
else { | |
return ( | |
<li className='Tabs-tablistItem' key={i}> | |
<AriaTabPanel.Tab | |
id={tabDescription.id} | |
className='Tabs-tab' | |
active={tabDescription.id === activeTab} | |
> | |
<div className={innerCl}> | |
{tabDescription.title} | |
</div> | |
</AriaTabPanel.Tab> | |
</li> | |
); | |
} | |
}); | |
const panels = tabDescriptions.map((tabDescription, i) => { | |
return ( | |
<AriaTabPanel.TabPanel | |
key={i} | |
tabId={tabDescription.id} | |
active={tabDescription.id === activeTab} | |
> | |
{tabDescription.content} | |
</AriaTabPanel.TabPanel> | |
); | |
}); | |
return ( | |
<div> | |
<div id='buttons'> | |
<button onClick={this.reduceTabCount.bind(this)}>Reduce to 2 tabs</button> | |
<button onClick={this.restoreTabCount.bind(this)}>Restore to 3 tabs</button> | |
</div> | |
<AriaTabPanel.Wrapper | |
onChange={this.setTab.bind(this)} | |
activeTabId={this.state.activeTab} | |
> | |
<AriaTabPanel.TabList> | |
<ul className='Tabs-tablist'> | |
{tabs} | |
</ul> | |
</AriaTabPanel.TabList> | |
<div className='Tabs-panel'> | |
{panels} | |
</div> | |
</AriaTabPanel.Wrapper> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<StatelessDemo />, | |
document.getElementById('stateless-demo') | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"react-aria-tabpanel": "4.2.2", | |
"babel-runtime": "6.18.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | |
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | |
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | |
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |
var _createClass2 = require('babel-runtime/helpers/createClass'); | |
var _createClass3 = _interopRequireDefault(_createClass2); | |
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | |
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | |
var _inherits2 = require('babel-runtime/helpers/inherits'); | |
var _inherits3 = _interopRequireDefault(_inherits2); | |
var _reactAriaTabpanel = require('react-aria-tabpanel'); | |
var _reactAriaTabpanel2 = _interopRequireDefault(_reactAriaTabpanel); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var tabDescriptions = [{ | |
title: 'one', | |
id: 't1', | |
content: React.createElement( | |
'div', | |
null, | |
'Lorem ', | |
React.createElement( | |
'a', | |
{ href: '#' }, | |
'ipsum' | |
), | |
' dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' | |
) | |
}, { | |
title: 'two', | |
id: 't2', | |
content: React.createElement( | |
'div', | |
null, | |
'Ut ', | |
React.createElement( | |
'a', | |
{ href: '#' }, | |
'enim' | |
), | |
' ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' | |
) | |
}, { | |
title: 'three', | |
id: 't3', | |
content: React.createElement( | |
'div', | |
null, | |
'Duis ', | |
React.createElement( | |
'a', | |
{ href: '#' }, | |
'aute' | |
), | |
' irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' | |
) | |
}]; | |
var StatelessDemo = function (_React$Component) { | |
(0, _inherits3.default)(StatelessDemo, _React$Component); | |
function StatelessDemo(props) { | |
(0, _classCallCheck3.default)(this, StatelessDemo); | |
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(StatelessDemo).call(this, props)); | |
_this.state = { | |
activeTab: 't1', | |
tabset: 'all' | |
}; | |
_this.reduceTabCount.bind(_this); | |
_this.restoreTabCount.bind(_this); | |
return _this; | |
} | |
(0, _createClass3.default)(StatelessDemo, [{ | |
key: 'setTab', | |
value: function setTab(newActiveTabId) { | |
this.setState({ activeTab: newActiveTabId }); | |
} | |
}, { | |
key: 'reduceTabCount', | |
value: function reduceTabCount() { | |
this.setState({ tabset: 'reduce' }); | |
} | |
}, { | |
key: 'restoreTabCount', | |
value: function restoreTabCount() { | |
console.log('restore');this.setState({ tabset: 'restore' }); | |
} | |
}, { | |
key: 'render', | |
value: function render() { | |
var _this2 = this; | |
var activeTab = this.state.activeTab; | |
var tabs = tabDescriptions.map(function (tabDescription, i) { | |
var innerCl = 'Tabs-tabInner'; | |
if (tabDescription.id === activeTab) innerCl += ' is-active'; | |
if (_this2.state.tabset === 'reduce' && i === 1) { | |
return undefined; | |
} else { | |
return React.createElement( | |
'li', | |
{ className: 'Tabs-tablistItem', key: i }, | |
React.createElement( | |
_reactAriaTabpanel2.default.Tab, | |
{ | |
id: tabDescription.id, | |
className: 'Tabs-tab', | |
active: tabDescription.id === activeTab | |
}, | |
React.createElement( | |
'div', | |
{ className: innerCl }, | |
tabDescription.title | |
) | |
) | |
); | |
} | |
}); | |
var panels = tabDescriptions.map(function (tabDescription, i) { | |
return React.createElement( | |
_reactAriaTabpanel2.default.TabPanel, | |
{ | |
key: i, | |
tabId: tabDescription.id, | |
active: tabDescription.id === activeTab | |
}, | |
tabDescription.content | |
); | |
}); | |
return React.createElement( | |
'div', | |
null, | |
React.createElement( | |
'div', | |
{ id: 'buttons' }, | |
React.createElement( | |
'button', | |
{ onClick: this.reduceTabCount.bind(this) }, | |
'Reduce to 2 tabs' | |
), | |
React.createElement( | |
'button', | |
{ onClick: this.restoreTabCount.bind(this) }, | |
'Restore to 3 tabs' | |
) | |
), | |
React.createElement( | |
_reactAriaTabpanel2.default.Wrapper, | |
{ | |
onChange: this.setTab.bind(this), | |
activeTabId: this.state.activeTab | |
}, | |
React.createElement( | |
_reactAriaTabpanel2.default.TabList, | |
null, | |
React.createElement( | |
'ul', | |
{ className: 'Tabs-tablist' }, | |
tabs | |
) | |
), | |
React.createElement( | |
'div', | |
{ className: 'Tabs-panel' }, | |
panels | |
) | |
) | |
); | |
} | |
}]); | |
return StatelessDemo; | |
}(React.Component); | |
ReactDOM.render(React.createElement(StatelessDemo, null), document.getElementById('stateless-demo')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment