@vitus-labs/elements 0.23.0-alpha.2 → 0.24.0

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.
@@ -72,7 +72,7 @@ var Styled$2 = config.styled(config.component) `
72
72
  })};
73
73
  `;
74
74
 
75
- const component$9 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
75
+ const component$a = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
76
76
  const debugProps = process.env.NODE_ENV !== 'production'
77
77
  ? {
78
78
  'data-vl-element': 'Element',
@@ -180,7 +180,7 @@ var Styled$1 = config.styled(config.component) `
180
180
  })};
181
181
  `;
182
182
 
183
- const component$7 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
183
+ const component$8 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
184
184
  const debugProps = process.env.NODE_ENV !== 'production'
185
185
  ? {
186
186
  'data-vl-element': contentType,
@@ -196,7 +196,7 @@ const component$7 = ({ contentType, tag, parentDirection, direction, alignX, ali
196
196
  extraStyles: extendCss,
197
197
  }, ...debugProps, ...props }));
198
198
  };
199
- var component$8 = memo(component$7);
199
+ var component$9 = memo(component$8);
200
200
 
201
201
  const INLINE_ELEMENTS = {
202
202
  span: true,
@@ -252,11 +252,11 @@ const EMPTY_ELEMENTS = {
252
252
  const isInlineElement = (tag) => tag ? INLINE_ELEMENTS[tag] : false;
253
253
  const getShouldBeEmpty = (tag) => tag ? EMPTY_ELEMENTS[tag] : false;
254
254
 
255
- const defaultBeforeAfterDirection = 'inline';
256
- const defaultDirection = 'rows';
255
+ const defaultDirection = 'inline';
256
+ const defaultContentDirection = 'rows';
257
257
  const defaultAlignX = 'left';
258
258
  const defaultAlignY = 'center';
259
- const component$6 = forwardRef(({ innerRef, tag, label, content, children, beforeContent, afterContent, block, equalCols, gap, direction = defaultDirection, alignX = defaultAlignX, alignY = defaultAlignY, css, contentCss, beforeContentCss, afterContentCss, contentDirection = defaultDirection, contentAlignX = defaultAlignX, contentAlignY = defaultAlignY, beforeContentDirection = defaultBeforeAfterDirection, beforeContentAlignX = defaultAlignX, beforeContentAlignY = defaultAlignY, afterContentDirection = defaultBeforeAfterDirection, afterContentAlignX = defaultAlignX, afterContentAlignY = defaultAlignY, ...props }, ref) => {
259
+ const component$7 = forwardRef(({ innerRef, tag, label, content, children, beforeContent, afterContent, block, equalCols, gap, direction, alignX = defaultAlignX, alignY = defaultAlignY, css, contentCss, beforeContentCss, afterContentCss, contentDirection = defaultContentDirection, contentAlignX = defaultAlignX, contentAlignY = defaultAlignY, beforeContentDirection = defaultDirection, beforeContentAlignX = defaultAlignX, beforeContentAlignY = defaultAlignY, afterContentDirection = defaultDirection, afterContentAlignX = defaultAlignX, afterContentAlignY = defaultAlignY, ...props }, ref) => {
260
260
  // --------------------------------------------------------
261
261
  // check if should render only single element
262
262
  // --------------------------------------------------------
@@ -317,18 +317,18 @@ const component$6 = forwardRef(({ innerRef, tag, label, content, children, befor
317
317
  // return simple/empty element like input or image etc.
318
318
  // --------------------------------------------------------
319
319
  if (shouldBeEmpty) {
320
- return React.createElement(component$9, { ...props, ...WRAPPER_PROPS });
320
+ return React.createElement(component$a, { ...props, ...WRAPPER_PROPS });
321
321
  }
322
322
  const contentRenderOutput = renderContent(CHILDREN);
323
- return (React.createElement(component$9, { ...props, ...WRAPPER_PROPS, isInline: isInline },
324
- beforeContent && (React.createElement(component$8, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, renderContent(beforeContent))),
325
- isSimpleElement ? (contentRenderOutput) : (React.createElement(component$8, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
326
- afterContent && (React.createElement(component$8, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, renderContent(afterContent)))));
323
+ return (React.createElement(component$a, { ...props, ...WRAPPER_PROPS, isInline: isInline },
324
+ beforeContent && (React.createElement(component$9, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, renderContent(beforeContent))),
325
+ isSimpleElement ? (contentRenderOutput) : (React.createElement(component$9, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
326
+ afterContent && (React.createElement(component$9, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, renderContent(afterContent)))));
327
327
  });
328
328
  const name$4 = `${PKG_NAME}/Element`;
329
- component$6.displayName = name$4;
330
- component$6.pkgName = PKG_NAME;
331
- component$6.VITUS_LABS__COMPONENT = name$4;
329
+ component$7.displayName = name$4;
330
+ component$7.pkgName = PKG_NAME;
331
+ component$7.VITUS_LABS__COMPONENT = name$4;
332
332
 
333
333
  /* eslint-disable no-param-reassign */
334
334
  const isNumber = (a, b) => Number.isInteger(a) && Number.isInteger(b);
@@ -393,7 +393,7 @@ const attachItemProps = ({ i, length, }) => {
393
393
  position,
394
394
  };
395
395
  };
396
- const component$5 = (props) => {
396
+ const component$6 = (props) => {
397
397
  const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
398
398
  const renderedElement = renderContent;
399
399
  const injectItemProps = useMemo(() => (typeof itemProps === 'function' ? itemProps : () => itemProps), [itemProps]);
@@ -531,19 +531,19 @@ const component$5 = (props) => {
531
531
  };
532
532
  return renderItems();
533
533
  };
534
- component$5.isIterator = true;
535
- component$5.RESERVED_PROPS = RESERVED_PROPS;
534
+ component$6.isIterator = true;
535
+ component$6.RESERVED_PROPS = RESERVED_PROPS;
536
536
 
537
- const component$4 = forwardRef(({ rootElement = false, ...props }, ref) => {
538
- const renderedList = React.createElement(component$5, { ...pick(props, component$5.RESERVED_PROPS) });
537
+ const component$5 = forwardRef(({ rootElement = false, ...props }, ref) => {
538
+ const renderedList = React.createElement(component$6, { ...pick(props, component$6.RESERVED_PROPS) });
539
539
  if (!rootElement)
540
540
  return renderedList;
541
- return (React.createElement(component$6, { ref: ref, ...omit(props, component$5.RESERVED_PROPS) }, renderedList));
541
+ return (React.createElement(component$7, { ref: ref, ...omit(props, component$6.RESERVED_PROPS) }, renderedList));
542
542
  });
543
543
  const name$3 = `${PKG_NAME}/List`;
544
- component$4.displayName = name$3;
545
- component$4.pkgName = PKG_NAME;
546
- component$4.VITUS_LABS__COMPONENT = name$3;
544
+ component$5.displayName = name$3;
545
+ component$5.pkgName = PKG_NAME;
546
+ component$5.VITUS_LABS__COMPONENT = name$3;
547
547
 
548
548
  const RESERVED_KEYS = [
549
549
  'type',
@@ -551,7 +551,7 @@ const RESERVED_KEYS = [
551
551
  'itemProps',
552
552
  'activeItemRequired',
553
553
  ];
554
- const component$3 = (WrappedComponent) => {
554
+ const component$4 = (WrappedComponent) => {
555
555
  const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
556
556
  const Enhanced = (props) => {
557
557
  const { type = 'single', activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
@@ -674,7 +674,7 @@ const component$3 = (WrappedComponent) => {
674
674
  return Enhanced;
675
675
  };
676
676
 
677
- const component$2 = ({ position = undefined, tag = 'div', children, }) => {
677
+ const component$3 = ({ position = undefined, tag = 'div', children, }) => {
678
678
  const [element] = useState(undefined);
679
679
  if (!position || !element)
680
680
  return null;
@@ -687,12 +687,14 @@ const component$2 = ({ position = undefined, tag = 'div', children, }) => {
687
687
  return createPortal(children, element);
688
688
  };
689
689
  const name$2 = `${PKG_NAME}/Portal`;
690
- component$2.displayName = name$2;
691
- component$2.pkgName = PKG_NAME;
692
- component$2.VITUS_LABS__COMPONENT = name$2;
690
+ component$3.displayName = name$2;
691
+ component$3.pkgName = PKG_NAME;
692
+ component$3.VITUS_LABS__COMPONENT = name$2;
693
693
 
694
694
  const context = createContext({});
695
- const useOverlayContext = () => useContext(context);
695
+ const { Provider } = context;
696
+ const useOverlayContext = () => useContext(context);
697
+ const component$2 = ({ children, blocked, setBlocked, setUnblocked, }) => (React.createElement(Provider, { value: { blocked, setBlocked, setUnblocked } }, children));
696
698
 
697
699
  var useOverlay = ({ isOpen = false, openOn = 'click', // click | hover
698
700
  closeOn = 'click', // click | 'clickOnTrigger' | 'clickOutsideContent' | hover | manual
@@ -743,15 +745,37 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
743
745
  return undefined;
744
746
  window.addEventListener('resize', handleContentPosition, false);
745
747
  window.addEventListener('scroll', handleContentPosition, false);
748
+ if (customScrollListener) {
749
+ customScrollListener.addEventListener('scroll', handleContentPosition, false);
750
+ }
746
751
  return () => {
747
752
  window.removeEventListener('resize', handleContentPosition, false);
748
753
  window.removeEventListener('scroll', handleContentPosition, false);
754
+ if (customScrollListener) {
755
+ customScrollListener.removeEventListener('scroll', handleContentPosition, false);
756
+ }
749
757
  };
750
758
  }, [active, customScrollListener]);
751
759
  // make sure scrolling is blocked in case of modal windows or when
752
760
  // customScroll is set
753
761
  useEffect(() => {
762
+ if (active) {
763
+ if (customScrollListener) {
764
+ // eslint-disable-next-line no-param-reassign
765
+ customScrollListener.style.overflow = 'hidden';
766
+ }
767
+ }
768
+ else {
769
+ if (customScrollListener) {
770
+ // eslint-disable-next-line no-param-reassign
771
+ customScrollListener.style.overflow = '';
772
+ }
773
+ }
754
774
  return () => {
775
+ if (customScrollListener) {
776
+ // eslint-disable-next-line no-param-reassign
777
+ customScrollListener.style.overflow = '';
778
+ }
755
779
  };
756
780
  }, [active, type, customScrollListener]);
757
781
  // only when content is active handle closing
@@ -759,11 +783,17 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
759
783
  if (!active)
760
784
  return undefined;
761
785
  window.addEventListener('scroll', handleVisibility, false);
786
+ if (customScrollListener) {
787
+ customScrollListener.addEventListener('scroll', handleVisibility, false);
788
+ }
762
789
  if (closeOnEsc) {
763
790
  window.addEventListener('keydown', handleEscKey, false);
764
791
  }
765
792
  return () => {
766
793
  window.removeEventListener('scroll', handleVisibility, false);
794
+ if (customScrollListener) {
795
+ customScrollListener.removeEventListener('scroll', handleVisibility, false);
796
+ }
767
797
  if (closeOnEsc) {
768
798
  window.removeEventListener('keydown', handleEscKey, false);
769
799
  }
@@ -787,7 +817,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
787
817
  window.removeEventListener('click', handleClick, false);
788
818
  window.removeEventListener('mousemove', handleVisibility, false);
789
819
  };
790
- }, [openOn, closeOn, blocked, disabled]);
820
+ }, [openOn, closeOn, blocked, disabled, active]);
791
821
  const isNodeOrChild = (ref) => (e) => {
792
822
  if (e && e.target && ref.current) {
793
823
  return ref.current.contains(e.target) || e.target === ref.current;
@@ -956,8 +986,8 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
956
986
  }
957
987
  };
958
988
  const handleContentPosition = throttle(calculateContentPosition, throttleDelay);
959
- const handleClick = useCallback(handleVisibilityByEventType, []);
960
- const handleVisibility = useCallback(throttle(handleVisibilityByEventType, throttleDelay), []);
989
+ const handleClick = handleVisibilityByEventType;
990
+ const handleVisibility = throttle(handleVisibilityByEventType, throttleDelay);
961
991
  const handleEscKey = (e) => {
962
992
  if (e.key === 'Escape') {
963
993
  hideContent();
@@ -1025,5 +1055,5 @@ component.pkgName = PKG_NAME;
1025
1055
  component.VITUS_LABS__COMPONENT = name;
1026
1056
  component.isText = true;
1027
1057
 
1028
- export { component$6 as Element, component$4 as List, component$1 as Overlay, component$2 as Portal, component as Text, useOverlay, component$3 as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
1058
+ export { component$7 as Element, component$5 as List, component$1 as Overlay, component$2 as OverlayProvider, component$3 as Portal, component as Text, useOverlay, component$4 as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
1029
1059
  //# sourceMappingURL=vitus-labs-elements.module.js.map