Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rc-tabs

Package Overview
Dependencies
Maintainers
2
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-tabs - npm Package Compare versions

Comparing version 6.0.2 to 7.0.0

lib/InkTabBar.js

4

HISTORY.md
# History
----
## 7.0.0 / 2016-08-29
- modularize tabBar and tabContent
## 6.0.0 / 2016-08-20

@@ -5,0 +9,0 @@

20

lib/TabPane.js

@@ -25,4 +25,9 @@ 'use strict';

propTypes: {
active: _react.PropTypes.bool
active: _react.PropTypes.bool,
destroyInactiveTabPane: _react.PropTypes.bool,
placeholder: _react.PropTypes.node
},
getDefaultProps: function getDefaultProps() {
return { placeholder: null };
},
render: function render() {

@@ -32,8 +37,9 @@ var _classnames;

var props = this.props;
this._isActived = this._isActived || props.active;
if (!this._isActived) {
return null;
}
var destroyInactiveTabPane = props.destroyInactiveTabPane;
var active = props.active;
this._isActived = this._isActived || active;
var prefixCls = props.rootPrefixCls + '-tabpane';
var cls = (0, _classnames3["default"])((_classnames = {}, (0, _defineProperty3["default"])(_classnames, prefixCls + '-hidden', !props.active), (0, _defineProperty3["default"])(_classnames, prefixCls, 1), _classnames));
var cls = (0, _classnames3["default"])((_classnames = {}, (0, _defineProperty3["default"])(_classnames, prefixCls + '-inactive', !active), (0, _defineProperty3["default"])(_classnames, prefixCls + '-active', active), (0, _defineProperty3["default"])(_classnames, prefixCls, 1), _classnames));
var isRender = destroyInactiveTabPane ? active : this._isActived;
return _react2["default"].createElement(

@@ -46,3 +52,3 @@ 'div',

},
props.children
isRender ? props.children : props.placeholder
);

@@ -49,0 +55,0 @@ }

@@ -23,10 +23,2 @@ 'use strict';

var _Nav = require('./Nav');
var _Nav2 = _interopRequireDefault(_Nav);
var _rcAnimate = require('rc-animate');
var _rcAnimate2 = _interopRequireDefault(_rcAnimate);
var _classnames2 = require('classnames');

@@ -55,13 +47,10 @@

destroyInactiveTabPane: _react.PropTypes.bool,
allowInkBar: _react.PropTypes.bool,
allowScrollBar: _react.PropTypes.bool,
onTabClick: _react.PropTypes.func,
renderTabBar: _react.PropTypes.func.isRequired,
renderTabContent: _react.PropTypes.func.isRequired,
onChange: _react.PropTypes.func,
children: _react.PropTypes.any,
tabBarExtraContent: _react.PropTypes.any,
animation: _react.PropTypes.string,
prefixCls: _react.PropTypes.string,
className: _react.PropTypes.string,
tabPosition: _react.PropTypes.string,
styles: _react.PropTypes.object
tabBarPosition: _react.PropTypes.string,
style: _react.PropTypes.object
},

@@ -73,11 +62,5 @@

destroyInactiveTabPane: false,
allowInkBar: true,
allowScrollBar: true,
tabBarExtraContent: null,
onChange: noop,
tabPosition: 'top',
style: {},
contentStyle: {},
styles: {},
onTabClick: noop
tabBarPosition: 'top',
style: {}
};

@@ -100,30 +83,13 @@ },

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
var newActiveKey = this.state.activeKey;
if ('activeKey' in nextProps) {
newActiveKey = nextProps.activeKey;
if (!newActiveKey) {
this.setState({
activeKey: newActiveKey
});
return;
}
this.setState({
activeKey: nextProps.activeKey
});
}
var found = void 0;
_react2["default"].Children.forEach(nextProps.children, function (child) {
if (child.key === newActiveKey) {
found = true;
}
});
if (found) {
this.setActiveKey(newActiveKey, nextProps);
} else {
this.setActiveKey(getDefaultActiveKey(nextProps), nextProps);
}
},
onTabClick: function onTabClick(key) {
this.setActiveKey(key);
this.props.onTabClick(key);
if (this.state.activeKey !== key) {
this.props.onChange(key);
onTabClick: function onTabClick(activeKey) {
if (this.tabBar.props.onTabClick) {
this.tabBar.props.onTabClick(activeKey);
}
this.setActiveKey(activeKey);
},

@@ -142,2 +108,12 @@ onNavKeyDown: function onNavKeyDown(e) {

},
setActiveKey: function setActiveKey(activeKey) {
if (this.state.activeKey !== activeKey) {
if (!('activeKey' in this.props)) {
this.setState({
activeKey: activeKey
});
}
this.props.onChange(activeKey);
}
},
getNextActiveKey: function getNextActiveKey(next) {

@@ -168,61 +144,2 @@ var activeKey = this.state.activeKey;

},
getTabPanes: function getTabPanes() {
var state = this.state;
var props = this.props;
var activeKey = state.activeKey;
var children = props.children;
var newChildren = [];
_react2["default"].Children.forEach(children, function (child) {
var key = child.key;
var active = activeKey === key;
newChildren.push(_react2["default"].cloneElement(child, {
active: active,
// eventKey: key,
rootPrefixCls: props.prefixCls
}));
});
return newChildren;
},
getIndexPair: function getIndexPair(props, currentActiveKey, activeKey) {
var keys = [];
_react2["default"].Children.forEach(props.children, function (c) {
keys.push(c.key);
});
var currentIndex = keys.indexOf(currentActiveKey);
var nextIndex = keys.indexOf(activeKey);
return {
currentIndex: currentIndex, nextIndex: nextIndex
};
},
setActiveKey: function setActiveKey(activeKey, ps) {
var props = ps || this.props;
var currentActiveKey = this.state.activeKey;
if (currentActiveKey === activeKey || 'activeKey' in props && props === this.props) {
return;
}
if (!currentActiveKey) {
this.setState({
activeKey: activeKey
});
} else {
var _getIndexPair = this.getIndexPair(props, currentActiveKey, activeKey);
var currentIndex = _getIndexPair.currentIndex;
var nextIndex = _getIndexPair.nextIndex;
// removed
if (currentIndex === -1) {
var newPair = this.getIndexPair(this.props, currentActiveKey, activeKey);
currentIndex = newPair.currentIndex;
nextIndex = newPair.nextIndex;
}
var tabMovingDirection = currentIndex > nextIndex ? 'backward' : 'forward';
this.setState({
activeKey: activeKey,
tabMovingDirection: tabMovingDirection
});
}
},
render: function render() {

@@ -232,69 +149,29 @@ var _classnames;

var props = this.props;
var destroyInactiveTabPane = props.destroyInactiveTabPane;
var prefixCls = props.prefixCls;
var tabPosition = props.tabPosition;
var tabBarPosition = props.tabBarPosition;
var className = props.className;
var animation = props.animation;
var styles = props.styles;
var renderTabContent = props.renderTabContent;
var renderTabBar = props.renderTabBar;
var cls = (0, _classnames3["default"])((_classnames = {}, (0, _defineProperty3["default"])(_classnames, prefixCls, 1), (0, _defineProperty3["default"])(_classnames, prefixCls + '-' + tabPosition, 1), (0, _defineProperty3["default"])(_classnames, className, !!className), _classnames));
var tabMovingDirection = this.state.tabMovingDirection;
var tabPanes = this.getTabPanes();
var transitionName = void 0;
transitionName = props.transitionName && props.transitionName[tabMovingDirection || 'backward'];
if (!transitionName && animation) {
transitionName = prefixCls + '-' + animation + '-' + (tabMovingDirection || 'backward');
}
if (destroyInactiveTabPane) {
tabPanes = tabPanes.filter(function (panel) {
return panel.props.active;
});
}
if (transitionName) {
if (destroyInactiveTabPane) {
tabPanes = _react2["default"].createElement(
_rcAnimate2["default"],
{
exclusive: true,
component: 'div',
transitionName: transitionName
},
tabPanes
);
} else {
tabPanes = _react2["default"].createElement(
_rcAnimate2["default"],
{
showProp: 'active',
exclusive: true,
component: 'div',
transitionName: transitionName
},
tabPanes
);
}
}
var contents = [_react2["default"].createElement(_Nav2["default"], {
var cls = (0, _classnames3["default"])((_classnames = {}, (0, _defineProperty3["default"])(_classnames, prefixCls, 1), (0, _defineProperty3["default"])(_classnames, prefixCls + '-' + tabBarPosition, 1), (0, _defineProperty3["default"])(_classnames, className, !!className), _classnames));
this.tabBar = renderTabBar();
var contents = [_react2["default"].cloneElement(this.tabBar, {
prefixCls: prefixCls,
key: 'nav',
allowInkBar: props.allowInkBar,
allowScrollBar: props.allowScrollBar,
key: 'tabBar',
onKeyDown: this.onNavKeyDown,
tabBarExtraContent: props.tabBarExtraContent,
tabPosition: tabPosition,
styles: styles,
tabBarPosition: tabBarPosition,
onTabClick: this.onTabClick,
tabMovingDirection: tabMovingDirection,
panels: props.children,
activeKey: this.state.activeKey
}), _react2["default"].createElement(
'div',
{
className: prefixCls + '-content',
style: props.contentStyle,
key: 'content'
},
tabPanes
)];
if (tabPosition === 'bottom') {
}), _react2["default"].cloneElement(renderTabContent(), {
prefixCls: prefixCls,
tabBarPosition: tabBarPosition,
activeKey: this.state.activeKey,
destroyInactiveTabPane: props.destroyInactiveTabPane,
children: props.children,
onChange: this.setActiveKey,
key: 'tabContent'
})];
if (tabBarPosition === 'bottom') {
contents.reverse();

@@ -301,0 +178,0 @@ }

@@ -6,58 +6,64 @@ 'use strict';

});
exports.getScroll = getScroll;
exports.offset = offset;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
exports.toArray = toArray;
exports.getActiveIndex = getActiveIndex;
exports.getActiveKey = getActiveKey;
exports.getPropertyName = getPropertyName;
exports.getTransformPropertyName = getTransformPropertyName;
function getScroll(w, top) {
var ret = w['page' + (top ? 'Y' : 'X') + 'Offset'];
var method = 'scroll' + (top ? 'Top' : 'Left');
if (typeof ret !== 'number') {
var d = w.document;
// ie6,7,8 standard mode
ret = d.documentElement[method];
if (typeof ret !== 'number') {
// quirks mode
ret = d.body[method];
exports.getTransitionPropertyName = getTransitionPropertyName;
exports.isVertical = isVertical;
exports.getTranslateByIndex = getTranslateByIndex;
exports.assign = assign;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function toArray(children) {
if (Array.isArray(children)) {
return children;
}
var c = [];
_react2["default"].Children.forEach(children, function (child) {
return c.push(child);
});
return c;
}
function getActiveIndex(children, activeKey) {
var c = toArray(children);
for (var i = 0; i < c.length; i++) {
if (c[i].key === activeKey) {
return i;
}
}
return ret;
return -1;
}
function offset(elem) {
var box = void 0;
var x = void 0;
var y = void 0;
var doc = elem.ownerDocument;
var body = doc.body;
var docElem = doc && doc.documentElement;
box = elem.getBoundingClientRect();
x = box.left;
y = box.top;
x -= docElem.clientLeft || body.clientLeft || 0;
y -= docElem.clientTop || body.clientTop || 0;
var w = doc.defaultView || doc.parentWindow;
x += getScroll(w);
y += getScroll(w, true);
return {
left: x, top: y
};
function getActiveKey(children, index) {
var c = toArray(children);
return c[index].key;
}
var transformPropertyName = void 0;
var names = {};
function getTransformPropertyName() {
function getPropertyName(name) {
var _transforms;
if (!window.getComputedStyle) {
return false;
}
if (transformPropertyName !== undefined) {
return transformPropertyName;
if (names[name] !== undefined) {
return names[name];
}
var Name = name.charAt(0).toUpperCase() + name.substring(1);
var el = document.createElement('p');
var has3d = void 0;
var transforms = {
webkitTransform: '-webkit-transform',
OTransform: '-o-transform',
msTransform: '-ms-transform',
MozTransform: '-moz-transform',
transform: 'transform'
};
var transforms = (_transforms = {}, (0, _defineProperty3["default"])(_transforms, 'webkit' + Name, '-webkit-' + name), (0, _defineProperty3["default"])(_transforms, 'ms' + Name, '-ms-' + name), (0, _defineProperty3["default"])(_transforms, 'Moz' + Name, '-moz-' + name), (0, _defineProperty3["default"])(_transforms, '' + name, '-webkit-' + name), _transforms);
var transformPropertyName = '';
// Add it to the body to get the computed style.

@@ -67,7 +73,3 @@ document.body.insertBefore(el, null);

if (el.style[t] !== undefined) {
el.style[t] = 'translate3d(1px,1px,1px)';
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
if (has3d !== undefined && has3d.length > 0 && has3d !== 'none') {
transformPropertyName = t;
}
transformPropertyName = t;
}

@@ -77,2 +79,28 @@ }

return transformPropertyName;
}
function getTransformPropertyName() {
return getPropertyName('transform');
}
function getTransitionPropertyName() {
return getPropertyName('transition');
}
function isVertical(tabBarPosition) {
return tabBarPosition === 'left' || tabBarPosition === 'right';
}
function getTranslateByIndex(index, tabBarPosition) {
var transformName = arguments.length <= 2 || arguments[2] === undefined ? getTransformPropertyName() : arguments[2];
var translate = isVertical(tabBarPosition) ? 'translateY' : 'translateX';
return (0, _defineProperty3["default"])({}, transformName, translate + '(' + -index * 100 + '%) translateZ(0)');
}
function assign(o1, o2) {
for (var i in o2) {
if (o2.hasOwnProperty(i)) {
o1[i] = o2[i];
}
}
}
{
"name": "rc-tabs",
"version": "6.0.2",
"version": "7.0.0",
"description": "tabs ui component for react",

@@ -56,4 +56,4 @@ "keywords": [

"classnames": "2.x",
"rc-animate": "2.x"
"react-hammerjs": "~0.5.0"
}
}
# rc-tabs
---
react tabs component
React Tabs

@@ -26,4 +26,10 @@ [![NPM version][npm-image]][npm-url]

<img src='http://gtms03.alicdn.com/tps/i3/TB1TIJ3HXXXXXcYaXXXR6PQLFXX-816-612.png' width='408'>
<img src='https://zos.alipayobjects.com/rmsportal/JwLASrsOYJuFRIt.png' width='408'>
## Example
http://localhost:8000/examples
online example: http://react-component.github.io/tabs/
## install

@@ -43,4 +49,5 @@

```js
var Tabs = require('rc-tabs');
var TabPane = Tabs.TabPane;
import Tabs, { TabPane } from 'rc-tabs';
import TabContent from 'rc-tabs/lib/TabContent';
import ScrollableInkTabBar from 'rc-tabs/lib/TabContent';

@@ -53,3 +60,8 @@ var callback = function(key){

(
<Tabs defaultActiveKey="2" onChange={callback}>
<Tabs
defaultActiveKey="2"
onChange={callback}
renderTabBar={()=><ScrollableInkTabBar />}
renderTabContent={()=><TabContent />}
>
<TabPane tab='tab 1' key="1">first</TabPane>

@@ -86,3 +98,3 @@ <TabPane tab='tab 2' key="2">second</TabPane>

<tr>
<td>tabPosition</td>
<td>tabBarPosition</td>
<td>String</td>

@@ -93,39 +105,2 @@ <th></th>

<tr>
<td>allowInkBar</td>
<td>Boolean</td>
<th>true</th>
<td>allow ink bar</td>
</tr>
<tr>
<td>allowScrollBar</td>
<td>Boolean</td>
<th>true</th>
<td>allow bar scrollable</td>
</tr>
<tr>
<td>styles</td>
<td>{nav, inkBar, bar}</td>
<th>{}</th>
<td>inline styles</td>
</tr>
<tr>
<td>animation</td>
<td>String</td>
<th></th>
<td>tabPane's animation. current only support slide-horizontal in assets/index.css</td>
</tr>
<tr>
<td>transitionName</td>
<td>Object</td>
<th></th>
<td>specify backward and forward transitionName. such as
```js
{
backward:'rc-tabs-slide-horizontal-backward',
forward:'rc-tabs-slide-horizontal-forward'
}
```
</td>
</tr>
<tr>
<td>defaultActiveKey</td>

@@ -137,18 +112,18 @@ <td>String</td>

<tr>
<td>onChange</td>
<td>Function(key)</td>
<th></th>
<td>called when tabPanel is changed</td>
<td>renderTabBar</td>
<td>():React.Node</td>
<th></th>
<td>How to render tab bar</td>
</tr>
<tr>
<td>onTabClick</td>
<td>Function(key)</td>
<th></th>
<td>called when tab is clicked</td>
<td>renderTabContent</td>
<td>():React.Node</td>
<th></th>
<td>How to render tab content</td>
</tr>
<tr>
<td>tabBarExtraContent</td>
<td>React Node</td>
<td>onChange</td>
<td>(key: string): void</td>
<th></th>
<td>extra content placed one the right of tab bar</td>
<td>called when tabPanel is changed</td>
</tr>

@@ -184,5 +159,11 @@ <tr>

</tr>
<tr>
<td>placeholder</td>
<td>React.Node</td>
<th></th>
<td>lazyrender children</td>
</tr>
<tr>
<td>tab</td>
<td>String</td>
<td>React.Node</td>
<th></th>

@@ -194,3 +175,112 @@ <td>current tab's title corresponding to current tabPane</td>

### lib/TabBar
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">name</th>
<th style="width: 50px;">type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>onTabClick</td>
<td>(key: string): void</td>
<th></th>
<td>callback when tab clicked</td>
</tr>
<tr>
<td>style</td>
<td></td>
<th></th>
<td>bar style</td>
</tr>
<tr>
<td>extraContent</td>
<td>React Node</td>
<th></th>
<td>extra content placed one the right of tab bar</td>
</tr>
</tbody>
</table>
### lib/InkTabBar
tab bar with ink indicator, in addition to tab bar props, extra props:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">name</th>
<th style="width: 50px;">type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>styles</td>
<td>{ inkBar }</td>
<th></th>
<td>can set inkBar style</td>
</tr>
</tbody>
</table>
### lib/ScrollableInkTabBar
scrollable tab bar with ink indicator, same with tab bar/ink bar props.
### lib/TabContent
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">name</th>
<th style="width: 50px;">type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>style</td>
<td>{}</td>
<th></th>
<td>tab content style</td>
</tr>
<tr>
<td>animation</td>
<td>true</td>
<th></th>
<td>whether tabpane change with animation</td>
</tr>
</tbody>
</table>
### lib/SwipeableTabContent
swipeable tab panes, in addition to lib/TabContent props, extra props:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width: 100px;">name</th>
<th style="width: 50px;">type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>hammerOptions</td>
<td>{}</td>
<th></th>
<td>options for react-hammerjs</td>
</tr>
</tbody>
</table>
## Development

@@ -203,8 +293,2 @@

## Example
http://localhost:8000/examples
online example: http://react-component.github.io/tabs/examples/
## Test Case

@@ -211,0 +295,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc