Skip to content

Commit

Permalink
Push lib folder to resemble official npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
vaevictis committed Jun 10, 2016
1 parent 5101f96 commit 607e011
Show file tree
Hide file tree
Showing 8 changed files with 651 additions and 0 deletions.
72 changes: 72 additions & 0 deletions lib/components/Tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function syncNodeAttributes(node, props) {
if (props.selected) {
node.setAttribute('tabindex', 0);
node.setAttribute('selected', 'selected');
if (props.focus) {
node.focus();
}
} else {
node.removeAttribute('tabindex');
node.removeAttribute('selected');
}
}

module.exports = _react2.default.createClass({
displayName: 'Tab',

propTypes: {
className: _react.PropTypes.string,
id: _react.PropTypes.string,
selected: _react.PropTypes.bool,
disabled: _react.PropTypes.bool,
panelId: _react.PropTypes.string,
children: _react.PropTypes.oneOfType([_react.PropTypes.array, _react.PropTypes.object, _react.PropTypes.string])
},

getDefaultProps: function getDefaultProps() {
return {
focus: false,
selected: false,
id: null,
panelId: null
};
},
componentDidMount: function componentDidMount() {
syncNodeAttributes((0, _reactDom.findDOMNode)(this), this.props);
},
componentDidUpdate: function componentDidUpdate() {
syncNodeAttributes((0, _reactDom.findDOMNode)(this), this.props);
},
render: function render() {
return _react2.default.createElement(
'li',
{
className: (0, _classnames2.default)('ReactTabs__Tab', this.props.className, {
'ReactTabs__Tab--selected': this.props.selected,
'ReactTabs__Tab--disabled': this.props.disabled
}),
role: 'tab',
id: this.props.id,
'aria-selected': this.props.selected ? 'true' : 'false',
'aria-expanded': this.props.selected ? 'true' : 'false',
'aria-disabled': this.props.disabled ? 'true' : 'false',
'aria-controls': this.props.panelId
},
this.props.children
);
}
});
31 changes: 31 additions & 0 deletions lib/components/TabList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = _react2.default.createClass({
displayName: 'TabList',

propTypes: {
className: _react.PropTypes.string,
children: _react.PropTypes.oneOfType([_react.PropTypes.object, _react.PropTypes.array])
},

render: function render() {
return _react2.default.createElement(
'ul',
{
className: (0, _classnames2.default)('ReactTabs__TabList', this.props.className),
role: 'tablist'
},
this.props.children
);
}
});
52 changes: 52 additions & 0 deletions lib/components/TabPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = _react2.default.createClass({
displayName: 'TabPanel',

propTypes: {
className: _react.PropTypes.string,
selected: _react.PropTypes.bool,
id: _react.PropTypes.string,
tabId: _react.PropTypes.string,
children: _react.PropTypes.oneOfType([_react.PropTypes.array, _react.PropTypes.object, _react.PropTypes.string])
},

contextTypes: {
forceRenderTabPanel: _react.PropTypes.bool
},

getDefaultProps: function getDefaultProps() {
return {
selected: false,
id: null,
tabId: null
};
},
render: function render() {
var children = this.context.forceRenderTabPanel || this.props.selected ? this.props.children : null;

return _react2.default.createElement(
'div',
{
className: (0, _classnames2.default)('ReactTabs__TabPanel', this.props.className, {
'ReactTabs__TabPanel--selected': this.props.selected
}),
role: 'tabpanel',
id: this.props.id,
'aria-labelledby': this.props.tabId,
style: { display: this.props.selected ? null : 'none' }
},
children
);
}
});
Loading

0 comments on commit 607e011

Please sign in to comment.