@vitus-labs/elements 0.22.0 → 0.23.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.
@@ -1,8 +1,8 @@
1
1
  import { makeItResponsive, alignContent, extendCss, value } from '@vitus-labs/unistyle';
2
2
  export { Provider } from '@vitus-labs/unistyle';
3
- import React, { forwardRef, memo, useMemo, createRef, Children, useState, useEffect, createContext, useContext, useRef, useCallback } from 'react';
3
+ import React, { forwardRef, memo, useMemo, createRef, useCallback, Children, useState, useEffect, createContext, useContext, useRef } from 'react';
4
4
  import { config, renderContent, get, isEmpty, pick, omit, context as context$1, throttle } from '@vitus-labs/core';
5
- import ReactDOM from 'react-dom';
5
+ import { createPortal } from 'react-dom';
6
6
 
7
7
  // eslint-disable-next-line import/prefer-default-export
8
8
  const PKG_NAME = '@vitus-labs/elements';
@@ -25,9 +25,7 @@ const styles$2 = ({ theme: t, css }) => css `
25
25
 
26
26
  ${t.extraStyles && extendCss(t.extraStyles)};
27
27
  `;
28
- const platformStyles = config.css `
29
- display: flex;
30
- `;
28
+ const platformStyles = 'display: flex;';
31
29
  var Styled$2 = config.styled(config.component) `
32
30
  position: relative;
33
31
  ${platformStyles};
@@ -48,7 +46,7 @@ var Styled$2 = config.styled(config.component) `
48
46
  })};
49
47
  `;
50
48
 
51
- const component$6 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
49
+ const component$9 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
52
50
  const debugProps = process.env.NODE_ENV !== 'production'
53
51
  ? {
54
52
  'data-vl-element': 'Element',
@@ -140,7 +138,7 @@ var Styled$1 = config.styled(config.component) `
140
138
  })};
141
139
  `;
142
140
 
143
- const component$4 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
141
+ const component$7 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
144
142
  const debugProps = process.env.NODE_ENV !== 'production'
145
143
  ? {
146
144
  'data-vl-element': contentType,
@@ -156,37 +154,19 @@ const component$4 = ({ contentType, tag, parentDirection, direction, alignX, ali
156
154
  extraStyles: extendCss,
157
155
  }, ...debugProps, ...props }));
158
156
  };
159
- var component$5 = memo(component$4);
157
+ var component$8 = memo(component$7);
160
158
 
161
- const defaultDirection = 'inline';
162
- const defaultContentDirection = 'rows';
159
+ const defaultBeforeAfterDirection = 'inline';
160
+ const defaultDirection = 'rows';
163
161
  const defaultAlignX = 'left';
164
162
  const defaultAlignY = 'center';
165
- const component$3 = 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) => {
163
+ 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) => {
166
164
  // --------------------------------------------------------
167
165
  // check if should render only single element
168
166
  // --------------------------------------------------------
169
167
  const shouldBeEmpty = !!props.dangerouslySetInnerHTML ||
170
168
  (false );
171
169
  // --------------------------------------------------------
172
- // common wrapper props
173
- // --------------------------------------------------------
174
- const WRAPPER_PROPS = {
175
- ref: ref || innerRef,
176
- extendCss: css,
177
- tag,
178
- block,
179
- contentDirection,
180
- alignX: contentAlignX,
181
- alignY: contentAlignY,
182
- as: undefined, // reset styled-components `as` prop
183
- };
184
- // --------------------------------------------------------
185
- // return simple/empty element like input
186
- // --------------------------------------------------------
187
- if (shouldBeEmpty)
188
- return React.createElement(component$6, { ...WRAPPER_PROPS, ...props });
189
- // --------------------------------------------------------
190
170
  // if not single element, calculate values
191
171
  // --------------------------------------------------------
192
172
  const isSimpleElement = !beforeContent && !afterContent;
@@ -196,8 +176,8 @@ const component$3 = forwardRef(({ innerRef, tag, label, content, children, befor
196
176
  // --------------------------------------------------------
197
177
  // direction & alignX & alignY calculations
198
178
  // --------------------------------------------------------
199
- const calculateDirection = useMemo(() => {
200
- let wrapperDirection;
179
+ const { wrapperDirection, wrapperAlignX, wrapperAlignY } = useMemo(() => {
180
+ let wrapperDirection = direction;
201
181
  let wrapperAlignX = alignX;
202
182
  let wrapperAlignY = alignY;
203
183
  if (isSimpleElement) {
@@ -220,21 +200,39 @@ const component$3 = forwardRef(({ innerRef, tag, label, content, children, befor
220
200
  contentDirection,
221
201
  contentAlignX,
222
202
  contentAlignY,
203
+ alignX,
204
+ alignY,
223
205
  direction,
224
206
  ]);
225
- const { wrapperDirection, wrapperAlignX, wrapperAlignY } = calculateDirection;
226
- const beforeContentRenderOutput = useMemo(() => renderContent(beforeContent), [beforeContent]);
227
- const afterContentRenderOutput = useMemo(() => renderContent(afterContent), [afterContent]);
228
- const contentRenderOutput = useMemo(() => renderContent(CHILDREN), [CHILDREN]);
229
- return (React.createElement(component$6, { ...props, ...WRAPPER_PROPS, isInline: isInline, direction: wrapperDirection, alignX: wrapperAlignX, alignY: wrapperAlignY },
230
- beforeContent && (React.createElement(component$5, { tag: SUB_TAG, contentType: "before", parentDirection: wrapperDirection, extendCss: beforeContentCss, direction: beforeContentDirection, alignX: beforeContentAlignX, alignY: beforeContentAlignY, equalCols: equalCols, gap: gap }, beforeContentRenderOutput)),
231
- isSimpleElement ? (contentRenderOutput) : (React.createElement(component$5, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
232
- afterContent && (React.createElement(component$5, { tag: SUB_TAG, contentType: "after", parentDirection: wrapperDirection, extendCss: afterContentCss, direction: afterContentDirection, alignX: afterContentAlignX, alignY: afterContentAlignY, equalCols: equalCols, gap: gap }, afterContentRenderOutput))));
207
+ // --------------------------------------------------------
208
+ // common wrapper props
209
+ // --------------------------------------------------------
210
+ const WRAPPER_PROPS = {
211
+ ref: ref || innerRef,
212
+ extendCss: css,
213
+ tag,
214
+ block,
215
+ direction: wrapperDirection,
216
+ alignX: wrapperAlignX,
217
+ alignY: wrapperAlignY,
218
+ as: undefined, // reset styled-components `as` prop
219
+ };
220
+ // --------------------------------------------------------
221
+ // return simple/empty element like input or image etc.
222
+ // --------------------------------------------------------
223
+ if (shouldBeEmpty) {
224
+ return React.createElement(component$9, { ...props, ...WRAPPER_PROPS });
225
+ }
226
+ const contentRenderOutput = renderContent(CHILDREN);
227
+ return (React.createElement(component$9, { ...props, ...WRAPPER_PROPS, isInline: isInline },
228
+ 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))),
229
+ isSimpleElement ? (contentRenderOutput) : (React.createElement(component$8, { tag: SUB_TAG, contentType: "content", parentDirection: wrapperDirection, extendCss: contentCss, direction: contentDirection, alignX: contentAlignX, alignY: contentAlignY, equalCols: equalCols }, contentRenderOutput)),
230
+ 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)))));
233
231
  });
234
232
  const name$4 = `${PKG_NAME}/Element`;
235
- component$3.displayName = name$4;
236
- component$3.pkgName = PKG_NAME;
237
- component$3.VITUS_LABS__COMPONENT = name$4;
233
+ component$6.displayName = name$4;
234
+ component$6.pkgName = PKG_NAME;
235
+ component$6.VITUS_LABS__COMPONENT = name$4;
238
236
 
239
237
  /* eslint-disable no-param-reassign */
240
238
  const isNumber = (a, b) => Number.isInteger(a) && Number.isInteger(b);
@@ -299,15 +297,16 @@ const attachItemProps = ({ i, length, }) => {
299
297
  position,
300
298
  };
301
299
  };
302
- const component$2 = (props) => {
300
+ const component$5 = (props) => {
303
301
  const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
304
- const renderedElement = (component, props) => renderContent(component, props);
305
- const injectItemProps = typeof itemProps === 'function'
306
- ? (props, extendedProps) => itemProps(props, extendedProps)
307
- : () => itemProps;
308
- const injectWrapItemProps = typeof wrapProps === 'function'
309
- ? (props, extendedProps) => wrapProps(props, extendedProps)
310
- : () => wrapProps;
302
+ const renderedElement = renderContent;
303
+ const injectItemProps = useMemo(() => (typeof itemProps === 'function' ? itemProps : () => itemProps), [itemProps]);
304
+ const injectWrapItemProps = useMemo(() => (typeof wrapProps === 'function' ? wrapProps : () => wrapProps), [wrapProps]);
305
+ const getKey = useCallback((item, index) => {
306
+ if (typeof itemKey === 'function')
307
+ return itemKey(item, index);
308
+ return index;
309
+ }, []);
311
310
  // --------------------------------------------------------
312
311
  // render children
313
312
  // --------------------------------------------------------
@@ -341,18 +340,11 @@ const component$2 = (props) => {
341
340
  // render array of strings or numbers
342
341
  // --------------------------------------------------------
343
342
  const renderSimpleArray = (data) => {
344
- const renderData = data.filter((item) => item !== null || item !== undefined // remove empty values
345
- );
346
- const { length } = renderData;
347
- // if it's empty
348
- if (renderData.length === 0)
343
+ const { length } = data;
344
+ // if the data array is empty
345
+ if (data.length === 0)
349
346
  return null;
350
- const getKey = (item, index) => {
351
- if (typeof itemKey === 'function')
352
- return itemKey(item, index);
353
- return index;
354
- };
355
- return renderData.map((item, i) => {
347
+ return data.map((item, i) => {
356
348
  const key = getKey(item, i);
357
349
  const keyName = valueName || 'children';
358
350
  const extendedProps = attachItemProps({
@@ -426,11 +418,11 @@ const component$2 = (props) => {
426
418
  // render props component + data
427
419
  // --------------------------------------------------------
428
420
  if (component && Array.isArray(data)) {
429
- const clearData = data.filter((item) => item !== null && item !== undefined);
430
- const isSimpleArray = clearData.every((item) => typeof item === 'string' || typeof item === 'number');
421
+ const clearData = useMemo(() => data.filter((item) => item !== null && item !== undefined), [data]);
422
+ const isSimpleArray = useMemo(() => clearData.every((item) => typeof item === 'string' || typeof item === 'number'), [clearData]);
431
423
  if (isSimpleArray)
432
424
  return renderSimpleArray(clearData);
433
- const isComplexArray = clearData.every((item) => typeof item === 'object');
425
+ const isComplexArray = useMemo(() => clearData.every((item) => typeof item === 'object'), [clearData]);
434
426
  if (isComplexArray)
435
427
  return renderComplexArray(clearData);
436
428
  return null;
@@ -443,19 +435,19 @@ const component$2 = (props) => {
443
435
  };
444
436
  return renderItems();
445
437
  };
446
- component$2.isIterator = true;
447
- component$2.RESERVED_PROPS = RESERVED_PROPS;
438
+ component$5.isIterator = true;
439
+ component$5.RESERVED_PROPS = RESERVED_PROPS;
448
440
 
449
- const Component$2 = forwardRef(({ rootElement = false, ...props }, ref) => {
450
- const renderedList = React.createElement(component$2, { ...pick(props, component$2.RESERVED_PROPS) });
441
+ const component$4 = forwardRef(({ rootElement = false, ...props }, ref) => {
442
+ const renderedList = React.createElement(component$5, { ...pick(props, component$5.RESERVED_PROPS) });
451
443
  if (!rootElement)
452
444
  return renderedList;
453
- return (React.createElement(component$3, { ref: ref, ...omit(props, component$2.RESERVED_PROPS) }, renderedList));
445
+ return (React.createElement(component$6, { ref: ref, ...omit(props, component$5.RESERVED_PROPS) }, renderedList));
454
446
  });
455
447
  const name$3 = `${PKG_NAME}/List`;
456
- Component$2.displayName = name$3;
457
- Component$2.pkgName = PKG_NAME;
458
- Component$2.VITUS_LABS__COMPONENT = name$3;
448
+ component$4.displayName = name$3;
449
+ component$4.pkgName = PKG_NAME;
450
+ component$4.VITUS_LABS__COMPONENT = name$3;
459
451
 
460
452
  const RESERVED_KEYS = [
461
453
  'type',
@@ -463,7 +455,7 @@ const RESERVED_KEYS = [
463
455
  'itemProps',
464
456
  'activeItemRequired',
465
457
  ];
466
- const Component$1 = (WrappedComponent) => {
458
+ const component$3 = (WrappedComponent) => {
467
459
  const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
468
460
  const Enhanced = (props) => {
469
461
  const { type = 'single', activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
@@ -582,11 +574,11 @@ const Component$1 = (WrappedComponent) => {
582
574
  return React.createElement(WrappedComponent, { ...rest, itemProps: attachItemProps });
583
575
  };
584
576
  Enhanced.RESERVED_KEYS = RESERVED_KEYS;
585
- Enhanced.displayName = `vitus-labs/elements/List/withActiveState(${displayName})`;
577
+ Enhanced.displayName = `@vitus-labs/elements/List/withActiveState(${displayName})`;
586
578
  return Enhanced;
587
579
  };
588
580
 
589
- const component$1 = ({ position = undefined, tag = 'div', children, }) => {
581
+ const component$2 = ({ position = undefined, tag = 'div', children, }) => {
590
582
  const [element] = useState(undefined);
591
583
  if (!position || !element)
592
584
  return null;
@@ -596,12 +588,12 @@ const component$1 = ({ position = undefined, tag = 'div', children, }) => {
596
588
  position.removeChild(element);
597
589
  };
598
590
  }, []);
599
- return ReactDOM.createPortal(children, element);
591
+ return createPortal(children, element);
600
592
  };
601
593
  const name$2 = `${PKG_NAME}/Portal`;
602
- component$1.displayName = name$2;
603
- component$1.pkgName = PKG_NAME;
604
- component$1.VITUS_LABS__COMPONENT = name$2;
594
+ component$2.displayName = name$2;
595
+ component$2.pkgName = PKG_NAME;
596
+ component$2.VITUS_LABS__COMPONENT = name$2;
605
597
 
606
598
  const context = createContext({});
607
599
  const useOverlayContext = () => useContext(context);
@@ -613,11 +605,11 @@ align = 'bottom', // * main align prop * top | left | bottom | right
613
605
  position = 'fixed', // absolute | fixed | relative | static
614
606
  alignX = 'left', // left | center | right
615
607
  alignY = 'bottom', // top | center | bottom
616
- offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc = true, disabled, }) => {
608
+ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc = true, disabled, onOpen, onClose, }) => {
617
609
  const { rootSize } = useContext(context$1);
618
610
  const ctx = useOverlayContext();
619
611
  const [blocked, handleBlocked] = useState(false);
620
- const [visible, setVisible] = useState(isOpen);
612
+ const [active, handleActive] = useState(isOpen);
621
613
  const [innerAlign, setInnerAlign] = useState(align);
622
614
  const [innerAlignX, setInnerAlignX] = useState(alignX);
623
615
  const [innerAlignY, setInnerAlignY] = useState(alignY);
@@ -625,100 +617,96 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
625
617
  const contentRef = useRef();
626
618
  const setBlocked = useCallback(() => handleBlocked(true), []);
627
619
  const setUnblocked = useCallback(() => handleBlocked(false), []);
620
+ const showContent = useCallback(() => {
621
+ handleActive(true);
622
+ }, []);
623
+ const hideContent = useCallback(() => {
624
+ handleActive(false);
625
+ }, []);
628
626
  // if an Overlay has an Overlay child, this will prevent closing parent child
627
+ // + calculate correct position when an Overlay is opened
629
628
  useEffect(() => {
630
- if (visible && ctx?.setBlocked)
631
- ctx.setBlocked();
632
- else if (!visible && ctx?.setUnblocked)
633
- ctx.setUnblocked();
634
- }, [visible]);
635
- // calculate correct position when an Overlay is opened
636
- useEffect(() => {
637
- if (visible)
629
+ if (active) {
638
630
  calculateContentPosition();
639
- }, [visible]);
640
- // handles calculationg correct position of content
631
+ if (ctx?.setBlocked)
632
+ ctx.setBlocked();
633
+ if (onOpen)
634
+ onOpen();
635
+ }
636
+ else {
637
+ if (ctx?.setUnblocked)
638
+ ctx.setUnblocked();
639
+ if (onClose)
640
+ onClose();
641
+ }
642
+ }, [active]);
643
+ // handles calculating correct position of content
641
644
  // on document events (or custom scroll if set)
642
645
  useEffect(() => {
643
- if (visible) {
644
- window.addEventListener('resize', handleContentPosition, false);
645
- window.addEventListener('scroll', handleContentPosition, false);
646
- if (customScrollListener) {
647
- customScrollListener.addEventListener('scroll', handleContentPosition, false);
648
- }
649
- }
646
+ if (!active)
647
+ return undefined;
648
+ window.addEventListener('resize', handleContentPosition, false);
649
+ window.addEventListener('scroll', handleContentPosition, false);
650
650
  return () => {
651
651
  window.removeEventListener('resize', handleContentPosition, false);
652
652
  window.removeEventListener('scroll', handleContentPosition, false);
653
- if (customScrollListener) {
654
- customScrollListener.removeEventListener('scroll', handleContentPosition, false);
655
- }
656
653
  };
657
- }, [visible, customScrollListener]);
654
+ }, [active, customScrollListener]);
658
655
  // make sure scrolling is blocked in case of modal windows or when
659
656
  // customScroll is set
660
657
  useEffect(() => {
661
658
  return () => {
662
659
  };
663
- }, [visible, type, customScrollListener]);
660
+ }, [active, type, customScrollListener]);
661
+ // only when content is active handle closing
664
662
  useEffect(() => {
665
- // enable overlay manipulation only when the state is NOT blocked=true
666
- // nor in disabled state
667
- if (!blocked || !disabled) {
668
- if (openOn === 'click' ||
669
- closeOn === 'click' ||
670
- closeOn === 'clickOnTrigger' ||
671
- closeOn === 'clickOutsideContent') {
672
- window.addEventListener('click', handleVisibilityByEventType, false);
673
- }
674
- if (openOn === 'hover' || closeOn === 'hover') {
675
- window.addEventListener('mousemove', handleMouseMove, false);
676
- }
677
- // only when content is visible
678
- if (visible) {
679
- if (customScrollListener) {
680
- customScrollListener.addEventListener('scroll', handleMouseMove, false);
681
- }
682
- window.addEventListener('scroll', handleMouseMove, false);
683
- if (closeOnEsc) {
684
- window.addEventListener('keydown', handleEscKey);
685
- }
686
- }
663
+ if (!active)
664
+ return undefined;
665
+ window.addEventListener('scroll', handleVisibility, false);
666
+ if (closeOnEsc) {
667
+ window.addEventListener('keydown', handleEscKey, false);
687
668
  }
688
669
  return () => {
689
- window.removeEventListener('scroll', handleMouseMove, false);
690
- window.removeEventListener('click', handleVisibilityByEventType, false);
691
- window.removeEventListener('mousemove', handleMouseMove, false);
670
+ window.removeEventListener('scroll', handleVisibility, false);
692
671
  if (closeOnEsc) {
693
- window.removeEventListener('keydown', handleEscKey);
694
- }
695
- if (customScrollListener) {
696
- customScrollListener.removeEventListener('scroll', handleMouseMove, false);
672
+ window.removeEventListener('keydown', handleEscKey, false);
697
673
  }
698
674
  };
699
- }, [openOn, closeOn, visible, blocked, disabled]);
700
- const observeTrigger = (e) => {
701
- if (e && e.target && triggerRef.current) {
702
- return (triggerRef.current.contains(e.target) || e.target === triggerRef.current);
675
+ }, [active, customScrollListener]);
676
+ useEffect(() => {
677
+ // enable overlay manipulation only when the state is NOT blocked=true
678
+ // nor in disabled state
679
+ if (blocked || disabled)
680
+ return undefined;
681
+ if (openOn === 'click' ||
682
+ closeOn === 'click' ||
683
+ closeOn === 'clickOnTrigger' ||
684
+ closeOn === 'clickOutsideContent') {
685
+ window.addEventListener('click', handleClick, false);
703
686
  }
704
- return false;
705
- };
706
- const observeContent = (e) => {
707
- if (e && e.target && contentRef.current) {
708
- return (contentRef.current.contains(e.target) || e.target === contentRef.current);
687
+ if (openOn === 'hover' || closeOn === 'hover') {
688
+ window.addEventListener('mousemove', handleVisibility, false);
689
+ }
690
+ return () => {
691
+ window.removeEventListener('click', handleClick, false);
692
+ window.removeEventListener('mousemove', handleVisibility, false);
693
+ };
694
+ }, [openOn, closeOn, blocked, disabled]);
695
+ const isNodeOrChild = (ref) => (e) => {
696
+ if (e && e.target && ref.current) {
697
+ return ref.current.contains(e.target) || e.target === ref.current;
709
698
  }
710
699
  return false;
711
700
  };
712
- const showContent = useCallback(() => {
713
- setVisible(true);
714
- }, []);
715
- const hideContent = useCallback(() => {
716
- setVisible(false);
717
- }, []);
701
+ const isTrigger = isNodeOrChild(triggerRef);
702
+ const isContent = isNodeOrChild(contentRef);
718
703
  const calculateContentPosition = () => {
719
- if (!visible)
704
+ if (!active)
720
705
  return;
721
706
  if (!triggerRef.current || !contentRef.current) {
707
+ if (process.env.NODE_ENV === 'development') {
708
+ console.warn('Cannot access `ref` of trigger or content component.');
709
+ }
722
710
  return;
723
711
  }
724
712
  const triggerDimensions = triggerRef.current.getBoundingClientRect();
@@ -839,21 +827,17 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
839
827
  contentRef.current.style.right = value([overlayPosition.right], rootSize);
840
828
  };
841
829
  const handleVisibilityByEventType = (e) => {
842
- if (!visible && !disabled) {
843
- if (openOn === 'hover' && e.type === 'mousemove') {
844
- if (observeTrigger(e)) {
845
- showContent();
846
- }
847
- }
848
- if (openOn === 'click' && e.type === 'click') {
849
- if (observeTrigger(e)) {
830
+ if (!active) {
831
+ if ((openOn === 'hover' && e.type === 'mousemove') ||
832
+ (openOn === 'click' && e.type === 'click')) {
833
+ if (isTrigger(e)) {
850
834
  showContent();
851
835
  }
852
836
  }
853
837
  }
854
- if (visible) {
838
+ if (active) {
855
839
  if (closeOn === 'hover' && e.type === 'mousemove') {
856
- if (!observeTrigger(e) && !observeContent(e)) {
840
+ if (!isTrigger(e) && !isContent(e)) {
857
841
  hideContent();
858
842
  }
859
843
  }
@@ -864,19 +848,20 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
864
848
  hideContent();
865
849
  }
866
850
  if (closeOn === 'clickOnTrigger' && e.type === 'click') {
867
- if (observeTrigger(e)) {
851
+ if (isTrigger(e)) {
868
852
  hideContent();
869
853
  }
870
854
  }
871
855
  if (closeOn === 'clickOutsideContent' && e.type === 'click') {
872
- if (!observeContent(e)) {
856
+ if (!isContent(e)) {
873
857
  hideContent();
874
858
  }
875
859
  }
876
860
  }
877
861
  };
878
862
  const handleContentPosition = throttle(calculateContentPosition, throttleDelay);
879
- const handleMouseMove = throttle(handleVisibilityByEventType, throttleDelay);
863
+ const handleClick = useCallback(handleVisibilityByEventType, []);
864
+ const handleVisibility = useCallback(throttle(handleVisibilityByEventType, throttleDelay), []);
880
865
  const handleEscKey = (e) => {
881
866
  if (e.key === 'Escape') {
882
867
  hideContent();
@@ -885,7 +870,7 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
885
870
  return {
886
871
  triggerRef,
887
872
  contentRef,
888
- active: visible,
873
+ active,
889
874
  align: innerAlign,
890
875
  alignX: innerAlignX,
891
876
  alignY: innerAlignY,
@@ -897,11 +882,12 @@ offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc
897
882
  };
898
883
  };
899
884
 
900
- const Component = ({ children, trigger, DOMLocation, triggerRefName = 'ref', contentRefName = 'ref', ...props }) => {
885
+ const component$1 = ({ children, trigger, DOMLocation, triggerRefName = 'ref', contentRefName = 'ref', ...props }) => {
901
886
  const { active, triggerRef, contentRef, showContent, hideContent, align, alignX, alignY, ...ctx } = useOverlay(props);
902
- const passHandlers = useMemo(() => props.openOn === 'manual' ||
903
- props.closeOn === 'manual' ||
904
- props.closeOn === 'clickOutsideContent', [props.openOn, props.closeOn]);
887
+ const { openOn, closeOn } = props;
888
+ const passHandlers = useMemo(() => openOn === 'manual' ||
889
+ closeOn === 'manual' ||
890
+ closeOn === 'clickOutsideContent', [openOn, closeOn]);
905
891
  return (React.createElement(React.Fragment, null,
906
892
  renderContent(trigger, {
907
893
  [triggerRefName]: triggerRef,
@@ -910,10 +896,10 @@ const Component = ({ children, trigger, DOMLocation, triggerRefName = 'ref', con
910
896
  }),
911
897
  false ));
912
898
  };
913
- const name$1 = `${PKG_NAME}/Ovelay`;
914
- Component.displayName = name$1;
915
- Component.pkgName = PKG_NAME;
916
- Component.VITUS_LABS__COMPONENT = name$1;
899
+ const name$1 = `${PKG_NAME}/Overlay`;
900
+ component$1.displayName = name$1;
901
+ component$1.pkgName = PKG_NAME;
902
+ component$1.VITUS_LABS__COMPONENT = name$1;
917
903
 
918
904
  const styles = ({ css, theme: t }) => css `
919
905
  ${t.extraStyles && extendCss(t.extraStyles)};
@@ -943,5 +929,5 @@ component.pkgName = PKG_NAME;
943
929
  component.VITUS_LABS__COMPONENT = name;
944
930
  component.isText = true;
945
931
 
946
- export { component$3 as Element, Component$2 as List, Component as Overlay, component$1 as Portal, component as Text, useOverlay, Component$1 as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
932
+ 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 };
947
933
  //# sourceMappingURL=vitus-labs-elements.native.js.map