useAction.js 897 B

1234567891011121314151617181920212223
  1. import * as React from 'react';
  2. function toArray(val) {
  3. return val ? Array.isArray(val) ? val : [val] : [];
  4. }
  5. export default function useAction(mobile, action, showAction, hideAction) {
  6. return React.useMemo(function () {
  7. var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
  8. var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
  9. var showActionSet = new Set(mergedShowAction);
  10. var hideActionSet = new Set(mergedHideAction);
  11. if (mobile) {
  12. if (showActionSet.has('hover')) {
  13. showActionSet.delete('hover');
  14. showActionSet.add('click');
  15. }
  16. if (hideActionSet.has('hover')) {
  17. hideActionSet.delete('hover');
  18. hideActionSet.add('click');
  19. }
  20. }
  21. return [showActionSet, hideActionSet];
  22. }, [mobile, action, showAction, hideAction]);
  23. }