Timeline.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use client";
  2. var __rest = this && this.__rest || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  6. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  7. }
  8. return t;
  9. };
  10. import * as React from 'react';
  11. import classNames from 'classnames';
  12. import { devUseWarning } from '../_util/warning';
  13. import { ConfigContext } from '../config-provider';
  14. import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
  15. // CSSINJS
  16. import useStyle from './style';
  17. import TimelineItem from './TimelineItem';
  18. import TimelineItemList from './TimelineItemList';
  19. import useItems from './useItems';
  20. const Timeline = props => {
  21. const {
  22. getPrefixCls,
  23. direction,
  24. timeline
  25. } = React.useContext(ConfigContext);
  26. const {
  27. prefixCls: customizePrefixCls,
  28. children,
  29. items,
  30. className,
  31. style
  32. } = props,
  33. restProps = __rest(props, ["prefixCls", "children", "items", "className", "style"]);
  34. const prefixCls = getPrefixCls('timeline', customizePrefixCls);
  35. // =================== Warning =====================
  36. if (process.env.NODE_ENV !== 'production') {
  37. const warning = devUseWarning('Timeline');
  38. warning.deprecated(!children, 'Timeline.Item', 'items');
  39. }
  40. // Style
  41. const rootCls = useCSSVarCls(prefixCls);
  42. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
  43. const mergedItems = useItems(items, children);
  44. return wrapCSSVar(/*#__PURE__*/React.createElement(TimelineItemList, Object.assign({}, restProps, {
  45. className: classNames(timeline === null || timeline === void 0 ? void 0 : timeline.className, className, cssVarCls, rootCls),
  46. style: Object.assign(Object.assign({}, timeline === null || timeline === void 0 ? void 0 : timeline.style), style),
  47. prefixCls: prefixCls,
  48. direction: direction,
  49. items: mergedItems,
  50. hashId: hashId
  51. })));
  52. };
  53. Timeline.Item = TimelineItem;
  54. if (process.env.NODE_ENV !== 'production') {
  55. Timeline.displayName = 'Timeline';
  56. }
  57. export default Timeline;