UNPKG

@appbuckets/react-ui

Version:
70 lines (63 loc) 1.6 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var React = require('react'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty( n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; }, } ); } }); } n['default'] = e; return Object.freeze(n); } var React__namespace = /*#__PURE__*/ _interopNamespace(React); /** * Use this hook to get automatically the active index * of a Tab Component. * Additionally function to force change will be returned * * @param initialValue */ function useTabsChange(initialValue) { // ---- // Internal State // ---- var _a = tslib.__read( React__namespace.useState( initialValue !== null && initialValue !== void 0 ? initialValue : 0 ), 2 ), activeIndex = _a[0], setActiveIndex = _a[1]; // ---- // Handler // ---- var handleTabsChange = React__namespace.useCallback(function (e, props) { var _a; /** Set the new ActiveIndex */ setActiveIndex((_a = props.activeIndex) !== null && _a !== void 0 ? _a : 0); }, []); // ---- // Hook Return // ---- return [activeIndex, handleTabsChange, setActiveIndex]; } exports.useTabsChange = useTabsChange;