UNPKG

2.77 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4var _excluded = ["prefixCls", "invalidate", "item", "renderItem", "responsive", "registerSize", "itemKey", "className", "style", "children", "display", "order", "component"];
5import * as React from 'react';
6import classNames from 'classnames';
7import ResizeObserver from 'rc-resize-observer'; // Use shared variable to save bundle size
8
9var UNDEFINED = undefined;
10
11function InternalItem(props, ref) {
12 var prefixCls = props.prefixCls,
13 invalidate = props.invalidate,
14 item = props.item,
15 renderItem = props.renderItem,
16 responsive = props.responsive,
17 registerSize = props.registerSize,
18 itemKey = props.itemKey,
19 className = props.className,
20 style = props.style,
21 children = props.children,
22 display = props.display,
23 order = props.order,
24 _props$component = props.component,
25 Component = _props$component === void 0 ? 'div' : _props$component,
26 restProps = _objectWithoutProperties(props, _excluded);
27
28 var mergedHidden = responsive && !display; // ================================ Effect ================================
29
30 function internalRegisterSize(width) {
31 registerSize(itemKey, width);
32 }
33
34 React.useEffect(function () {
35 return function () {
36 internalRegisterSize(null);
37 };
38 }, []); // ================================ Render ================================
39
40 var childNode = renderItem && item !== UNDEFINED ? renderItem(item) : children;
41 var overflowStyle;
42
43 if (!invalidate) {
44 overflowStyle = {
45 opacity: mergedHidden ? 0 : 1,
46 height: mergedHidden ? 0 : UNDEFINED,
47 overflowY: mergedHidden ? 'hidden' : UNDEFINED,
48 order: responsive ? order : UNDEFINED,
49 pointerEvents: mergedHidden ? 'none' : UNDEFINED,
50 position: mergedHidden ? 'absolute' : UNDEFINED
51 };
52 }
53
54 var overflowProps = {};
55
56 if (mergedHidden) {
57 overflowProps['aria-hidden'] = true;
58 }
59
60 var itemNode = /*#__PURE__*/React.createElement(Component, _extends({
61 className: classNames(!invalidate && prefixCls, className),
62 style: _objectSpread(_objectSpread({}, overflowStyle), style)
63 }, overflowProps, restProps, {
64 ref: ref
65 }), childNode);
66
67 if (responsive) {
68 itemNode = /*#__PURE__*/React.createElement(ResizeObserver, {
69 onResize: function onResize(_ref) {
70 var offsetWidth = _ref.offsetWidth;
71 internalRegisterSize(offsetWidth);
72 }
73 }, itemNode);
74 }
75
76 return itemNode;
77}
78
79var Item = /*#__PURE__*/React.forwardRef(InternalItem);
80Item.displayName = 'Item';
81export default Item;
\No newline at end of file