@via-profit/ui-kit 0.1.8 → 0.2.1-alpha.3
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/Accordion/index.d.ts +4 -4
- package/Autocomplete/AutocompleteContainer.d.ts +34 -7
- package/Autocomplete/AutocompleteContainer.js +28 -24
- package/Autocomplete/AutocompleteItem.d.ts +1 -1
- package/Autocomplete/AutocompleteTextField.d.ts +3 -0
- package/Autocomplete/AutocompleteTextField.js +63 -1
- package/Autocomplete/OverrideMenuList.d.ts +4 -0
- package/Autocomplete/OverrideMenuList.js +39 -0
- package/Autocomplete/context.d.ts +9 -1
- package/Autocomplete/context.js +15 -1
- package/Autocomplete/index.js +9 -10
- package/Autocomplete2/Autocomplete2.d.ts +12 -0
- package/Autocomplete2/Autocomplete2.js +83 -0
- package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
- package/Autocomplete2/Autocomplete2TextField.js +39 -0
- package/Autocomplete2/index.d.ts +2 -0
- package/Autocomplete2/index.js +7 -0
- package/Avatar/AvatarBase.d.ts +4 -4
- package/Avatar/index.js +1 -1
- package/Badge/BadgeBase.d.ts +4 -4
- package/Badge/BadgeDeleteButton.js +6 -6
- package/Badge/BadgeOutlined.js +2 -2
- package/Badge/BadgeStandard.js +1 -1
- package/Button/ButtonBase.d.ts +3 -3
- package/Button/ButtonOutlined.js +1 -1
- package/Button/ButtonPlain.js +1 -1
- package/Button/ButtonStandard.js +4 -11
- package/Calendar/CalendarCell.js +22 -4
- package/Calendar/CalendarComponent.d.ts +226 -0
- package/Calendar/CalendarComponent.js +572 -0
- package/Calendar/CalendarControlButton.js +16 -9
- package/Calendar/CalendarDayBadge.js +1 -1
- package/Calendar/CalendarEmptyCell.d.ts +2 -2
- package/Calendar/CalendarEmptyCell.js +8 -3
- package/Calendar/CalendarHeading.js +2 -1
- package/Calendar/CalendarMonthCell.js +0 -5
- package/Calendar/CalendarSubheading.js +3 -2
- package/Calendar/CalendarWeekDayCell.d.ts +10 -0
- package/Calendar/CalendarWeekDayCell.js +32 -0
- package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
- package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
- package/Calendar/CalendarWeekRow.d.ts +2 -2
- package/Calendar/CalendarWeekRow.js +2 -1
- package/Calendar/CalendarWeekRowButton.d.ts +13 -0
- package/Calendar/CalendarWeekRowButton.js +31 -0
- package/Calendar/CalendarYearCell.js +5 -5
- package/Calendar/CalendarYearsSelector.d.ts +39 -1
- package/Calendar/CalendarYearsSelector.js +52 -16
- package/Calendar/IconChevronDown.d.ts +3 -0
- package/Calendar/IconChevronDown.js +31 -0
- package/Calendar/index.d.ts +7 -220
- package/Calendar/index.js +19 -274
- package/Calendar/use-calendar.d.ts +1 -1
- package/Calendar/use-calendar.js +102 -155
- package/Color/Color.d.ts +138 -0
- package/Color/Color.js +324 -0
- package/Color/ColorGenerator.d.ts +29 -0
- package/Color/ColorGenerator.js +141 -0
- package/Color/ColorParser.d.ts +20 -0
- package/Color/ColorParser.js +284 -0
- package/Color/index.d.ts +4 -122
- package/Color/index.js +18 -473
- package/DatePicker/index.d.ts +2 -17
- package/DatePicker/index.js +47 -61
- package/DatePicker/useDatePickerFormat.js +5 -5
- package/ErrorBoundary/Fallback.d.ts +3 -0
- package/ErrorBoundary/Fallback.js +51 -0
- package/ErrorBoundary/RenderError.d.ts +6 -0
- package/ErrorBoundary/RenderError.js +80 -0
- package/ErrorBoundary/index.d.ts +7 -11
- package/ErrorBoundary/index.js +4 -51
- package/Highlighted/index.d.ts +3 -3
- package/LoadingIndicator/Spinner.d.ts +5 -3
- package/LoadingIndicator/Spinner.js +61 -32
- package/LoadingIndicator/index.d.ts +3 -3
- package/LoadingIndicator/index.js +15 -2
- package/MaskedField/index.d.ts +1 -1
- package/MaskedField/index.js +11 -10
- package/Menu/AutoHeightWrapper.d.ts +6 -0
- package/Menu/AutoHeightWrapper.js +43 -0
- package/Menu/MeasuredItem.d.ts +10 -0
- package/Menu/MeasuredItem.js +51 -0
- package/Menu/MenuContainer.d.ts +53 -20
- package/Menu/MenuContainer.js +18 -11
- package/Menu/MenuItem.d.ts +24 -7
- package/Menu/MenuItem.js +13 -6
- package/Menu/MenuList.d.ts +4 -2
- package/Menu/MenuList.js +26 -6
- package/Menu/VirtualizedItem.d.ts +22 -0
- package/Menu/VirtualizedItem.js +69 -0
- package/Menu/VirtualizedList.d.ts +18 -0
- package/Menu/VirtualizedList.js +28 -0
- package/Menu/VirtualizedListComponent.d.ts +20 -0
- package/Menu/VirtualizedListComponent.js +305 -0
- package/Menu/index.d.ts +3 -1
- package/Menu/index.js +4 -7
- package/Modal/BaseModal/RenderModal.d.ts +3 -3
- package/Modal/BaseModal/index.d.ts +3 -3
- package/Modal/ConfirmBox/index.d.ts +5 -5
- package/Modal/Drawer/index.d.ts +5 -5
- package/Modal/MessageBox/index.d.ts +5 -5
- package/Popper/Popper.d.ts +148 -0
- package/Popper/Popper.js +113 -0
- package/Popper/PopperContainer.d.ts +2 -0
- package/Popper/PopperContainer.js +3 -6
- package/Popper/index.d.ts +5 -22
- package/Popper/index.js +18 -264
- package/Popper/usePopprer.d.ts +110 -0
- package/Popper/usePopprer.js +505 -0
- package/Selectbox/SelectboxButton.d.ts +5 -0
- package/Selectbox/SelectboxButton.js +48 -8
- package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
- package/Selectbox/SelectboxButtonWrapper.js +1 -17
- package/Selectbox/SelectboxMenu.d.ts +12 -0
- package/Selectbox/SelectboxMenu.js +50 -0
- package/Selectbox/index.d.ts +13 -13
- package/Selectbox/index.js +115 -97
- package/Surface/index.d.ts +5 -5
- package/Surface/index.js +1 -1
- package/Swiper/Swiper.d.ts +44 -0
- package/Swiper/Swiper.js +139 -0
- package/Swiper/SwiperContainer.d.ts +7 -0
- package/Swiper/SwiperContainer.js +14 -0
- package/Swiper/SwiperSlide.d.ts +7 -0
- package/Swiper/SwiperSlide.js +55 -0
- package/Swiper/SwiperTrack.d.ts +14 -0
- package/Swiper/SwiperTrack.js +58 -0
- package/Swiper/SwiperWrapper.d.ts +14 -0
- package/Swiper/SwiperWrapper.js +60 -0
- package/Swiper/index.d.ts +7 -0
- package/Swiper/index.js +26 -0
- package/Switch/SwitchDot.js +1 -1
- package/Switch/SwitchTrack.js +1 -1
- package/Switch/index.d.ts +8 -8
- package/TextArea/index.d.ts +7 -7
- package/TextField/TextFieldContainer.d.ts +2 -2
- package/TextField/TextFieldContainer.js +5 -3
- package/TextField/TextFieldErrorText.d.ts +2 -2
- package/TextField/TextFieldErrorText.js +5 -4
- package/TextField/TextFieldIconWrapper.d.ts +3 -3
- package/TextField/TextFieldIconWrapper.js +5 -3
- package/TextField/TextFieldInput.d.ts +2 -2
- package/TextField/TextFieldInput.js +6 -4
- package/TextField/TextFieldInputWrapper.d.ts +2 -2
- package/TextField/TextFieldInputWrapper.js +5 -3
- package/TextField/TextFieldLabel.d.ts +2 -2
- package/TextField/TextFieldLabel.js +5 -3
- package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
- package/TextField/TextFieldLabelAsterisk.js +5 -3
- package/TextField/index.d.ts +15 -8
- package/TextField/index.js +49 -22
- package/ThemeProvider/createTheme.js +2 -2
- package/package.json +1 -1
- package/Calendar/reducer.d.ts +0 -14
- package/Calendar/reducer.js +0 -26
- /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
- /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
package/Popper/Popper.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
17
|
+
var t = {};
|
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
19
|
+
t[p] = s[p];
|
|
20
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
22
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
23
|
+
t[p[i]] = s[p[i]];
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.PORTAL_ID = void 0;
|
|
32
|
+
const react_1 = __importDefault(require("react"));
|
|
33
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
34
|
+
const PopperContainer_1 = __importDefault(require("./PopperContainer"));
|
|
35
|
+
const usePopprer_1 = require("./usePopprer");
|
|
36
|
+
__exportStar(require("./usePopprer"), exports);
|
|
37
|
+
exports.PORTAL_ID = 'ui-kit-portal';
|
|
38
|
+
const Popper = (props, ref) => {
|
|
39
|
+
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = 'fixed', viewportMargin = 30, autoFlip = true, offset = 0, onAnchorPosChanged } = props, nativeProps = __rest(props, ["isOpen", "children", "anchorElement", "zIndex", "overrides", "anchorPos", "positionStrategy", "viewportMargin", "autoFlip", "offset", "onAnchorPosChanged"]);
|
|
40
|
+
const [domLoaded, setDomLoaded] = react_1.default.useState(false);
|
|
41
|
+
const { actualPlacement, style, popperRef, isVisible } = (0, usePopprer_1.usePopper)({
|
|
42
|
+
anchorElement,
|
|
43
|
+
anchorPos,
|
|
44
|
+
positionStrategy,
|
|
45
|
+
autoFlip,
|
|
46
|
+
offset,
|
|
47
|
+
viewportMargin,
|
|
48
|
+
isOpen,
|
|
49
|
+
});
|
|
50
|
+
const overridesMap = react_1.default.useMemo(() => ({
|
|
51
|
+
Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || PopperContainer_1.default,
|
|
52
|
+
}), [overrides]);
|
|
53
|
+
/**
|
|
54
|
+
* Client render detection
|
|
55
|
+
*/
|
|
56
|
+
react_1.default.useEffect(() => {
|
|
57
|
+
setDomLoaded(true);
|
|
58
|
+
}, []);
|
|
59
|
+
const portalEl = react_1.default.useMemo(() => {
|
|
60
|
+
if (typeof window === 'undefined') {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const node = window.document.body.querySelector(`#${exports.PORTAL_ID}`);
|
|
64
|
+
if (node) {
|
|
65
|
+
return node;
|
|
66
|
+
}
|
|
67
|
+
const newNode = window.document.createElement('div');
|
|
68
|
+
newNode.setAttribute('id', exports.PORTAL_ID);
|
|
69
|
+
if (positionStrategy === 'absolute') {
|
|
70
|
+
newNode.style.position = 'relative';
|
|
71
|
+
}
|
|
72
|
+
window.document.body.appendChild(newNode);
|
|
73
|
+
return newNode;
|
|
74
|
+
}, [positionStrategy]);
|
|
75
|
+
react_1.default.useEffect(() => {
|
|
76
|
+
if (anchorPos !== actualPlacement && typeof onAnchorPosChanged === 'function') {
|
|
77
|
+
onAnchorPosChanged(actualPlacement);
|
|
78
|
+
}
|
|
79
|
+
}, [anchorPos, actualPlacement, onAnchorPosChanged]);
|
|
80
|
+
const renderNode = react_1.default.useCallback(() => (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { style: Object.assign(Object.assign(Object.assign(Object.assign({}, style), nativeProps.style), { opacity: isVisible ? 1 : 0, pointerEvents: isVisible ? 'auto' : 'none' }), (positionStrategy === 'fixed' && {
|
|
81
|
+
zIndex: zIndex,
|
|
82
|
+
})), zIndex: zIndex, positionStrategy: positionStrategy, "data-popper-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
83
|
+
popperRef.current = el;
|
|
84
|
+
if (ref) {
|
|
85
|
+
if (typeof ref === 'function') {
|
|
86
|
+
ref(el);
|
|
87
|
+
}
|
|
88
|
+
if (typeof ref === 'object') {
|
|
89
|
+
ref.current = el;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} }), children)), [
|
|
93
|
+
overridesMap,
|
|
94
|
+
nativeProps,
|
|
95
|
+
style,
|
|
96
|
+
isVisible,
|
|
97
|
+
// getTransformOrigin,
|
|
98
|
+
actualPlacement,
|
|
99
|
+
positionStrategy,
|
|
100
|
+
zIndex,
|
|
101
|
+
children,
|
|
102
|
+
popperRef,
|
|
103
|
+
ref,
|
|
104
|
+
]);
|
|
105
|
+
if (!isOpen) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (positionStrategy === 'fixed') {
|
|
109
|
+
return domLoaded && portalEl ? react_dom_1.default.createPortal(renderNode(), portalEl, exports.PORTAL_ID) : null;
|
|
110
|
+
}
|
|
111
|
+
return renderNode();
|
|
112
|
+
};
|
|
113
|
+
exports.default = react_1.default.forwardRef(Popper);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
export type PositionStrategy = 'absolute' | 'fixed';
|
|
2
3
|
export interface PopperContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
4
|
readonly zIndex?: number;
|
|
4
5
|
readonly disablePortal?: boolean;
|
|
6
|
+
readonly positionStrategy?: PositionStrategy;
|
|
5
7
|
}
|
|
6
8
|
declare const _default: React.ForwardRefExoticComponent<PopperContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
7
9
|
export default _default;
|
|
@@ -17,14 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const react_1 = __importDefault(require("react"));
|
|
18
18
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
19
|
const StyledContainer = styled_1.default.div `
|
|
20
|
+
position: ${({ $positionStrategy }) => $positionStrategy};
|
|
20
21
|
z-index: ${({ theme, $zIndex, $disablePortal }) => typeof $zIndex !== 'undefined' ? $zIndex : $disablePortal ? undefined : theme.zIndex.modal};
|
|
21
|
-
pointer-events: none;
|
|
22
|
-
& > * {
|
|
23
|
-
pointer-events: all;
|
|
24
|
-
}
|
|
25
22
|
`;
|
|
26
23
|
const PopperContainer = (props, ref) => {
|
|
27
|
-
const { children, disablePortal, zIndex } = props, nativeProps = __rest(props, ["children", "disablePortal", "zIndex"]);
|
|
28
|
-
return (react_1.default.createElement(StyledContainer, Object.assign({ "$disablePortal": disablePortal, "$zIndex": zIndex }, nativeProps, { ref: ref }), children));
|
|
24
|
+
const { children, disablePortal, zIndex, positionStrategy = 'fixed' } = props, nativeProps = __rest(props, ["children", "disablePortal", "zIndex", "positionStrategy"]);
|
|
25
|
+
return (react_1.default.createElement(StyledContainer, Object.assign({ "$disablePortal": disablePortal, "$zIndex": zIndex, "$positionStrategy": positionStrategy }, nativeProps, { ref: ref }), children));
|
|
29
26
|
};
|
|
30
27
|
exports.default = react_1.default.forwardRef(PopperContainer);
|
package/Popper/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
readonly anchorElement?: HTMLElement | null;
|
|
7
|
-
readonly anchorPos?: AnchorPos;
|
|
8
|
-
readonly zindex?: number;
|
|
9
|
-
/**
|
|
10
|
-
* Overridable components map
|
|
11
|
-
*/
|
|
12
|
-
readonly overrides?: PopperOverrides;
|
|
13
|
-
}
|
|
14
|
-
export interface PopperOverrides {
|
|
15
|
-
/**
|
|
16
|
-
* Popper Container
|
|
17
|
-
*/
|
|
18
|
-
readonly Container?: React.ForwardRefExoticComponent<PopperContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
19
|
-
}
|
|
20
|
-
export declare const PORTAL_ID = "ui-kit-portal";
|
|
21
|
-
declare const _default: React.ForwardRefExoticComponent<PopperProps & React.RefAttributes<HTMLDivElement>>;
|
|
22
|
-
export default _default;
|
|
1
|
+
import Popper from './Popper';
|
|
2
|
+
export * from './Popper';
|
|
3
|
+
export * from './PopperContainer';
|
|
4
|
+
export * from './usePopprer';
|
|
5
|
+
export default Popper;
|
package/Popper/index.js
CHANGED
|
@@ -1,270 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
12
15
|
};
|
|
13
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
18
|
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.
|
|
22
|
-
const Popper = (props, ref) => {
|
|
23
|
-
const { isOpen, children, anchorElement, zindex, overrides, anchorPos = 'auto' } = props, nativeProps = __rest(props, ["isOpen", "children", "anchorElement", "zindex", "overrides", "anchorPos"]);
|
|
24
|
-
const [style, setStyle] = react_1.default.useState(null);
|
|
25
|
-
const [domLoaded, setDomLoaded] = react_1.default.useState(false);
|
|
26
|
-
const disablePortal = react_1.default.useMemo(() => anchorPos === 'static', [anchorPos]);
|
|
27
|
-
if (anchorPos !== 'static' && typeof anchorElement === 'undefined') {
|
|
28
|
-
throw new Error('[@via-profit/ui-kit] When the «anchorPos» is «satic» then «anchorElement» most be an element or null, but got undefined');
|
|
29
|
-
}
|
|
30
|
-
// if (anchorPos === 'static' && !disablePortal) {
|
|
31
|
-
// throw new Error(
|
|
32
|
-
// '[@via-profit/ui-kit] When the «anchorPos» is «satic» then «disablePortal» most be false',
|
|
33
|
-
// );
|
|
34
|
-
// }
|
|
35
|
-
const overridesMap = react_1.default.useMemo(() => ({
|
|
36
|
-
Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || PopperContainer_1.default,
|
|
37
|
-
}), [overrides]);
|
|
38
|
-
/**
|
|
39
|
-
* Client render detection
|
|
40
|
-
*/
|
|
41
|
-
react_1.default.useEffect(() => {
|
|
42
|
-
if (!disablePortal) {
|
|
43
|
-
setDomLoaded(true);
|
|
44
|
-
}
|
|
45
|
-
}, [disablePortal]);
|
|
46
|
-
const portalEl = react_1.default.useMemo(() => {
|
|
47
|
-
if (typeof window === 'undefined') {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
const node = window.document.body.querySelector(`#${exports.PORTAL_ID}`);
|
|
51
|
-
if (node) {
|
|
52
|
-
return node;
|
|
53
|
-
}
|
|
54
|
-
const newNode = window.document.createElement('div');
|
|
55
|
-
newNode.setAttribute('id', exports.PORTAL_ID);
|
|
56
|
-
window.document.body.appendChild(newNode);
|
|
57
|
-
return newNode;
|
|
58
|
-
}, []);
|
|
59
|
-
const calculateStyles = react_1.default.useCallback(() => {
|
|
60
|
-
// For a static placement
|
|
61
|
-
if (anchorPos === 'static') {
|
|
62
|
-
setStyle({
|
|
63
|
-
// backgroundColor: 'rgba(123, 255, 0, 0.5)',
|
|
64
|
-
position: 'static',
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// For a dinamic position
|
|
69
|
-
if (anchorElement) {
|
|
70
|
-
const anchorRect = anchorElement.getBoundingClientRect();
|
|
71
|
-
switch (anchorPos) {
|
|
72
|
-
case 'bottom-start':
|
|
73
|
-
setStyle({
|
|
74
|
-
position: 'absolute',
|
|
75
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
76
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
77
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
78
|
-
width: Math.floor(window.innerWidth - anchorRect.left - 15),
|
|
79
|
-
// backgroundColor: 'rgba(255, 0, 0, .5)',
|
|
80
|
-
display: 'flex',
|
|
81
|
-
alignItems: 'flex-start',
|
|
82
|
-
justifyContent: 'flex-start',
|
|
83
|
-
});
|
|
84
|
-
break;
|
|
85
|
-
case 'top-start':
|
|
86
|
-
setStyle({
|
|
87
|
-
position: 'absolute',
|
|
88
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
89
|
-
top: window.scrollY,
|
|
90
|
-
height: anchorRect.top,
|
|
91
|
-
width: Math.floor(window.innerWidth - anchorRect.left - 15),
|
|
92
|
-
display: 'flex',
|
|
93
|
-
alignItems: 'flex-end',
|
|
94
|
-
justifyContent: 'flex-start',
|
|
95
|
-
// backgroundColor: 'rgba(0, 102, 255, 0.5)',
|
|
96
|
-
});
|
|
97
|
-
break;
|
|
98
|
-
case 'top':
|
|
99
|
-
setStyle({
|
|
100
|
-
position: 'absolute',
|
|
101
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
102
|
-
top: window.scrollY,
|
|
103
|
-
height: anchorRect.top,
|
|
104
|
-
width: anchorRect.width,
|
|
105
|
-
// backgroundColor: 'rgba(208, 255, 0, 0.5)',
|
|
106
|
-
display: 'flex',
|
|
107
|
-
alignItems: 'center',
|
|
108
|
-
flexDirection: 'column',
|
|
109
|
-
justifyContent: 'flex-end',
|
|
110
|
-
});
|
|
111
|
-
break;
|
|
112
|
-
case 'bottom':
|
|
113
|
-
setStyle({
|
|
114
|
-
position: 'absolute',
|
|
115
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
116
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
117
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
118
|
-
width: anchorRect.width,
|
|
119
|
-
// backgroundColor: 'rgba(0, 247, 255, 0.5)',
|
|
120
|
-
display: 'flex',
|
|
121
|
-
alignItems: 'center',
|
|
122
|
-
flexDirection: 'column',
|
|
123
|
-
justifyContent: 'flex-start',
|
|
124
|
-
});
|
|
125
|
-
break;
|
|
126
|
-
case 'top-end':
|
|
127
|
-
setStyle({
|
|
128
|
-
position: 'absolute',
|
|
129
|
-
left: 0,
|
|
130
|
-
width: Math.floor(anchorRect.left + window.scrollX + anchorRect.width),
|
|
131
|
-
top: window.scrollY,
|
|
132
|
-
height: anchorRect.top,
|
|
133
|
-
display: 'flex',
|
|
134
|
-
alignItems: 'flex-end',
|
|
135
|
-
justifyContent: 'flex-end',
|
|
136
|
-
// backgroundColor: 'rgba(174, 0, 255, 0.5)',
|
|
137
|
-
});
|
|
138
|
-
break;
|
|
139
|
-
case 'bottom-end':
|
|
140
|
-
setStyle({
|
|
141
|
-
position: 'absolute',
|
|
142
|
-
left: 0,
|
|
143
|
-
width: Math.floor(anchorRect.left + window.scrollX + anchorRect.width),
|
|
144
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
145
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
146
|
-
display: 'flex',
|
|
147
|
-
alignItems: 'flex-start',
|
|
148
|
-
justifyContent: 'flex-end',
|
|
149
|
-
// backgroundColor: 'rgba(174, 0, 255, 0.5)',
|
|
150
|
-
});
|
|
151
|
-
break;
|
|
152
|
-
case 'top-start-end':
|
|
153
|
-
setStyle({
|
|
154
|
-
position: 'absolute',
|
|
155
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
156
|
-
top: window.scrollY,
|
|
157
|
-
height: anchorRect.top,
|
|
158
|
-
width: anchorRect.width,
|
|
159
|
-
// backgroundColor: 'rgba(0, 102, 255, 0.5)',
|
|
160
|
-
display: 'flex',
|
|
161
|
-
alignItems: 'stretch',
|
|
162
|
-
flexDirection: 'column',
|
|
163
|
-
justifyContent: 'flex-end',
|
|
164
|
-
});
|
|
165
|
-
break;
|
|
166
|
-
case 'bottom-start-end':
|
|
167
|
-
setStyle({
|
|
168
|
-
position: 'absolute',
|
|
169
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
170
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
171
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
172
|
-
width: anchorRect.width,
|
|
173
|
-
// backgroundColor: 'rgba(255, 81, 0, 0.5)',
|
|
174
|
-
display: 'flex',
|
|
175
|
-
alignItems: 'stretch',
|
|
176
|
-
flexDirection: 'column',
|
|
177
|
-
justifyContent: 'flex-start',
|
|
178
|
-
});
|
|
179
|
-
break;
|
|
180
|
-
case 'auto-start-end':
|
|
181
|
-
{
|
|
182
|
-
if (anchorRect.top >
|
|
183
|
-
Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5)) {
|
|
184
|
-
setStyle({
|
|
185
|
-
position: 'absolute',
|
|
186
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
187
|
-
top: window.scrollY,
|
|
188
|
-
height: anchorRect.top,
|
|
189
|
-
width: anchorRect.width,
|
|
190
|
-
display: 'flex',
|
|
191
|
-
alignItems: 'stretch',
|
|
192
|
-
flexDirection: 'column',
|
|
193
|
-
justifyContent: 'flex-end',
|
|
194
|
-
// backgroundColor: 'rgba(0, 102, 255, 0.5)',
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
setStyle({
|
|
199
|
-
position: 'absolute',
|
|
200
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
201
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
202
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
203
|
-
width: anchorRect.width,
|
|
204
|
-
display: 'flex',
|
|
205
|
-
alignItems: 'stretch',
|
|
206
|
-
flexDirection: 'column',
|
|
207
|
-
justifyContent: 'flex-start',
|
|
208
|
-
// backgroundColor: 'rgba(255, 187, 0, 0.5)',
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
break;
|
|
213
|
-
case 'auto':
|
|
214
|
-
default:
|
|
215
|
-
{
|
|
216
|
-
if (anchorRect.top >
|
|
217
|
-
Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5)) {
|
|
218
|
-
setStyle({
|
|
219
|
-
position: 'absolute',
|
|
220
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
221
|
-
top: window.scrollY,
|
|
222
|
-
height: anchorRect.top,
|
|
223
|
-
width: Math.floor(window.innerWidth - anchorRect.left - 15),
|
|
224
|
-
display: 'flex',
|
|
225
|
-
alignItems: 'flex-end',
|
|
226
|
-
// backgroundColor: 'rgba(0, 102, 255, 0.5)',
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
setStyle({
|
|
231
|
-
position: 'absolute',
|
|
232
|
-
left: Math.floor(anchorRect.left + window.scrollX),
|
|
233
|
-
top: Math.floor(anchorRect.top + window.scrollY + anchorRect.height),
|
|
234
|
-
height: Math.floor(window.innerHeight - anchorRect.top - anchorRect.height - 5),
|
|
235
|
-
width: Math.floor(window.innerWidth - anchorRect.left - 15),
|
|
236
|
-
// backgroundColor: 'rgba(255, 0, 0, .5)',
|
|
237
|
-
display: 'flex',
|
|
238
|
-
alignItems: 'flex-start',
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
setStyle(null);
|
|
247
|
-
}, [anchorElement, anchorPos]);
|
|
248
|
-
react_1.default.useEffect(() => {
|
|
249
|
-
window.addEventListener('resize', calculateStyles);
|
|
250
|
-
window.addEventListener('scroll', calculateStyles);
|
|
251
|
-
return () => {
|
|
252
|
-
window.removeEventListener('resize', calculateStyles);
|
|
253
|
-
window.removeEventListener('scroll', calculateStyles);
|
|
254
|
-
};
|
|
255
|
-
}, [calculateStyles]);
|
|
256
|
-
react_1.default.useEffect(() => {
|
|
257
|
-
if (isOpen && (anchorElement || anchorPos === 'static')) {
|
|
258
|
-
calculateStyles();
|
|
259
|
-
}
|
|
260
|
-
}, [isOpen, anchorElement, anchorPos, calculateStyles]);
|
|
261
|
-
const renderNode = react_1.default.useCallback(() => (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { style: Object.assign(Object.assign({}, style), nativeProps.style), zIndex: zindex, disablePortal: disablePortal, ref: ref }), style && children)), [children, disablePortal, nativeProps, overridesMap, ref, style, zindex]);
|
|
262
|
-
if (!isOpen || !style) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
if (disablePortal) {
|
|
266
|
-
return renderNode();
|
|
267
|
-
}
|
|
268
|
-
return domLoaded && portalEl ? react_dom_1.default.createPortal(renderNode(), portalEl, exports.PORTAL_ID) : null;
|
|
269
|
-
};
|
|
270
|
-
exports.default = react_1.default.forwardRef(Popper);
|
|
20
|
+
const Popper_1 = __importDefault(require("./Popper"));
|
|
21
|
+
__exportStar(require("./Popper"), exports);
|
|
22
|
+
__exportStar(require("./PopperContainer"), exports);
|
|
23
|
+
__exportStar(require("./usePopprer"), exports);
|
|
24
|
+
exports.default = Popper_1.default;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PositionStrategy } from './PopperContainer';
|
|
3
|
+
/**
|
|
4
|
+
* Base directions for popper positioning.
|
|
5
|
+
* These are the primary axes around which the popper can be placed.
|
|
6
|
+
*
|
|
7
|
+
* @default 'bottom' (when used as anchorPos)
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* type Direction = 'top' | 'bottom' | 'left' | 'right';
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type Direction = 'top' | 'left' | 'right' | 'bottom';
|
|
14
|
+
/**
|
|
15
|
+
* Auto placement modifiers that enable intelligent positioning.
|
|
16
|
+
* The popper will automatically choose the best placement that fits in the viewport.
|
|
17
|
+
* - `auto`: Dynamically selects the optimal direction
|
|
18
|
+
* - `auto-top`, `auto-bottom`, `auto-left`, `auto-right`: Auto placement with priority given to the specified direction
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // Will try to place on top first, but will flip if needed
|
|
23
|
+
* <Popper anchorPos="auto-top">...</Popper>
|
|
24
|
+
*
|
|
25
|
+
* // Will try all directions equally
|
|
26
|
+
* <Popper anchorPos="auto">...</Popper>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type AutoModifier = 'auto' | 'auto-top' | 'auto-bottom' | 'auto-left' | 'auto-right';
|
|
30
|
+
/**
|
|
31
|
+
* Precise placement modifiers for fine-tuned positioning.
|
|
32
|
+
* These combine a base direction with specific alignment options:
|
|
33
|
+
* - `start`/`end`: Aligns to the beginning or end of the anchor (useful for RTL layouts)
|
|
34
|
+
* - `left`/`right`: Horizontal alignment for vertical placements
|
|
35
|
+
* - `top`/`bottom`: Vertical alignment for horizontal placements
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // Corner placements
|
|
40
|
+
* <Popper anchorPos="top-left">Aligns to top-left corner</Popper>
|
|
41
|
+
*
|
|
42
|
+
* // Logical placements (RTL-friendly)
|
|
43
|
+
* <Popper anchorPos="bottom-start">Aligns to bottom edge, start side</Popper>
|
|
44
|
+
*
|
|
45
|
+
* // Side alignments
|
|
46
|
+
* <Popper anchorPos="left-top">Aligns to left side, top edge</Popper>
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export type Modifier = 'top-start' | 'top-end' | 'top-left' | 'top-right' | 'bottom-end' | 'bottom-start' | 'bottom-right' | 'bottom-left' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom' | 'bottom-fill' | 'top-fill';
|
|
50
|
+
/**
|
|
51
|
+
* Available placement options for the popper.
|
|
52
|
+
* Combines basic directions, precise modifiers, and auto-placement options
|
|
53
|
+
* to provide full control over popper positioning.
|
|
54
|
+
*
|
|
55
|
+
* Categories:
|
|
56
|
+
* - **Basic directions**: `top`, `bottom`, `left`, `right` - Centered placement
|
|
57
|
+
* - **Corner placements**: `top-left`, `top-right`, `bottom-left`, `bottom-right` - Aligned to corners
|
|
58
|
+
* - **Logical placements**: `top-start`, `top-end`, `bottom-start`, `bottom-end` - RTL-aware alignment
|
|
59
|
+
* - **Side alignments**: `left-top`, `left-bottom`, `right-top`, `right-bottom` - Edge-aligned
|
|
60
|
+
* - **Auto placements**: `auto`, `auto-top`, `auto-bottom`, `auto-left`, `auto-right` - Intelligent positioning
|
|
61
|
+
*
|
|
62
|
+
* @default 'bottom'
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* // Basic centered placement
|
|
66
|
+
* <Popper anchorPos="bottom">Centered below anchor</Popper>
|
|
67
|
+
*
|
|
68
|
+
* // Corner placement
|
|
69
|
+
* <Popper anchorPos="top-right">Attached to top-right corner</Popper>
|
|
70
|
+
*
|
|
71
|
+
* // Auto placement with priority
|
|
72
|
+
* <Popper anchorPos="auto-left">Try left first, then find best fit</Popper>
|
|
73
|
+
*
|
|
74
|
+
* // RTL-aware placement
|
|
75
|
+
* <Popper anchorPos="top-start">Respects text direction</Popper>
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export type AnchorPos = Direction | Modifier | AutoModifier;
|
|
79
|
+
export interface UsePopperProps {
|
|
80
|
+
readonly anchorElement: HTMLElement | null;
|
|
81
|
+
readonly anchorPos?: AnchorPos;
|
|
82
|
+
readonly positionStrategy?: PositionStrategy;
|
|
83
|
+
readonly autoFlip?: boolean;
|
|
84
|
+
readonly offset?: number;
|
|
85
|
+
readonly viewportMargin?: number;
|
|
86
|
+
readonly isOpen?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface UsePopperResult {
|
|
89
|
+
readonly actualPlacement: AnchorPos;
|
|
90
|
+
readonly style: React.CSSProperties | null;
|
|
91
|
+
readonly popperRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
92
|
+
readonly isVisible: boolean;
|
|
93
|
+
readonly calculatePosition: () => void;
|
|
94
|
+
readonly scrollableAncestor: HTMLElement | Window | null;
|
|
95
|
+
readonly setActualPlacement: React.Dispatch<React.SetStateAction<AnchorPos>>;
|
|
96
|
+
readonly setStyle: React.Dispatch<React.SetStateAction<React.CSSProperties | null>>;
|
|
97
|
+
readonly setIsVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Finds the closest scrollable ancestor of an element.
|
|
101
|
+
* A scrollable element is one that has overflow set to auto, scroll, or overlay
|
|
102
|
+
* and has content that overflows, allowing scrolling.
|
|
103
|
+
*
|
|
104
|
+
* @param element - The element to start searching from
|
|
105
|
+
* @param includeHidden - Whether to consider elements with overflow: hidden
|
|
106
|
+
* @returns The closest scrollable ancestor or window if none found
|
|
107
|
+
*/
|
|
108
|
+
export declare const findScrollableAncestor: (element: HTMLElement | null, includeHidden?: boolean) => HTMLElement | Window | null;
|
|
109
|
+
export declare const usePopper: ({ anchorElement, anchorPos, positionStrategy, autoFlip, offset, viewportMargin, isOpen, }: UsePopperProps) => UsePopperResult;
|
|
110
|
+
export default usePopper;
|