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

react-context-tabs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-context-tabs - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0-alpha

lib/Context.d.ts

4

.vscode/settings.json

@@ -9,3 +9,5 @@ {

"lib/**/*": true
}
},
"eslint.enable": false,
"typescript.tsdk": "node_modules/typescript/lib"
}

@@ -0,1 +1,7 @@

**2.0.0-alpha** - _2018-01-09_
- Use current React context API.
- Convert to TypeScript.
- Always update `PersistentTabPanel` even when invisible.
- Remove prop-types.
**1.2.1** - _2017-10-20_

@@ -2,0 +8,0 @@ - Fix React peer dependency version range.

@@ -1,32 +0,17 @@

'use strict';
exports.__esModule = true;
exports.TabPanel = exports.TabList = exports.Tabs = exports.Tab = exports.PersistentTabPanel = undefined;
var _PersistentTabPanel = require('./PersistentTabPanel');
var _PersistentTabPanel2 = _interopRequireDefault(_PersistentTabPanel);
var _Tab = require('./Tab');
var _Tab2 = _interopRequireDefault(_Tab);
var _Tabs = require('./Tabs');
var _Tabs2 = _interopRequireDefault(_Tabs);
var _TabList = require('./TabList');
var _TabList2 = _interopRequireDefault(_TabList);
var _TabPanel = require('./TabPanel');
var _TabPanel2 = _interopRequireDefault(_TabPanel);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.PersistentTabPanel = _PersistentTabPanel2.default;
exports.Tab = _Tab2.default;
exports.Tabs = _Tabs2.default;
exports.TabList = _TabList2.default;
exports.TabPanel = _TabPanel2.default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ControlledTabs_1 = require("./ControlledTabs");
exports.ControlledTabs = ControlledTabs_1.ControlledTabs;
var PersistentTabPanel_1 = require("./PersistentTabPanel");
exports.PersistentTabPanel = PersistentTabPanel_1.PersistentTabPanel;
var Tab_1 = require("./Tab");
exports.Tab = Tab_1.Tab;
var TabList_1 = require("./TabList");
exports.TabList = TabList_1.TabList;
var TabPanel_1 = require("./TabPanel");
exports.TabPanel = TabPanel_1.TabPanel;
var Tabs_1 = require("./Tabs");
exports.Tabs = Tabs_1.Tabs;
var UncontrolledTabs_1 = require("./UncontrolledTabs");
exports.UncontrolledTabs = UncontrolledTabs_1.UncontrolledTabs;
//# sourceMappingURL=index.js.map

@@ -1,92 +0,40 @@

'use strict';
exports.__esModule = true;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _shallowequal = require('shallowequal');
var _shallowequal2 = _interopRequireDefault(_shallowequal);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var PersistentTabPanel = function (_Component) {
_inherits(PersistentTabPanel, _Component);
function PersistentTabPanel(props, context) {
_classCallCheck(this, PersistentTabPanel);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
_this.state = {
shouldRender: props.tabId === context.selectedTabId,
isSelected: props.tabId === context.selectedTabId
};
return _this;
}
PersistentTabPanel.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
var isSelected = nextContext.selectedTabId === nextProps.tabId;
if (isSelected && !this.state.shouldRender) {
this.setState({ shouldRender: true });
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importStar(require("react"));
const Context_1 = require("./Context");
class PersistentTabPanelImpl extends react_1.PureComponent {
constructor() {
super(...arguments);
this.state = {
shouldRender: this.props.isSelected,
};
}
this.setState({ isSelected: isSelected });
};
PersistentTabPanel.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState, nextContext) {
if (!this.state.isSelected && !nextState.isSelected) {
return false;
componentWillReceiveProps(nextProps) {
if (!this.state.shouldRender && nextProps.isSelected) {
this.setState({ shouldRender: true });
}
}
return !(0, _shallowequal2.default)(this.props, nextProps) || !(0, _shallowequal2.default)(this.context, nextContext);
};
PersistentTabPanel.prototype.render = function render() {
if (!this.state.shouldRender) {
return false;
render() {
if (!this.state.shouldRender) {
return null;
}
const { children, className, isSelected } = this.props;
return (react_1.default.createElement("section", { className: classnames_1.default("TabPanel", className), style: isSelected ? undefined : { display: "none" } }, children));
}
var _props = this.props,
children = _props.children,
className = _props.className;
var isSelected = this.state.isSelected;
return _react2.default.createElement(
'section',
{ className: (0, _classnames2.default)('TabPanel', className),
style: { display: isSelected ? undefined : 'none' }
},
children
);
};
return PersistentTabPanel;
}(_react.Component);
exports.default = PersistentTabPanel;
PersistentTabPanel.propTypes = {
children: _propTypes2.default.node,
tabId: _propTypes2.default.any.isRequired
};
PersistentTabPanel.contextTypes = {
selectedTabId: _propTypes2.default.any
};
}
function PersistentTabPanel({ tabId, children, className }) {
return (react_1.default.createElement(Context_1.Consumer, null, ({ selectedTabId }) => (react_1.default.createElement(PersistentTabPanelImpl, { isSelected: selectedTabId === tabId, className: className }, children))));
}
exports.PersistentTabPanel = PersistentTabPanel;
//# sourceMappingURL=PersistentTabPanel.js.map

@@ -1,94 +0,32 @@

'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Tab = function (_Component) {
_inherits(Tab, _Component);
function Tab(props, context) {
_classCallCheck(this, Tab);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.handleClick = _this.handleClick.bind(_this);
return _this;
}
Tab.prototype.handleClick = function handleClick(event) {
var _context = this.context,
selectedTabId = _context.selectedTabId,
setSelectedTabId = _context.setSelectedTabId;
var _props = this.props,
disabled = _props.disabled,
tabId = _props.tabId;
if (!(selectedTabId === tabId) && !disabled) {
setSelectedTabId(tabId);
}
};
Tab.prototype.render = function render() {
var _props2 = this.props,
children = _props2.children,
className = _props2.className,
disabled = _props2.disabled,
tabId = _props2.tabId,
rest = _objectWithoutProperties(_props2, ['children', 'className', 'disabled', 'tabId']);
var selectedTabId = this.context.selectedTabId;
return _react2.default.createElement(
'li',
_extends({
className: (0, _classnames2.default)('Tab', className, {
isSelected: selectedTabId === tabId,
isDisabled: disabled
}),
onClick: this.handleClick
}, rest),
children
);
};
return Tab;
}(_react.Component);
exports.default = Tab;
Tab.propTypes = {
children: _propTypes2.default.node.isRequired,
className: _propTypes2.default.string,
disabled: _propTypes2.default.bool,
tabId: _propTypes2.default.any.isRequired
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Tab.contextTypes = {
selectedTabId: _propTypes2.default.any,
setSelectedTabId: _propTypes2.default.func.isRequired
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importDefault(require("react"));
const Context_1 = require("./Context");
function Tab(props) {
const { className, disabled, tabId } = props, rest = __rest(props, ["className", "disabled", "tabId"]);
return (react_1.default.createElement(Context_1.Consumer, null, ({ selectedTabId, setSelectedTabId }) => {
const isSelected = selectedTabId === tabId;
const clickHandler = () => {
setSelectedTabId(tabId);
};
return (react_1.default.createElement("li", Object.assign({ className: classnames_1.default("Tab", className, {
isDisabled: disabled,
isSelected
}), onClick: disabled || isSelected ? undefined : clickHandler }, rest)));
}));
}
exports.Tab = Tab;
//# sourceMappingURL=Tab.js.map

@@ -1,40 +0,22 @@

'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = TabList;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importDefault(require("react"));
function TabList(props) {
var children = props.children,
className = props.className,
rest = _objectWithoutProperties(props, ['children', 'className']);
return _react2.default.createElement(
'ul',
_extends({ className: (0, _classnames2.default)('TabList', className) }, rest),
children
);
const { children, className } = props, rest = __rest(props, ["children", "className"]);
return (react_1.default.createElement("ul", Object.assign({ className: classnames_1.default("TabList", className) }, rest), children));
}
TabList.propTypes = {
children: _propTypes2.default.node,
className: _propTypes2.default.string
};
exports.TabList = TabList;
//# sourceMappingURL=TabList.js.map

@@ -1,40 +0,14 @@

'use strict';
exports.__esModule = true;
exports.default = TabPanel;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function TabPanel(_ref, _ref2) {
var children = _ref.children,
className = _ref.className,
tabId = _ref.tabId;
var selectedTabId = _ref2.selectedTabId;
return tabId === selectedTabId && _react2.default.createElement(
'section',
{ className: (0, _classnames2.default)('TabPanel', className) },
children
);
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const classnames_1 = __importDefault(require("classnames"));
const react_1 = __importDefault(require("react"));
const Context_1 = require("./Context");
function TabPanel(props) {
const { children, className, tabId } = props;
return (react_1.default.createElement(Context_1.Consumer, null, ({ selectedTabId }) => tabId !== selectedTabId ? null : (react_1.default.createElement("section", { className: classnames_1.default("TabPanel", className) }, children))));
}
TabPanel.propTypes = {
children: _propTypes2.default.node,
tabId: _propTypes2.default.any.isRequired
};
TabPanel.contextTypes = {
selectedTabId: _propTypes2.default.any
};
exports.TabPanel = TabPanel;
//# sourceMappingURL=TabPanel.js.map

@@ -1,134 +0,18 @@

'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = Tabs;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ControlledTabs = function (_Component) {
_inherits(ControlledTabs, _Component);
function ControlledTabs(props) {
_classCallCheck(this, ControlledTabs);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.setSelectedTabId = _this.setSelectedTabId.bind(_this);
return _this;
}
ControlledTabs.prototype.setSelectedTabId = function setSelectedTabId(tabId) {
var _props = this.props,
onTabChange = _props.onTabChange,
selectedTabId = _props.selectedTabId;
onTabChange(tabId, selectedTabId);
};
ControlledTabs.prototype.getChildContext = function getChildContext() {
return {
selectedTabId: this.props.selectedTabId,
setSelectedTabId: this.setSelectedTabId
};
};
ControlledTabs.prototype.render = function render() {
var _props2 = this.props,
children = _props2.children,
onTabChange = _props2.onTabChange,
selectedTabId = _props2.selectedTabId,
rest = _objectWithoutProperties(_props2, ['children', 'onTabChange', 'selectedTabId']);
return _react2.default.createElement(
'div',
rest,
children
);
};
return ControlledTabs;
}(_react.Component);
ControlledTabs.propTypes = {
children: _propTypes2.default.node,
selectedTabId: _propTypes2.default.any.isRequired,
onTabChange: _propTypes2.default.func.isRequired
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
ControlledTabs.childContextTypes = {
selectedTabId: _propTypes2.default.any,
setSelectedTabId: _propTypes2.default.func.isRequired
};
var UncontrolledTabs = function (_Component2) {
_inherits(UncontrolledTabs, _Component2);
function UncontrolledTabs(props) {
_classCallCheck(this, UncontrolledTabs);
var _this2 = _possibleConstructorReturn(this, _Component2.call(this, props));
_this2.state = { selectedTabId: props.defaultTabId };
_this2.handleTabChange = _this2.handleTabChange.bind(_this2);
return _this2;
}
UncontrolledTabs.prototype.handleTabChange = function handleTabChange(selectedTabId, previousTabId) {
var onTabChange = this.props.onTabChange;
this.setState({ selectedTabId: selectedTabId });
onTabChange && onTabChange(selectedTabId, previousTabId);
};
UncontrolledTabs.prototype.render = function render() {
var _props3 = this.props,
children = _props3.children,
defaultTabId = _props3.defaultTabId,
onTabChange = _props3.onTabChange,
rest = _objectWithoutProperties(_props3, ['children', 'defaultTabId', 'onTabChange']);
return _react2.default.createElement(
ControlledTabs,
_extends({
selectedTabId: this.state.selectedTabId,
onTabChange: this.handleTabChange
}, rest),
children
);
};
return UncontrolledTabs;
}(_react.Component);
UncontrolledTabs.propTypes = {
children: _propTypes2.default.node,
defaultTabId: _propTypes2.default.any.isRequired,
onTabChange: _propTypes2.default.func
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const ControlledTabs_1 = require("./ControlledTabs");
const UncontrolledTabs_1 = require("./UncontrolledTabs");
function isControlled(props) {
return props.selectedTabId !== undefined;
}
function Tabs(props) {
return props.selectedTabId == null ? _react2.default.createElement(UncontrolledTabs, props) : _react2.default.createElement(ControlledTabs, props);
return isControlled(props)
? react_1.default.createElement(ControlledTabs_1.ControlledTabs, Object.assign({}, props))
: react_1.default.createElement(UncontrolledTabs_1.UncontrolledTabs, Object.assign({}, props));
}
Tabs.propTypes = {
selectedTabId: _propTypes2.default.any
};
exports.Tabs = Tabs;
//# sourceMappingURL=Tabs.js.map
{
"name": "react-context-tabs",
"version": "1.2.1",
"version": "2.0.0-alpha",
"description": "Flexible tabs for React",

@@ -8,5 +8,5 @@ "main": "lib/index.js",

"test": "echo \"Error: no test specified\" && exit 1",
"lint": "standard src/**/*.js",
"build": "babel src --out-dir lib && cp -r src/styles lib/styles",
"prepublish": "npm run lint && npm run build"
"build": "tsc",
"lint": "tslint --project tsconfig.json --format stylish",
"prepublishOnly": "npm run lint && npm run build"
},

@@ -33,13 +33,10 @@ "repository": {

"dependencies": {
"classnames": "^2.2.5",
"shallowequal": "^0.2.2"
"classnames": "^2.2.6"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-2": "^6.13.0",
"prop-types": "^15.6.0",
"standard": "^7.1.2"
"@types/classnames": "^2.2.6",
"@types/react": "^16.7.18",
"tslint": "^5.11.0",
"typescript": "^3.2.2"
}
}
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