useLegacyItems.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var __rest = this && this.__rest || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  4. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  5. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  6. }
  7. return t;
  8. };
  9. import * as React from 'react';
  10. import toArray from "rc-util/es/Children/toArray";
  11. import { devUseWarning } from '../../_util/warning';
  12. function filter(items) {
  13. return items.filter(item => item);
  14. }
  15. function useLegacyItems(items, children) {
  16. if (process.env.NODE_ENV !== 'production') {
  17. const warning = devUseWarning('Tabs');
  18. warning.deprecated(!children, 'Tabs.TabPane', 'items');
  19. }
  20. if (items) {
  21. return items.map(item => {
  22. var _a;
  23. const mergedDestroyOnHidden = (_a = item.destroyOnHidden) !== null && _a !== void 0 ? _a : item.destroyInactiveTabPane;
  24. return Object.assign(Object.assign({}, item), {
  25. // TODO: In the future, destroyInactiveTabPane in rc-tabs needs to be upgrade to destroyOnHidden
  26. destroyInactiveTabPane: mergedDestroyOnHidden
  27. });
  28. });
  29. }
  30. const childrenItems = toArray(children).map(node => {
  31. if (/*#__PURE__*/React.isValidElement(node)) {
  32. const {
  33. key,
  34. props
  35. } = node;
  36. const _a = props || {},
  37. {
  38. tab
  39. } = _a,
  40. restProps = __rest(_a, ["tab"]);
  41. const item = Object.assign(Object.assign({
  42. key: String(key)
  43. }, restProps), {
  44. label: tab
  45. });
  46. return item;
  47. }
  48. return null;
  49. });
  50. return filter(childrenItems);
  51. }
  52. export default useLegacyItems;