@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.
@@ -79,7 +79,7 @@ var Styled$2 = core.config.styled(core.config.component) `
79
79
  })};
80
80
  `;
81
81
 
82
- const component$9 = React.forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
82
+ const component$a = React.forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
83
83
  const debugProps = process.env.NODE_ENV !== 'production'
84
84
  ? {
85
85
  'data-vl-element': 'Element',
@@ -187,7 +187,7 @@ var Styled$1 = core.config.styled(core.config.component) `
187
187
  })};
188
188
  `;
189
189
 
190
- const component$7 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
190
+ const component$8 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
191
191
  const debugProps = process.env.NODE_ENV !== 'production'
192
192
  ? {
193
193
  'data-vl-element': contentType,
@@ -203,7 +203,7 @@ const component$7 = ({ contentType, tag, parentDirection, direction, alignX, ali
203
203
  extraStyles: extendCss,
204
204
  }, ...debugProps, ...props }));
205
205
  };
206
- var component$8 = React.memo(component$7);
206
+ var component$9 = React.memo(component$8);
207
207
 
208
208
  const INLINE_ELEMENTS = {
209
209
  span: true,
@@ -259,11 +259,11 @@ const EMPTY_ELEMENTS = {
259
259
  const isInlineElement = (tag) => tag ? INLINE_ELEMENTS[tag] : false;
260
260
  const getShouldBeEmpty = (tag) => tag ? EMPTY_ELEMENTS[tag] : false;
261
261
 
262
- const defaultBeforeAfterDirection = 'inline';
263
- const defaultDirection = 'rows';
262
+ const defaultDirection = 'inline';
263
+ const defaultContentDirection = 'rows';
264
264
  const defaultAlignX = 'left';
265
265
  const defaultAlignY = 'center';
266
- const component$6 = React.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) => {
266
+ const component$7 = React.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) => {
267
267
  // --------------------------------------------------------
268
268
  // check if should render only single element
269
269
  // --------------------------------------------------------
@@ -324,18 +324,18 @@ const component$6 = React.forwardRef(({ innerRef, tag, label, content, children,
324
324
  // return simple/empty element like input or image etc.
325
325
  // --------------------------------------------------------
326
326
  if (shouldBeEmpty) {
327
- return React__default["default"].createElement(component$9, { ...props, ...WRAPPER_PROPS });
327
+ return React__default["default"].createElement(component$a, { ...props, ...WRAPPER_PROPS });
328
328
  }
329
329
  const contentRenderOutput = core.renderContent(CHILDREN);
330
- return (React__default["default"].createElement(component$9, { ...props, ...WRAPPER_PROPS, isInline: isInline },
331
- beforeContent && (React__default["default"].createElement(component$8, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, core.renderContent(beforeContent))),
332
- isSimpleElement ? (contentRenderOutput) : (React__default["default"].createElement(component$8, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
333
- afterContent && (React__default["default"].createElement(component$8, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, core.renderContent(afterContent)))));
330
+ return (React__default["default"].createElement(component$a, { ...props, ...WRAPPER_PROPS, isInline: isInline },
331
+ beforeContent && (React__default["default"].createElement(component$9, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, core.renderContent(beforeContent))),
332
+ isSimpleElement ? (contentRenderOutput) : (React__default["default"].createElement(component$9, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
333
+ afterContent && (React__default["default"].createElement(component$9, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, core.renderContent(afterContent)))));
334
334
  });
335
335
  const name$4 = `${PKG_NAME}/Element`;
336
- component$6.displayName = name$4;
337
- component$6.pkgName = PKG_NAME;
338
- component$6.VITUS_LABS__COMPONENT = name$4;
336
+ component$7.displayName = name$4;
337
+ component$7.pkgName = PKG_NAME;
338
+ component$7.VITUS_LABS__COMPONENT = name$4;
339
339
 
340
340
  /* eslint-disable no-param-reassign */
341
341
  const isNumber = (a, b) => Number.isInteger(a) && Number.isInteger(b);
@@ -400,7 +400,7 @@ const attachItemProps = ({ i, length, }) => {
400
400
  position,
401
401
  };
402
402
  };
403
- const component$5 = (props) => {
403
+ const component$6 = (props) => {
404
404
  const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
405
405
  const renderedElement = core.renderContent;
406
406
  const injectItemProps = React.useMemo(() => (typeof itemProps === 'function' ? itemProps : () => itemProps), [itemProps]);
@@ -538,19 +538,19 @@ const component$5 = (props) => {
538
538
  };
539
539
  return renderItems();
540
540
  };
541
- component$5.isIterator = true;
542
- component$5.RESERVED_PROPS = RESERVED_PROPS;
541
+ component$6.isIterator = true;
542
+ component$6.RESERVED_PROPS = RESERVED_PROPS;
543
543
 
544
- const component$4 = React.forwardRef(({ rootElement = false, ...props }, ref) => {
545
- const renderedList = React__default["default"].createElement(component$5, { ...core.pick(props, component$5.RESERVED_PROPS) });
544
+ const component$5 = React.forwardRef(({ rootElement = false, ...props }, ref) => {
545
+ const renderedList = React__default["default"].createElement(component$6, { ...core.pick(props, component$6.RESERVED_PROPS) });
546
546
  if (!rootElement)
547
547
  return renderedList;
548
- return (React__default["default"].createElement(component$6, { ref: ref, ...core.omit(props, component$5.RESERVED_PROPS) }, renderedList));
548
+ return (React__default["default"].createElement(component$7, { ref: ref, ...core.omit(props, component$6.RESERVED_PROPS) }, renderedList));
549
549
  });
550
550
  const name$3 = `${PKG_NAME}/List`;
551
- component$4.displayName = name$3;
552
- component$4.pkgName = PKG_NAME;
553
- component$4.VITUS_LABS__COMPONENT = name$3;
551
+ component$5.displayName = name$3;
552
+ component$5.pkgName = PKG_NAME;
553
+ component$5.VITUS_LABS__COMPONENT = name$3;
554
554
 
555
555
  const RESERVED_KEYS = [
556
556
  'type',
@@ -558,7 +558,7 @@ const RESERVED_KEYS = [
558
558
  'itemProps',
559
559
  'activeItemRequired',
560
560
  ];
561
- const component$3 = (WrappedComponent) => {
561
+ const component$4 = (WrappedComponent) => {
562
562
  const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
563
563
  const Enhanced = (props) => {
564
564
  const { type = 'single', activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
@@ -681,7 +681,7 @@ const component$3 = (WrappedComponent) => {
681
681
  return Enhanced;
682
682
  };
683
683
 
684
- const component$2 = ({ position = undefined, tag = 'div', children, }) => {
684
+ const component$3 = ({ position = undefined, tag = 'div', children, }) => {
685
685
  const [element] = React.useState(undefined);
686
686
  if (!position || !element)
687
687
  return null;
@@ -691,12 +691,14 @@ const component$2 = ({ position = undefined, tag = 'div', children, }) => {
691
691
  return reactDom.createPortal(children, element);
692
692
  };
693
693
  const name$2 = `${PKG_NAME}/Portal`;
694
- component$2.displayName = name$2;
695
- component$2.pkgName = PKG_NAME;
696
- component$2.VITUS_LABS__COMPONENT = name$2;
694
+ component$3.displayName = name$2;
695
+ component$3.pkgName = PKG_NAME;
696
+ component$3.VITUS_LABS__COMPONENT = name$2;
697
697
 
698
698
  const context = React.createContext({});
699
- const useOverlayContext = () => React.useContext(context);
699
+ const { Provider } = context;
700
+ const useOverlayContext = () => React.useContext(context);
701
+ const component$2 = ({ children, blocked, setBlocked, setUnblocked, }) => (React__default["default"].createElement(Provider, { value: { blocked, setBlocked, setUnblocked } }, children));
700
702
 
701
703
  var useOverlay = ({ isOpen = false, openOn = 'click', // click | hover
702
704
  closeOn = 'click', // click | 'clickOnTrigger' | 'clickOutsideContent' | hover | manual
@@ -747,15 +749,37 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
747
749
  return undefined;
748
750
  window.addEventListener('resize', handleContentPosition, false);
749
751
  window.addEventListener('scroll', handleContentPosition, false);
752
+ if (customScrollListener) {
753
+ customScrollListener.addEventListener('scroll', handleContentPosition, false);
754
+ }
750
755
  return () => {
751
756
  window.removeEventListener('resize', handleContentPosition, false);
752
757
  window.removeEventListener('scroll', handleContentPosition, false);
758
+ if (customScrollListener) {
759
+ customScrollListener.removeEventListener('scroll', handleContentPosition, false);
760
+ }
753
761
  };
754
762
  }, [active, customScrollListener]);
755
763
  // make sure scrolling is blocked in case of modal windows or when
756
764
  // customScroll is set
757
765
  React.useEffect(() => {
766
+ if (active) {
767
+ if (customScrollListener) {
768
+ // eslint-disable-next-line no-param-reassign
769
+ customScrollListener.style.overflow = 'hidden';
770
+ }
771
+ }
772
+ else {
773
+ if (customScrollListener) {
774
+ // eslint-disable-next-line no-param-reassign
775
+ customScrollListener.style.overflow = '';
776
+ }
777
+ }
758
778
  return () => {
779
+ if (customScrollListener) {
780
+ // eslint-disable-next-line no-param-reassign
781
+ customScrollListener.style.overflow = '';
782
+ }
759
783
  };
760
784
  }, [active, type, customScrollListener]);
761
785
  // only when content is active handle closing
@@ -763,11 +787,17 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
763
787
  if (!active)
764
788
  return undefined;
765
789
  window.addEventListener('scroll', handleVisibility, false);
790
+ if (customScrollListener) {
791
+ customScrollListener.addEventListener('scroll', handleVisibility, false);
792
+ }
766
793
  if (closeOnEsc) {
767
794
  window.addEventListener('keydown', handleEscKey, false);
768
795
  }
769
796
  return () => {
770
797
  window.removeEventListener('scroll', handleVisibility, false);
798
+ if (customScrollListener) {
799
+ customScrollListener.removeEventListener('scroll', handleVisibility, false);
800
+ }
771
801
  if (closeOnEsc) {
772
802
  window.removeEventListener('keydown', handleEscKey, false);
773
803
  }
@@ -791,7 +821,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
791
821
  window.removeEventListener('click', handleClick, false);
792
822
  window.removeEventListener('mousemove', handleVisibility, false);
793
823
  };
794
- }, [openOn, closeOn, blocked, disabled]);
824
+ }, [openOn, closeOn, blocked, disabled, active]);
795
825
  const isNodeOrChild = (ref) => (e) => {
796
826
  if (e && e.target && ref.current) {
797
827
  return ref.current.contains(e.target) || e.target === ref.current;
@@ -960,8 +990,8 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
960
990
  }
961
991
  };
962
992
  const handleContentPosition = core.throttle(calculateContentPosition, throttleDelay);
963
- const handleClick = React.useCallback(handleVisibilityByEventType, []);
964
- const handleVisibility = React.useCallback(core.throttle(handleVisibilityByEventType, throttleDelay), []);
993
+ const handleClick = handleVisibilityByEventType;
994
+ const handleVisibility = core.throttle(handleVisibilityByEventType, throttleDelay);
965
995
  const handleEscKey = (e) => {
966
996
  if (e.key === 'Escape') {
967
997
  hideContent();
@@ -1033,12 +1063,13 @@ Object.defineProperty(exports, 'Provider', {
1033
1063
  enumerable: true,
1034
1064
  get: function () { return unistyle.Provider; }
1035
1065
  });
1036
- exports.Element = component$6;
1037
- exports.List = component$4;
1066
+ exports.Element = component$7;
1067
+ exports.List = component$5;
1038
1068
  exports.Overlay = component$1;
1039
- exports.Portal = component$2;
1069
+ exports.OverlayProvider = component$2;
1070
+ exports.Portal = component$3;
1040
1071
  exports.Text = component;
1041
1072
  exports.useOverlay = useOverlay;
1042
- exports.withActiveState = component$3;
1073
+ exports.withActiveState = component$4;
1043
1074
  exports.withEqualSizeBeforeAfter = withEqualBeforeAfter;
1044
1075
  //# sourceMappingURL=vitus-labs-elements.js.map