ywana-core8 0.0.901 → 0.0.902

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.
package/dist/index.cjs CHANGED
@@ -442,40 +442,45 @@ var Button = function Button(_ref) {
442
442
  action: click
443
443
  }) : null, /*#__PURE__*/React__default["default"].createElement(Text, null, label));
444
444
  };
445
+
446
+ /**
447
+ * Action Button
448
+ */
445
449
  var ActionButton = function ActionButton(props) {
446
- var icon = props.icon,
447
- _props$state = props.state,
448
- state = _props$state === void 0 ? "normal" : _props$state,
449
- action = props.action,
450
+ var execute = function execute() {
451
+ try {
452
+ var _temp = function () {
453
+ if (states[_state]) {
454
+ return Promise.resolve(states[_state].action()).then(function (newState) {
455
+ if (newState) setState(newState);
456
+ });
457
+ }
458
+ }();
459
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
460
+ } catch (e) {
461
+ return Promise.reject(e);
462
+ }
463
+ };
464
+ var states = props.states,
465
+ state = props.state,
450
466
  className = props.className;
451
- var _useState = React.useState("normal"),
467
+ var _useState = React.useState(),
452
468
  _state = _useState[0],
453
469
  setState = _useState[1];
454
470
  React.useEffect(function () {
455
471
  setState(state);
456
472
  }, [state]);
457
- function activate() {
458
- setState("running");
459
- if (action) action();
460
- }
461
- var actionIcon = icon;
462
- switch (_state) {
463
- case "normal":
464
- actionIcon = icon;
465
- break;
466
- case "running":
467
- actionIcon = "rotate_right";
468
- break;
469
- case "success":
470
- actionIcon = "task_alt";
471
- break;
472
- case "error":
473
- actionIcon = "error";
474
- break;
475
- }
473
+ React.useEffect(function () {
474
+ if (states[_state] && states[_state].autoexec) execute();
475
+ }, [_state]);
476
+ if (!_state) return null;
477
+ var _states$_state = states[_state],
478
+ icon = _states$_state.icon,
479
+ label = _states$_state.label;
476
480
  return /*#__PURE__*/React__default["default"].createElement(Button, _extends({}, props, {
477
- icon: actionIcon,
478
- action: activate,
481
+ icon: icon,
482
+ label: label,
483
+ action: execute,
479
484
  className: className + " action-btn " + _state
480
485
  }));
481
486
  };