@true-engineering/true-react-common-ui-kit 3.13.0 → 3.14.0
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/README.md +13 -0
- package/dist/components/NewMoreMenu/NewMoreMenu.d.ts +1 -1
- package/dist/components/WithPopup/WithPopup.d.ts +2 -0
- package/dist/true-react-common-ui-kit.js +17 -10
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +16 -9
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/IconButton/IconButton.styles.ts +0 -4
- package/src/components/NewMoreMenu/NewMoreMenu.stories.tsx +1 -0
- package/src/components/NewMoreMenu/NewMoreMenu.tsx +6 -1
- package/src/components/WithPopup/WithPopup.stories.tsx +1 -0
- package/src/components/WithPopup/WithPopup.tsx +13 -4
package/package.json
CHANGED
|
@@ -10,7 +10,10 @@ import { IWithPopupProps, WithPopup } from '../WithPopup';
|
|
|
10
10
|
import { useStyles, INewMoreMenuStyles } from './NewMoreMenu.styles';
|
|
11
11
|
|
|
12
12
|
export interface INewMoreMenuProps
|
|
13
|
-
extends Pick<
|
|
13
|
+
extends Pick<
|
|
14
|
+
IWithPopupProps,
|
|
15
|
+
'middlewares' | 'shouldHideOnScroll' | 'shouldRenderInBody' | 'canBeFlipped'
|
|
16
|
+
>,
|
|
14
17
|
ICommonProps<INewMoreMenuStyles> {
|
|
15
18
|
items: IListItem[];
|
|
16
19
|
/** @default false */
|
|
@@ -31,6 +34,7 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
31
34
|
middlewares,
|
|
32
35
|
shouldHideOnScroll,
|
|
33
36
|
shouldRenderInBody,
|
|
37
|
+
canBeFlipped,
|
|
34
38
|
tweakStyles,
|
|
35
39
|
}) => {
|
|
36
40
|
const classes = useStyles({ theme: tweakStyles });
|
|
@@ -55,6 +59,7 @@ export const NewMoreMenu: FC<INewMoreMenuProps> = ({
|
|
|
55
59
|
middlewares={middlewares}
|
|
56
60
|
shouldHideOnScroll={shouldHideOnScroll}
|
|
57
61
|
shouldRenderInBody={shouldRenderInBody}
|
|
62
|
+
canBeFlipped={canBeFlipped}
|
|
58
63
|
isDisabled={isButtonDisabled}
|
|
59
64
|
tweakStyles={tweakWithPopupStyles}
|
|
60
65
|
trigger={({ isActive }) => (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC, ReactNode, useState, MouseEvent } from 'react';
|
|
1
|
+
import { FC, ReactNode, useState, MouseEvent, useMemo } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { addDataTestId, isFunction } from '@true-engineering/true-react-platform-helpers';
|
|
4
4
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Middleware,
|
|
13
13
|
FloatingPortal,
|
|
14
14
|
offset,
|
|
15
|
+
flip,
|
|
15
16
|
} from '@floating-ui/react';
|
|
16
17
|
import { addDataAttributes } from '../../helpers';
|
|
17
18
|
import { ICommonProps } from '../../types';
|
|
@@ -36,6 +37,8 @@ export interface IWithPopupProps extends ICommonProps<IWithPopupStyles> {
|
|
|
36
37
|
/** @default 6 */
|
|
37
38
|
popupOffset?: number;
|
|
38
39
|
/** @default false */
|
|
40
|
+
canBeFlipped?: boolean;
|
|
41
|
+
/** @default false */
|
|
39
42
|
isDisabled?: boolean;
|
|
40
43
|
onToggle?: (isActive: boolean) => void;
|
|
41
44
|
}
|
|
@@ -43,13 +46,14 @@ export interface IWithPopupProps extends ICommonProps<IWithPopupStyles> {
|
|
|
43
46
|
export const WithPopup: FC<IWithPopupProps> = ({
|
|
44
47
|
trigger,
|
|
45
48
|
children,
|
|
46
|
-
middlewares,
|
|
49
|
+
middlewares: initialMiddlewares,
|
|
47
50
|
eventType = 'click',
|
|
48
51
|
placement = eventType === 'click' ? 'bottom-end' : 'top',
|
|
49
52
|
shouldHideOnScroll = false,
|
|
50
53
|
shouldRenderInBody = false,
|
|
51
54
|
hoverDelay = 0,
|
|
52
55
|
popupOffset = DEFAULT_OFFSET,
|
|
56
|
+
canBeFlipped = false,
|
|
53
57
|
isDisabled = false,
|
|
54
58
|
tweakStyles,
|
|
55
59
|
data,
|
|
@@ -63,6 +67,11 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
63
67
|
const Trigger = trigger;
|
|
64
68
|
const Popup = children;
|
|
65
69
|
|
|
70
|
+
const middleware = useMemo(
|
|
71
|
+
() => [offset(popupOffset), ...(canBeFlipped ? [flip()] : []), ...(initialMiddlewares ?? [])],
|
|
72
|
+
[popupOffset, canBeFlipped, initialMiddlewares],
|
|
73
|
+
);
|
|
74
|
+
|
|
66
75
|
const handleToggle = (isActive: boolean, event?: MouseEvent | Event) => {
|
|
67
76
|
event?.stopPropagation();
|
|
68
77
|
if (!isDisabled) {
|
|
@@ -77,7 +86,7 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
77
86
|
|
|
78
87
|
const { refs, floatingStyles, context } = useFloating({
|
|
79
88
|
open: isOpen,
|
|
80
|
-
middleware
|
|
89
|
+
middleware,
|
|
81
90
|
whileElementsMounted: autoUpdate,
|
|
82
91
|
placement,
|
|
83
92
|
onOpenChange: handleToggle,
|
|
@@ -98,7 +107,7 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
98
107
|
return (
|
|
99
108
|
<div
|
|
100
109
|
ref={refs.setReference}
|
|
101
|
-
{...getReferenceProps}
|
|
110
|
+
{...getReferenceProps()}
|
|
102
111
|
className={clsx(classes.root, { [classes.disabled]: isDisabled })}
|
|
103
112
|
{...addDataTestId(testId)}
|
|
104
113
|
{...addDataAttributes(data)}
|