@ccs-ui/rc-pro 1.1.1-rc15 → 1.1.1-rc17

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.
@@ -12,7 +12,8 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { Drawer } from 'antd';
14
14
  import classNames from 'classnames';
15
- import { forwardRef, useImperativeHandle, useState } from 'react';
15
+ import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
16
+ import { DialogButtonHolder } from "./button";
16
17
  import { DialogContentContext } from "./context";
17
18
  import DialogForm from "./form";
18
19
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -31,6 +32,8 @@ var HookDrawer = function HookDrawer(_ref, ref) {
31
32
  _useState2 = _slicedToArray(_useState, 2),
32
33
  innerConfig = _useState2[0],
33
34
  setInnerConfig = _useState2[1];
35
+ var buttonRef = useRef(null);
36
+ var footerRef = useRef(null);
34
37
  var afterClose = function afterClose() {
35
38
  hookAfterClose();
36
39
  };
@@ -81,6 +84,9 @@ var HookDrawer = function HookDrawer(_ref, ref) {
81
84
  padding: 0
82
85
  };
83
86
  }
87
+ styles.mask = _objectSpread({
88
+ background: 'rgba(0, 0, 0, 0.1)'
89
+ }, styles.mask);
84
90
  return /*#__PURE__*/_jsx(Drawer, _objectSpread(_objectSpread({
85
91
  afterOpenChange: function afterOpenChange(open) {
86
92
  if (!open) afterClose();
@@ -88,9 +94,6 @@ var HookDrawer = function HookDrawer(_ref, ref) {
88
94
  }, innerConfig), {}, {
89
95
  onClose: close,
90
96
  className: classNames('ccs-dialog-drawer', innerConfig.className),
91
- maskStyle: _objectSpread({
92
- background: 'rgba(0, 0, 0, 0.1)'
93
- }, innerConfig.maskStyle),
94
97
  styles: styles,
95
98
  rootStyle: _objectSpread(_objectSpread({}, !isCrInProp ? {
96
99
  position: 'absolute'
@@ -99,10 +102,17 @@ var HookDrawer = function HookDrawer(_ref, ref) {
99
102
  boxShadow: 'none'
100
103
  } : {}), innerConfig.contentWrapperStyle),
101
104
  getContainer: isCrInProp ? innerConfig.getContainer : onGetContainer,
102
- extra: null,
105
+ extra: /*#__PURE__*/_jsx(DialogButtonHolder, {
106
+ ref: buttonRef
107
+ }),
108
+ footer: /*#__PURE__*/_jsx(DialogButtonHolder, {
109
+ ref: footerRef
110
+ }),
103
111
  children: /*#__PURE__*/_jsx(DialogContentContext.Provider, {
104
112
  value: {
113
+ buttonRef: buttonRef,
105
114
  closeDialog: close,
115
+ drawerFooterRef: footerRef,
106
116
  formInitialValues: ((_config$form = config.form) === null || _config$form === void 0 ? void 0 : _config$form.initialValues) || {}
107
117
  },
108
118
  children: config.form ? /*#__PURE__*/_jsx(DialogForm, {
@@ -14,6 +14,7 @@ import { Modal } from 'antd';
14
14
  import classNames from 'classnames';
15
15
  import { forwardRef, useImperativeHandle, useRef, useState } from 'react';
16
16
  import Draggable from 'react-draggable';
17
+ import { DialogButtonHolder } from "./button";
17
18
  import { DialogContentContext } from "./context";
18
19
  import DialogForm from "./form";
19
20
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -81,10 +82,7 @@ var HookModal = function HookModal(_ref2, ref) {
81
82
  _useState4 = _slicedToArray(_useState3, 2),
82
83
  dragState = _useState4[0],
83
84
  setDragState = _useState4[1];
84
- var _useState5 = useState(false),
85
- _useState6 = _slicedToArray(_useState5, 2),
86
- hasButtons = _useState6[0],
87
- setHasButtons = _useState6[1];
85
+ var buttonRef = useRef(null);
88
86
  var afterClose = function afterClose() {
89
87
  var _innerConfig$afterClo;
90
88
  if (config.destroyOnClose !== false) hookAfterClose();
@@ -124,18 +122,15 @@ var HookModal = function HookModal(_ref2, ref) {
124
122
  };
125
123
  });
126
124
  var styles = innerConfig.styles || {};
127
- styles.body = _objectSpread(_objectSpread({
128
- position: 'relative'
129
- }, styles.body), hasButtons ? {
130
- paddingBottom: 44
131
- } : {});
132
125
  return /*#__PURE__*/_jsx(Modal, _objectSpread(_objectSpread({
133
126
  onCancel: close,
134
127
  afterClose: afterClose
135
128
  }, innerConfig), {}, {
136
129
  styles: styles,
137
130
  className: classNames('ccs-dialog-modal', innerConfig.className),
138
- footer: null,
131
+ footer: /*#__PURE__*/_jsx(DialogButtonHolder, {
132
+ ref: buttonRef
133
+ }),
139
134
  title: /*#__PURE__*/_jsx("div", {
140
135
  style: {
141
136
  width: '100%',
@@ -168,10 +163,8 @@ var HookModal = function HookModal(_ref2, ref) {
168
163
  },
169
164
  children: /*#__PURE__*/_jsx(DialogContentContext.Provider, {
170
165
  value: {
166
+ buttonRef: buttonRef,
171
167
  closeDialog: close,
172
- onHasModalButtons: function onHasModalButtons() {
173
- return setHasButtons(true);
174
- },
175
168
  formInitialValues: ((_config$form = config.form) === null || _config$form === void 0 ? void 0 : _config$form.initialValues) || {}
176
169
  },
177
170
  children: config.form ? /*#__PURE__*/_jsx(DialogForm, {
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  interface DialogButtonsProps {
3
3
  okText?: string;
4
4
  cancelText?: string;
@@ -8,5 +8,9 @@ interface DialogButtonsProps {
8
8
  hideCancel?: boolean;
9
9
  onOk?: (values?: any) => void;
10
10
  }
11
- export default function CcsDialogButtons({ okText, okAuth, loading, children, hideCancel, cancelText, onOk, }: DialogButtonsProps): import("react/jsx-runtime").JSX.Element | null;
11
+ export type DialogButtonRef = {
12
+ onSetButtons: (e: React.ReactElement) => void;
13
+ };
14
+ export declare const DialogButtonHolder: React.MemoExoticComponent<React.ForwardRefExoticComponent<React.RefAttributes<DialogButtonRef>>>;
15
+ export default function CcsDialogButtons({ okText, okAuth, loading, children, hideCancel, cancelText, onOk, }: DialogButtonsProps): null;
12
16
  export {};
@@ -4,13 +4,35 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
13
  import { CcsAuth } from "./..";
8
14
  import { Button, Form } from 'antd';
9
- import { useEffect } from 'react';
15
+ import React, { useEffect, useImperativeHandle, useState } from 'react';
10
16
  import CcsDialog from '.';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
17
  import { Fragment as _Fragment } from "react/jsx-runtime";
18
+ import { jsx as _jsx } from "react/jsx-runtime";
13
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
20
+ export var DialogButtonHolder = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function (_props, ref) {
21
+ var _useState = useState(),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ buttons = _useState2[0],
24
+ setButtons = _useState2[1];
25
+ useImperativeHandle(ref, function () {
26
+ return {
27
+ onSetButtons: function onSetButtons(e) {
28
+ return setButtons(e);
29
+ }
30
+ };
31
+ });
32
+ return /*#__PURE__*/_jsx(_Fragment, {
33
+ children: buttons
34
+ });
35
+ }));
14
36
  export default function CcsDialogButtons(_ref) {
15
37
  var okText = _ref.okText,
16
38
  okAuth = _ref.okAuth,
@@ -21,12 +43,9 @@ export default function CcsDialogButtons(_ref) {
21
43
  onOk = _ref.onOk;
22
44
  var _CcsDialog$useInstanc = CcsDialog.useInstance(),
23
45
  closeDialog = _CcsDialog$useInstanc.closeDialog,
24
- onHasModalButtons = _CcsDialog$useInstanc.onHasModalButtons,
46
+ buttonRef = _CcsDialog$useInstanc.buttonRef,
25
47
  formInitialValues = _CcsDialog$useInstanc.formInitialValues;
26
48
  var form = Form.useFormInstance();
27
- useEffect(function () {
28
- if (onHasModalButtons) onHasModalButtons();
29
- }, []);
30
49
  var onOkClick = function onOkClick() {
31
50
  if (!onOk) return;
32
51
 
@@ -39,9 +58,10 @@ export default function CcsDialogButtons(_ref) {
39
58
  }
40
59
  onOk();
41
60
  };
42
- return onOk || children ? /*#__PURE__*/_jsx(_Fragment, {
43
- children: /*#__PURE__*/_jsxs("div", {
44
- className: "ccs-dialog-buttons",
61
+ useEffect(function () {
62
+ var _buttonRef$current;
63
+ if (!onOk && !children) return;
64
+ var btns = /*#__PURE__*/_jsxs(_Fragment, {
45
65
  children: [children, onOk && /*#__PURE__*/_jsxs(_Fragment, {
46
66
  children: [!hideCancel && /*#__PURE__*/_jsx(Button, {
47
67
  onClick: closeDialog,
@@ -54,6 +74,8 @@ export default function CcsDialogButtons(_ref) {
54
74
  children: okText || '确定'
55
75
  })]
56
76
  })]
57
- })
58
- }) : null;
77
+ });
78
+ (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.onSetButtons(btns);
79
+ });
80
+ return null;
59
81
  }
@@ -1,11 +1,15 @@
1
1
  import { Store } from 'antd/es/form/interface';
2
- import React from 'react';
2
+ import React, { RefObject } from 'react';
3
+ import { DialogButtonRef } from './button';
3
4
  export interface DialogContextType<T = Store> {
4
5
  /** 表单初始值 */
5
6
  formInitialValues: T;
7
+ /** 按钮 ref */
8
+ buttonRef: RefObject<DialogButtonRef>;
9
+ /** drawer footer ref */
10
+ drawerFooterRef?: RefObject<DialogButtonRef>;
6
11
  /** 关闭弹框,可以设置返回值 */
7
12
  closeDialog: (e?: any) => void;
8
- onHasModalButtons?: () => void;
9
13
  }
10
14
  declare const DialogContentContext: React.Context<DialogContextType<any>>;
11
15
  declare const useDialogContext: <T = Store>() => DialogContextType<T>;
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ interface DialogButtonsProps {
3
+ okText?: string;
4
+ cancelText?: string;
5
+ okAuth?: string;
6
+ loading?: boolean;
7
+ children?: ReactNode;
8
+ hideCancel?: boolean;
9
+ onOk?: (values?: any) => void;
10
+ }
11
+ export default function CcsDrawerFooter({ okText, okAuth, loading, children, hideCancel, cancelText, onOk, }: DialogButtonsProps): null;
12
+ export {};
@@ -0,0 +1,59 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import { CcsAuth } from "./..";
8
+ import { Button, Form } from 'antd';
9
+ import { useEffect } from 'react';
10
+ import CcsDialog from '.';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export default function CcsDrawerFooter(_ref) {
15
+ var okText = _ref.okText,
16
+ okAuth = _ref.okAuth,
17
+ loading = _ref.loading,
18
+ children = _ref.children,
19
+ hideCancel = _ref.hideCancel,
20
+ cancelText = _ref.cancelText,
21
+ onOk = _ref.onOk;
22
+ var _CcsDialog$useInstanc = CcsDialog.useInstance(),
23
+ closeDialog = _CcsDialog$useInstanc.closeDialog,
24
+ drawerFooterRef = _CcsDialog$useInstanc.drawerFooterRef,
25
+ formInitialValues = _CcsDialog$useInstanc.formInitialValues;
26
+ var form = Form.useFormInstance();
27
+ var onOkClick = function onOkClick() {
28
+ if (!onOk) return;
29
+
30
+ // form返回表单值和所有初始值
31
+ if (form) {
32
+ form.validateFields().then(function (values) {
33
+ onOk(_objectSpread(_objectSpread({}, formInitialValues), values));
34
+ });
35
+ return;
36
+ }
37
+ onOk();
38
+ };
39
+ useEffect(function () {
40
+ var _drawerFooterRef$curr;
41
+ if (!onOk && !children) return;
42
+ var btns = /*#__PURE__*/_jsxs(_Fragment, {
43
+ children: [children, onOk && /*#__PURE__*/_jsxs(_Fragment, {
44
+ children: [!hideCancel && /*#__PURE__*/_jsx(Button, {
45
+ onClick: closeDialog,
46
+ children: cancelText || '取消'
47
+ }), /*#__PURE__*/_jsx(CcsAuth.Button, {
48
+ auth: okAuth || '',
49
+ type: "primary",
50
+ loading: loading,
51
+ onClick: onOkClick,
52
+ children: okText || '确定'
53
+ })]
54
+ })]
55
+ });
56
+ drawerFooterRef === null || drawerFooterRef === void 0 ? void 0 : (_drawerFooterRef$curr = drawerFooterRef.current) === null || _drawerFooterRef$curr === void 0 ? void 0 : _drawerFooterRef$curr.onSetButtons(btns);
57
+ });
58
+ return null;
59
+ }
@@ -1,11 +1,17 @@
1
1
  import CcsDialogButtons from './button';
2
2
  import { useDialogContext } from './context';
3
+ import CcsDrawerFooter from './drawer-footer';
3
4
  import useCcsDialog from './hook';
4
5
  import './index.less';
5
6
  interface DialogInterface {
6
- Buttons: typeof CcsDialogButtons;
7
+ /** 获取openModal,openDrawer方法 */
7
8
  useDialog: typeof useCcsDialog;
9
+ /** dialog 实例 */
8
10
  useInstance: typeof useDialogContext;
11
+ /** dialog 按钮 */
12
+ Buttons: typeof CcsDialogButtons;
13
+ /** drawer footer */
14
+ DrawerFooter: typeof CcsDrawerFooter;
9
15
  }
10
16
  declare const CcsDialog: DialogInterface;
11
17
  export default CcsDialog;
@@ -1,9 +1,11 @@
1
1
  import CcsDialogButtons from "./button";
2
2
  import { useDialogContext } from "./context";
3
+ import CcsDrawerFooter from "./drawer-footer";
3
4
  import useCcsDialog from "./hook";
4
5
  import "./index.less";
5
6
  var CcsDialog = {};
6
7
  CcsDialog.Buttons = CcsDialogButtons;
7
8
  CcsDialog.useDialog = useCcsDialog;
8
9
  CcsDialog.useInstance = useDialogContext;
10
+ CcsDialog.DrawerFooter = CcsDrawerFooter;
9
11
  export default CcsDialog;
@@ -1,25 +1,10 @@
1
- .ccs-dialog-buttons {
2
- position: absolute;
3
- bottom: 0;
4
- right: 0;
5
- z-index: 1;
6
-
1
+ .ant-drawer-extra {
7
2
  .ant-btn + .ant-btn:not(.ant-dropdown-trigger) {
8
3
  margin-bottom: 0;
9
- margin-left: 8px;
4
+ margin-inline-start: 8px;
10
5
  }
11
6
  }
12
7
 
13
- .ccs-dialog-drawer {
14
- .ccs-dialog-buttons {
15
- right: 16px;
16
- top: 0;
17
- bottom: auto;
18
- height: 57px;
19
- line-height: 56px;
20
- }
21
-
22
- .ant-drawer-header {
23
- padding: 16px;
24
- }
8
+ .ant-drawer-footer {
9
+ overflow: hidden;
25
10
  }
@@ -52,11 +52,6 @@
52
52
  padding: 0;
53
53
  }
54
54
 
55
- .ant-form-inline {
56
- .ant-form-item:last-child {
57
- margin-inline-end: 0;
58
- }
59
- }
60
55
  label {
61
56
  white-space: nowrap;
62
57
  }
@@ -74,6 +69,10 @@
74
69
  align-items: flex-end;
75
70
  justify-content: end;
76
71
  overflow: hidden;
72
+
73
+ .ant-form-item:last-child {
74
+ margin-inline-end: 0;
75
+ }
77
76
  }
78
77
  }
79
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "1.1.1-rc15",
3
+ "version": "1.1.1-rc17",
4
4
  "description": "A react pro components",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",
package/es/drawer.zip DELETED
Binary file
package/es/modal.zip DELETED
Binary file