tabler-react-2 0.1.99 → 0.1.100

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.
@@ -107,42 +107,51 @@ var DangerConfirm = function DangerConfirm(_ref3) {
107
107
  }
108
108
  }, commitText))))));
109
109
  };
110
- var useConfirm = exports.useConfirm = function useConfirm(options) {
111
- var title = options === null || options === void 0 ? void 0 : options.title;
112
- var text = options === null || options === void 0 ? void 0 : options.text;
113
- var commitText = options === null || options === void 0 ? void 0 : options.commitText;
114
- var cancelText = options === null || options === void 0 ? void 0 : options.cancelText;
110
+ var useConfirm = exports.useConfirm = function useConfirm() {
111
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
115
112
  var _useState = (0, _react.useState)({
116
113
  open: false,
117
- resolve: null
114
+ resolve: null,
115
+ title: options.title,
116
+ text: options.text,
117
+ commitText: options.commitText,
118
+ cancelText: options.cancelText
118
119
  }),
119
120
  _useState2 = _slicedToArray(_useState, 2),
120
121
  confirmState = _useState2[0],
121
122
  setConfirmState = _useState2[1];
122
- var confirm = (0, _react.useCallback)(function (message) {
123
+ var confirm = (0, _react.useCallback)(function () {
124
+ var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
123
125
  return new Promise(function (resolve) {
126
+ var _newOptions$title, _newOptions$text, _newOptions$commitTex, _newOptions$cancelTex;
124
127
  setConfirmState({
125
128
  open: true,
126
- resolve: resolve
129
+ resolve: resolve,
130
+ title: (_newOptions$title = newOptions.title) !== null && _newOptions$title !== void 0 ? _newOptions$title : options.title,
131
+ text: (_newOptions$text = newOptions.text) !== null && _newOptions$text !== void 0 ? _newOptions$text : options.text,
132
+ commitText: (_newOptions$commitTex = newOptions.commitText) !== null && _newOptions$commitTex !== void 0 ? _newOptions$commitTex : options.commitText,
133
+ cancelText: (_newOptions$cancelTex = newOptions.cancelText) !== null && _newOptions$cancelTex !== void 0 ? _newOptions$cancelTex : options.cancelText
127
134
  });
128
135
  });
129
- }, []);
130
- var handleDecision = function handleDecision(decision) {
136
+ }, [options]);
137
+ var handleDecision = (0, _react.useCallback)(function (decision) {
131
138
  if (confirmState.resolve) {
132
139
  confirmState.resolve(decision);
133
- setConfirmState(_objectSpread(_objectSpread({}, confirmState), {}, {
134
- open: false,
135
- resolve: null
136
- }));
140
+ setConfirmState(function (prev) {
141
+ return _objectSpread(_objectSpread({}, prev), {}, {
142
+ open: false,
143
+ resolve: null
144
+ });
145
+ });
137
146
  }
138
- };
147
+ }, [confirmState]);
139
148
  var ConfirmModal = /*#__PURE__*/_react["default"].createElement(DangerConfirm, {
140
149
  open: confirmState.open,
141
150
  onDecision: handleDecision,
142
- title: title || "Are you sure?",
143
- text: text || "This action cannot be undone.",
144
- commitText: commitText || "Confirm",
145
- cancelText: cancelText || "Cancel"
151
+ title: confirmState.title || "Are you sure?",
152
+ text: confirmState.text || "This action cannot be undone.",
153
+ commitText: confirmState.commitText || "Confirm",
154
+ cancelText: confirmState.cancelText || "Cancel"
146
155
  });
147
156
  return {
148
157
  confirm: confirm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tabler-react-2",
3
- "version": "0.1.99",
3
+ "version": "0.1.100",
4
4
  "description": "A react implementation of Tabler ui",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {