1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 | var __rest = this && this.__rest || function (s, e) {
|
5 | var t = {};
|
6 | for (var p in s) {
|
7 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
8 | }
|
9 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
10 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
11 | }
|
12 | return t;
|
13 | };
|
14 | import classNames from 'classnames';
|
15 | import toArray from "rc-util/es/Children/toArray";
|
16 | import * as React from 'react';
|
17 | import { ConfigContext } from '../config-provider';
|
18 | import useStyle from './style';
|
19 | export var SpaceCompactItemContext = React.createContext(null);
|
20 | export var useCompactItemContext = function useCompactItemContext(prefixCls, direction) {
|
21 | var compactItemContext = React.useContext(SpaceCompactItemContext);
|
22 | var compactItemClassnames = React.useMemo(function () {
|
23 | var _classNames;
|
24 | if (!compactItemContext) return '';
|
25 | var compactDirection = compactItemContext.compactDirection,
|
26 | isFirstItem = compactItemContext.isFirstItem,
|
27 | isLastItem = compactItemContext.isLastItem;
|
28 | var separator = compactDirection === 'vertical' ? '-vertical-' : '-';
|
29 | return classNames((_classNames = {}, _defineProperty(_classNames, prefixCls + "-compact" + separator + "item", true), _defineProperty(_classNames, prefixCls + "-compact" + separator + "first-item", isFirstItem), _defineProperty(_classNames, prefixCls + "-compact" + separator + "last-item", isLastItem), _defineProperty(_classNames, prefixCls + "-compact" + separator + "item-rtl", direction === 'rtl'), _classNames));
|
30 | }, [prefixCls, direction, compactItemContext]);
|
31 | return {
|
32 | compactSize: compactItemContext === null || compactItemContext === void 0 ? void 0 : compactItemContext.compactSize,
|
33 | compactDirection: compactItemContext === null || compactItemContext === void 0 ? void 0 : compactItemContext.compactDirection,
|
34 | compactItemClassnames: compactItemClassnames
|
35 | };
|
36 | };
|
37 | export var NoCompactStyle = function NoCompactStyle(_ref) {
|
38 | var children = _ref.children;
|
39 | return React.createElement(SpaceCompactItemContext.Provider, {
|
40 | value: null
|
41 | }, children);
|
42 | };
|
43 | var CompactItem = function CompactItem(_a) {
|
44 | var children = _a.children,
|
45 | otherProps = __rest(_a, ["children"]);
|
46 | return React.createElement(SpaceCompactItemContext.Provider, {
|
47 | value: otherProps
|
48 | }, children);
|
49 | };
|
50 | var Compact = function Compact(props) {
|
51 | var _classNames2;
|
52 | var _React$useContext = React.useContext(ConfigContext),
|
53 | getPrefixCls = _React$useContext.getPrefixCls,
|
54 | directionConfig = _React$useContext.direction;
|
55 | var _props$size = props.size,
|
56 | size = _props$size === void 0 ? 'middle' : _props$size,
|
57 | direction = props.direction,
|
58 | block = props.block,
|
59 | customizePrefixCls = props.prefixCls,
|
60 | className = props.className,
|
61 | children = props.children,
|
62 | restProps = __rest(props, ["size", "direction", "block", "prefixCls", "className", "children"]);
|
63 | var prefixCls = getPrefixCls('space-compact', customizePrefixCls);
|
64 | var _useStyle = useStyle(prefixCls),
|
65 | _useStyle2 = _slicedToArray(_useStyle, 2),
|
66 | wrapSSR = _useStyle2[0],
|
67 | hashId = _useStyle2[1];
|
68 | var clx = classNames(prefixCls, hashId, (_classNames2 = {}, _defineProperty(_classNames2, prefixCls + "-rtl", directionConfig === 'rtl'), _defineProperty(_classNames2, prefixCls + "-block", block), _defineProperty(_classNames2, prefixCls + "-vertical", direction === 'vertical'), _classNames2), className);
|
69 | var compactItemContext = React.useContext(SpaceCompactItemContext);
|
70 | var childNodes = toArray(children);
|
71 | var nodes = React.useMemo(function () {
|
72 | return childNodes.map(function (child, i) {
|
73 | var key = child && child.key || prefixCls + "-item-" + i;
|
74 | return React.createElement(CompactItem, {
|
75 | key: key,
|
76 | compactSize: size,
|
77 | compactDirection: direction,
|
78 | isFirstItem: i === 0 && (!compactItemContext || (compactItemContext === null || compactItemContext === void 0 ? void 0 : compactItemContext.isFirstItem)),
|
79 | isLastItem: i === childNodes.length - 1 && (!compactItemContext || (compactItemContext === null || compactItemContext === void 0 ? void 0 : compactItemContext.isLastItem))
|
80 | }, child);
|
81 | });
|
82 | }, [size, childNodes, compactItemContext]);
|
83 |
|
84 | if (childNodes.length === 0) {
|
85 | return null;
|
86 | }
|
87 | return wrapSSR( React.createElement("div", _extends({
|
88 | className: clx
|
89 | }, restProps), nodes));
|
90 | };
|
91 | export default Compact; |
\ | No newline at end of file |