@true-engineering/true-react-common-ui-kit 4.0.0-alpha2 → 4.0.0-alpha3

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": "4.0.0-alpha2",
3
+ "version": "4.0.0-alpha3",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -91,6 +91,7 @@ Default.args = {
91
91
  shouldRenderInBody: true,
92
92
  shouldHideOnScroll: false,
93
93
  shouldStopPropagation: true,
94
+ shouldShowArrow: false,
94
95
  };
95
96
 
96
97
  Default.parameters = {
@@ -20,6 +20,8 @@ export const useStyles = createThemedStyles('WithPopup', {
20
20
  outline: 'none',
21
21
  },
22
22
 
23
+ arrow: {},
24
+
23
25
  animationEnd: {},
24
26
 
25
27
  animationStart: {},
@@ -1,7 +1,6 @@
1
- import { FC, useState } from 'react';
1
+ import { FC, useRef, useState } from 'react';
2
2
  import clsx from 'clsx';
3
3
  import {
4
- addDataTestId,
5
4
  applyAction,
6
5
  stopPropagation,
7
6
  addDataAttributes,
@@ -23,10 +22,14 @@ import {
23
22
  UseHoverProps,
24
23
  safePolygon,
25
24
  useFocus,
25
+ FloatingArrow,
26
+ arrow,
26
27
  } from '@floating-ui/react';
27
- import { ICommonProps, IRenderNode } from '../../types';
28
+ import { ICommonProps, IDataAttributes, IRenderNode } from '../../types';
28
29
  import { DEFAULT_OFFSET } from './constants';
30
+ import { minWidthRelativeToTrigger } from './helpers';
29
31
  import {
32
+ IPopupArrowProps,
30
33
  IPopupEventType,
31
34
  IReferenceProps,
32
35
  IWithPopupChildrenProps,
@@ -47,7 +50,9 @@ export interface IWithPopupProps extends ICommonProps<IWithPopupStyles> {
47
50
  hoverDelay?: UseHoverProps['delay'];
48
51
  /** @default 6 */
49
52
  popupOffset?: OffsetOptions;
50
- /** @default true */
53
+ arrowProps?: IPopupArrowProps;
54
+ popupData?: IDataAttributes;
55
+ /** @default true, if eventType === click */
51
56
  shouldStopPropagation?: boolean;
52
57
  /** @default false */
53
58
  shouldHideOnScroll?: boolean;
@@ -60,6 +65,11 @@ export interface IWithPopupProps extends ICommonProps<IWithPopupStyles> {
60
65
  canBeFlipped?: boolean;
61
66
  /** @default false */
62
67
  isDisabled?: boolean;
68
+ /** @default false */
69
+ shouldShowArrow?: boolean;
70
+ /** Должна ли минимальная ширина попапа быть равна ширине триггера
71
+ * @default false */
72
+ isMinWidthSameAsTrigger?: boolean;
63
73
  onToggle?: (isActive: boolean, event?: IWithPopupToggleEvent) => void;
64
74
  }
65
75
 
@@ -71,12 +81,16 @@ export const WithPopup: FC<IWithPopupProps> = ({
71
81
  placement = eventType === 'click' ? 'bottom-end' : 'top',
72
82
  hoverDelay = 0,
73
83
  popupOffset = DEFAULT_OFFSET,
74
- shouldStopPropagation = true,
84
+ arrowProps,
85
+ popupData,
86
+ shouldStopPropagation = eventType === 'click',
75
87
  shouldHideOnScroll = false,
76
88
  shouldRenderInBody = true,
77
89
  canBeFlipped = true,
78
90
  isTriggerWrapped = eventType === 'hover',
79
91
  isDisabled = false,
92
+ shouldShowArrow = false,
93
+ isMinWidthSameAsTrigger = false,
80
94
  tweakStyles,
81
95
  data,
82
96
  testId,
@@ -86,6 +100,8 @@ export const WithPopup: FC<IWithPopupProps> = ({
86
100
 
87
101
  const [isOpen, setIsOpen] = useState(false);
88
102
 
103
+ const arrowRef = useRef<SVGSVGElement>(null);
104
+
89
105
  const handleToggle = (isActive: boolean, event?: IWithPopupToggleEvent) => {
90
106
  event?.stopPropagation();
91
107
  if (!isDisabled) {
@@ -103,7 +119,9 @@ export const WithPopup: FC<IWithPopupProps> = ({
103
119
  middleware: [
104
120
  offset(popupOffset),
105
121
  canBeFlipped && flip({ fallbackAxisSideDirection: 'start' }),
122
+ isMinWidthSameAsTrigger && minWidthRelativeToTrigger,
106
123
  ...middlewares,
124
+ shouldShowArrow && arrow({ element: arrowRef }),
107
125
  ],
108
126
  whileElementsMounted: autoUpdate,
109
127
  placement,
@@ -155,8 +173,7 @@ export const WithPopup: FC<IWithPopupProps> = ({
155
173
  [classes.active]: isOpen,
156
174
  })}
157
175
  {...referenceProps}
158
- {...addDataTestId(testId)}
159
- {...addDataAttributes(data)}
176
+ {...addDataAttributes(data, testId)}
160
177
  >
161
178
  {triggerElement}
162
179
  </div>
@@ -165,16 +182,25 @@ export const WithPopup: FC<IWithPopupProps> = ({
165
182
  )}
166
183
  {isMounted && (
167
184
  <FloatingPortal
168
- root={!shouldRenderInBody ? (refs.reference.current as HTMLDivElement) : undefined}
185
+ root={shouldRenderInBody ? document.body : (refs.reference.current as HTMLElement)}
169
186
  >
170
187
  <div
188
+ ref={refs.setFloating}
171
189
  style={floatingStyles}
172
190
  className={classes.popup}
173
- ref={refs.setFloating}
174
191
  {...getFloatingProps()}
192
+ {...addDataAttributes(popupData)}
175
193
  >
176
194
  <div className={classes[`dropdown-${status}`]}>
177
- {applyAction(children, { onClose: handleClose })}
195
+ {shouldShowArrow && (
196
+ <FloatingArrow
197
+ {...arrowProps}
198
+ ref={arrowRef}
199
+ context={context}
200
+ className={classes.arrow}
201
+ />
202
+ )}
203
+ {applyAction(children, { floatingContext: context, onClose: handleClose })}
178
204
  </div>
179
205
  </div>
180
206
  </FloatingPortal>
@@ -0,0 +1,9 @@
1
+ import { Middleware, size } from '@floating-ui/react';
2
+
3
+ export const minWidthRelativeToTrigger: Middleware = size({
4
+ apply({ rects, elements }) {
5
+ Object.assign(elements.floating.style, {
6
+ minWidth: `${rects.reference.width}px`,
7
+ });
8
+ },
9
+ });
@@ -1,4 +1,5 @@
1
1
  import type { MouseEvent, KeyboardEvent } from 'react';
2
+ import type { FloatingArrowProps, UseFloatingReturn } from '@floating-ui/react';
2
3
  import type { IDataAttributesProps, IDomElementInteractions } from '../../types';
3
4
  import type { POPUP_EVENT_TYPES } from './constants';
4
5
 
@@ -21,5 +22,11 @@ export interface IWithPopupTriggerProps {
21
22
  }
22
23
 
23
24
  export interface IWithPopupChildrenProps {
25
+ floatingContext: UseFloatingReturn['context'];
24
26
  onClose: (event?: IWithPopupToggleEvent) => void;
25
27
  }
28
+
29
+ export type IPopupArrowProps = Pick<
30
+ FloatingArrowProps,
31
+ 'width' | 'height' | 'tipRadius' | 'staticOffset' | 'd' | 'stroke' | 'strokeWidth'
32
+ >;
@@ -1,6 +1,12 @@
1
1
  import { ITooltipStyles } from '../Tooltip';
2
2
  import { IWithPopupStyles } from '../WithPopup';
3
3
 
4
+ export const withPopupStyles: IWithPopupStyles = {
5
+ popup: {
6
+ zIndex: 9999,
7
+ },
8
+ };
9
+
4
10
  export interface IWithTooltipStyles {
5
11
  tweakWithPopup?: IWithPopupStyles;
6
12
  tweakTooltip?: ITooltipStyles;
@@ -4,7 +4,7 @@ import { useTweakStyles } from '../../hooks';
4
4
  import { ICommonProps } from '../../types';
5
5
  import { ITooltipProps, Tooltip } from '../Tooltip';
6
6
  import { IWithPopupProps, WithPopup } from '../WithPopup';
7
- import { IWithTooltipStyles } from './WithTooltip.styles';
7
+ import { IWithTooltipStyles, withPopupStyles } from './WithTooltip.styles';
8
8
 
9
9
  export interface IWithTooltipProps
10
10
  extends Omit<
@@ -32,17 +32,21 @@ export const WithTooltip: FC<IWithTooltipProps> = ({
32
32
  tooltipView = 'tooltip',
33
33
  tooltipType = 'info',
34
34
  isDisabled = false,
35
+ popupData,
35
36
  tweakStyles,
36
37
  ...restProps
37
38
  }) => {
38
39
  const tweakWithPopupStyles = useTweakStyles({
40
+ innerStyles: withPopupStyles,
39
41
  tweakStyles,
40
42
  className: 'tweakWithPopup',
43
+ currentComponentName: 'WithTooltip',
41
44
  });
42
45
 
43
46
  const tweakTooltipStyles = useTweakStyles({
44
47
  tweakStyles,
45
48
  className: 'tweakTooltip',
49
+ currentComponentName: 'WithTooltip',
46
50
  });
47
51
 
48
52
  return (
@@ -50,8 +54,9 @@ export const WithTooltip: FC<IWithTooltipProps> = ({
50
54
  trigger={children}
51
55
  placement={placement}
52
56
  eventType={eventType}
53
- isTriggerWrapped
57
+ popupData={{ ...popupData, tooltipView }}
54
58
  isDisabled={isDisabled || !isReactNodeNotEmpty(tooltipText)}
59
+ isTriggerWrapped
55
60
  tweakStyles={tweakWithPopupStyles}
56
61
  {...restProps}
57
62
  >
@@ -91,9 +91,12 @@ export const helpers = {
91
91
 
92
92
  // Chromium
93
93
  '@supports selector(::-webkit-scrollbar)': {
94
+ '--webkit-scrollbar-width': '10px',
95
+ '--webkit-scrollbar-height': '10px',
96
+
94
97
  '&::-webkit-scrollbar': {
95
- height: 10,
96
- width: 10,
98
+ width: 'var(--webkit-scrollbar-width)',
99
+ height: 'var(--webkit-scrollbar-height)',
97
100
 
98
101
  '&-thumb': {
99
102
  width: 6,