useAction.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = useAction;
  7. var React = _interopRequireWildcard(require("react"));
  8. function toArray(val) {
  9. return val ? Array.isArray(val) ? val : [val] : [];
  10. }
  11. function useAction(mobile, action, showAction, hideAction) {
  12. return React.useMemo(function () {
  13. var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
  14. var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
  15. var showActionSet = new Set(mergedShowAction);
  16. var hideActionSet = new Set(mergedHideAction);
  17. if (mobile) {
  18. if (showActionSet.has('hover')) {
  19. showActionSet.delete('hover');
  20. showActionSet.add('click');
  21. }
  22. if (hideActionSet.has('hover')) {
  23. hideActionSet.delete('hover');
  24. hideActionSet.add('click');
  25. }
  26. }
  27. return [showActionSet, hideActionSet];
  28. }, [mobile, action, showAction, hideAction]);
  29. }