@via-profit/ui-kit 0.2.2 → 0.2.4
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/Autocomplete/AutocompleteContainer.d.ts +5 -4
- package/Autocomplete/AutocompleteContainer.js +128 -142
- package/Autocomplete/AutocompleteItem.js +1 -1
- package/Autocomplete/context.d.ts +3 -5
- package/Autocomplete/context.js +22 -14
- package/Highlighted/index.js +10 -5
- package/Highlighted/splitTextIntoParts.d.ts +5 -0
- package/Highlighted/splitTextIntoParts.js +46 -0
- package/Menu/MenuContainer.d.ts +24 -2
- package/Menu/MenuContainer.js +193 -242
- package/Menu/MenuList.d.ts +1 -0
- package/Menu/MenuList.js +15 -16
- package/Popper/Popper.d.ts +3 -2
- package/Popper/Popper.js +9 -7
- package/Popper/PopperContainer.d.ts +0 -1
- package/Popper/PopperContainer.js +8 -3
- package/Popper/index.d.ts +1 -1
- package/Popper/index.js +1 -1
- package/Popper/usePopper.d.ts +111 -0
- package/Popper/usePopper.js +489 -0
- package/Selectbox/SelectboxButton.js +2 -27
- package/Selectbox/SelectboxMenu.d.ts +0 -2
- package/Selectbox/SelectboxMenu.js +13 -5
- package/Selectbox/index.d.ts +5 -3
- package/Selectbox/index.js +4 -4
- package/Swiper/Swiper.d.ts +0 -2
- package/Swiper/Swiper.js +1 -18
- package/package.json +1 -1
package/Popper/Popper.js
CHANGED
|
@@ -32,19 +32,20 @@ exports.PORTAL_ID = void 0;
|
|
|
32
32
|
const react_1 = __importDefault(require("react"));
|
|
33
33
|
const react_dom_1 = __importDefault(require("react-dom"));
|
|
34
34
|
const PopperContainer_1 = __importDefault(require("./PopperContainer"));
|
|
35
|
-
const
|
|
36
|
-
__exportStar(require("./
|
|
35
|
+
const usePopper_1 = require("./usePopper");
|
|
36
|
+
__exportStar(require("./usePopper"), exports);
|
|
37
37
|
exports.PORTAL_ID = 'ui-kit-portal';
|
|
38
38
|
const Popper = (props, ref) => {
|
|
39
|
-
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = 'fixed', viewportMargin = 30, autoFlip =
|
|
39
|
+
const { isOpen, children, anchorElement, zIndex, overrides, anchorPos = 'auto', positionStrategy = 'fixed', viewportMargin = 30, autoFlip = false, alternativePlacements, offset = 0, onAnchorPosChanged } = props, nativeProps = __rest(props, ["isOpen", "children", "anchorElement", "zIndex", "overrides", "anchorPos", "positionStrategy", "viewportMargin", "autoFlip", "alternativePlacements", "offset", "onAnchorPosChanged"]);
|
|
40
40
|
const [domLoaded, setDomLoaded] = react_1.default.useState(false);
|
|
41
|
-
const { actualPlacement, style, popperRef, isVisible } = (0,
|
|
41
|
+
const { actualPlacement, style, popperRef, isVisible } = (0, usePopper_1.usePopper)({
|
|
42
42
|
anchorElement,
|
|
43
43
|
anchorPos,
|
|
44
44
|
positionStrategy,
|
|
45
45
|
autoFlip,
|
|
46
46
|
offset,
|
|
47
47
|
viewportMargin,
|
|
48
|
+
alternativePlacements,
|
|
48
49
|
isOpen,
|
|
49
50
|
});
|
|
50
51
|
const overridesMap = react_1.default.useMemo(() => ({
|
|
@@ -77,8 +78,9 @@ const Popper = (props, ref) => {
|
|
|
77
78
|
onAnchorPosChanged(actualPlacement);
|
|
78
79
|
}
|
|
79
80
|
}, [anchorPos, actualPlacement, onAnchorPosChanged]);
|
|
81
|
+
const childrenMemo = react_1.default.useMemo(() => children, [children]);
|
|
80
82
|
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
|
-
|
|
83
|
+
position: 'fixed',
|
|
82
84
|
})), zIndex: zIndex, positionStrategy: positionStrategy, "data-popper-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
83
85
|
popperRef.current = el;
|
|
84
86
|
if (ref) {
|
|
@@ -89,7 +91,7 @@ const Popper = (props, ref) => {
|
|
|
89
91
|
ref.current = el;
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
} }),
|
|
94
|
+
} }), childrenMemo)), [
|
|
93
95
|
overridesMap,
|
|
94
96
|
nativeProps,
|
|
95
97
|
style,
|
|
@@ -98,7 +100,7 @@ const Popper = (props, ref) => {
|
|
|
98
100
|
actualPlacement,
|
|
99
101
|
positionStrategy,
|
|
100
102
|
zIndex,
|
|
101
|
-
|
|
103
|
+
childrenMemo,
|
|
102
104
|
popperRef,
|
|
103
105
|
ref,
|
|
104
106
|
]);
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
export type PositionStrategy = 'absolute' | 'fixed';
|
|
3
3
|
export interface PopperContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
4
|
readonly zIndex?: number;
|
|
5
|
-
readonly disablePortal?: boolean;
|
|
6
5
|
readonly positionStrategy?: PositionStrategy;
|
|
7
6
|
}
|
|
8
7
|
declare const _default: React.ForwardRefExoticComponent<PopperContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -18,10 +18,15 @@ const react_1 = __importDefault(require("react"));
|
|
|
18
18
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
19
|
const StyledContainer = styled_1.default.div `
|
|
20
20
|
position: ${({ $positionStrategy }) => $positionStrategy};
|
|
21
|
-
z-index: ${({ theme, $zIndex, $
|
|
21
|
+
z-index: ${({ theme, $zIndex, $positionStrategy }) => {
|
|
22
|
+
if (typeof $zIndex !== 'undefined') {
|
|
23
|
+
return $zIndex;
|
|
24
|
+
}
|
|
25
|
+
return $positionStrategy === 'fixed' ? theme.zIndex.modal : undefined;
|
|
26
|
+
}};
|
|
22
27
|
`;
|
|
23
28
|
const PopperContainer = (props, ref) => {
|
|
24
|
-
const { children,
|
|
25
|
-
return (react_1.default.createElement(StyledContainer, Object.assign({ "$
|
|
29
|
+
const { children, zIndex, positionStrategy = 'fixed' } = props, nativeProps = __rest(props, ["children", "zIndex", "positionStrategy"]);
|
|
30
|
+
return (react_1.default.createElement(StyledContainer, Object.assign({ "$zIndex": zIndex, "$positionStrategy": positionStrategy }, nativeProps, { ref: ref }), children));
|
|
26
31
|
};
|
|
27
32
|
exports.default = react_1.default.forwardRef(PopperContainer);
|
package/Popper/index.d.ts
CHANGED
package/Popper/index.js
CHANGED
|
@@ -20,5 +20,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
const Popper_1 = __importDefault(require("./Popper"));
|
|
21
21
|
__exportStar(require("./Popper"), exports);
|
|
22
22
|
__exportStar(require("./PopperContainer"), exports);
|
|
23
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./usePopper"), exports);
|
|
24
24
|
exports.default = Popper_1.default;
|
|
@@ -0,0 +1,111 @@
|
|
|
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 alternativePlacements?: readonly AnchorPos[];
|
|
83
|
+
readonly positionStrategy?: PositionStrategy;
|
|
84
|
+
readonly autoFlip?: boolean;
|
|
85
|
+
readonly offset?: number;
|
|
86
|
+
readonly viewportMargin?: number;
|
|
87
|
+
readonly isOpen?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface UsePopperResult {
|
|
90
|
+
readonly actualPlacement: AnchorPos;
|
|
91
|
+
readonly style: React.CSSProperties | null;
|
|
92
|
+
readonly popperRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
93
|
+
readonly isVisible: boolean;
|
|
94
|
+
readonly calculatePosition: () => void;
|
|
95
|
+
readonly scrollableAncestor: HTMLElement | Window | null;
|
|
96
|
+
readonly setActualPlacement: React.Dispatch<React.SetStateAction<AnchorPos>>;
|
|
97
|
+
readonly setStyle: React.Dispatch<React.SetStateAction<React.CSSProperties | null>>;
|
|
98
|
+
readonly setIsVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Finds the closest scrollable ancestor of an element.
|
|
102
|
+
* A scrollable element is one that has overflow set to auto, scroll, or overlay
|
|
103
|
+
* and has content that overflows, allowing scrolling.
|
|
104
|
+
*
|
|
105
|
+
* @param element - The element to start searching from
|
|
106
|
+
* @param includeHidden - Whether to consider elements with overflow: hidden
|
|
107
|
+
* @returns The closest scrollable ancestor or window if none found
|
|
108
|
+
*/
|
|
109
|
+
export declare const findScrollableAncestor: (element: HTMLElement | null, includeHidden?: boolean) => HTMLElement | Window | null;
|
|
110
|
+
export declare const usePopper: (props: UsePopperProps) => UsePopperResult;
|
|
111
|
+
export default usePopper;
|