@qoretechnologies/reqore 0.25.8 → 0.25.10

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.
Files changed (53) hide show
  1. package/__tests__/dropdown.test.tsx +133 -12
  2. package/dist/components/Collection/index.d.ts +2 -2
  3. package/dist/components/Collection/index.d.ts.map +1 -1
  4. package/dist/components/Collection/index.js +6 -6
  5. package/dist/components/Collection/index.js.map +1 -1
  6. package/dist/components/Collection/item.d.ts +2 -2
  7. package/dist/components/Collection/item.d.ts.map +1 -1
  8. package/dist/components/Collection/item.js +6 -3
  9. package/dist/components/Collection/item.js.map +1 -1
  10. package/dist/components/Dropdown/index.d.ts +8 -7
  11. package/dist/components/Dropdown/index.d.ts.map +1 -1
  12. package/dist/components/Dropdown/index.js +12 -5
  13. package/dist/components/Dropdown/index.js.map +1 -1
  14. package/dist/components/Dropdown/item.d.ts +2 -2
  15. package/dist/components/Dropdown/item.d.ts.map +1 -1
  16. package/dist/components/Dropdown/item.js.map +1 -1
  17. package/dist/components/Dropdown/list.d.ts +9 -2
  18. package/dist/components/Dropdown/list.d.ts.map +1 -1
  19. package/dist/components/Dropdown/list.js +13 -5
  20. package/dist/components/Dropdown/list.js.map +1 -1
  21. package/dist/components/InternalPopover/index.d.ts.map +1 -1
  22. package/dist/components/InternalPopover/index.js +0 -1
  23. package/dist/components/InternalPopover/index.js.map +1 -1
  24. package/dist/components/Panel/index.d.ts +3 -2
  25. package/dist/components/Panel/index.d.ts.map +1 -1
  26. package/dist/components/Panel/index.js +16 -17
  27. package/dist/components/Panel/index.js.map +1 -1
  28. package/dist/components/Popover/index.d.ts +1 -1
  29. package/dist/components/Popover/index.d.ts.map +1 -1
  30. package/dist/components/Popover/index.js +4 -2
  31. package/dist/components/Popover/index.js.map +1 -1
  32. package/dist/hooks/usePopover.d.ts.map +1 -1
  33. package/dist/hooks/usePopover.js +23 -9
  34. package/dist/hooks/usePopover.js.map +1 -1
  35. package/dist/hooks/useWhyDidYouUpdate.d.ts +2 -0
  36. package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -0
  37. package/dist/hooks/useWhyDidYouUpdate.js +47 -0
  38. package/dist/hooks/useWhyDidYouUpdate.js.map +1 -0
  39. package/package.json +1 -1
  40. package/src/components/Collection/index.tsx +3 -2
  41. package/src/components/Collection/item.tsx +6 -3
  42. package/src/components/Dropdown/index.tsx +62 -36
  43. package/src/components/Dropdown/item.tsx +3 -6
  44. package/src/components/Dropdown/list.tsx +82 -56
  45. package/src/components/InternalPopover/index.tsx +0 -2
  46. package/src/components/Panel/index.tsx +71 -59
  47. package/src/components/Popover/index.tsx +53 -38
  48. package/src/hooks/usePopover.tsx +34 -20
  49. package/src/hooks/useWhyDidYouUpdate.ts +32 -0
  50. package/src/stories/Collection/Collection.stories.tsx +1 -1
  51. package/src/stories/Dropdown/Dropdown.stories.tsx +62 -34
  52. package/src/stories/Panel/Panel.stories.tsx +9 -4
  53. package/tests.json +1 -1
@@ -1,33 +1,31 @@
1
1
  import { size } from 'lodash';
2
- import React from 'react';
2
+ import React, { memo, useMemo } from 'react';
3
3
  import { ReqorePopover } from '../..';
4
4
  import { IPopoverOptions } from '../../hooks/usePopover';
5
5
  import { IReqoreIconName } from '../../types/icons';
6
6
  import ReqoreButton, { IReqoreButtonProps } from '../Button';
7
- import { IReqoreDropdownItemProps } from './item';
8
- import ReqoreDropdownList from './list';
7
+ import ReqoreDropdownList, { IReqoreDropdownItem, TDropdownItemOnClick } from './list';
9
8
 
10
- export interface IReqoreDropdownProps<T> extends IPopoverOptions {
11
- items?: IReqoreDropdownItemProps[];
9
+ export interface IReqoreDropdownProps extends Partial<IPopoverOptions> {
10
+ items?: IReqoreDropdownItem[];
12
11
  multiSelect?: boolean;
13
12
  buttonStyle?: React.CSSProperties;
14
13
  listStyle?: React.CSSProperties;
15
14
  component?: any;
16
- componentProps?: T;
17
15
  filterable?: boolean;
18
16
  label?: any;
19
17
  children?: any;
20
- width?: string;
18
+ listWidth?: string;
21
19
  icon?: IReqoreIconName;
22
20
  rightIcon?: IReqoreIconName;
23
21
  caretPosition?: 'left' | 'right';
24
22
  isDefaultOpen?: boolean;
23
+ onItemSelect?: TDropdownItemOnClick;
25
24
  }
26
25
 
27
- const ReqoreDropdown = <T extends unknown = IReqoreButtonProps>({
26
+ function ReqoreDropdown<T extends unknown = IReqoreButtonProps>({
28
27
  items,
29
28
  component,
30
- componentProps,
31
29
  label,
32
30
  children,
33
31
  multiSelect,
@@ -40,43 +38,71 @@ const ReqoreDropdown = <T extends unknown = IReqoreButtonProps>({
40
38
  rightIcon,
41
39
  caretPosition = 'left',
42
40
  isDefaultOpen = false,
41
+ onItemSelect,
42
+ closeOnOutsideClick,
43
+ blur,
44
+ closeOnAnyClick,
45
+ content,
46
+ delay,
47
+ maxHeight,
48
+ maxWidth,
49
+ noArrow = true,
50
+ opaque,
51
+ openOnMount,
52
+ show,
53
+ targetElement,
54
+ useTargetWidth,
55
+ listWidth,
43
56
  ...rest
44
- }: IReqoreDropdownProps<T>) => {
57
+ }: IReqoreDropdownProps & T) {
58
+ const componentProps = useMemo(
59
+ () =>
60
+ ({
61
+ ...rest,
62
+ icon: caretPosition === 'left' ? icon || 'ArrowDownSFill' : rightIcon,
63
+ rightIcon: caretPosition === 'right' ? icon || 'ArrowDownSFill' : rightIcon,
64
+ style: buttonStyle,
65
+ disabled: !size(items),
66
+ className: `${(rest as any)?.className || ''} reqore-dropdown-control`,
67
+ } as T),
68
+ [items, icon, rightIcon, buttonStyle, caretPosition, rest]
69
+ );
70
+
71
+ const popoverContent = useMemo(() => {
72
+ return size(items) ? (
73
+ <ReqoreDropdownList
74
+ multiSelect={multiSelect}
75
+ listStyle={listStyle}
76
+ width={useTargetWidth ? '100%' : listWidth}
77
+ items={items}
78
+ filterable={filterable}
79
+ onItemSelect={onItemSelect}
80
+ />
81
+ ) : undefined;
82
+ }, [items]);
83
+
45
84
  return (
46
85
  <ReqorePopover
47
- {...rest}
86
+ closeOnOutsideClick={closeOnOutsideClick}
87
+ blur={blur}
88
+ closeOnAnyClick={closeOnAnyClick}
89
+ delay={delay}
90
+ maxHeight={maxHeight}
91
+ maxWidth={maxWidth}
92
+ noArrow={noArrow}
93
+ opaque={opaque}
94
+ useTargetWidth={useTargetWidth}
48
95
  component={component || ReqoreButton}
49
- componentProps={
50
- {
51
- icon: caretPosition === 'left' ? icon || 'ArrowDownSFill' : rightIcon,
52
- rightIcon: caretPosition === 'right' ? icon || 'ArrowDownSFill' : rightIcon,
53
- style: buttonStyle,
54
- disabled: !size(items),
55
- ...rest,
56
- ...((componentProps || {}) as Object),
57
- className: `${(componentProps as any)?.className || ''} reqore-dropdown-control`,
58
- } as T
59
- }
96
+ componentProps={componentProps}
60
97
  noWrapper
61
98
  placement={placement || 'bottom-start'}
62
99
  handler={handler || 'click'}
63
100
  openOnMount={isDefaultOpen}
64
- content={
65
- size(items) ? (
66
- <ReqoreDropdownList
67
- multiSelect={multiSelect}
68
- listStyle={listStyle}
69
- width={rest.useTargetWidth ? '100%' : rest.width}
70
- items={items}
71
- filterable={filterable}
72
- />
73
- ) : undefined
74
- }
75
- noArrow
101
+ content={popoverContent}
76
102
  >
77
103
  {children || label}
78
104
  </ReqorePopover>
79
105
  );
80
- };
106
+ }
81
107
 
82
- export default ReqoreDropdown;
108
+ export default memo(ReqoreDropdown) as typeof ReqoreDropdown;
@@ -1,13 +1,10 @@
1
1
  import { ReqoreMenuDivider, ReqoreMenuItem } from '../..';
2
2
  import { IReqoreMenuDividerProps } from '../Menu/divider';
3
- import { IReqoreMenuItemProps } from '../Menu/item';
3
+ import { IReqoreDropdownItem } from './list';
4
4
 
5
- export interface IReqoreDropdownItemProps extends IReqoreMenuItemProps {}
5
+ export interface IReqoreDropdownItemProps extends Omit<IReqoreDropdownItem, 'value' | 'onClick'> {}
6
6
 
7
- export const ReqoreDropdownItem = ({
8
- children,
9
- ...rest
10
- }: IReqoreDropdownItemProps) => (
7
+ export const ReqoreDropdownItem = ({ children, ...rest }: IReqoreDropdownItemProps) => (
11
8
  <ReqoreMenuItem {...rest} rightIcon={rest.selected ? 'CheckLine' : undefined}>
12
9
  {children}
13
10
  </ReqoreMenuItem>
@@ -1,80 +1,106 @@
1
- import React, { useEffect, useMemo, useState } from 'react';
1
+ import React, { memo, useEffect, useMemo, useState } from 'react';
2
2
  import { IReqoreComponent } from '../../types/global';
3
3
  import ReqoreInput from '../Input';
4
4
  import ReqoreMenu from '../Menu';
5
5
  import ReqoreMenuItem, { IReqoreMenuItemProps } from '../Menu/item';
6
6
  import { ReqoreSpacer } from '../Spacer';
7
7
 
8
+ export type TDropdownItemOnClick = (item: IReqoreDropdownItem) => void;
9
+ export interface IReqoreDropdownItem extends Omit<IReqoreMenuItemProps, 'onClick'> {
10
+ value: any;
11
+ label?: string;
12
+ onClick?: TDropdownItemOnClick;
13
+ }
14
+
8
15
  export interface IReqoreDropdownListProps extends IReqoreComponent {
9
- items?: IReqoreMenuItemProps[];
16
+ items?: IReqoreDropdownItem[];
10
17
  multiSelect?: boolean;
11
18
  listStyle?: React.CSSProperties;
12
19
  width?: string;
13
20
  height?: string;
14
21
  filterable?: boolean;
22
+ onItemSelect?: TDropdownItemOnClick;
15
23
  }
16
24
 
17
- const ReqoreDropdownList = ({
18
- items,
19
- multiSelect,
20
- listStyle,
21
- _popoverId,
22
- filterable,
23
- width,
24
- height,
25
- }: IReqoreDropdownListProps) => {
26
- const [_items, setItems] = useState<IReqoreMenuItemProps[]>(items);
27
- const [query, setQuery] = useState<string>('');
25
+ const ReqoreDropdownList = memo(
26
+ ({
27
+ items,
28
+ multiSelect,
29
+ listStyle,
30
+ _popoverId,
31
+ filterable,
32
+ width,
33
+ height,
34
+ onItemSelect,
35
+ }: IReqoreDropdownListProps) => {
36
+ const [_items, setItems] = useState<IReqoreDropdownItem[]>(items);
37
+ const [query, setQuery] = useState<string>('');
28
38
 
29
- useEffect(() => {
30
- setItems(items);
31
- }, [items]);
39
+ useEffect(() => {
40
+ setItems(items);
41
+ }, [items]);
32
42
 
33
- const filteredItems: IReqoreMenuItemProps[] = useMemo(() => {
34
- if (!filterable || query === '') {
35
- return _items;
36
- }
43
+ const filteredItems: IReqoreDropdownItem[] = useMemo(() => {
44
+ if (!filterable || query === '') {
45
+ return _items;
46
+ }
37
47
 
38
- return _items.filter((item) => {
39
- const text = item.label || item.children;
48
+ return _items.filter((item) => {
49
+ const text = item.label || item.value || item.children;
40
50
 
41
- if (!text) {
42
- return false;
43
- }
51
+ if (!text) {
52
+ return false;
53
+ }
44
54
 
45
- return text.toString().toLowerCase().indexOf(query.toLowerCase()) !== -1;
46
- });
47
- }, [items, query, _items]);
55
+ return text.toString().toLowerCase().indexOf(query.toLowerCase()) !== -1;
56
+ });
57
+ }, [items, query, _items]);
48
58
 
49
- const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
50
- setQuery(event.target.value);
51
- };
59
+ const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
60
+ setQuery(event.target.value);
61
+ };
62
+
63
+ const handleItemClick = (item: IReqoreDropdownItem): void => {
64
+ if (item.onClick) {
65
+ item.onClick(item);
66
+ }
67
+
68
+ if (onItemSelect) {
69
+ onItemSelect(item);
70
+ }
71
+ };
52
72
 
53
- return (
54
- <ReqoreMenu
55
- _insidePopover={!multiSelect}
56
- _popoverId={_popoverId}
57
- style={listStyle}
58
- width={width}
59
- maxHeight={height || '300px'}
60
- >
61
- {filterable && (
62
- <>
63
- <ReqoreInput
64
- value={query}
65
- onChange={handleQueryChange}
66
- placeholder='Filter'
67
- autoFocus
68
- onClearClick={() => setQuery('')}
73
+ return (
74
+ <ReqoreMenu
75
+ _insidePopover={!multiSelect}
76
+ _popoverId={_popoverId}
77
+ style={listStyle}
78
+ width={width}
79
+ maxHeight={height || '300px'}
80
+ >
81
+ {filterable && (
82
+ <>
83
+ <ReqoreInput
84
+ value={query}
85
+ onChange={handleQueryChange}
86
+ placeholder='Filter'
87
+ onClearClick={() => setQuery('')}
88
+ />
89
+ <ReqoreSpacer height={10} />
90
+ </>
91
+ )}
92
+ {filteredItems.map((item: IReqoreDropdownItem, index: number) => (
93
+ <ReqoreMenuItem
94
+ key={index}
95
+ {...item}
96
+ label={item.label || item.value}
97
+ onClick={() => handleItemClick(item)}
98
+ rightIcon={item.selected ? 'CheckLine' : undefined}
69
99
  />
70
- <ReqoreSpacer height={10} />
71
- </>
72
- )}
73
- {filteredItems.map((item: IReqoreMenuItemProps, index: number) => (
74
- <ReqoreMenuItem key={index} {...item} rightIcon={item.selected ? 'CheckLine' : undefined} />
75
- ))}
76
- </ReqoreMenu>
77
- );
78
- };
100
+ ))}
101
+ </ReqoreMenu>
102
+ );
103
+ }
104
+ );
79
105
 
80
106
  export default ReqoreDropdownList;
@@ -133,8 +133,6 @@ const InternalPopover: React.FC<IReqoreInternalPopoverProps> = ({
133
133
  ],
134
134
  });
135
135
 
136
- console.log(opaque);
137
-
138
136
  useEffect(() => {
139
137
  if (popperRef.current) {
140
138
  updatePopover?.(id, { popperRef });
@@ -31,13 +31,13 @@ import ReqoreButton, { IReqoreButtonProps } from '../Button';
31
31
  import { StyledCollectionItemContent } from '../Collection/item';
32
32
  import ReqoreControlGroup from '../ControlGroup';
33
33
  import ReqoreDropdown from '../Dropdown';
34
- import { IReqoreDropdownItemProps } from '../Dropdown/item';
34
+ import { IReqoreDropdownItem } from '../Dropdown/list';
35
35
  import ReqoreIcon from '../Icon';
36
36
 
37
37
  export interface IReqorePanelAction extends IReqoreButtonProps, IWithReqoreTooltip, IReqoreIntent {
38
38
  label?: string | number;
39
39
  onClick?: () => void;
40
- actions?: IReqoreDropdownItemProps[];
40
+ actions?: IReqoreDropdownItem[];
41
41
  customContent?: () => string | React.ReactNode;
42
42
  }
43
43
 
@@ -78,6 +78,7 @@ export interface IReqorePanelProps
78
78
 
79
79
  export interface IStyledPanel extends IReqorePanelProps {
80
80
  theme: IReqoreTheme;
81
+ noHorizontalPadding?: boolean;
81
82
  }
82
83
 
83
84
  export const StyledPanel = styled.div<IStyledPanel>`
@@ -135,7 +136,8 @@ export const StyledPanelTitle = styled.div<IStyledPanel>`
135
136
  justify-content: space-between;
136
137
  height: 40px;
137
138
  align-items: center;
138
- padding: 0 5px 0 15px;
139
+ padding: ${({ noHorizontalPadding }: IStyledPanel) =>
140
+ `0 5px 0 ${noHorizontalPadding ? 0 : '15px'}`};
139
141
  border-bottom: ${({ theme, isCollapsed, flat, opacity = 1 }) =>
140
142
  !isCollapsed && !flat
141
143
  ? `1px solid ${rgba(changeLightness(getMainBackgroundColor(theme), 0.2), opacity)}`
@@ -167,7 +169,12 @@ export const StyledPanelBottomActions = styled(StyledPanelTitle)`
167
169
  export const StyledPanelContent = styled.div<IStyledPanel>`
168
170
  display: ${({ isCollapsed }) => (isCollapsed ? 'none' : undefined)};
169
171
  min-height: ${({ isCollapsed }) => (isCollapsed ? undefined : '40px')};
170
- padding: ${({ padded, contentSize }) => (!padded ? undefined : TEXT_FROM_SIZE[contentSize])}px;
172
+ padding: ${({ padded, contentSize, noHorizontalPadding }) =>
173
+ !padded
174
+ ? undefined
175
+ : noHorizontalPadding
176
+ ? `${TEXT_FROM_SIZE[contentSize]}px 0`
177
+ : `${TEXT_FROM_SIZE[contentSize]}px`};
171
178
  // The padding is not needed when the panel is minimal and has title, since
172
179
  // the title already has padding and is transparent
173
180
  padding-top: ${({ minimal, hasLabel }) => (minimal && hasLabel ? '0px' : undefined)};
@@ -260,66 +267,68 @@ export const ReqorePanel = forwardRef(
260
267
  [leftBottomActions, rightBottomActions]
261
268
  );
262
269
 
263
- const renderActions = (
264
- actionOrActions: IReqorePanelAction | IReqorePanelAction[],
265
- index: number
266
- ) => {
267
- if (Array.isArray(actionOrActions)) {
268
- return (
269
- <ReqoreControlGroup stack minimal>
270
- {actionOrActions.map(renderActions)}
271
- </ReqoreControlGroup>
272
- );
273
- }
274
-
275
- const { id, actions, label, intent, className, customContent, ...rest }: IReqorePanelAction =
276
- actionOrActions;
270
+ const renderActions = useCallback(
271
+ (actionOrActions: IReqorePanelAction | IReqorePanelAction[], index: number) => {
272
+ if (Array.isArray(actionOrActions)) {
273
+ return (
274
+ <ReqoreControlGroup stack minimal>
275
+ {actionOrActions.map(renderActions)}
276
+ </ReqoreControlGroup>
277
+ );
278
+ }
279
+
280
+ const {
281
+ id,
282
+ actions,
283
+ label,
284
+ intent,
285
+ className,
286
+ customContent,
287
+ ...rest
288
+ }: IReqorePanelAction = actionOrActions;
289
+
290
+ if (size(actions)) {
291
+ return (
292
+ <ReqoreDropdown<IReqoreButtonProps>
293
+ {...rest}
294
+ key={index}
295
+ label={label}
296
+ items={actions}
297
+ intent={intent}
298
+ className={className}
299
+ onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.stopPropagation()}
300
+ id={id}
301
+ />
302
+ );
303
+ }
304
+
305
+ if (customContent) {
306
+ return customContent();
307
+ }
277
308
 
278
- if (size(actions)) {
279
309
  return (
280
- <ReqoreDropdown
310
+ <ReqoreButton
281
311
  {...rest}
312
+ id={id}
282
313
  key={index}
283
- label={label}
284
- componentProps={{
285
- intent,
286
- id,
287
- minimal: true,
288
- className,
289
- onClick: (e: React.MouseEvent<HTMLButtonElement>) => {
290
- e.stopPropagation();
291
- },
292
- }}
293
- items={actions}
294
- />
314
+ className={className}
315
+ customTheme={theme}
316
+ intent={intent}
317
+ onClick={
318
+ rest.onClick
319
+ ? (e: React.MouseEvent<HTMLButtonElement>) => {
320
+ e.stopPropagation();
321
+ rest.onClick?.();
322
+ }
323
+ : undefined
324
+ }
325
+ >
326
+ {label}
327
+ </ReqoreButton>
295
328
  );
296
- }
297
-
298
- if (customContent) {
299
- return customContent();
300
- }
301
-
302
- return (
303
- <ReqoreButton
304
- {...rest}
305
- id={id}
306
- key={index}
307
- className={className}
308
- customTheme={theme}
309
- intent={intent}
310
- onClick={
311
- rest.onClick
312
- ? (e: React.MouseEvent<HTMLButtonElement>) => {
313
- e.stopPropagation();
314
- rest.onClick?.();
315
- }
316
- : undefined
317
- }
318
- >
319
- {label}
320
- </ReqoreButton>
321
- );
322
- };
329
+ },
330
+ [actions, theme]
331
+ );
323
332
 
324
333
  const HTMLheaderElement = useMemo(() => {
325
334
  return `h${headerSize}` as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
@@ -354,6 +363,7 @@ export const ReqorePanel = forwardRef(
354
363
  onClick={handleCollapseClick}
355
364
  theme={theme}
356
365
  opacity={rest.opacity ?? (minimal ? 0 : 1)}
366
+ noHorizontalPadding={rest.opacity === 0}
357
367
  >
358
368
  <StyledPanelTitleHeader>
359
369
  {icon && (
@@ -401,6 +411,7 @@ export const ReqorePanel = forwardRef(
401
411
  padded={padded}
402
412
  minimal={minimal}
403
413
  contentSize={contentSize}
414
+ noHorizontalPadding={rest.opacity === 0}
404
415
  >
405
416
  {children}
406
417
  </StyledPanelContent>
@@ -411,6 +422,7 @@ export const ReqorePanel = forwardRef(
411
422
  className='reqore-panel-bottom-actions'
412
423
  theme={theme}
413
424
  opacity={rest.opacity ?? (minimal ? 0 : 1)}
425
+ noHorizontalPadding={rest.opacity === 0}
414
426
  >
415
427
  <ReqoreControlGroup minimal>{leftBottomActions.map(renderActions)}</ReqoreControlGroup>
416
428
  <ReqoreControlGroup minimal>{rightBottomActions.map(renderActions)}</ReqoreControlGroup>
@@ -1,6 +1,7 @@
1
- import React, { useState } from 'react';
1
+ import React, { memo, useState } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import usePopover, { IPopoverOptions } from '../../hooks/usePopover';
4
+ import { useWhyDidYouUpdate } from '../../hooks/useWhyDidYouUpdate';
4
5
  import { IReqoreComponent } from '../../types/global';
5
6
 
6
7
  export interface IReqorePopoverProps extends IReqoreComponent, IPopoverOptions {
@@ -17,49 +18,63 @@ export const StyledPopover = styled.span`
17
18
  overflow: hidden;
18
19
  `;
19
20
 
20
- const Popover = ({
21
- component: Component,
22
- componentProps,
23
- children,
24
- isReqoreComponent,
25
- noWrapper,
26
- wrapperTag = 'span',
27
- wrapperStyle = {},
28
- _insidePopover,
29
- _popoverId,
30
- ...rest
31
- }: IReqorePopoverProps) => {
32
- const [ref, setRef] = useState(undefined);
21
+ const Popover = memo(
22
+ ({
23
+ component: Component,
24
+ componentProps,
25
+ children,
26
+ isReqoreComponent,
27
+ noWrapper,
28
+ wrapperTag = 'span',
29
+ wrapperStyle = {},
30
+ _insidePopover,
31
+ _popoverId,
32
+ ...rest
33
+ }: IReqorePopoverProps) => {
34
+ const [ref, setRef] = useState(undefined);
33
35
 
34
- usePopover({ targetElement: ref, ...rest });
36
+ useWhyDidYouUpdate('popover', {
37
+ component: Component,
38
+ componentProps,
39
+ children,
40
+ isReqoreComponent,
41
+ noWrapper,
42
+ wrapperTag,
43
+ wrapperStyle,
44
+ _insidePopover,
45
+ _popoverId,
46
+ ...rest,
47
+ });
48
+ usePopover({ targetElement: ref, ...rest });
49
+
50
+ if (isReqoreComponent || noWrapper) {
51
+ return (
52
+ <Component
53
+ {...componentProps}
54
+ _insidePopover={_insidePopover}
55
+ _popoverId={_popoverId}
56
+ ref={setRef}
57
+ >
58
+ {children}
59
+ </Component>
60
+ );
61
+ }
35
62
 
36
- if (isReqoreComponent || noWrapper) {
37
63
  return (
38
- <Component
39
- {...componentProps}
40
- _insidePopover={_insidePopover}
41
- _popoverId={_popoverId}
64
+ // @ts-ignore
65
+ <StyledPopover
66
+ // @ts-ignore
67
+ as={wrapperTag}
68
+ className='reqore-popover-wrapper'
42
69
  ref={setRef}
70
+ style={wrapperStyle}
43
71
  >
44
- {children}
45
- </Component>
72
+ <Component {...componentProps} _insidePopover={_insidePopover} _popoverId={_popoverId}>
73
+ {children}
74
+ </Component>
75
+ </StyledPopover>
46
76
  );
47
77
  }
48
-
49
- return (
50
- // @ts-ignore
51
- <StyledPopover
52
- // @ts-ignore
53
- as={wrapperTag}
54
- className='reqore-popover-wrapper'
55
- ref={setRef}
56
- style={wrapperStyle}
57
- >
58
- <Component {...componentProps} _insidePopover={_insidePopover} _popoverId={_popoverId}>
59
- {children}
60
- </Component>
61
- </StyledPopover>
62
- );
63
- };
78
+ );
64
79
 
65
80
  export default Popover;