@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.
- package/lib/analysis/vitus-labs-elements.browser.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.module.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.native.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.umd.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.umd.min.js.html +1 -1
- package/lib/index.d.ts +16 -7
- package/lib/types/Element/component.d.ts +2 -3
- package/lib/types/Element/index.d.ts +2 -2
- package/lib/types/Element/types.d.ts +9 -1
- package/lib/types/List/component.d.ts +4 -4
- package/lib/types/List/withActiveState.d.ts +2 -2
- package/lib/types/Overlay/component.d.ts +2 -2
- package/lib/types/Overlay/useOverlay.d.ts +3 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/vitus-labs-elements.browser.js +180 -179
- package/lib/vitus-labs-elements.browser.js.map +1 -1
- package/lib/vitus-labs-elements.js +164 -178
- package/lib/vitus-labs-elements.js.map +1 -1
- package/lib/vitus-labs-elements.module.js +161 -174
- package/lib/vitus-labs-elements.module.js.map +1 -1
- package/lib/vitus-labs-elements.native.js +157 -171
- package/lib/vitus-labs-elements.native.js.map +1 -1
- package/lib/vitus-labs-elements.umd.js +164 -178
- package/lib/vitus-labs-elements.umd.js.map +1 -1
- package/lib/vitus-labs-elements.umd.min.js +6 -8
- package/lib/vitus-labs-elements.umd.min.js.map +1 -1
- package/package.json +9 -9
|
@@ -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
|
|
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
|
|
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 =
|
|
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$
|
|
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$
|
|
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$
|
|
157
|
+
var component$8 = memo(component$7);
|
|
160
158
|
|
|
161
|
-
const
|
|
162
|
-
const
|
|
159
|
+
const defaultBeforeAfterDirection = 'inline';
|
|
160
|
+
const defaultDirection = 'rows';
|
|
163
161
|
const defaultAlignX = 'left';
|
|
164
162
|
const defaultAlignY = 'center';
|
|
165
|
-
const component$
|
|
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
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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$
|
|
236
|
-
component$
|
|
237
|
-
component$
|
|
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$
|
|
300
|
+
const component$5 = (props) => {
|
|
303
301
|
const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
|
|
304
|
-
const renderedElement =
|
|
305
|
-
const injectItemProps = typeof itemProps === 'function'
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
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$
|
|
447
|
-
component$
|
|
438
|
+
component$5.isIterator = true;
|
|
439
|
+
component$5.RESERVED_PROPS = RESERVED_PROPS;
|
|
448
440
|
|
|
449
|
-
const
|
|
450
|
-
const renderedList = React.createElement(component$
|
|
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$
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
|
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 =
|
|
577
|
+
Enhanced.displayName = `@vitus-labs/elements/List/withActiveState(${displayName})`;
|
|
586
578
|
return Enhanced;
|
|
587
579
|
};
|
|
588
580
|
|
|
589
|
-
const component$
|
|
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
|
|
591
|
+
return createPortal(children, element);
|
|
600
592
|
};
|
|
601
593
|
const name$2 = `${PKG_NAME}/Portal`;
|
|
602
|
-
component$
|
|
603
|
-
component$
|
|
604
|
-
component$
|
|
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 [
|
|
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 (
|
|
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
|
-
|
|
640
|
-
|
|
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 (
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
}, [
|
|
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
|
-
}, [
|
|
660
|
+
}, [active, type, customScrollListener]);
|
|
661
|
+
// only when content is active handle closing
|
|
664
662
|
useEffect(() => {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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',
|
|
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
|
-
}, [
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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
|
|
713
|
-
|
|
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 (!
|
|
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 (!
|
|
843
|
-
if (openOn === 'hover' && e.type === 'mousemove')
|
|
844
|
-
|
|
845
|
-
|
|
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 (
|
|
838
|
+
if (active) {
|
|
855
839
|
if (closeOn === 'hover' && e.type === 'mousemove') {
|
|
856
|
-
if (!
|
|
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 (
|
|
851
|
+
if (isTrigger(e)) {
|
|
868
852
|
hideContent();
|
|
869
853
|
}
|
|
870
854
|
}
|
|
871
855
|
if (closeOn === 'clickOutsideContent' && e.type === 'click') {
|
|
872
|
-
if (!
|
|
856
|
+
if (!isContent(e)) {
|
|
873
857
|
hideContent();
|
|
874
858
|
}
|
|
875
859
|
}
|
|
876
860
|
}
|
|
877
861
|
};
|
|
878
862
|
const handleContentPosition = throttle(calculateContentPosition, throttleDelay);
|
|
879
|
-
const
|
|
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
|
|
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
|
|
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
|
|
903
|
-
|
|
904
|
-
|
|
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}/
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
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$
|
|
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
|