@via-profit/ui-kit 0.1.8 → 0.2.1-alpha.1
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 +1 -1
- package/Autocomplete/AutocompleteContainer.js +1 -1
- package/Avatar/AvatarBase.d.ts +4 -4
- package/Badge/BadgeBase.d.ts +4 -4
- package/Button/ButtonBase.d.ts +3 -3
- package/Calendar/CalendarCell.js +18 -4
- package/Calendar/CalendarMonthCell.js +0 -5
- package/Calendar/CalendarYearCell.js +5 -5
- package/Calendar/index.d.ts +25 -21
- package/Calendar/index.js +89 -82
- package/Calendar/reducer.d.ts +4 -1
- package/Calendar/reducer.js +27 -3
- package/Calendar/use-calendar.js +102 -155
- package/DatePicker/index.js +1 -1
- package/Highlighted/index.d.ts +3 -3
- package/Menu/MenuContainer.d.ts +2 -2
- package/Menu/MenuContainer.js +2 -2
- package/Menu/index.js +2 -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 +221 -0
- package/Popper/Popper.js +99 -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 +25 -0
- package/Popper/usePopprer.js +330 -0
- package/Selectbox/index.d.ts +8 -8
- package/Selectbox/index.js +2 -2
- package/Surface/index.d.ts +5 -5
- package/Switch/index.d.ts +8 -8
- package/TextArea/index.d.ts +7 -7
- package/TextField/index.d.ts +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PopperContainerProps, 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';
|
|
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 PopperProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
80
|
+
/**
|
|
81
|
+
* Controls the visibility of the popper.
|
|
82
|
+
* When `true`, the popper is rendered and positioned.
|
|
83
|
+
*
|
|
84
|
+
* @required
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* <Popper isOpen={true}>...</Popper>
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
readonly isOpen: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* The HTML element to which the popper will be attached and positioned relative to.
|
|
93
|
+
* If `null` or undefined, the popper will not be positioned.
|
|
94
|
+
*
|
|
95
|
+
* @default undefined
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* const [anchor, setAnchor] = useState<HTMLButtonElement | null>(null);
|
|
99
|
+
* <Popper anchorElement={anchor}>...</Popper>
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
readonly anchorElement?: HTMLElement | null;
|
|
103
|
+
/**
|
|
104
|
+
* Determines the preferred placement of the popper relative to the anchor element.
|
|
105
|
+
* The actual placement may change if `autoFlip` is enabled and there's not enough space.
|
|
106
|
+
*
|
|
107
|
+
* @default 'auto'
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* <Popper anchorPos="top-start">...</Popper>
|
|
111
|
+
* <Popper anchorPos="bottom-end">...</Popper>
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
readonly anchorPos?: AnchorPos;
|
|
115
|
+
/**
|
|
116
|
+
* The z-index value for the popper container.
|
|
117
|
+
* Used to control the stacking order of the popper relative to other elements.
|
|
118
|
+
*
|
|
119
|
+
* @default theme.zIndex.modal
|
|
120
|
+
* @example
|
|
121
|
+
* ```tsx
|
|
122
|
+
* <Popper zIndex={9999}>...</Popper>
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
readonly zIndex?: number;
|
|
126
|
+
/**
|
|
127
|
+
* When enabled, the popper will automatically try to find the best placement
|
|
128
|
+
* if the preferred placement doesn't fit in the viewport.
|
|
129
|
+
* The component will iterate through possible placements until it finds one that fits.
|
|
130
|
+
*
|
|
131
|
+
* @default true
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* <Popper autoFlip={true}>...</Popper> // Will flip if needed
|
|
135
|
+
* <Popper autoFlip={false}>...</Popper> // Will always use preferred placement
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
readonly autoFlip?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Additional offset (in pixels) from the anchor element.
|
|
141
|
+
* Positive values move the popper away from the anchor, negative values move it closer.
|
|
142
|
+
*
|
|
143
|
+
* @default 0
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* <Popper offset={8}>...</Popper> // 8px gap between anchor and popper
|
|
147
|
+
* <Popper offset={-4}>...</Popper> // Overlap the anchor by 4px
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
readonly offset?: number;
|
|
151
|
+
/**
|
|
152
|
+
* The positioning strategy to use.
|
|
153
|
+
* - `'fixed'`: Positions relative to the viewport. Works reliably in all cases.
|
|
154
|
+
* - `'absolute'`: Positions relative to the nearest positioned ancestor.
|
|
155
|
+
* When using 'absolute', make sure a parent element has `position: relative`.
|
|
156
|
+
*
|
|
157
|
+
* @default 'absolute'
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* <Popper positionStrategy="absolute">...</Popper> // Relative to positioned parent (recommended)
|
|
161
|
+
* <Popper positionStrategy="fixed">...</Popper> // Relative to viewport
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
readonly positionStrategy?: PositionStrategy;
|
|
165
|
+
/**
|
|
166
|
+
* Minimum distance (in pixels) that the popper must maintain from the viewport edges.
|
|
167
|
+
* Used to prevent the popper from being positioned too close to the screen boundaries.
|
|
168
|
+
* The popper will try to flip to another placement if it cannot maintain this margin.
|
|
169
|
+
*
|
|
170
|
+
* @default 8
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* // Larger margin for better visibility
|
|
174
|
+
* <Popper viewportMargin={16}>...</Popper>
|
|
175
|
+
*
|
|
176
|
+
* // No margin (allow touching edges)
|
|
177
|
+
* <Popper viewportMargin={0}>...</Popper>
|
|
178
|
+
*
|
|
179
|
+
* // Different margins for different devices
|
|
180
|
+
* <Popper viewportMargin={isMobile ? 8 : 16}>...</Popper>
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
readonly viewportMargin?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Overridable components map for customizing the popper's internal structure.
|
|
186
|
+
* Allows replacing default components with custom implementations while maintaining functionality.
|
|
187
|
+
*
|
|
188
|
+
* @default undefined
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* <Popper
|
|
192
|
+
* overrides={{
|
|
193
|
+
* Container: CustomContainerComponent,
|
|
194
|
+
* }}
|
|
195
|
+
* >
|
|
196
|
+
* ...
|
|
197
|
+
* </Popper>
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
readonly overrides?: PopperOverrides;
|
|
201
|
+
}
|
|
202
|
+
export interface PopperOverrides {
|
|
203
|
+
/**
|
|
204
|
+
* Custom container component for the popper content.
|
|
205
|
+
* This component wraps the popper's children and handles positioning styles.
|
|
206
|
+
*
|
|
207
|
+
* @default PopperContainer
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* const CustomContainer = React.forwardRef((props, ref) => (
|
|
211
|
+
* <div ref={ref} {...props} className="custom-popper" />
|
|
212
|
+
* ));
|
|
213
|
+
*
|
|
214
|
+
* <Popper overrides={{ Container: CustomContainer }} />
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
readonly Container?: React.ComponentType<PopperContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
218
|
+
}
|
|
219
|
+
export declare const PORTAL_ID = "ui-kit-portal";
|
|
220
|
+
declare const _default: React.ForwardRefExoticComponent<PopperProps & React.RefAttributes<HTMLDivElement>>;
|
|
221
|
+
export default _default;
|
package/Popper/Popper.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.PORTAL_ID = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
20
|
+
const PopperContainer_1 = __importDefault(require("./PopperContainer"));
|
|
21
|
+
const usePopprer_1 = require("./usePopprer");
|
|
22
|
+
exports.PORTAL_ID = 'ui-kit-portal';
|
|
23
|
+
const Popper = (props, ref) => {
|
|
24
|
+
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = 'absolute', viewportMargin = 30, autoFlip = true, offset = 0 } = props, nativeProps = __rest(props, ["isOpen", "children", "anchorElement", "zIndex", "overrides", "anchorPos", "positionStrategy", "viewportMargin", "autoFlip", "offset"]);
|
|
25
|
+
const [domLoaded, setDomLoaded] = react_1.default.useState(false);
|
|
26
|
+
const { actualPlacement, style, popperRef, isVisible, getTransformOrigin } = (0, usePopprer_1.usePopper)({
|
|
27
|
+
anchorElement,
|
|
28
|
+
anchorPos,
|
|
29
|
+
positionStrategy,
|
|
30
|
+
autoFlip,
|
|
31
|
+
offset,
|
|
32
|
+
viewportMargin,
|
|
33
|
+
isOpen,
|
|
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
|
+
setDomLoaded(true);
|
|
43
|
+
}, []);
|
|
44
|
+
const portalEl = react_1.default.useMemo(() => {
|
|
45
|
+
if (typeof window === 'undefined') {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const node = window.document.body.querySelector(`#${exports.PORTAL_ID}`);
|
|
49
|
+
if (node) {
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
const newNode = window.document.createElement('div');
|
|
53
|
+
newNode.setAttribute('id', exports.PORTAL_ID);
|
|
54
|
+
// Важно для absolute позиционирования
|
|
55
|
+
if (positionStrategy === 'absolute') {
|
|
56
|
+
newNode.style.position = 'relative';
|
|
57
|
+
}
|
|
58
|
+
window.document.body.appendChild(newNode);
|
|
59
|
+
return newNode;
|
|
60
|
+
}, [positionStrategy]);
|
|
61
|
+
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,
|
|
62
|
+
// transform: isVisible ? 'scale(1)' : 'scale(0.95)',
|
|
63
|
+
transition: 'opacity 120ms ease-in-out, left 120ms cubic-bezier(0.22, 0.61, 0.36, 1), top 120ms cubic-bezier(0.22, 0.61, 0.36, 1)',
|
|
64
|
+
// transformOrigin: getTransformOrigin(actualPlacement),
|
|
65
|
+
pointerEvents: isVisible ? 'auto' : 'none' }), (positionStrategy === 'fixed' && {
|
|
66
|
+
zIndex: zIndex,
|
|
67
|
+
})), zIndex: zIndex, "data-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
68
|
+
popperRef.current = el;
|
|
69
|
+
if (ref) {
|
|
70
|
+
if (typeof ref === 'function') {
|
|
71
|
+
ref(el);
|
|
72
|
+
}
|
|
73
|
+
if (typeof ref === 'object') {
|
|
74
|
+
ref.current = el;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} }), children)), [
|
|
78
|
+
overridesMap,
|
|
79
|
+
nativeProps,
|
|
80
|
+
style,
|
|
81
|
+
isVisible,
|
|
82
|
+
getTransformOrigin,
|
|
83
|
+
actualPlacement,
|
|
84
|
+
positionStrategy,
|
|
85
|
+
zIndex,
|
|
86
|
+
children,
|
|
87
|
+
ref,
|
|
88
|
+
popperRef,
|
|
89
|
+
]);
|
|
90
|
+
if (!isOpen) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (positionStrategy === 'fixed') {
|
|
94
|
+
return domLoaded && portalEl ? react_dom_1.default.createPortal(renderNode(), portalEl, exports.PORTAL_ID) : null;
|
|
95
|
+
}
|
|
96
|
+
// Для absolute стратегии - рендерим рядом с anchor (in-place)
|
|
97
|
+
return renderNode();
|
|
98
|
+
};
|
|
99
|
+
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 = 'absolute' } = 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;
|