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