@qoretechnologies/reqore 0.32.0 → 0.32.3

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 (171) hide show
  1. package/.github/workflows/tests.yml +3 -1
  2. package/__tests__/breadcrumbs.test.tsx +46 -28
  3. package/__tests__/button.test.tsx +18 -0
  4. package/__tests__/checkbox.test.tsx +19 -1
  5. package/__tests__/collection.test.tsx +9 -0
  6. package/__tests__/icon.test.tsx +19 -1
  7. package/__tests__/input.test.tsx +18 -0
  8. package/__tests__/messages.test.tsx +16 -0
  9. package/__tests__/modal.test.tsx +4 -4
  10. package/__tests__/notifications.test.tsx +6 -6
  11. package/__tests__/panel.test.tsx +19 -1
  12. package/__tests__/textarea.test.tsx +18 -0
  13. package/__tests__/tree.test.tsx +3 -1
  14. package/dist/components/Breadcrumbs/item.d.ts.map +1 -1
  15. package/dist/components/Breadcrumbs/item.js +6 -2
  16. package/dist/components/Breadcrumbs/item.js.map +1 -1
  17. package/dist/components/Button/index.d.ts.map +1 -1
  18. package/dist/components/Button/index.js +18 -4
  19. package/dist/components/Button/index.js.map +1 -1
  20. package/dist/components/Checkbox/index.d.ts.map +1 -1
  21. package/dist/components/Checkbox/index.js +8 -4
  22. package/dist/components/Checkbox/index.js.map +1 -1
  23. package/dist/components/Collection/index.d.ts +2 -1
  24. package/dist/components/Collection/index.d.ts.map +1 -1
  25. package/dist/components/Collection/index.js +15 -12
  26. package/dist/components/Collection/index.js.map +1 -1
  27. package/dist/components/Collection/item.js +2 -2
  28. package/dist/components/Collection/item.js.map +1 -1
  29. package/dist/components/Comment/index.d.ts +0 -1
  30. package/dist/components/Comment/index.d.ts.map +1 -1
  31. package/dist/components/ControlGroup/index.d.ts.map +1 -1
  32. package/dist/components/ControlGroup/index.js +5 -3
  33. package/dist/components/ControlGroup/index.js.map +1 -1
  34. package/dist/components/Drawer/index.d.ts +1 -1
  35. package/dist/components/Drawer/index.d.ts.map +1 -1
  36. package/dist/components/Drawer/index.js +1 -1
  37. package/dist/components/Drawer/index.js.map +1 -1
  38. package/dist/components/Dropdown/item.d.ts +0 -1
  39. package/dist/components/Dropdown/item.d.ts.map +1 -1
  40. package/dist/components/Icon/index.d.ts.map +1 -1
  41. package/dist/components/Icon/index.js +8 -4
  42. package/dist/components/Icon/index.js.map +1 -1
  43. package/dist/components/Input/index.d.ts.map +1 -1
  44. package/dist/components/Input/index.js +4 -4
  45. package/dist/components/Input/index.js.map +1 -1
  46. package/dist/components/InputClearButton/index.d.ts +0 -1
  47. package/dist/components/InputClearButton/index.d.ts.map +1 -1
  48. package/dist/components/InternalPopover/index.d.ts.map +1 -1
  49. package/dist/components/InternalPopover/index.js +2 -1
  50. package/dist/components/InternalPopover/index.js.map +1 -1
  51. package/dist/components/Menu/item.d.ts +1 -1
  52. package/dist/components/Menu/item.d.ts.map +1 -1
  53. package/dist/components/Menu/item.js +3 -6
  54. package/dist/components/Menu/item.js.map +1 -1
  55. package/dist/components/Message/index.d.ts.map +1 -1
  56. package/dist/components/Message/index.js +6 -2
  57. package/dist/components/Message/index.js.map +1 -1
  58. package/dist/components/Modal/index.d.ts +0 -1
  59. package/dist/components/Modal/index.d.ts.map +1 -1
  60. package/dist/components/Panel/index.d.ts +1 -0
  61. package/dist/components/Panel/index.d.ts.map +1 -1
  62. package/dist/components/Panel/index.js +13 -9
  63. package/dist/components/Panel/index.js.map +1 -1
  64. package/dist/components/Panel/panel.screenshot.d.ts +0 -1
  65. package/dist/components/Panel/panel.screenshot.d.ts.map +1 -1
  66. package/dist/components/Paragraph/index.js +1 -1
  67. package/dist/components/Sidebar/item.d.ts +0 -1
  68. package/dist/components/Sidebar/item.d.ts.map +1 -1
  69. package/dist/components/Sidebar/item.js +1 -3
  70. package/dist/components/Sidebar/item.js.map +1 -1
  71. package/dist/components/Spinner/index.d.ts +3 -3
  72. package/dist/components/Spinner/index.d.ts.map +1 -1
  73. package/dist/components/Spinner/index.js +13 -2
  74. package/dist/components/Spinner/index.js.map +1 -1
  75. package/dist/components/Table/header.d.ts +0 -1
  76. package/dist/components/Table/header.d.ts.map +1 -1
  77. package/dist/components/Tag/index.d.ts.map +1 -1
  78. package/dist/components/Tag/index.js +7 -4
  79. package/dist/components/Tag/index.js.map +1 -1
  80. package/dist/components/Textarea/index.d.ts.map +1 -1
  81. package/dist/components/Textarea/index.js +7 -6
  82. package/dist/components/Textarea/index.js.map +1 -1
  83. package/dist/components/Tree/index.d.ts +0 -1
  84. package/dist/components/Tree/index.d.ts.map +1 -1
  85. package/dist/components/Tree/index.js +2 -4
  86. package/dist/components/Tree/index.js.map +1 -1
  87. package/dist/containers/PopoverProvider.d.ts.map +1 -1
  88. package/dist/containers/PopoverProvider.js +2 -2
  89. package/dist/containers/PopoverProvider.js.map +1 -1
  90. package/dist/containers/ReqoreProvider.d.ts.map +1 -1
  91. package/dist/containers/ReqoreProvider.js +4 -0
  92. package/dist/containers/ReqoreProvider.js.map +1 -1
  93. package/dist/containers/ThemeProvider.d.ts +1 -2
  94. package/dist/containers/ThemeProvider.d.ts.map +1 -1
  95. package/dist/containers/ThemeProvider.js +3 -3
  96. package/dist/containers/ThemeProvider.js.map +1 -1
  97. package/dist/context/PopoverContext.d.ts +1 -2
  98. package/dist/context/PopoverContext.d.ts.map +1 -1
  99. package/dist/context/PopoverContext.js +2 -2
  100. package/dist/context/PopoverContext.js.map +1 -1
  101. package/dist/context/ReqoreContext.d.ts +3 -2
  102. package/dist/context/ReqoreContext.d.ts.map +1 -1
  103. package/dist/context/ReqoreContext.js +5 -3
  104. package/dist/context/ReqoreContext.js.map +1 -1
  105. package/dist/context/ThemeContext.d.ts +1 -2
  106. package/dist/context/ThemeContext.d.ts.map +1 -1
  107. package/dist/context/ThemeContext.js +2 -2
  108. package/dist/context/ThemeContext.js.map +1 -1
  109. package/dist/hooks/useLatestZIndex.d.ts.map +1 -1
  110. package/dist/hooks/useLatestZIndex.js +3 -2
  111. package/dist/hooks/useLatestZIndex.js.map +1 -1
  112. package/dist/hooks/usePopover.d.ts +0 -1
  113. package/dist/hooks/usePopover.d.ts.map +1 -1
  114. package/dist/hooks/usePopover.js +4 -3
  115. package/dist/hooks/usePopover.js.map +1 -1
  116. package/dist/hooks/useReqore.js +2 -2
  117. package/dist/hooks/useReqore.js.map +1 -1
  118. package/dist/hooks/useReqoreContext.d.ts +3 -0
  119. package/dist/hooks/useReqoreContext.d.ts.map +1 -0
  120. package/dist/hooks/useReqoreContext.js +19 -0
  121. package/dist/hooks/useReqoreContext.js.map +1 -0
  122. package/dist/hooks/useReqoreEffect.js +2 -5
  123. package/dist/hooks/useReqoreEffect.js.map +1 -1
  124. package/dist/hooks/useTheme.d.ts.map +1 -1
  125. package/dist/hooks/useTheme.js +20 -20
  126. package/dist/hooks/useTheme.js.map +1 -1
  127. package/dist/index.d.ts +2 -0
  128. package/dist/index.d.ts.map +1 -1
  129. package/dist/index.js +6 -2
  130. package/dist/index.js.map +1 -1
  131. package/package.json +18 -16
  132. package/src/components/Breadcrumbs/item.tsx +7 -3
  133. package/src/components/Button/index.tsx +25 -7
  134. package/src/components/Checkbox/index.tsx +9 -5
  135. package/src/components/Collection/index.tsx +21 -9
  136. package/src/components/Collection/item.tsx +3 -3
  137. package/src/components/ControlGroup/index.tsx +4 -2
  138. package/src/components/Drawer/index.tsx +4 -4
  139. package/src/components/Icon/index.tsx +9 -5
  140. package/src/components/Input/index.tsx +5 -9
  141. package/src/components/InternalPopover/index.tsx +2 -1
  142. package/src/components/Menu/item.tsx +6 -9
  143. package/src/components/Message/index.tsx +6 -2
  144. package/src/components/Panel/index.tsx +14 -7
  145. package/src/components/Paragraph/index.tsx +1 -1
  146. package/src/components/Sidebar/item.tsx +2 -4
  147. package/src/components/Spinner/index.tsx +11 -3
  148. package/src/components/Tag/index.tsx +9 -6
  149. package/src/components/Textarea/index.tsx +6 -8
  150. package/src/components/Tree/index.tsx +5 -8
  151. package/src/containers/PopoverProvider.tsx +2 -2
  152. package/src/containers/ReqoreProvider.tsx +5 -1
  153. package/src/containers/ThemeProvider.tsx +3 -13
  154. package/src/context/PopoverContext.tsx +1 -1
  155. package/src/context/ReqoreContext.tsx +4 -1
  156. package/src/context/ThemeContext.tsx +1 -1
  157. package/src/hooks/useLatestZIndex.ts +5 -3
  158. package/src/hooks/usePopover.tsx +4 -3
  159. package/src/hooks/useReqore.ts +1 -1
  160. package/src/hooks/useReqoreContext.ts +16 -0
  161. package/src/hooks/useReqoreEffect.ts +3 -3
  162. package/src/hooks/useTheme.ts +21 -17
  163. package/src/index.tsx +2 -0
  164. package/src/stories/Button/Button.stories.tsx +7 -0
  165. package/src/stories/Collection/Collection.stories.tsx +6 -3
  166. package/src/stories/Drawer/Drawer.stories.tsx +4 -3
  167. package/src/stories/Modal/Modal.stories.tsx +3 -4
  168. package/src/stories/Notifications/Interactive.stories.tsx +3 -4
  169. package/src/stories/Panel/Panel.stories.tsx +1 -0
  170. package/src/stories/Spinner/Spinner.stories.tsx +7 -2
  171. package/tests.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { size } from 'lodash';
2
2
  import { useMemo, useState } from 'react';
3
- import { useUpdateEffect } from 'react-use';
3
+ import { useDebounce, useUpdateEffect } from 'react-use';
4
4
  import styled, { css } from 'styled-components';
5
5
  import { PADDING_FROM_SIZE } from '../../constants/sizes';
6
6
  import { IReqoreIconName } from '../../types/icons';
@@ -46,6 +46,7 @@ export interface IReqoreCollectionProps
46
46
  showAs?: 'list' | 'grid';
47
47
  showSelectedFirst?: boolean;
48
48
  selectedIcon?: IReqoreIconName;
49
+ searchDelay?: number;
49
50
 
50
51
  childrenBefore?: React.ReactNode;
51
52
  childrenAfter?: React.ReactNode;
@@ -93,6 +94,7 @@ export const ReqoreCollection = ({
93
94
  onQueryChange,
94
95
  childrenBefore,
95
96
  childrenAfter,
97
+ searchDelay = 300,
96
98
  emptyMessage = 'No data in this collection, try changing your search query or filters',
97
99
  sortButtonTooltip = (sort) => (sort === 'desc' ? 'Sort ascending' : 'Sort descending'),
98
100
  displayButtonTooltip = (display) => (display === 'grid' ? 'Show as list' : 'Show as grid'),
@@ -102,6 +104,7 @@ export const ReqoreCollection = ({
102
104
  const [_showAs, setShowAs] = useState<'list' | 'grid'>(showAs);
103
105
  const [sort, setSort] = useState<'asc' | 'desc'>('asc');
104
106
  const [query, setQuery] = useState<string>('');
107
+ const [preQuery, setPreQuery] = useState<string>('');
105
108
 
106
109
  useUpdateEffect(() => {
107
110
  setShowAs(showAs);
@@ -111,6 +114,14 @@ export const ReqoreCollection = ({
111
114
  onQueryChange?.(query);
112
115
  }, [query]);
113
116
 
117
+ useDebounce(
118
+ () => {
119
+ setQuery(preQuery);
120
+ },
121
+ searchDelay,
122
+ [preQuery]
123
+ );
124
+
114
125
  const sortedItems: IReqoreCollectionItemProps[] = useMemo(() => {
115
126
  if (!sortable) {
116
127
  return items;
@@ -141,7 +152,7 @@ export const ReqoreCollection = ({
141
152
  });
142
153
  }, [items, sort]);
143
154
 
144
- const filteredItems: IReqoreCollectionItemProps[] = useMemo(() => {
155
+ const finalItems: IReqoreCollectionItemProps[] = useMemo(() => {
145
156
  if (!filterable || query === '') {
146
157
  return sortedItems;
147
158
  }
@@ -159,11 +170,10 @@ export const ReqoreCollection = ({
159
170
  });
160
171
  }, [items, query, sortedItems]);
161
172
 
162
- const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
163
- setQuery(event.target.value);
173
+ const handlePreQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => {
174
+ setPreQuery(event.target.value);
164
175
  };
165
176
 
166
- const finalItems = filteredItems;
167
177
  const finalActions: TReqorePanelActions = useMemo(() => {
168
178
  let actions: TReqorePanelActions = rest.actions ? [...rest.actions] : [];
169
179
 
@@ -171,10 +181,11 @@ export const ReqoreCollection = ({
171
181
  responsive: false,
172
182
  group: [
173
183
  {
174
- icon: _showAs === 'grid' ? 'ListOrdered' : 'GridLine',
184
+ icon: _showAs === 'grid' ? 'ListUnordered' : 'GridLine',
175
185
  onClick: () => setShowAs(_showAs === 'grid' ? 'list' : 'grid'),
176
186
  tooltip: displayButtonTooltip(_showAs),
177
187
  disabled: !size(finalItems),
188
+ textAlign: 'center',
178
189
  ...displayButtonProps,
179
190
  },
180
191
  ],
@@ -186,6 +197,7 @@ export const ReqoreCollection = ({
186
197
  onClick: () => setSort(sort === 'desc' ? 'asc' : 'desc'),
187
198
  tooltip: sortButtonTooltip(sort),
188
199
  disabled: !size(finalItems),
200
+ textAlign: 'center',
189
201
  ...sortButtonProps,
190
202
  });
191
203
  }
@@ -200,8 +212,8 @@ export const ReqoreCollection = ({
200
212
  fixed: false,
201
213
  placeholder: inputPlaceholder(finalItems),
202
214
  onClearClick: () => setQuery(''),
203
- onChange: handleQueryChange,
204
- value: query,
215
+ onChange: handlePreQueryChange,
216
+ value: preQuery,
205
217
  icon: 'Search2Line',
206
218
  minimal: false,
207
219
  ...inputProps,
@@ -211,7 +223,7 @@ export const ReqoreCollection = ({
211
223
  }
212
224
 
213
225
  return [...actions, toolbarGroup];
214
- }, [filterable, handleQueryChange, query, rest.actions, _showAs, sort, sortable, finalItems]);
226
+ }, [filterable, preQuery, query, rest.actions, _showAs, sort, sortable, finalItems]);
215
227
 
216
228
  return (
217
229
  <ReqorePanel
@@ -1,10 +1,10 @@
1
1
  import { map, size } from 'lodash';
2
2
  import { rgba } from 'polished';
3
- import { useContext, useEffect, useRef, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  import { useDebounce, useMeasure } from 'react-use';
5
5
  import styled, { css } from 'styled-components';
6
- import ReqoreContext from '../../context/ReqoreContext';
7
6
  import { changeDarkness, getMainBackgroundColor } from '../../helpers/colors';
7
+ import { useReqoreProperty } from '../../hooks/useReqoreContext';
8
8
  import { useReqoreTheme } from '../../hooks/useTheme';
9
9
  import { StyledBackdrop } from '../Drawer';
10
10
  import {
@@ -84,7 +84,7 @@ export const ReqoreCollectionItem = ({
84
84
  ...rest
85
85
  }: IReqoreCollectionItemProps) => {
86
86
  const [isSelected, setIsSelected] = useState(false);
87
- const { getAndIncreaseZIndex } = useContext(ReqoreContext);
87
+ const getAndIncreaseZIndex = useReqoreProperty('getAndIncreaseZIndex');
88
88
  const ref = useRef<HTMLDivElement>(null);
89
89
  const [contentRef, sizes] = useMeasure();
90
90
  const originalDimensions = useRef(null);
@@ -13,6 +13,8 @@ import {
13
13
  IWithReqoreMinimal,
14
14
  IWithReqoreSize,
15
15
  } from '../../types/global';
16
+ import { StyledHeader } from '../Header';
17
+ import { StyledParagraph } from '../Paragraph';
16
18
 
17
19
  export interface IReqoreControlGroupProps
18
20
  extends React.HTMLAttributes<HTMLDivElement>,
@@ -83,7 +85,7 @@ export const StyledReqoreControlGroup = styled.div<IReqoreControlGroupStyle>`
83
85
  return undefined;
84
86
  }}
85
87
 
86
- > * {
88
+ > *, > ${StyledParagraph}, > ${StyledHeader} {
87
89
  margin-top: ${({ fill, verticalAlign }) =>
88
90
  !fill && (verticalAlign === 'flex-end' || verticalAlign === 'center') ? 'auto' : undefined};
89
91
  margin-bottom: ${({ fill, verticalAlign }) =>
@@ -334,7 +336,7 @@ const ReqoreControlGroup = memo(
334
336
 
335
337
  let newProps = {
336
338
  ...child.props,
337
- key: index,
339
+ key: child.props.reactKey || child.props.key || index,
338
340
  minimal:
339
341
  child.props?.minimal || child.props?.minimal === false
340
342
  ? child.props.minimal
@@ -1,10 +1,10 @@
1
1
  import { animated, useTransition } from '@react-spring/web';
2
2
  import { rgba } from 'polished';
3
3
  import { Resizable } from 're-resizable';
4
- import { useContext, useEffect, useMemo, useState } from 'react';
4
+ import { useEffect, useMemo, useState } from 'react';
5
5
  import { createPortal } from 'react-dom';
6
6
  import styled, { css } from 'styled-components';
7
- import { ReqoreContext } from '../..';
7
+ import { useReqoreProperty } from '../..';
8
8
  import { SPRING_CONFIG, SPRING_CONFIG_NO_ANIMATIONS } from '../../constants/animations';
9
9
  import { IReqoreTheme } from '../../constants/theme';
10
10
  import ReqoreThemeProvider from '../../containers/ThemeProvider';
@@ -147,7 +147,7 @@ const getSpringConfig = (isModal?: boolean, position?: TPosition, floating?: boo
147
147
  leave: { opacity: 0, [position]: '-80px' },
148
148
  };
149
149
 
150
- export const ReqoreDrawer = ({
150
+ export const ReqoreDrawer: React.FC<IReqoreDrawerProps> = ({
151
151
  children,
152
152
  isOpen,
153
153
  isHidden,
@@ -173,7 +173,7 @@ export const ReqoreDrawer = ({
173
173
  actions = [],
174
174
  ...rest
175
175
  }: IReqoreDrawerProps) => {
176
- const { animations } = useContext(ReqoreContext);
176
+ const animations = useReqoreProperty('animations');
177
177
  const theme = useReqoreTheme('main', customTheme, intent);
178
178
  const layout = useMemo(
179
179
  () =>
@@ -1,9 +1,9 @@
1
- import React, { forwardRef, memo, useContext } from 'react';
1
+ import React, { forwardRef, memo } from 'react';
2
2
  import { IconContext } from 'react-icons';
3
3
  import { IconBaseProps, IconType } from 'react-icons/lib';
4
4
  import * as RemixIcons from 'react-icons/ri';
5
5
  import styled, { css, keyframes } from 'styled-components';
6
- import { ReqoreThemeContext } from '../..';
6
+ import { useReqoreTheme } from '../..';
7
7
  import { ICON_FROM_SIZE, PADDING_FROM_SIZE, TSizes } from '../../constants/sizes';
8
8
  import { getColorFromMaybeString } from '../../helpers/colors';
9
9
  import { isStringSize } from '../../helpers/utils';
@@ -97,7 +97,8 @@ const ReqoreIcon = memo(
97
97
  ref
98
98
  ) => {
99
99
  const { targetRef } = useCombinedRefs(ref);
100
- const theme = useContext(ReqoreThemeContext);
100
+ const [iconRef, setIconRef] = React.useState<HTMLSpanElement>(undefined);
101
+ const theme = useReqoreTheme();
101
102
  const Icon: IconType = RemixIcons[`Ri${icon}`];
102
103
  const finalColor: string | undefined = intent
103
104
  ? theme.intents[intent]
@@ -109,7 +110,7 @@ const ReqoreIcon = memo(
109
110
  : wrapperSize
110
111
  : finalSize;
111
112
 
112
- useTooltip(targetRef.current, tooltip);
113
+ useTooltip(iconRef, tooltip);
113
114
 
114
115
  if (image) {
115
116
  return (
@@ -145,7 +146,10 @@ const ReqoreIcon = memo(
145
146
  <StyledIconWrapper
146
147
  {...rest}
147
148
  as={wrapperElement}
148
- ref={targetRef}
149
+ ref={(ref) => {
150
+ targetRef.current = ref;
151
+ setIconRef(ref);
152
+ }}
149
153
  margin={margin}
150
154
  size={size}
151
155
  style={{ width: finalWrapperSize, height: finalWrapperSize, ...style }}
@@ -1,5 +1,5 @@
1
1
  import { rgba } from 'polished';
2
- import React, { forwardRef, useRef } from 'react';
2
+ import React, { forwardRef, useState } from 'react';
3
3
  import styled, { css } from 'styled-components';
4
4
  import {
5
5
  PADDING_FROM_SIZE,
@@ -188,15 +188,11 @@ const ReqoreInput = forwardRef<HTMLDivElement, IReqoreInputProps>(
188
188
  ref
189
189
  ) => {
190
190
  const { targetRef } = useCombinedRefs(ref);
191
- const inputRef = useRef<HTMLInputElement>(null);
191
+ const [inputRef, setInputRef] = useState<HTMLInputElement>(null);
192
192
  const theme = useReqoreTheme('main', customTheme, intent);
193
193
 
194
- useTooltip(targetRef.current, tooltip);
195
- useAutoFocus(
196
- inputRef.current,
197
- readOnly || rest.disabled ? undefined : focusRules,
198
- rest.onChange
199
- );
194
+ useTooltip(inputRef, tooltip);
195
+ useAutoFocus(inputRef, readOnly || rest.disabled ? undefined : focusRules, rest.onChange);
200
196
 
201
197
  return (
202
198
  <StyledInputWrapper
@@ -227,7 +223,7 @@ const ReqoreInput = forwardRef<HTMLDivElement, IReqoreInputProps>(
227
223
  }}
228
224
  onChange={!readOnly && !rest?.disabled ? rest?.onChange : undefined}
229
225
  as='input'
230
- ref={inputRef}
226
+ ref={(ref) => setInputRef(ref)}
231
227
  theme={theme}
232
228
  _size={size}
233
229
  minimal={minimal}
@@ -1,9 +1,10 @@
1
1
  import { cloneDeep, isString } from 'lodash';
2
2
  import { rgba } from 'polished';
3
- import React, { memo, MutableRefObject, useContext, useEffect, useRef, useState } from 'react';
3
+ import React, { MutableRefObject, memo, useEffect, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { usePopper } from 'react-popper';
6
6
  import styled, { css } from 'styled-components';
7
+ import { useContext } from 'use-context-selector';
7
8
  import { RADIUS_FROM_SIZE } from '../../constants/sizes';
8
9
  import { IReqoreTheme } from '../../constants/theme';
9
10
  import { IPopoverData } from '../../containers/PopoverProvider';
@@ -1,9 +1,8 @@
1
- import React, { forwardRef, useContext } from 'react';
1
+ import React, { forwardRef } from 'react';
2
+ import { useContext } from 'use-context-selector';
2
3
  import { ReqoreButton, ReqoreControlGroup } from '../..';
3
4
  import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
4
5
  import PopoverContext from '../../context/PopoverContext';
5
- import { useCombinedRefs } from '../../hooks/useCombinedRefs';
6
- import { useTooltip } from '../../hooks/useTooltip';
7
6
  import { IReqoreComponent } from '../../types/global';
8
7
  import { IReqoreButtonProps } from '../Button';
9
8
 
@@ -33,7 +32,7 @@ export interface IReqoreMenuItemRightIconStyle {
33
32
  intent?: TReqoreIntent;
34
33
  }
35
34
 
36
- const ReqoreMenuItem = forwardRef<HTMLDivElement, IReqoreMenuItemProps>(
35
+ const ReqoreMenuItem = forwardRef<HTMLButtonElement, IReqoreMenuItemProps>(
37
36
  (
38
37
  {
39
38
  children,
@@ -53,10 +52,9 @@ const ReqoreMenuItem = forwardRef<HTMLDivElement, IReqoreMenuItemProps>(
53
52
  flat = true,
54
53
  ...rest
55
54
  }: IReqoreMenuItemProps,
56
- ref: any
55
+ ref
57
56
  ) => {
58
57
  const { removePopover } = useContext(PopoverContext);
59
- const { targetRef } = useCombinedRefs(ref);
60
58
 
61
59
  const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
62
60
  event.persist();
@@ -81,8 +79,6 @@ const ReqoreMenuItem = forwardRef<HTMLDivElement, IReqoreMenuItemProps>(
81
79
  }
82
80
  };
83
81
 
84
- useTooltip(targetRef.current, tooltip);
85
-
86
82
  return (
87
83
  <ReqoreControlGroup stack={!!onRightIconClick} fluid>
88
84
  <ReqoreButton
@@ -94,11 +90,12 @@ const ReqoreMenuItem = forwardRef<HTMLDivElement, IReqoreMenuItemProps>(
94
90
  fluid
95
91
  onClick={handleClick}
96
92
  active={selected}
97
- ref={targetRef}
93
+ ref={ref}
98
94
  disabled={disabled}
99
95
  intent={intent}
100
96
  icon={icon}
101
97
  rightIcon={onRightIconClick ? undefined : rightIcon}
98
+ tooltip={tooltip}
102
99
  >
103
100
  {label || children}
104
101
  </ReqoreButton>
@@ -87,8 +87,9 @@ const ReqoreMessage = memo(
87
87
  const [internalTimeout, setInternalTimeout] = useState<NodeJS.Timeout | null>(null);
88
88
  const theme = useReqoreTheme('main', customTheme, intent);
89
89
  const { targetRef } = useCombinedRefs(ref);
90
+ const [itemRef, setItemRef] = useState<HTMLDivElement>(undefined);
90
91
 
91
- useTooltip(targetRef.current, tooltip);
92
+ useTooltip(itemRef, tooltip);
92
93
 
93
94
  useMount(() => {
94
95
  if (duration) {
@@ -142,7 +143,10 @@ const ReqoreMessage = memo(
142
143
  fluid={fluid}
143
144
  fixed={fixed}
144
145
  className={`${rest?.className || ''} reqore-message`}
145
- ref={targetRef}
146
+ ref={(ref) => {
147
+ targetRef.current = ref;
148
+ setItemRef(ref);
149
+ }}
146
150
  size={size}
147
151
  theme={theme}
148
152
  >
@@ -21,7 +21,7 @@ import {
21
21
  } from '../../helpers/colors';
22
22
  import { getOneHigherSize, isActionShown } from '../../helpers/utils';
23
23
  import { useCombinedRefs } from '../../hooks/useCombinedRefs';
24
- import { useReqore } from '../../hooks/useReqore';
24
+ import { useReqoreProperty } from '../../hooks/useReqoreContext';
25
25
  import { useReqoreTheme } from '../../hooks/useTheme';
26
26
  import { useTooltip } from '../../hooks/useTooltip';
27
27
  import { ACTIVE_ICON_SCALE, INACTIVE_ICON_SCALE } from '../../styles';
@@ -102,6 +102,7 @@ export interface IReqorePanelProps
102
102
  transparent?: boolean;
103
103
  iconColor?: TReqoreEffectColor;
104
104
  responsiveActions?: boolean;
105
+ responsiveTitle?: boolean;
105
106
  }
106
107
 
107
108
  export interface IStyledPanel extends IReqorePanelProps {
@@ -187,7 +188,7 @@ export const StyledPanel = styled(StyledEffect)<IStyledPanel>`
187
188
 
188
189
  export const StyledPanelTitle = styled.div<IStyledPanel>`
189
190
  display: flex;
190
- flex-flow: ${({ isMobile }) => (isMobile ? 'column' : 'row')};
191
+ flex-flow: ${({ responsive, isMobile }) => (responsive ? (isMobile ? 'column' : 'row') : 'row')};
191
192
  background-color: ${({ theme, opacity = 1 }: IStyledPanel) =>
192
193
  rgba(changeLightness(getMainBackgroundColor(theme), 0.03), opacity)};
193
194
  justify-content: space-between;
@@ -295,6 +296,7 @@ export const ReqorePanel = forwardRef<HTMLDivElement, IReqorePanelProps>(
295
296
  iconProps = {},
296
297
  fluid,
297
298
  responsiveActions = true,
299
+ responsiveTitle = true,
298
300
  size: panelSize = 'normal',
299
301
  ...rest
300
302
  }: IReqorePanelProps,
@@ -308,10 +310,11 @@ export const ReqorePanel = forwardRef<HTMLDivElement, IReqorePanelProps>(
308
310
  ? { main: Object.values(contentEffect.gradient.colors)[0] as TReqoreEffectColor }
309
311
  : undefined)
310
312
  );
311
- const { isMobile } = useReqore();
313
+ const isMobile = useReqoreProperty('isMobile');
312
314
  const { targetRef } = useCombinedRefs(ref);
315
+ const [itemRef, setItemRef] = useState<HTMLDivElement>(undefined);
313
316
 
314
- useTooltip(targetRef.current, tooltip);
317
+ useTooltip(itemRef, tooltip);
315
318
 
316
319
  useUpdateEffect(() => {
317
320
  setIsCollapsed(!!isCollapsed);
@@ -421,8 +424,8 @@ export const ReqorePanel = forwardRef<HTMLDivElement, IReqorePanelProps>(
421
424
  stack
422
425
  customTheme={rest.customTheme || theme}
423
426
  size={rest.size}
424
- fixed={rest.fixed ? true : false}
425
- fluid={rest.fluid ? true : false}
427
+ fixed={rest.fixed}
428
+ fluid={rest.fluid}
426
429
  key={index}
427
430
  >
428
431
  {group.map((action, index) => renderActions(action, index, true))}
@@ -517,7 +520,10 @@ export const ReqorePanel = forwardRef<HTMLDivElement, IReqorePanelProps>(
517
520
  <StyledPanel
518
521
  {...rest}
519
522
  as={rest.as || 'div'}
520
- ref={targetRef}
523
+ ref={(ref) => {
524
+ targetRef.current = ref;
525
+ setItemRef(ref);
526
+ }}
521
527
  isCollapsed={_isCollapsed}
522
528
  rounded={rounded}
523
529
  flat={flat}
@@ -540,6 +546,7 @@ export const ReqorePanel = forwardRef<HTMLDivElement, IReqorePanelProps>(
540
546
  size={contentSize || panelSize}
541
547
  opacity={opacity ?? (minimal ? 0 : 1)}
542
548
  noHorizontalPadding={noHorizontalPadding}
549
+ responsive={responsiveTitle}
543
550
  isMobile={isMobile}
544
551
  >
545
552
  {hasTitleHeader && (
@@ -15,8 +15,8 @@ export interface IReqoreParagraphProps
15
15
  }
16
16
 
17
17
  export const StyledParagraph = styled(StyledTextEffect)`
18
- margin: 0;
19
18
  padding: 0;
19
+ margin: 0;
20
20
  color: ${({ theme, intent }) => (intent ? theme.intents[intent] : 'inherit')};
21
21
  font-size: ${({ _size }) => (isStringSize(_size) ? `${TEXT_FROM_SIZE[_size]}px` : _size)};
22
22
  `;
@@ -1,11 +1,9 @@
1
1
  import classnames from 'classnames';
2
2
  import map from 'lodash/map';
3
- import { useContext } from 'react';
4
3
  import { useMount } from 'react-use';
5
4
  import { IQorusSidebarItem } from '.';
6
- import { ReqorePopover } from '../..';
5
+ import { ReqorePopover, useReqoreTheme } from '../..';
7
6
  import { IReqoreTheme } from '../../constants/theme';
8
- import ThemeContext from '../../context/ThemeContext';
9
7
  import { getMainColor, getReadableColor } from '../../helpers/colors';
10
8
  import { isActiveMulti } from '../../helpers/sidebar';
11
9
  import ReqoreIcon from '../Icon';
@@ -202,7 +200,7 @@ const SidebarItemWrapper = ({
202
200
  useNativeTitle,
203
201
  onClick,
204
202
  }: SidebarItemProps) => {
205
- const theme: IReqoreTheme = useContext(ThemeContext);
203
+ const theme: IReqoreTheme = useReqoreTheme();
206
204
 
207
205
  useMount(() => {
208
206
  if (
@@ -3,10 +3,12 @@ import { ReqoreIcon, ReqoreP } from '../..';
3
3
  import { TSizes } from '../../constants/sizes';
4
4
  import { TReqoreIntent } from '../../constants/theme';
5
5
  import { IWithReqoreEffect } from '../../types/global';
6
- import ReqoreControlGroup from '../ControlGroup';
6
+ import ReqoreControlGroup, { IReqoreControlGroupProps } from '../ControlGroup';
7
7
  import { IReqoreEffect, TReqoreEffectColor } from '../Effect';
8
8
 
9
- export interface IReqoreSpinnerProps extends IWithReqoreEffect {
9
+ export interface IReqoreSpinnerProps
10
+ extends Omit<IReqoreControlGroupProps, 'children' | 'size'>,
11
+ IWithReqoreEffect {
10
12
  size?: TSizes | string;
11
13
  intent?: TReqoreIntent;
12
14
  children?: any;
@@ -27,6 +29,7 @@ export const ReqoreSpinner = ({
27
29
  effect,
28
30
  iconMargin,
29
31
  centered,
32
+ ...rest
30
33
  }: IReqoreSpinnerProps) => {
31
34
  const renderContent = useCallback(() => {
32
35
  return (
@@ -44,7 +47,12 @@ export const ReqoreSpinner = ({
44
47
 
45
48
  if (children) {
46
49
  return (
47
- <ReqoreControlGroup vertical={centered} horizontalAlign={centered ? 'center' : undefined}>
50
+ <ReqoreControlGroup
51
+ {...rest}
52
+ vertical={centered}
53
+ horizontalAlign={centered ? 'center' : undefined}
54
+ verticalAlign='center'
55
+ >
48
56
  {renderContent()}
49
57
  <ReqoreP
50
58
  size={size}
@@ -1,8 +1,8 @@
1
1
  import _size from 'lodash/size';
2
2
  import { rgba } from 'polished';
3
- import React, { forwardRef, useContext } from 'react';
3
+ import React, { forwardRef, useState } from 'react';
4
4
  import styled, { css } from 'styled-components';
5
- import { ReqorePopover } from '../..';
5
+ import { ReqorePopover, useReqoreTheme } from '../..';
6
6
  import {
7
7
  BADGE_SIZE_TO_PX,
8
8
  PADDING_FROM_SIZE,
@@ -12,7 +12,6 @@ import {
12
12
  TSizes,
13
13
  } from '../../constants/sizes';
14
14
  import { IReqoreTheme, TReqoreIntent } from '../../constants/theme';
15
- import ThemeContext from '../../context/ThemeContext';
16
15
  import {
17
16
  changeLightness,
18
17
  getColorFromMaybeString,
@@ -264,9 +263,10 @@ const ReqoreTag = forwardRef<HTMLSpanElement, IReqoreTagProps>(
264
263
  ref
265
264
  ) => {
266
265
  const { targetRef } = useCombinedRefs(ref);
267
- const theme: IReqoreTheme = useContext<IReqoreTheme>(ThemeContext);
266
+ const theme: IReqoreTheme = useReqoreTheme();
267
+ const [itemRef, setItemRef] = useState<HTMLDivElement>(undefined);
268
268
 
269
- useTooltip(targetRef.current, tooltip);
269
+ useTooltip(itemRef, tooltip);
270
270
 
271
271
  // If color or intent was specified, set the color
272
272
  const getCustomColor = (itemIntent?: TReqoreIntent): TReqoreHexColor => {
@@ -292,7 +292,10 @@ const ReqoreTag = forwardRef<HTMLSpanElement, IReqoreTagProps>(
292
292
  color={getCustomColor(intent)}
293
293
  className={`${className || ''} reqore-tag`}
294
294
  size={size}
295
- ref={targetRef}
295
+ ref={(ref) => {
296
+ targetRef.current = ref;
297
+ setItemRef(ref);
298
+ }}
296
299
  asBadge={asBadge}
297
300
  minimal={minimal}
298
301
  removable={!!onRemoveClick}
@@ -146,6 +146,7 @@ const ReqoreInput = forwardRef<HTMLTextAreaElement, IReqoreTextareaProps>(
146
146
  ref
147
147
  ) => {
148
148
  const { targetRef }: any = useCombinedRefs(ref);
149
+ const [inputRef, setInputRef] = useState<HTMLTextAreaElement>(null);
149
150
  const theme = useReqoreTheme('main', customTheme, intent);
150
151
  const [_value, setValue] = useState(value || '');
151
152
 
@@ -153,13 +154,9 @@ const ReqoreInput = forwardRef<HTMLTextAreaElement, IReqoreTextareaProps>(
153
154
  setValue(value || '');
154
155
  }, [value]);
155
156
 
156
- useTooltip(targetRef?.current, tooltip);
157
- useAutosizeTextArea(targetRef?.current, _value, scaleWithContent);
158
- useAutoFocus(
159
- targetRef.current,
160
- rest.readOnly || rest.disabled ? undefined : focusRules,
161
- onChange
162
- );
157
+ useTooltip(inputRef, tooltip);
158
+ useAutosizeTextArea(inputRef, _value, scaleWithContent);
159
+ useAutoFocus(inputRef, rest.readOnly || rest.disabled ? undefined : focusRules, onChange);
163
160
 
164
161
  return (
165
162
  <StyledTextareaWrapper
@@ -171,6 +168,7 @@ const ReqoreInput = forwardRef<HTMLTextAreaElement, IReqoreTextareaProps>(
171
168
  _size={size}
172
169
  theme={theme}
173
170
  style={wrapperStyle}
171
+ ref={targetRef}
174
172
  >
175
173
  <StyledTextarea
176
174
  {...rest}
@@ -185,7 +183,7 @@ const ReqoreInput = forwardRef<HTMLTextAreaElement, IReqoreTextareaProps>(
185
183
  as='textarea'
186
184
  className={`${className || ''} reqore-control reqore-textarea`}
187
185
  _size={size}
188
- ref={targetRef}
186
+ ref={(ref) => setInputRef(ref)}
189
187
  theme={theme}
190
188
  rounded={rounded}
191
189
  rows={1}
@@ -1,10 +1,9 @@
1
1
  import { cloneDeep, size as lodashSize } from 'lodash';
2
- import { useContext, useState } from 'react';
2
+ import { useState } from 'react';
3
3
  import styled from 'styled-components';
4
- import { ReqoreMessage, ReqorePanel, ReqoreTextarea } from '../..';
4
+ import { ReqoreMessage, ReqorePanel, ReqoreTextarea, useReqoreProperty } from '../..';
5
5
  import { IReqoreTheme } from '../../constants/theme';
6
- import ReqoreContext from '../../context/ReqoreContext';
7
- import { getLineCount, getTypeFromValue } from '../../helpers/utils';
6
+ import { getTypeFromValue } from '../../helpers/utils';
8
7
  import { IWithReqoreSize } from '../../types/global';
9
8
  import ReqoreButton from '../Button';
10
9
  import ReqoreControlGroup from '../ControlGroup';
@@ -45,7 +44,7 @@ export const ReqoreTree = ({
45
44
  const [items, setItems] = useState({});
46
45
  const [allExpanded, setAllExpanded] = useState(expanded || !showControls);
47
46
  const [_showTypes, setShowTypes] = useState(showTypes);
48
- const { addNotification } = useContext(ReqoreContext);
47
+ const addNotification = useReqoreProperty('addNotification');
49
48
 
50
49
  const handleCopyClick = () => {
51
50
  setMode('copy');
@@ -173,7 +172,6 @@ export const ReqoreTree = ({
173
172
  }
174
173
 
175
174
  const textData: string = renderText(data);
176
- const lineCount: number = getLineCount(textData);
177
175
 
178
176
  return (
179
177
  <ReqorePanel
@@ -224,12 +222,11 @@ export const ReqoreTree = ({
224
222
  <ReqoreTextarea
225
223
  className='reqore-tree-textarea'
226
224
  id='tree-content'
227
- defaultValue={textData}
225
+ value={textData}
228
226
  scaleWithContent
229
227
  size={size}
230
228
  fluid
231
229
  readOnly
232
- rows={lineCount > 20 ? 20 : lineCount}
233
230
  />
234
231
  )}
235
232
  </ReqorePanel>
@@ -1,9 +1,9 @@
1
1
  import { size } from 'lodash';
2
2
  import React, { MutableRefObject, useCallback, useEffect, useState } from 'react';
3
+ import { useReqoreProperty } from '..';
3
4
  import Popover from '../components/InternalPopover';
4
5
  import PopoverContext from '../context/PopoverContext';
5
6
  import { IPopoverOptions } from '../hooks/usePopover';
6
- import { useReqore } from '../hooks/useReqore';
7
7
 
8
8
  export interface IReqorePopoverProviderProps {
9
9
  children: any;
@@ -17,7 +17,7 @@ export interface IPopoverData extends IPopoverOptions {
17
17
 
18
18
  const PopoverProvider: React.FC<IReqorePopoverProviderProps> = ({ children, uiScale }) => {
19
19
  const [popovers, setPopovers] = useState<IPopoverData[]>([]);
20
- const { closePopoversOnEscPress } = useReqore();
20
+ const closePopoversOnEscPress = useReqoreProperty('closePopoversOnEscPress');
21
21
 
22
22
  const handleClick = useCallback(
23
23
  (event: MouseEvent) => {