@vitus-labs/elements 0.61.0 → 0.62.0-alpha.2

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.
@@ -896,15 +896,16 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
896
896
  break;
897
897
  }
898
898
  }
899
- const calc = (param) => value(param, rootSize);
899
+ const setValue = (param) => value(param, rootSize);
900
900
  // ADD POSITION STYLES TO CONTENT
901
901
  contentRef.current.style.position = position;
902
- contentRef.current.style.top = calc(overlayPosition.top);
903
- contentRef.current.style.bottom = calc(overlayPosition.bottom);
904
- contentRef.current.style.left = calc(overlayPosition.left);
905
- contentRef.current.style.right = calc(overlayPosition.right);
902
+ contentRef.current.style.top = setValue(overlayPosition.top);
903
+ contentRef.current.style.bottom = setValue(overlayPosition.bottom);
904
+ contentRef.current.style.left = setValue(overlayPosition.left);
905
+ contentRef.current.style.right = setValue(overlayPosition.right);
906
906
  }, [
907
907
  active,
908
+ type,
908
909
  align,
909
910
  alignX,
910
911
  alignY,
@@ -912,9 +913,13 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
912
913
  offsetY,
913
914
  position,
914
915
  rootSize,
915
- type,
916
916
  ]);
917
- const handleVisibilityByEventType = (e) => {
917
+ const handleVisibilityByEventType = useCallback((e) => {
918
+ if (blocked)
919
+ return;
920
+ if (disabled) {
921
+ hideContent();
922
+ }
918
923
  if (!active) {
919
924
  if ((openOn === 'hover' && e.type === 'mousemove') ||
920
925
  (openOn === 'click' && e.type === 'click')) {
@@ -946,10 +951,22 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
946
951
  }
947
952
  }
948
953
  }
949
- };
950
- const handleContentPosition = throttle(calculateContentPosition, throttleDelay);
951
- const handleClick = handleVisibilityByEventType;
952
- const handleVisibility = throttle(handleVisibilityByEventType, throttleDelay);
954
+ }, [
955
+ active,
956
+ blocked,
957
+ closeOn,
958
+ disabled,
959
+ hideContent,
960
+ isContent,
961
+ isTrigger,
962
+ openOn,
963
+ showContent,
964
+ ]);
965
+ const handleContentPosition = useMemo(() => throttle(calculateContentPosition, throttleDelay), [calculateContentPosition, throttleDelay]);
966
+ const observeClick = useCallback(handleVisibilityByEventType, [
967
+ handleVisibilityByEventType,
968
+ ]);
969
+ const observeVisibility = useMemo(() => throttle(handleVisibilityByEventType, throttleDelay), [handleVisibilityByEventType, throttleDelay]);
953
970
  const handleEscKey = useCallback((e) => {
954
971
  if (e.key === 'Escape') {
955
972
  hideContent();
@@ -958,17 +975,12 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
958
975
  useEffect(() => {
959
976
  if (disabled) {
960
977
  hideContent();
978
+ return;
961
979
  }
962
- }, [disabled, hideContent]);
963
- // calculate position on every position change state
964
- useEffect(() => {
965
- if (active) {
966
- // hack-ish way to correctly calculate position for the first time
967
- // without calling it twice the posittion is somehow wrong
968
- calculateContentPosition();
969
- calculateContentPosition();
970
- }
971
- }, [active, align, alignX, alignX, calculateContentPosition]);
980
+ handleActive(isOpen);
981
+ setInnerAlignX(alignX);
982
+ setInnerAlignY(alignY);
983
+ }, [disabled, isOpen, alignX, alignY, hideContent]);
972
984
  // if an Overlay has an Overlay child, this will prevent closing parent child
973
985
  // + calculate correct position when an Overlay is opened
974
986
  useEffect(() => {
@@ -977,6 +989,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
977
989
  onOpen();
978
990
  if (ctx && ctx.setBlocked)
979
991
  ctx.setBlocked();
992
+ calculateContentPosition();
980
993
  }
981
994
  else {
982
995
  if (onClose)
@@ -984,7 +997,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
984
997
  if (ctx && ctx.setUnblocked)
985
998
  ctx.setUnblocked();
986
999
  }
987
- }, [active, onOpen, onClose, ctx]);
1000
+ }, [active, onOpen, onClose, ctx, calculateContentPosition]);
988
1001
  // handles calculating correct position of content
989
1002
  // on document events (or custom scroll if set)
990
1003
  useEffect(() => {
@@ -1006,18 +1019,6 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
1006
1019
  // make sure scrolling is blocked in case of modal windows or when
1007
1020
  // customScroll is set
1008
1021
  useEffect(() => {
1009
- if (active) {
1010
- if (customScrollListener && closeOn !== 'hover') {
1011
- // eslint-disable-next-line no-param-reassign
1012
- customScrollListener.style.overflow = 'hidden';
1013
- }
1014
- }
1015
- else {
1016
- if (customScrollListener) {
1017
- // eslint-disable-next-line no-param-reassign
1018
- customScrollListener.style.overflow = '';
1019
- }
1020
- }
1021
1022
  return () => {
1022
1023
  if (customScrollListener) {
1023
1024
  // eslint-disable-next-line no-param-reassign
@@ -1027,42 +1028,49 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
1027
1028
  }, [active, type, customScrollListener, closeOn]);
1028
1029
  // only when content is active handle closing
1029
1030
  useEffect(() => {
1030
- if (!active)
1031
+ if (!active || blocked)
1031
1032
  return undefined;
1032
- document.addEventListener('scroll', handleVisibility, false);
1033
+ document.addEventListener('scroll', observeVisibility, false);
1033
1034
  if (customScrollListener) {
1034
- customScrollListener.addEventListener('scroll', handleVisibility, false);
1035
+ customScrollListener.addEventListener('scroll', observeVisibility, false);
1035
1036
  }
1036
1037
  if (closeOnEsc) {
1037
1038
  document.addEventListener('keydown', handleEscKey, false);
1038
1039
  }
1039
1040
  return () => {
1040
- document.removeEventListener('scroll', handleVisibility, false);
1041
+ document.removeEventListener('scroll', observeVisibility, false);
1041
1042
  if (customScrollListener) {
1042
- customScrollListener.removeEventListener('scroll', handleVisibility, false);
1043
+ customScrollListener.removeEventListener('scroll', observeVisibility, false);
1043
1044
  }
1044
1045
  if (closeOnEsc) {
1045
1046
  document.removeEventListener('keydown', handleEscKey, false);
1046
1047
  }
1047
1048
  };
1048
- }, [active, customScrollListener, closeOnEsc, handleVisibility, handleEscKey]);
1049
+ }, [
1050
+ active,
1051
+ blocked,
1052
+ customScrollListener,
1053
+ closeOnEsc,
1054
+ observeVisibility,
1055
+ handleEscKey,
1056
+ ]);
1049
1057
  useEffect(() => {
1050
1058
  // enable overlay manipulation only when the state is NOT blocked=true
1051
- // nor in disabled state
1059
+ // nor in disabled=true state
1052
1060
  if (blocked || disabled)
1053
1061
  return undefined;
1054
1062
  if (openOn === 'click' ||
1055
1063
  closeOn === 'click' ||
1056
1064
  closeOn === 'clickOnTrigger' ||
1057
1065
  closeOn === 'clickOutsideContent') {
1058
- document.addEventListener('click', handleClick, false);
1066
+ document.addEventListener('click', observeClick, false);
1059
1067
  }
1060
1068
  if (openOn === 'hover' || closeOn === 'hover') {
1061
- document.addEventListener('mousemove', handleVisibility, false);
1069
+ document.addEventListener('mousemove', observeVisibility, false);
1062
1070
  }
1063
1071
  return () => {
1064
- document.removeEventListener('click', handleClick, false);
1065
- document.removeEventListener('mousemove', handleVisibility, false);
1072
+ document.removeEventListener('click', observeClick, false);
1073
+ document.removeEventListener('mousemove', observeVisibility, false);
1066
1074
  };
1067
1075
  }, [
1068
1076
  openOn,
@@ -1070,8 +1078,8 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
1070
1078
  blocked,
1071
1079
  disabled,
1072
1080
  active,
1073
- handleClick,
1074
- handleVisibility,
1081
+ observeClick,
1082
+ observeVisibility,
1075
1083
  ]);
1076
1084
  return {
1077
1085
  triggerRef,