Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import React from 'react';
  4. import requiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
  5. import { useUncontrolled } from 'uncontrollable';
  6. import Nav from './Nav';
  7. import NavLink from './NavLink';
  8. import NavItem from './NavItem';
  9. import TabContainer from './TabContainer';
  10. import TabContent from './TabContent';
  11. import TabPane from './TabPane';
  12. import { forEach, map } from './ElementChildren';
  13. var defaultProps = {
  14. variant: 'tabs',
  15. mountOnEnter: false,
  16. unmountOnExit: false
  17. };
  18. function getDefaultActiveKey(children) {
  19. var defaultActiveKey;
  20. forEach(children, function (child) {
  21. if (defaultActiveKey == null) {
  22. defaultActiveKey = child.props.eventKey;
  23. }
  24. });
  25. return defaultActiveKey;
  26. }
  27. function renderTab(child) {
  28. var _child$props = child.props,
  29. title = _child$props.title,
  30. eventKey = _child$props.eventKey,
  31. disabled = _child$props.disabled,
  32. tabClassName = _child$props.tabClassName,
  33. id = _child$props.id;
  34. if (title == null) {
  35. return null;
  36. }
  37. return /*#__PURE__*/React.createElement(NavItem, {
  38. as: NavLink,
  39. eventKey: eventKey,
  40. disabled: disabled,
  41. id: id,
  42. className: tabClassName
  43. }, title);
  44. }
  45. var Tabs = React.forwardRef(function (props, ref) {
  46. var _useUncontrolled = useUncontrolled(props, {
  47. activeKey: 'onSelect'
  48. }),
  49. id = _useUncontrolled.id,
  50. onSelect = _useUncontrolled.onSelect,
  51. transition = _useUncontrolled.transition,
  52. mountOnEnter = _useUncontrolled.mountOnEnter,
  53. unmountOnExit = _useUncontrolled.unmountOnExit,
  54. children = _useUncontrolled.children,
  55. _useUncontrolled$acti = _useUncontrolled.activeKey,
  56. activeKey = _useUncontrolled$acti === void 0 ? getDefaultActiveKey(children) : _useUncontrolled$acti,
  57. controlledProps = _objectWithoutPropertiesLoose(_useUncontrolled, ["id", "onSelect", "transition", "mountOnEnter", "unmountOnExit", "children", "activeKey"]);
  58. return /*#__PURE__*/React.createElement(TabContainer, {
  59. ref: ref,
  60. id: id,
  61. activeKey: activeKey,
  62. onSelect: onSelect,
  63. transition: transition,
  64. mountOnEnter: mountOnEnter,
  65. unmountOnExit: unmountOnExit
  66. }, /*#__PURE__*/React.createElement(Nav, _extends({}, controlledProps, {
  67. role: "tablist",
  68. as: "nav"
  69. }), map(children, renderTab)), /*#__PURE__*/React.createElement(TabContent, null, map(children, function (child) {
  70. var childProps = _extends({}, child.props);
  71. delete childProps.title;
  72. delete childProps.disabled;
  73. delete childProps.tabClassName;
  74. return /*#__PURE__*/React.createElement(TabPane, childProps);
  75. })));
  76. });
  77. Tabs.defaultProps = defaultProps;
  78. Tabs.displayName = 'Tabs';
  79. export default Tabs;