index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode } from "vue";
  3. var __rest = this && this.__rest || function (s, e) {
  4. var t = {};
  5. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  8. }
  9. return t;
  10. };
  11. import { computed, defineComponent } from 'vue';
  12. import { useConfigContextInject } from '../config-provider/context';
  13. import useConfigInject from '../config-provider/hooks/useConfigInject';
  14. import useStyle from './style';
  15. import { isPresetSize } from '../_util/gapSize';
  16. import omit from '../_util/omit';
  17. import { withInstall } from '../_util/type';
  18. import { flexProps } from './interface';
  19. import createFlexClassNames from './utils';
  20. const AFlex = defineComponent({
  21. name: 'AFlex',
  22. inheritAttrs: false,
  23. props: flexProps(),
  24. setup(props, _ref) {
  25. let {
  26. slots,
  27. attrs
  28. } = _ref;
  29. const {
  30. flex: ctxFlex,
  31. direction: ctxDirection
  32. } = useConfigContextInject();
  33. const {
  34. prefixCls
  35. } = useConfigInject('flex', props);
  36. const [wrapSSR, hashId] = useStyle(prefixCls);
  37. const mergedCls = computed(() => {
  38. var _a;
  39. return [prefixCls.value, hashId.value, createFlexClassNames(prefixCls.value, props), {
  40. [`${prefixCls.value}-rtl`]: ctxDirection.value === 'rtl',
  41. [`${prefixCls.value}-gap-${props.gap}`]: isPresetSize(props.gap),
  42. [`${prefixCls.value}-vertical`]: (_a = props.vertical) !== null && _a !== void 0 ? _a : ctxFlex === null || ctxFlex === void 0 ? void 0 : ctxFlex.value.vertical
  43. }];
  44. });
  45. return () => {
  46. var _a;
  47. const {
  48. flex,
  49. gap,
  50. component: Component = 'div'
  51. } = props,
  52. othersProps = __rest(props, ["flex", "gap", "component"]);
  53. const mergedStyle = {};
  54. if (flex) {
  55. mergedStyle.flex = flex;
  56. }
  57. if (gap && !isPresetSize(gap)) {
  58. mergedStyle.gap = `${gap}px`;
  59. }
  60. return wrapSSR(_createVNode(Component, _objectSpread({
  61. "class": [attrs.class, mergedCls.value],
  62. "style": [attrs.style, mergedStyle]
  63. }, omit(othersProps, ['justify', 'wrap', 'align', 'vertical'])), {
  64. default: () => [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]
  65. }));
  66. };
  67. }
  68. });
  69. export default withInstall(AFlex);