@v-c/dialog 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { useGetRefContext } from "../../context.js";
2
2
  import { computed, createVNode, defineComponent, mergeProps, shallowRef } from "vue";
3
- import { classNames, clsx } from "@v-c/util";
3
+ import { classNames, clsx, isVueRenderable } from "@v-c/util";
4
4
  import pickAttrs from "@v-c/util/dist/pickAttrs";
5
5
  import { useLockFocus } from "@v-c/util/dist/Dom/focus";
6
6
  import { useFocusBoundaryProvider } from "@v-c/util/dist/Dom/focusBoundary";
@@ -24,11 +24,13 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
24
24
  const contentStyle = {};
25
25
  if (width !== void 0) contentStyle.width = getStylePxValue(width);
26
26
  if (height !== void 0) contentStyle.height = getStylePxValue(height);
27
- const footerNode = footer ? createVNode("div", {
27
+ const hasFooter = isVueRenderable(footer);
28
+ const hasTitle = isVueRenderable(title);
29
+ const footerNode = hasFooter ? createVNode("div", {
28
30
  "class": classNames(`${prefixCls}-footer`, modalClassNames?.footer),
29
31
  "style": { ...modalStyles?.footer }
30
32
  }, [footer]) : null;
31
- const headerNode = title ? createVNode("div", {
33
+ const headerNode = hasTitle ? createVNode("div", {
32
34
  "class": classNames(`${prefixCls}-header`, modalClassNames?.header),
33
35
  "style": { ...modalStyles?.header }
34
36
  }, [createVNode("div", {
@@ -74,7 +76,7 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
74
76
  return createVNode("div", mergeProps({
75
77
  "key": "dialog-element",
76
78
  "role": "dialog"
77
- }, { "aria-labelledby": title ? ariaId : null }, {
79
+ }, { "aria-labelledby": hasTitle ? ariaId : null }, {
78
80
  "aria-modal": "true",
79
81
  "ref": mergeRefFun,
80
82
  "style": {
@@ -345,6 +347,11 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
345
347
  required: false,
346
348
  default: void 0
347
349
  },
350
+ scrollLock: {
351
+ type: Boolean,
352
+ required: false,
353
+ default: void 0
354
+ },
348
355
  panelRef: {
349
356
  required: false,
350
357
  default: void 0
@@ -306,6 +306,11 @@ var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
306
306
  required: false,
307
307
  default: void 0
308
308
  },
309
+ scrollLock: {
310
+ type: Boolean,
311
+ required: false,
312
+ default: void 0
313
+ },
309
314
  panelRef: {
310
315
  required: false,
311
316
  default: void 0
@@ -65,7 +65,10 @@ var Dialog = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
65
65
  saveLastOutSideActiveElementRef();
66
66
  nextTick(() => {
67
67
  const wrapEl = wrapperRef.value;
68
- if (wrapEl) isFixedPos.value = getComputedStyle(wrapEl).position === "fixed";
68
+ if (wrapEl) {
69
+ const computedStyle = getComputedStyle(wrapEl);
70
+ isFixedPos.value = computedStyle.position === "fixed";
71
+ }
69
72
  });
70
73
  if (!getMotionName(props.prefixCls, props.transitionName, props.animation)) nextTick(() => {
71
74
  onDialogVisibleChanged(true);
@@ -120,7 +123,7 @@ var Dialog = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
120
123
  }), slots)])]);
121
124
  };
122
125
  }, {
123
- props: /* @__PURE__ */ mergeDefaults({
126
+ props: /*@__PURE__*/ mergeDefaults({
124
127
  className: {
125
128
  type: String,
126
129
  required: false,
@@ -353,6 +356,11 @@ var Dialog = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
353
356
  required: false,
354
357
  default: void 0
355
358
  },
359
+ scrollLock: {
360
+ type: Boolean,
361
+ required: false,
362
+ default: void 0
363
+ },
356
364
  panelRef: {
357
365
  required: false,
358
366
  default: void 0
@@ -17,15 +17,16 @@ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
17
17
  if (props.visible) animatedVisible.value = true;
18
18
  }, { immediate: true });
19
19
  return () => {
20
- const { visible, getContainer, forceRender, destroyOnHidden = false, afterClose } = props;
20
+ const { visible, getContainer, forceRender, destroyOnHidden = false, scrollLock = true, afterClose } = props;
21
+ const { scrollLock: _, ...restProps } = props;
21
22
  if (!forceRender && destroyOnHidden && !animatedVisible.value) return null;
22
23
  return createVNode(Portal, {
23
24
  "open": visible || forceRender || animatedVisible.value,
24
25
  "autoDestroy": false,
25
26
  "onEsc": onEsc,
26
27
  "getContainer": getContainer,
27
- "autoLock": visible || animatedVisible.value
28
- }, { default: () => [createVNode(Dialog, mergeProps(props, {
28
+ "autoLock": scrollLock && (visible || animatedVisible.value)
29
+ }, { default: () => [createVNode(Dialog, mergeProps(restProps, {
29
30
  "destroyOnHidden": destroyOnHidden,
30
31
  "afterClose": () => {
31
32
  (props.closable && typeof props.closable === "object" ? props.closable : {}).afterClose?.();
@@ -35,7 +36,7 @@ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
35
36
  }), slots)] });
36
37
  };
37
38
  }, {
38
- props: /* @__PURE__ */ mergeDefaults({
39
+ props: /*@__PURE__*/ mergeDefaults({
39
40
  className: {
40
41
  type: String,
41
42
  required: false,
@@ -268,6 +269,11 @@ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
268
269
  required: false,
269
270
  default: void 0
270
271
  },
272
+ scrollLock: {
273
+ type: Boolean,
274
+ required: false,
275
+ default: void 0
276
+ },
271
277
  panelRef: {
272
278
  required: false,
273
279
  default: void 0
@@ -4,11 +4,11 @@ import { CSSProperties } from 'vue';
4
4
  export type SemanticName = 'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask' | 'close';
5
5
  export type ModalClassNames = Partial<Record<SemanticName, string>>;
6
6
  export type ModalStyles = Partial<Record<SemanticName, CSSProperties>>;
7
- export type ClosableType = {
7
+ export interface ClosableType {
8
8
  closeIcon?: VueNode;
9
9
  disabled?: boolean;
10
10
  afterClose?: () => any;
11
- };
11
+ }
12
12
  export interface IDialogPropTypes {
13
13
  className?: string;
14
14
  keyboard?: boolean;
@@ -53,5 +53,7 @@ export interface IDialogPropTypes {
53
53
  forceRender?: boolean;
54
54
  focusTriggerAfterClose?: boolean;
55
55
  focusTrap?: boolean;
56
+ /** Control whether to lock body scroll when modal opens. Default is true. */
57
+ scrollLock?: boolean;
56
58
  panelRef?: any;
57
59
  }
package/dist/util.js CHANGED
@@ -5,6 +5,7 @@ function getMotionName(prefixCls, transitionName, animationName) {
5
5
  return motionName;
6
6
  }
7
7
  function getScroll(w, top) {
8
+ if (!w) return 0;
8
9
  let ret = w[`page${top ? "Y" : "X"}Offset`];
9
10
  const method = `scroll${top ? "Top" : "Left"}`;
10
11
  if (typeof ret !== "number") {
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@v-c/dialog",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.2.1",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/dialog",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/antdv-next/vue-components.git"
10
+ },
5
11
  "exports": {
6
12
  ".": {
7
13
  "types": "./dist/index.d.ts",
@@ -25,8 +31,8 @@
25
31
  "vue": "^3.0.0"
26
32
  },
27
33
  "dependencies": {
28
- "@v-c/util": "^1.0.19",
29
- "@v-c/portal": "^1.0.8"
34
+ "@v-c/portal": "^1.0.8",
35
+ "@v-c/util": "^1.2.0"
30
36
  },
31
37
  "scripts": {
32
38
  "build": "vite build",