index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 React from 'react';
  11. import classNames from 'classnames';
  12. import omit from "rc-util/es/omit";
  13. import { isPresetSize } from '../_util/gapSize';
  14. import { ConfigContext } from '../config-provider';
  15. import useStyle from './style';
  16. import createFlexClassNames from './utils';
  17. const Flex = /*#__PURE__*/React.forwardRef((props, ref) => {
  18. const {
  19. prefixCls: customizePrefixCls,
  20. rootClassName,
  21. className,
  22. style,
  23. flex,
  24. gap,
  25. vertical = false,
  26. component: Component = 'div'
  27. } = props,
  28. othersProps = __rest(props, ["prefixCls", "rootClassName", "className", "style", "flex", "gap", "vertical", "component"]);
  29. const {
  30. flex: ctxFlex,
  31. direction: ctxDirection,
  32. getPrefixCls
  33. } = React.useContext(ConfigContext);
  34. const prefixCls = getPrefixCls('flex', customizePrefixCls);
  35. const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
  36. const mergedVertical = vertical !== null && vertical !== void 0 ? vertical : ctxFlex === null || ctxFlex === void 0 ? void 0 : ctxFlex.vertical;
  37. const mergedCls = classNames(className, rootClassName, ctxFlex === null || ctxFlex === void 0 ? void 0 : ctxFlex.className, prefixCls, hashId, cssVarCls, createFlexClassNames(prefixCls, props), {
  38. [`${prefixCls}-rtl`]: ctxDirection === 'rtl',
  39. [`${prefixCls}-gap-${gap}`]: isPresetSize(gap),
  40. [`${prefixCls}-vertical`]: mergedVertical
  41. });
  42. const mergedStyle = Object.assign(Object.assign({}, ctxFlex === null || ctxFlex === void 0 ? void 0 : ctxFlex.style), style);
  43. if (flex) {
  44. mergedStyle.flex = flex;
  45. }
  46. if (gap && !isPresetSize(gap)) {
  47. mergedStyle.gap = gap;
  48. }
  49. return wrapCSSVar(/*#__PURE__*/React.createElement(Component, Object.assign({
  50. ref: ref,
  51. className: mergedCls,
  52. style: mergedStyle
  53. }, omit(othersProps, ['justify', 'wrap', 'align']))));
  54. });
  55. if (process.env.NODE_ENV !== 'production') {
  56. Flex.displayName = 'Flex';
  57. }
  58. export default Flex;