@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -47,10 +47,6 @@ export const useStyles = createThemedStyles('IconButton', {
47
47
  },
48
48
 
49
49
  loading: {
50
- '& $content': {
51
- visibility: 'hidden',
52
- },
53
-
54
50
  '& $loader': {
55
51
  display: 'block',
56
52
  },
@@ -59,6 +59,7 @@ const Template: ComponentStory<typeof NewMoreMenu> = (args) => (
59
59
  export const Default = Template.bind({});
60
60
 
61
61
  Default.args = {
62
+ canBeFlipped: false,
62
63
  isDisabled: false,
63
64
  hasDefaultStateBackground: true,
64
65
  placement: 'bottom-end',
@@ -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<IWithPopupProps, 'middlewares' | 'shouldHideOnScroll' | 'shouldRenderInBody'>,
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 }) => (
@@ -65,6 +65,7 @@ const Template: ComponentStory<typeof WithPopup> = (args) => (
65
65
  export const Default = Template.bind({});
66
66
 
67
67
  Default.args = {
68
+ canBeFlipped: false,
68
69
  isDisabled: false,
69
70
  shouldRenderInBody: true,
70
71
  shouldHideOnScroll: false,
@@ -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: [offset(popupOffset), ...(middlewares ?? [])],
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)}