1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | var _excluded = ["prefixCls", "invalidate", "item", "renderItem", "responsive", "registerSize", "itemKey", "className", "style", "children", "display", "order", "component"];
|
5 | import * as React from 'react';
|
6 | import classNames from 'classnames';
|
7 | import ResizeObserver from 'rc-resize-observer';
|
8 |
|
9 | var UNDEFINED = undefined;
|
10 |
|
11 | function 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;
|
29 |
|
30 | function internalRegisterSize(width) {
|
31 | registerSize(itemKey, width);
|
32 | }
|
33 |
|
34 | React.useEffect(function () {
|
35 | return function () {
|
36 | internalRegisterSize(null);
|
37 | };
|
38 | }, []);
|
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 = 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 = 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 |
|
79 | var Item = React.forwardRef(InternalItem);
|
80 | Item.displayName = 'Item';
|
81 | export default Item; |
\ | No newline at end of file |