@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
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@vitus-labs/unistyle'), require('react'), require('@vitus-labs/core'), require('react-dom')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@vitus-labs/unistyle', 'react', '@vitus-labs/core', 'react-dom'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vitusLabsElements = {}, global.unistyle, global.React, global.core, global.ReactDOM));
|
|
5
|
-
})(this, (function (exports, unistyle, React, core,
|
|
5
|
+
})(this, (function (exports, unistyle, React, core, reactDom) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
-
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
11
10
|
|
|
12
11
|
// eslint-disable-next-line import/prefer-default-export
|
|
13
12
|
const PKG_NAME = '@vitus-labs/elements';
|
|
@@ -38,7 +37,7 @@
|
|
|
38
37
|
`};
|
|
39
38
|
`};
|
|
40
39
|
|
|
41
|
-
${t.
|
|
40
|
+
${t.alignY === 'block' &&
|
|
42
41
|
css `
|
|
43
42
|
height: 100%;
|
|
44
43
|
`};
|
|
@@ -56,10 +55,7 @@
|
|
|
56
55
|
|
|
57
56
|
${t.extraStyles && unistyle.extendCss(t.extraStyles)};
|
|
58
57
|
`;
|
|
59
|
-
const platformStyles =
|
|
60
|
-
box-sizing: border-box;
|
|
61
|
-
`
|
|
62
|
-
;
|
|
58
|
+
const platformStyles = 'box-sizing: border-box;' ;
|
|
63
59
|
var Styled$2 = core.config.styled(core.config.component) `
|
|
64
60
|
position: relative;
|
|
65
61
|
${platformStyles};
|
|
@@ -80,7 +76,7 @@
|
|
|
80
76
|
})};
|
|
81
77
|
`;
|
|
82
78
|
|
|
83
|
-
const component$
|
|
79
|
+
const component$9 = React.forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
|
|
84
80
|
const debugProps = process.env.NODE_ENV !== 'production'
|
|
85
81
|
? {
|
|
86
82
|
'data-vl-element': 'Element',
|
|
@@ -94,6 +90,8 @@
|
|
|
94
90
|
};
|
|
95
91
|
const needsFix = !props.dangerouslySetInnerHTML && tag && isWebFixNeeded(tag)
|
|
96
92
|
;
|
|
93
|
+
// eslint-disable-next-line no-nested-ternary
|
|
94
|
+
const asTag = (isInline ? 'span' : 'div') ;
|
|
97
95
|
if (!needsFix || false) {
|
|
98
96
|
return (React__default["default"].createElement(Styled$2, { ...COMMON_PROPS, "$element": {
|
|
99
97
|
block,
|
|
@@ -108,7 +106,7 @@
|
|
|
108
106
|
block,
|
|
109
107
|
extraStyles: extendCss,
|
|
110
108
|
} },
|
|
111
|
-
React__default["default"].createElement(Styled$2, { as:
|
|
109
|
+
React__default["default"].createElement(Styled$2, { as: asTag, "$childFix": true, "$element": {
|
|
112
110
|
direction,
|
|
113
111
|
alignX,
|
|
114
112
|
alignY,
|
|
@@ -186,7 +184,7 @@
|
|
|
186
184
|
})};
|
|
187
185
|
`;
|
|
188
186
|
|
|
189
|
-
const component$
|
|
187
|
+
const component$7 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
|
|
190
188
|
const debugProps = process.env.NODE_ENV !== 'production'
|
|
191
189
|
? {
|
|
192
190
|
'data-vl-element': contentType,
|
|
@@ -202,7 +200,7 @@
|
|
|
202
200
|
extraStyles: extendCss,
|
|
203
201
|
}, ...debugProps, ...props }));
|
|
204
202
|
};
|
|
205
|
-
var component$
|
|
203
|
+
var component$8 = React.memo(component$7);
|
|
206
204
|
|
|
207
205
|
const INLINE_ELEMENTS = {
|
|
208
206
|
span: true,
|
|
@@ -258,35 +256,17 @@
|
|
|
258
256
|
const isInlineElement = (tag) => tag ? INLINE_ELEMENTS[tag] : false;
|
|
259
257
|
const getShouldBeEmpty = (tag) => tag ? EMPTY_ELEMENTS[tag] : false;
|
|
260
258
|
|
|
261
|
-
const
|
|
262
|
-
const
|
|
259
|
+
const defaultBeforeAfterDirection = 'inline';
|
|
260
|
+
const defaultDirection = 'rows';
|
|
263
261
|
const defaultAlignX = 'left';
|
|
264
262
|
const defaultAlignY = 'center';
|
|
265
|
-
const component$
|
|
263
|
+
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
264
|
// --------------------------------------------------------
|
|
267
265
|
// check if should render only single element
|
|
268
266
|
// --------------------------------------------------------
|
|
269
267
|
const shouldBeEmpty = !!props.dangerouslySetInnerHTML ||
|
|
270
268
|
(tag && getShouldBeEmpty(tag));
|
|
271
269
|
// --------------------------------------------------------
|
|
272
|
-
// common wrapper props
|
|
273
|
-
// --------------------------------------------------------
|
|
274
|
-
const WRAPPER_PROPS = {
|
|
275
|
-
ref: ref || innerRef,
|
|
276
|
-
extendCss: css,
|
|
277
|
-
tag,
|
|
278
|
-
block,
|
|
279
|
-
contentDirection,
|
|
280
|
-
alignX: contentAlignX,
|
|
281
|
-
alignY: contentAlignY,
|
|
282
|
-
as: undefined, // reset styled-components `as` prop
|
|
283
|
-
};
|
|
284
|
-
// --------------------------------------------------------
|
|
285
|
-
// return simple/empty element like input
|
|
286
|
-
// --------------------------------------------------------
|
|
287
|
-
if (shouldBeEmpty)
|
|
288
|
-
return React__default["default"].createElement(component$6, { ...WRAPPER_PROPS, ...props });
|
|
289
|
-
// --------------------------------------------------------
|
|
290
270
|
// if not single element, calculate values
|
|
291
271
|
// --------------------------------------------------------
|
|
292
272
|
const isSimpleElement = !beforeContent && !afterContent;
|
|
@@ -296,8 +276,8 @@
|
|
|
296
276
|
// --------------------------------------------------------
|
|
297
277
|
// direction & alignX & alignY calculations
|
|
298
278
|
// --------------------------------------------------------
|
|
299
|
-
const
|
|
300
|
-
let wrapperDirection;
|
|
279
|
+
const { wrapperDirection, wrapperAlignX, wrapperAlignY } = React.useMemo(() => {
|
|
280
|
+
let wrapperDirection = direction;
|
|
301
281
|
let wrapperAlignX = alignX;
|
|
302
282
|
let wrapperAlignY = alignY;
|
|
303
283
|
if (isSimpleElement) {
|
|
@@ -320,21 +300,39 @@
|
|
|
320
300
|
contentDirection,
|
|
321
301
|
contentAlignX,
|
|
322
302
|
contentAlignY,
|
|
303
|
+
alignX,
|
|
304
|
+
alignY,
|
|
323
305
|
direction,
|
|
324
306
|
]);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
307
|
+
// --------------------------------------------------------
|
|
308
|
+
// common wrapper props
|
|
309
|
+
// --------------------------------------------------------
|
|
310
|
+
const WRAPPER_PROPS = {
|
|
311
|
+
ref: ref || innerRef,
|
|
312
|
+
extendCss: css,
|
|
313
|
+
tag,
|
|
314
|
+
block,
|
|
315
|
+
direction: wrapperDirection,
|
|
316
|
+
alignX: wrapperAlignX,
|
|
317
|
+
alignY: wrapperAlignY,
|
|
318
|
+
as: undefined, // reset styled-components `as` prop
|
|
319
|
+
};
|
|
320
|
+
// --------------------------------------------------------
|
|
321
|
+
// return simple/empty element like input or image etc.
|
|
322
|
+
// --------------------------------------------------------
|
|
323
|
+
if (shouldBeEmpty) {
|
|
324
|
+
return React__default["default"].createElement(component$9, { ...props, ...WRAPPER_PROPS });
|
|
325
|
+
}
|
|
326
|
+
const contentRenderOutput = core.renderContent(CHILDREN);
|
|
327
|
+
return (React__default["default"].createElement(component$9, { ...props, ...WRAPPER_PROPS, isInline: isInline },
|
|
328
|
+
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))),
|
|
329
|
+
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)),
|
|
330
|
+
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)))));
|
|
333
331
|
});
|
|
334
332
|
const name$4 = `${PKG_NAME}/Element`;
|
|
335
|
-
component$
|
|
336
|
-
component$
|
|
337
|
-
component$
|
|
333
|
+
component$6.displayName = name$4;
|
|
334
|
+
component$6.pkgName = PKG_NAME;
|
|
335
|
+
component$6.VITUS_LABS__COMPONENT = name$4;
|
|
338
336
|
|
|
339
337
|
/* eslint-disable no-param-reassign */
|
|
340
338
|
const isNumber = (a, b) => Number.isInteger(a) && Number.isInteger(b);
|
|
@@ -399,15 +397,16 @@
|
|
|
399
397
|
position,
|
|
400
398
|
};
|
|
401
399
|
};
|
|
402
|
-
const component$
|
|
400
|
+
const component$5 = (props) => {
|
|
403
401
|
const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps, } = props;
|
|
404
|
-
const renderedElement =
|
|
405
|
-
const injectItemProps = typeof itemProps === 'function'
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
402
|
+
const renderedElement = core.renderContent;
|
|
403
|
+
const injectItemProps = React.useMemo(() => (typeof itemProps === 'function' ? itemProps : () => itemProps), [itemProps]);
|
|
404
|
+
const injectWrapItemProps = React.useMemo(() => (typeof wrapProps === 'function' ? wrapProps : () => wrapProps), [wrapProps]);
|
|
405
|
+
const getKey = React.useCallback((item, index) => {
|
|
406
|
+
if (typeof itemKey === 'function')
|
|
407
|
+
return itemKey(item, index);
|
|
408
|
+
return index;
|
|
409
|
+
}, []);
|
|
411
410
|
// --------------------------------------------------------
|
|
412
411
|
// render children
|
|
413
412
|
// --------------------------------------------------------
|
|
@@ -441,18 +440,11 @@
|
|
|
441
440
|
// render array of strings or numbers
|
|
442
441
|
// --------------------------------------------------------
|
|
443
442
|
const renderSimpleArray = (data) => {
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
// if it's empty
|
|
448
|
-
if (renderData.length === 0)
|
|
443
|
+
const { length } = data;
|
|
444
|
+
// if the data array is empty
|
|
445
|
+
if (data.length === 0)
|
|
449
446
|
return null;
|
|
450
|
-
|
|
451
|
-
if (typeof itemKey === 'function')
|
|
452
|
-
return itemKey(item, index);
|
|
453
|
-
return index;
|
|
454
|
-
};
|
|
455
|
-
return renderData.map((item, i) => {
|
|
447
|
+
return data.map((item, i) => {
|
|
456
448
|
const key = getKey(item, i);
|
|
457
449
|
const keyName = valueName || 'children';
|
|
458
450
|
const extendedProps = attachItemProps({
|
|
@@ -526,11 +518,11 @@
|
|
|
526
518
|
// render props component + data
|
|
527
519
|
// --------------------------------------------------------
|
|
528
520
|
if (component && Array.isArray(data)) {
|
|
529
|
-
const clearData = data.filter((item) => item !== null && item !== undefined);
|
|
530
|
-
const isSimpleArray = clearData.every((item) => typeof item === 'string' || typeof item === 'number');
|
|
521
|
+
const clearData = React.useMemo(() => data.filter((item) => item !== null && item !== undefined), [data]);
|
|
522
|
+
const isSimpleArray = React.useMemo(() => clearData.every((item) => typeof item === 'string' || typeof item === 'number'), [clearData]);
|
|
531
523
|
if (isSimpleArray)
|
|
532
524
|
return renderSimpleArray(clearData);
|
|
533
|
-
const isComplexArray = clearData.every((item) => typeof item === 'object');
|
|
525
|
+
const isComplexArray = React.useMemo(() => clearData.every((item) => typeof item === 'object'), [clearData]);
|
|
534
526
|
if (isComplexArray)
|
|
535
527
|
return renderComplexArray(clearData);
|
|
536
528
|
return null;
|
|
@@ -543,19 +535,19 @@
|
|
|
543
535
|
};
|
|
544
536
|
return renderItems();
|
|
545
537
|
};
|
|
546
|
-
component$
|
|
547
|
-
component$
|
|
538
|
+
component$5.isIterator = true;
|
|
539
|
+
component$5.RESERVED_PROPS = RESERVED_PROPS;
|
|
548
540
|
|
|
549
|
-
const
|
|
550
|
-
const renderedList = React__default["default"].createElement(component$
|
|
541
|
+
const component$4 = React.forwardRef(({ rootElement = false, ...props }, ref) => {
|
|
542
|
+
const renderedList = React__default["default"].createElement(component$5, { ...core.pick(props, component$5.RESERVED_PROPS) });
|
|
551
543
|
if (!rootElement)
|
|
552
544
|
return renderedList;
|
|
553
|
-
return (React__default["default"].createElement(component$
|
|
545
|
+
return (React__default["default"].createElement(component$6, { ref: ref, ...core.omit(props, component$5.RESERVED_PROPS) }, renderedList));
|
|
554
546
|
});
|
|
555
547
|
const name$3 = `${PKG_NAME}/List`;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
548
|
+
component$4.displayName = name$3;
|
|
549
|
+
component$4.pkgName = PKG_NAME;
|
|
550
|
+
component$4.VITUS_LABS__COMPONENT = name$3;
|
|
559
551
|
|
|
560
552
|
const RESERVED_KEYS = [
|
|
561
553
|
'type',
|
|
@@ -563,7 +555,7 @@
|
|
|
563
555
|
'itemProps',
|
|
564
556
|
'activeItemRequired',
|
|
565
557
|
];
|
|
566
|
-
const
|
|
558
|
+
const component$3 = (WrappedComponent) => {
|
|
567
559
|
const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
568
560
|
const Enhanced = (props) => {
|
|
569
561
|
const { type = 'single', activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
|
|
@@ -682,23 +674,23 @@
|
|
|
682
674
|
return React__default["default"].createElement(WrappedComponent, { ...rest, itemProps: attachItemProps });
|
|
683
675
|
};
|
|
684
676
|
Enhanced.RESERVED_KEYS = RESERVED_KEYS;
|
|
685
|
-
Enhanced.displayName =
|
|
677
|
+
Enhanced.displayName = `@vitus-labs/elements/List/withActiveState(${displayName})`;
|
|
686
678
|
return Enhanced;
|
|
687
679
|
};
|
|
688
680
|
|
|
689
|
-
const component$
|
|
681
|
+
const component$2 = ({ position = undefined, tag = 'div', children, }) => {
|
|
690
682
|
const [element] = React.useState(undefined);
|
|
691
683
|
if (!position || !element)
|
|
692
684
|
return null;
|
|
693
685
|
React.useEffect(() => {
|
|
694
686
|
return undefined;
|
|
695
687
|
}, []);
|
|
696
|
-
return
|
|
688
|
+
return reactDom.createPortal(children, element);
|
|
697
689
|
};
|
|
698
690
|
const name$2 = `${PKG_NAME}/Portal`;
|
|
699
|
-
component$
|
|
700
|
-
component$
|
|
701
|
-
component$
|
|
691
|
+
component$2.displayName = name$2;
|
|
692
|
+
component$2.pkgName = PKG_NAME;
|
|
693
|
+
component$2.VITUS_LABS__COMPONENT = name$2;
|
|
702
694
|
|
|
703
695
|
const context = React.createContext({});
|
|
704
696
|
const useOverlayContext = () => React.useContext(context);
|
|
@@ -710,11 +702,11 @@
|
|
|
710
702
|
position = 'fixed', // absolute | fixed | relative | static
|
|
711
703
|
alignX = 'left', // left | center | right
|
|
712
704
|
alignY = 'bottom', // top | center | bottom
|
|
713
|
-
offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc = true, disabled, }) => {
|
|
705
|
+
offsetX = 0, offsetY = 0, throttleDelay = 200, customScrollListener, closeOnEsc = true, disabled, onOpen, onClose, }) => {
|
|
714
706
|
const { rootSize } = React.useContext(core.context);
|
|
715
707
|
const ctx = useOverlayContext();
|
|
716
708
|
const [blocked, handleBlocked] = React.useState(false);
|
|
717
|
-
const [
|
|
709
|
+
const [active, handleActive] = React.useState(isOpen);
|
|
718
710
|
const [innerAlign, setInnerAlign] = React.useState(align);
|
|
719
711
|
const [innerAlignX, setInnerAlignX] = React.useState(alignX);
|
|
720
712
|
const [innerAlignY, setInnerAlignY] = React.useState(alignY);
|
|
@@ -722,100 +714,96 @@
|
|
|
722
714
|
const contentRef = React.useRef();
|
|
723
715
|
const setBlocked = React.useCallback(() => handleBlocked(true), []);
|
|
724
716
|
const setUnblocked = React.useCallback(() => handleBlocked(false), []);
|
|
717
|
+
const showContent = React.useCallback(() => {
|
|
718
|
+
handleActive(true);
|
|
719
|
+
}, []);
|
|
720
|
+
const hideContent = React.useCallback(() => {
|
|
721
|
+
handleActive(false);
|
|
722
|
+
}, []);
|
|
725
723
|
// if an Overlay has an Overlay child, this will prevent closing parent child
|
|
724
|
+
// + calculate correct position when an Overlay is opened
|
|
726
725
|
React.useEffect(() => {
|
|
727
|
-
if (
|
|
728
|
-
ctx.setBlocked();
|
|
729
|
-
else if (!visible && ctx?.setUnblocked)
|
|
730
|
-
ctx.setUnblocked();
|
|
731
|
-
}, [visible]);
|
|
732
|
-
// calculate correct position when an Overlay is opened
|
|
733
|
-
React.useEffect(() => {
|
|
734
|
-
if (visible)
|
|
726
|
+
if (active) {
|
|
735
727
|
calculateContentPosition();
|
|
736
|
-
|
|
737
|
-
|
|
728
|
+
if (ctx?.setBlocked)
|
|
729
|
+
ctx.setBlocked();
|
|
730
|
+
if (onOpen)
|
|
731
|
+
onOpen();
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
if (ctx?.setUnblocked)
|
|
735
|
+
ctx.setUnblocked();
|
|
736
|
+
if (onClose)
|
|
737
|
+
onClose();
|
|
738
|
+
}
|
|
739
|
+
}, [active]);
|
|
740
|
+
// handles calculating correct position of content
|
|
738
741
|
// on document events (or custom scroll if set)
|
|
739
742
|
React.useEffect(() => {
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
customScrollListener.addEventListener('scroll', handleContentPosition, false);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
743
|
+
if (!active)
|
|
744
|
+
return undefined;
|
|
745
|
+
window.addEventListener('resize', handleContentPosition, false);
|
|
746
|
+
window.addEventListener('scroll', handleContentPosition, false);
|
|
747
747
|
return () => {
|
|
748
748
|
window.removeEventListener('resize', handleContentPosition, false);
|
|
749
749
|
window.removeEventListener('scroll', handleContentPosition, false);
|
|
750
|
-
if (customScrollListener) {
|
|
751
|
-
customScrollListener.removeEventListener('scroll', handleContentPosition, false);
|
|
752
|
-
}
|
|
753
750
|
};
|
|
754
|
-
}, [
|
|
751
|
+
}, [active, customScrollListener]);
|
|
755
752
|
// make sure scrolling is blocked in case of modal windows or when
|
|
756
753
|
// customScroll is set
|
|
757
754
|
React.useEffect(() => {
|
|
758
755
|
return () => {
|
|
759
756
|
};
|
|
760
|
-
}, [
|
|
757
|
+
}, [active, type, customScrollListener]);
|
|
758
|
+
// only when content is active handle closing
|
|
761
759
|
React.useEffect(() => {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
closeOn === 'clickOnTrigger' ||
|
|
768
|
-
closeOn === 'clickOutsideContent') {
|
|
769
|
-
window.addEventListener('click', handleVisibilityByEventType, false);
|
|
770
|
-
}
|
|
771
|
-
if (openOn === 'hover' || closeOn === 'hover') {
|
|
772
|
-
window.addEventListener('mousemove', handleMouseMove, false);
|
|
773
|
-
}
|
|
774
|
-
// only when content is visible
|
|
775
|
-
if (visible) {
|
|
776
|
-
if (customScrollListener) {
|
|
777
|
-
customScrollListener.addEventListener('scroll', handleMouseMove, false);
|
|
778
|
-
}
|
|
779
|
-
window.addEventListener('scroll', handleMouseMove, false);
|
|
780
|
-
if (closeOnEsc) {
|
|
781
|
-
window.addEventListener('keydown', handleEscKey);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
760
|
+
if (!active)
|
|
761
|
+
return undefined;
|
|
762
|
+
window.addEventListener('scroll', handleVisibility, false);
|
|
763
|
+
if (closeOnEsc) {
|
|
764
|
+
window.addEventListener('keydown', handleEscKey, false);
|
|
784
765
|
}
|
|
785
766
|
return () => {
|
|
786
|
-
window.removeEventListener('scroll',
|
|
787
|
-
window.removeEventListener('click', handleVisibilityByEventType, false);
|
|
788
|
-
window.removeEventListener('mousemove', handleMouseMove, false);
|
|
767
|
+
window.removeEventListener('scroll', handleVisibility, false);
|
|
789
768
|
if (closeOnEsc) {
|
|
790
|
-
window.removeEventListener('keydown', handleEscKey);
|
|
791
|
-
}
|
|
792
|
-
if (customScrollListener) {
|
|
793
|
-
customScrollListener.removeEventListener('scroll', handleMouseMove, false);
|
|
769
|
+
window.removeEventListener('keydown', handleEscKey, false);
|
|
794
770
|
}
|
|
795
771
|
};
|
|
796
|
-
}, [
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
772
|
+
}, [active, customScrollListener]);
|
|
773
|
+
React.useEffect(() => {
|
|
774
|
+
// enable overlay manipulation only when the state is NOT blocked=true
|
|
775
|
+
// nor in disabled state
|
|
776
|
+
if (blocked || disabled)
|
|
777
|
+
return undefined;
|
|
778
|
+
if (openOn === 'click' ||
|
|
779
|
+
closeOn === 'click' ||
|
|
780
|
+
closeOn === 'clickOnTrigger' ||
|
|
781
|
+
closeOn === 'clickOutsideContent') {
|
|
782
|
+
window.addEventListener('click', handleClick, false);
|
|
800
783
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
784
|
+
if (openOn === 'hover' || closeOn === 'hover') {
|
|
785
|
+
window.addEventListener('mousemove', handleVisibility, false);
|
|
786
|
+
}
|
|
787
|
+
return () => {
|
|
788
|
+
window.removeEventListener('click', handleClick, false);
|
|
789
|
+
window.removeEventListener('mousemove', handleVisibility, false);
|
|
790
|
+
};
|
|
791
|
+
}, [openOn, closeOn, blocked, disabled]);
|
|
792
|
+
const isNodeOrChild = (ref) => (e) => {
|
|
793
|
+
if (e && e.target && ref.current) {
|
|
794
|
+
return ref.current.contains(e.target) || e.target === ref.current;
|
|
806
795
|
}
|
|
807
796
|
return false;
|
|
808
797
|
};
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
}, []);
|
|
812
|
-
const hideContent = React.useCallback(() => {
|
|
813
|
-
setVisible(false);
|
|
814
|
-
}, []);
|
|
798
|
+
const isTrigger = isNodeOrChild(triggerRef);
|
|
799
|
+
const isContent = isNodeOrChild(contentRef);
|
|
815
800
|
const calculateContentPosition = () => {
|
|
816
|
-
if (!
|
|
801
|
+
if (!active)
|
|
817
802
|
return;
|
|
818
803
|
if (!triggerRef.current || !contentRef.current) {
|
|
804
|
+
if (process.env.NODE_ENV === 'development') {
|
|
805
|
+
console.warn('Cannot access `ref` of trigger or content component.');
|
|
806
|
+
}
|
|
819
807
|
return;
|
|
820
808
|
}
|
|
821
809
|
const triggerDimensions = triggerRef.current.getBoundingClientRect();
|
|
@@ -936,21 +924,17 @@
|
|
|
936
924
|
contentRef.current.style.right = unistyle.value([overlayPosition.right], rootSize);
|
|
937
925
|
};
|
|
938
926
|
const handleVisibilityByEventType = (e) => {
|
|
939
|
-
if (!
|
|
940
|
-
if (openOn === 'hover' && e.type === 'mousemove')
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
if (openOn === 'click' && e.type === 'click') {
|
|
946
|
-
if (observeTrigger(e)) {
|
|
927
|
+
if (!active) {
|
|
928
|
+
if ((openOn === 'hover' && e.type === 'mousemove') ||
|
|
929
|
+
(openOn === 'click' && e.type === 'click')) {
|
|
930
|
+
if (isTrigger(e)) {
|
|
947
931
|
showContent();
|
|
948
932
|
}
|
|
949
933
|
}
|
|
950
934
|
}
|
|
951
|
-
if (
|
|
935
|
+
if (active) {
|
|
952
936
|
if (closeOn === 'hover' && e.type === 'mousemove') {
|
|
953
|
-
if (!
|
|
937
|
+
if (!isTrigger(e) && !isContent(e)) {
|
|
954
938
|
hideContent();
|
|
955
939
|
}
|
|
956
940
|
}
|
|
@@ -961,19 +945,20 @@
|
|
|
961
945
|
hideContent();
|
|
962
946
|
}
|
|
963
947
|
if (closeOn === 'clickOnTrigger' && e.type === 'click') {
|
|
964
|
-
if (
|
|
948
|
+
if (isTrigger(e)) {
|
|
965
949
|
hideContent();
|
|
966
950
|
}
|
|
967
951
|
}
|
|
968
952
|
if (closeOn === 'clickOutsideContent' && e.type === 'click') {
|
|
969
|
-
if (!
|
|
953
|
+
if (!isContent(e)) {
|
|
970
954
|
hideContent();
|
|
971
955
|
}
|
|
972
956
|
}
|
|
973
957
|
}
|
|
974
958
|
};
|
|
975
959
|
const handleContentPosition = core.throttle(calculateContentPosition, throttleDelay);
|
|
976
|
-
const
|
|
960
|
+
const handleClick = React.useCallback(handleVisibilityByEventType, []);
|
|
961
|
+
const handleVisibility = React.useCallback(core.throttle(handleVisibilityByEventType, throttleDelay), []);
|
|
977
962
|
const handleEscKey = (e) => {
|
|
978
963
|
if (e.key === 'Escape') {
|
|
979
964
|
hideContent();
|
|
@@ -982,7 +967,7 @@
|
|
|
982
967
|
return {
|
|
983
968
|
triggerRef,
|
|
984
969
|
contentRef,
|
|
985
|
-
active
|
|
970
|
+
active,
|
|
986
971
|
align: innerAlign,
|
|
987
972
|
alignX: innerAlignX,
|
|
988
973
|
alignY: innerAlignY,
|
|
@@ -994,11 +979,12 @@
|
|
|
994
979
|
};
|
|
995
980
|
};
|
|
996
981
|
|
|
997
|
-
const
|
|
982
|
+
const component$1 = ({ children, trigger, DOMLocation, triggerRefName = 'ref', contentRefName = 'ref', ...props }) => {
|
|
998
983
|
const { active, triggerRef, contentRef, showContent, hideContent, align, alignX, alignY, ...ctx } = useOverlay(props);
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
|
|
984
|
+
const { openOn, closeOn } = props;
|
|
985
|
+
const passHandlers = React.useMemo(() => openOn === 'manual' ||
|
|
986
|
+
closeOn === 'manual' ||
|
|
987
|
+
closeOn === 'clickOutsideContent', [openOn, closeOn]);
|
|
1002
988
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
1003
989
|
core.renderContent(trigger, {
|
|
1004
990
|
[triggerRefName]: triggerRef,
|
|
@@ -1007,10 +993,10 @@
|
|
|
1007
993
|
}),
|
|
1008
994
|
false ));
|
|
1009
995
|
};
|
|
1010
|
-
const name$1 = `${PKG_NAME}/
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
996
|
+
const name$1 = `${PKG_NAME}/Overlay`;
|
|
997
|
+
component$1.displayName = name$1;
|
|
998
|
+
component$1.pkgName = PKG_NAME;
|
|
999
|
+
component$1.VITUS_LABS__COMPONENT = name$1;
|
|
1014
1000
|
|
|
1015
1001
|
const styles = ({ css, theme: t }) => css `
|
|
1016
1002
|
${t.extraStyles && unistyle.extendCss(t.extraStyles)};
|
|
@@ -1044,13 +1030,13 @@
|
|
|
1044
1030
|
enumerable: true,
|
|
1045
1031
|
get: function () { return unistyle.Provider; }
|
|
1046
1032
|
});
|
|
1047
|
-
exports.Element = component$
|
|
1048
|
-
exports.List =
|
|
1049
|
-
exports.Overlay =
|
|
1050
|
-
exports.Portal = component$
|
|
1033
|
+
exports.Element = component$6;
|
|
1034
|
+
exports.List = component$4;
|
|
1035
|
+
exports.Overlay = component$1;
|
|
1036
|
+
exports.Portal = component$2;
|
|
1051
1037
|
exports.Text = component;
|
|
1052
1038
|
exports.useOverlay = useOverlay;
|
|
1053
|
-
exports.withActiveState =
|
|
1039
|
+
exports.withActiveState = component$3;
|
|
1054
1040
|
exports.withEqualSizeBeforeAfter = withEqualBeforeAfter;
|
|
1055
1041
|
|
|
1056
1042
|
Object.defineProperty(exports, '__esModule', { value: true });
|