react-side-sheet-pro 0.1.5 → 0.1.6
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.
|
@@ -74,53 +74,66 @@ var SideSheetProvider = exports.SideSheetProvider = function SideSheetProvider(_
|
|
|
74
74
|
var close = (0, _react.useCallback)(/*#__PURE__*/function () {
|
|
75
75
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
|
|
76
76
|
var _itemsToClose;
|
|
77
|
-
var
|
|
77
|
+
var force,
|
|
78
|
+
itemsToClose,
|
|
79
|
+
_iterator,
|
|
80
|
+
_step,
|
|
81
|
+
_item$options$onClose,
|
|
82
|
+
_item$options,
|
|
83
|
+
item,
|
|
84
|
+
_item$options$confirm,
|
|
85
|
+
_item$options$confirm2,
|
|
86
|
+
confirmCallback,
|
|
87
|
+
confirmed,
|
|
88
|
+
duration,
|
|
89
|
+
_args = arguments;
|
|
78
90
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
79
91
|
while (1) switch (_context.prev = _context.next) {
|
|
80
92
|
case 0:
|
|
93
|
+
force = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
|
|
81
94
|
itemsToClose = id === null ? _toConsumableArray(stackRef.current) : stackRef.current.filter(function (i) {
|
|
82
95
|
return i.id === id;
|
|
83
96
|
});
|
|
84
97
|
_iterator = _createForOfIteratorHelper(itemsToClose);
|
|
85
|
-
_context.prev =
|
|
98
|
+
_context.prev = 3;
|
|
86
99
|
_iterator.s();
|
|
87
|
-
case
|
|
100
|
+
case 5:
|
|
88
101
|
if ((_step = _iterator.n()).done) {
|
|
89
|
-
_context.next =
|
|
102
|
+
_context.next = 17;
|
|
90
103
|
break;
|
|
91
104
|
}
|
|
92
105
|
item = _step.value;
|
|
93
|
-
if (!item.options.confirmBeforeClose) {
|
|
94
|
-
_context.next =
|
|
106
|
+
if (!(!force && item.options.confirmBeforeClose)) {
|
|
107
|
+
_context.next = 14;
|
|
95
108
|
break;
|
|
96
109
|
}
|
|
97
110
|
confirmCallback = (_item$options$confirm = item.options.confirmCallback) !== null && _item$options$confirm !== void 0 ? _item$options$confirm : config.confirmCallback;
|
|
98
|
-
_context.next =
|
|
111
|
+
_context.next = 11;
|
|
99
112
|
return confirmCallback((_item$options$confirm2 = item.options.confirmMessage) !== null && _item$options$confirm2 !== void 0 ? _item$options$confirm2 : config.confirmMessage);
|
|
100
|
-
case
|
|
113
|
+
case 11:
|
|
101
114
|
confirmed = _context.sent;
|
|
102
115
|
if (confirmed) {
|
|
103
|
-
_context.next =
|
|
116
|
+
_context.next = 14;
|
|
104
117
|
break;
|
|
105
118
|
}
|
|
106
119
|
return _context.abrupt("return");
|
|
107
|
-
case 13:
|
|
108
|
-
(_item$options$onClose = (_item$options = item.options).onClose) === null || _item$options$onClose === void 0 || _item$options$onClose.call(_item$options, item.id);
|
|
109
120
|
case 14:
|
|
110
|
-
|
|
121
|
+
(_item$options$onClose = (_item$options = item.options).onClose) === null || _item$options$onClose === void 0 || _item$options$onClose.call(_item$options, item.id);
|
|
122
|
+
case 15:
|
|
123
|
+
_context.next = 5;
|
|
111
124
|
break;
|
|
112
|
-
case
|
|
113
|
-
_context.next =
|
|
125
|
+
case 17:
|
|
126
|
+
_context.next = 22;
|
|
114
127
|
break;
|
|
115
|
-
case
|
|
116
|
-
_context.prev =
|
|
117
|
-
_context.t0 = _context["catch"](
|
|
128
|
+
case 19:
|
|
129
|
+
_context.prev = 19;
|
|
130
|
+
_context.t0 = _context["catch"](3);
|
|
118
131
|
_iterator.e(_context.t0);
|
|
119
|
-
case
|
|
120
|
-
_context.prev =
|
|
132
|
+
case 22:
|
|
133
|
+
_context.prev = 22;
|
|
121
134
|
_iterator.f();
|
|
122
|
-
return _context.finish(
|
|
123
|
-
case
|
|
135
|
+
return _context.finish(22);
|
|
136
|
+
case 25:
|
|
124
137
|
if (!config.enableOverflow && stackRef.current.length <= itemsToClose.length) {
|
|
125
138
|
document.body.style.overflow = overflowRef.current;
|
|
126
139
|
}
|
|
@@ -144,11 +157,11 @@ var SideSheetProvider = exports.SideSheetProvider = function SideSheetProvider(_
|
|
|
144
157
|
});
|
|
145
158
|
}
|
|
146
159
|
}, duration);
|
|
147
|
-
case
|
|
160
|
+
case 29:
|
|
148
161
|
case "end":
|
|
149
162
|
return _context.stop();
|
|
150
163
|
}
|
|
151
|
-
}, _callee, null, [[
|
|
164
|
+
}, _callee, null, [[3, 19, 22, 25]]);
|
|
152
165
|
}));
|
|
153
166
|
return function (_x) {
|
|
154
167
|
return _ref2.apply(this, arguments);
|
package/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ interface SideOptions {
|
|
|
22
22
|
}
|
|
23
23
|
interface SideElementProps {
|
|
24
24
|
sideId: number;
|
|
25
|
-
close: (id: number | null) => Promise<void>;
|
|
25
|
+
close: (id: number | null, force?: boolean) => Promise<void>;
|
|
26
26
|
open: (element: SideElement, options?: SideOptions) => number;
|
|
27
27
|
update: (id: number, options: SideOptions) => void;
|
|
28
28
|
options: SideOptions;
|
|
@@ -36,7 +36,7 @@ interface SideStackItem {
|
|
|
36
36
|
}
|
|
37
37
|
interface SideSheetContextValue {
|
|
38
38
|
open: (el: SideElement, opts?: SideOptions) => number;
|
|
39
|
-
close: (id: number | null) => Promise<void>;
|
|
39
|
+
close: (id: number | null, force?: boolean) => Promise<void>;
|
|
40
40
|
update: (id: number, opts: SideOptions) => void;
|
|
41
41
|
config: SideSheetOptions;
|
|
42
42
|
}
|
package/package.json
CHANGED
|
@@ -56,14 +56,14 @@ export const SideSheetProvider: React.FC<{
|
|
|
56
56
|
return id;
|
|
57
57
|
}, []);
|
|
58
58
|
|
|
59
|
-
const close = useCallback(async (id: number | null) => {
|
|
59
|
+
const close = useCallback(async (id: number | null, force = false) => {
|
|
60
60
|
const itemsToClose =
|
|
61
61
|
id === null
|
|
62
62
|
? [...stackRef.current]
|
|
63
63
|
: stackRef.current.filter(i => i.id === id);
|
|
64
64
|
|
|
65
65
|
for (const item of itemsToClose) {
|
|
66
|
-
if (item.options.confirmBeforeClose) {
|
|
66
|
+
if (! force && item.options.confirmBeforeClose) {
|
|
67
67
|
const confirmCallback =
|
|
68
68
|
item.options.confirmCallback ?? config.confirmCallback;
|
|
69
69
|
const confirmed = await confirmCallback(
|
package/src/types/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface SideStackItem {
|
|
|
42
42
|
|
|
43
43
|
export interface SideSheetContextValue {
|
|
44
44
|
open: (el: SideElement, opts?: SideOptions) => number;
|
|
45
|
-
close: (id: number | null) => Promise<void>;
|
|
45
|
+
close: (id: number | null, force: boolean) => Promise<void>;
|
|
46
46
|
update: (id: number, opts: SideOptions) => void;
|
|
47
47
|
config: SideSheetOptions;
|
|
48
48
|
}
|