@qoretechnologies/reqore 0.44.0 → 0.45.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.
Files changed (222) hide show
  1. package/package.json +1 -1
  2. package/tests.json +1 -1
  3. package/.eslintrc.js +0 -40
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  6. package/.github/ISSUE_TEMPLATE/new-component.md +0 -20
  7. package/.github/ISSUE_TEMPLATE/visual-bug-report.md +0 -38
  8. package/.github/workflows/beta_release.yml +0 -100
  9. package/.github/workflows/tests.yml +0 -84
  10. package/.gitpod.yml +0 -11
  11. package/.jest-test-results.json +0 -1
  12. package/.prettierrc +0 -7
  13. package/.vscode/settings.json +0 -0
  14. package/__tests__/breadcrumbs.test.tsx +0 -75
  15. package/__tests__/button.test.tsx +0 -218
  16. package/__tests__/checkbox.test.tsx +0 -45
  17. package/__tests__/collection.test.tsx +0 -243
  18. package/__tests__/containers/paging.test.tsx +0 -138
  19. package/__tests__/control_group.test.tsx +0 -32
  20. package/__tests__/drawer.test.tsx +0 -140
  21. package/__tests__/dropdown.test.tsx +0 -381
  22. package/__tests__/effect.test.tsx +0 -70
  23. package/__tests__/heading.test.tsx +0 -58
  24. package/__tests__/helpers/colors.test.tsx +0 -18
  25. package/__tests__/helpers/table.test.tsx +0 -67
  26. package/__tests__/hooks/useLatestZIndex.test.tsx +0 -10
  27. package/__tests__/hooks/useReqorePaging.test.tsx +0 -271
  28. package/__tests__/hooks/useTheme.test.tsx +0 -31
  29. package/__tests__/icon.test.tsx +0 -53
  30. package/__tests__/input.test.tsx +0 -482
  31. package/__tests__/layout.test.tsx +0 -37
  32. package/__tests__/menu.test.tsx +0 -65
  33. package/__tests__/messages.test.tsx +0 -79
  34. package/__tests__/modal.test.tsx +0 -204
  35. package/__tests__/multiselect.test.tsx +0 -458
  36. package/__tests__/navbar.test.tsx +0 -31
  37. package/__tests__/notifications.test.tsx +0 -178
  38. package/__tests__/pagination.test.tsx +0 -437
  39. package/__tests__/panel.test.tsx +0 -243
  40. package/__tests__/popover.test.tsx +0 -282
  41. package/__tests__/radiogroup.test.tsx +0 -47
  42. package/__tests__/setup.js +0 -8
  43. package/__tests__/stories/Collection.stories.tsx +0 -0
  44. package/__tests__/table.test.tsx +0 -647
  45. package/__tests__/tabs.test.tsx +0 -321
  46. package/__tests__/tag.test.tsx +0 -160
  47. package/__tests__/textarea.test.tsx +0 -467
  48. package/__tests__/timeAgo.test.tsx +0 -27
  49. package/__tests__/tree.test.tsx +0 -58
  50. package/build-storybook.log +0 -491
  51. package/chromatic.config.json +0 -1
  52. package/icons.ts +0 -1
  53. package/migration-storybook.log +0 -56
  54. package/public/logo-dark.png +0 -0
  55. package/public/logo.png +0 -0
  56. package/public/q-symbol-small.png +0 -0
  57. package/public/q-symbol.png +0 -0
  58. package/public/qoreLogo-dark.png +0 -0
  59. package/public/qoreLogo.png +0 -0
  60. package/src/components/Breadcrumbs/index.tsx +0 -254
  61. package/src/components/Breadcrumbs/item.tsx +0 -44
  62. package/src/components/Button/index.tsx +0 -633
  63. package/src/components/Checkbox/index.tsx +0 -388
  64. package/src/components/Collection/index.tsx +0 -426
  65. package/src/components/Collection/item.tsx +0 -267
  66. package/src/components/Columns/column.tsx +0 -27
  67. package/src/components/Columns/index.tsx +0 -41
  68. package/src/components/Comment/index.tsx +0 -141
  69. package/src/components/CommentFeed/index.tsx +0 -34
  70. package/src/components/Content/index.tsx +0 -34
  71. package/src/components/Content/wrapper.tsx +0 -36
  72. package/src/components/ControlGroup/index.tsx +0 -523
  73. package/src/components/DatePicker/index.tsx +0 -347
  74. package/src/components/Drawer/backdrop.tsx +0 -54
  75. package/src/components/Drawer/index.tsx +0 -365
  76. package/src/components/Dropdown/index.tsx +0 -153
  77. package/src/components/Dropdown/item.tsx +0 -33
  78. package/src/components/Dropdown/list.tsx +0 -222
  79. package/src/components/Effect/index.tsx +0 -464
  80. package/src/components/ExportModal/index.tsx +0 -99
  81. package/src/components/Header/index.tsx +0 -81
  82. package/src/components/Icon/index.tsx +0 -184
  83. package/src/components/Input/index.tsx +0 -295
  84. package/src/components/InputClearButton/index.tsx +0 -59
  85. package/src/components/InternalPopover/index.tsx +0 -303
  86. package/src/components/KeyValueTable/index.tsx +0 -192
  87. package/src/components/Label/index.tsx +0 -10
  88. package/src/components/Layout/content.tsx +0 -31
  89. package/src/components/Layout/index.tsx +0 -55
  90. package/src/components/Menu/divider.tsx +0 -92
  91. package/src/components/Menu/index.tsx +0 -141
  92. package/src/components/Menu/item.tsx +0 -137
  93. package/src/components/Menu/section.tsx +0 -81
  94. package/src/components/Message/index.tsx +0 -220
  95. package/src/components/Modal/index.tsx +0 -26
  96. package/src/components/MultiSelect/index.tsx +0 -288
  97. package/src/components/Navbar/divider.tsx +0 -50
  98. package/src/components/Navbar/group.tsx +0 -53
  99. package/src/components/Navbar/index.tsx +0 -82
  100. package/src/components/Navbar/item.tsx +0 -92
  101. package/src/components/Notifications/index.tsx +0 -57
  102. package/src/components/Notifications/notification.tsx +0 -362
  103. package/src/components/Paging/index.tsx +0 -321
  104. package/src/components/Panel/LabelEditor.tsx +0 -67
  105. package/src/components/Panel/NonResponsiveActions.tsx +0 -79
  106. package/src/components/Panel/__screenshots__/linux/panel-SomePanel.png +0 -0
  107. package/src/components/Panel/index.tsx +0 -912
  108. package/src/components/Panel/panel.screenshot.tsx +0 -29
  109. package/src/components/Paragraph/index.tsx +0 -43
  110. package/src/components/Popover/index.tsx +0 -68
  111. package/src/components/RadioGroup/index.tsx +0 -71
  112. package/src/components/Slider/index.tsx +0 -358
  113. package/src/components/Spacer/index.tsx +0 -142
  114. package/src/components/Spinner/index.tsx +0 -74
  115. package/src/components/Table/body.tsx +0 -109
  116. package/src/components/Table/cell.tsx +0 -136
  117. package/src/components/Table/header.tsx +0 -236
  118. package/src/components/Table/headerCell.tsx +0 -203
  119. package/src/components/Table/helpers.ts +0 -308
  120. package/src/components/Table/index.tsx +0 -797
  121. package/src/components/Table/row.tsx +0 -288
  122. package/src/components/Table/value.tsx +0 -28
  123. package/src/components/Tabs/content.tsx +0 -68
  124. package/src/components/Tabs/index.tsx +0 -124
  125. package/src/components/Tabs/item.tsx +0 -198
  126. package/src/components/Tabs/list.tsx +0 -381
  127. package/src/components/Tag/group.tsx +0 -73
  128. package/src/components/Tag/index.tsx +0 -463
  129. package/src/components/Textarea/index.tsx +0 -277
  130. package/src/components/TimeAgo/index.tsx +0 -15
  131. package/src/components/Tree/index.tsx +0 -271
  132. package/src/constants/animations.ts +0 -9
  133. package/src/constants/colors.ts +0 -13
  134. package/src/constants/paging.ts +0 -93
  135. package/src/constants/sizes.ts +0 -185
  136. package/src/constants/theme.ts +0 -122
  137. package/src/containers/Paging.tsx +0 -136
  138. package/src/containers/PopoverProvider.tsx +0 -124
  139. package/src/containers/ReqoreProvider.tsx +0 -289
  140. package/src/containers/ThemeProvider.tsx +0 -12
  141. package/src/containers/UIProvider.tsx +0 -101
  142. package/src/context/PopoverContext.tsx +0 -11
  143. package/src/context/ReqoreContext.tsx +0 -47
  144. package/src/context/ThemeContext.tsx +0 -4
  145. package/src/helpers/animations.ts +0 -13
  146. package/src/helpers/colors.ts +0 -335
  147. package/src/helpers/time.ts +0 -21
  148. package/src/helpers/utils.ts +0 -152
  149. package/src/hooks/useAutoFocus.ts +0 -106
  150. package/src/hooks/useCloneThroughFragments.ts +0 -39
  151. package/src/hooks/useCombinedRefs.ts +0 -26
  152. package/src/hooks/useLatestZIndex.ts +0 -13
  153. package/src/hooks/useOutsideClick.ts +0 -29
  154. package/src/hooks/usePaging.ts +0 -128
  155. package/src/hooks/usePopover.tsx +0 -220
  156. package/src/hooks/useQueryWithDelay.ts +0 -30
  157. package/src/hooks/useReqore.ts +0 -12
  158. package/src/hooks/useReqoreContext.ts +0 -16
  159. package/src/hooks/useReqoreEffect.ts +0 -49
  160. package/src/hooks/useTextareaAutoSize.ts +0 -22
  161. package/src/hooks/useTheme.ts +0 -48
  162. package/src/hooks/useTooltip.ts +0 -40
  163. package/src/hooks/useWhyDidYouUpdate.ts +0 -32
  164. package/src/icons.json +0 -2295
  165. package/src/index.tsx +0 -80
  166. package/src/mock/breadcrumbs.ts +0 -146
  167. package/src/mock/collectionData.tsx +0 -380
  168. package/src/mock/data.json +0 -11000
  169. package/src/mock/icons.ts +0 -32
  170. package/src/mock/menu.ts +0 -93
  171. package/src/mock/multiSelect.ts +0 -71
  172. package/src/mock/object.json +0 -317
  173. package/src/mock/styleMock.js +0 -1
  174. package/src/mock/tableData.ts +0 -64
  175. package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +0 -27
  176. package/src/stories/Button/Button.stories.tsx +0 -405
  177. package/src/stories/Checkbox/Checkbox.stories.tsx +0 -75
  178. package/src/stories/Collection/Collection.stories.tsx +0 -317
  179. package/src/stories/Columns/Columns.stories.tsx +0 -158
  180. package/src/stories/Comment/Comment.stories.tsx +0 -136
  181. package/src/stories/ControlGroup/ControlGroup.stories.tsx +0 -399
  182. package/src/stories/DatePicker/DatePicker.stories.tsx +0 -348
  183. package/src/stories/Drawer/Drawer.stories.tsx +0 -294
  184. package/src/stories/Dropdown/Dropdown.stories.tsx +0 -375
  185. package/src/stories/Dropdown/DropdownTests.stories.tsx +0 -111
  186. package/src/stories/ExportModal/ExportModal.stories.tsx +0 -18
  187. package/src/stories/Header/Header.stories.tsx +0 -108
  188. package/src/stories/Icon/Icon.stories.tsx +0 -162
  189. package/src/stories/Input/Input.stories.tsx +0 -220
  190. package/src/stories/KeyValueTable/KeyValueTable.stories.tsx +0 -346
  191. package/src/stories/Label/Label.stories.tsx +0 -33
  192. package/src/stories/Menu/Menu.stories.tsx +0 -367
  193. package/src/stories/Message/Message.stories.tsx +0 -167
  194. package/src/stories/Modal/Manager.stories.tsx +0 -192
  195. package/src/stories/Modal/Modal.stories.tsx +0 -252
  196. package/src/stories/MultiSelect/MultiSelect.stories.tsx +0 -140
  197. package/src/stories/Navbar/Navbar.stories.tsx +0 -119
  198. package/src/stories/Notifications/Interactive.stories.tsx +0 -117
  199. package/src/stories/Notifications/Notification.stories.tsx +0 -216
  200. package/src/stories/Notifications/Notifications.stories.tsx +0 -81
  201. package/src/stories/Paging/Paging.stories.tsx +0 -255
  202. package/src/stories/Panel/Panel.stories.tsx +0 -753
  203. package/src/stories/Paragraph/Paragraph.stories.tsx +0 -108
  204. package/src/stories/Popover/Popover.stories.tsx +0 -510
  205. package/src/stories/RadioGroup/RadioGroup.stories.tsx +0 -212
  206. package/src/stories/Slider/Slider.stories.tsx +0 -173
  207. package/src/stories/Spacer/Spacer.stories.tsx +0 -100
  208. package/src/stories/Spinner/Spinner.stories.tsx +0 -82
  209. package/src/stories/Table/Table.stories.tsx +0 -571
  210. package/src/stories/Tabs/Tabs.stories.tsx +0 -346
  211. package/src/stories/Tag/Tag.stories.tsx +0 -381
  212. package/src/stories/Tag/TagGroup.stories.tsx +0 -307
  213. package/src/stories/TextArea/TextArea.stories.tsx +0 -287
  214. package/src/stories/TextArea/TextAreaTests.stories.tsx +0 -108
  215. package/src/stories/Tree/Tree.stories.tsx +0 -124
  216. package/src/stories/Wrapper.tsx +0 -13
  217. package/src/stories/utils/args.ts +0 -151
  218. package/src/stories/utils.ts +0 -39
  219. package/src/styles.ts +0 -124
  220. package/src/types/global.ts +0 -211
  221. package/src/types/icons.ts +0 -2272
  222. package/tsconfig.prod.json +0 -26
@@ -1,29 +0,0 @@
1
- import { MutableRefObject, useCallback, useEffect } from 'react';
2
-
3
- const useOutsideClick = (
4
- targetElement?: MutableRefObject<any>,
5
- checkTarget?: boolean,
6
- callback?: () => void
7
- ): void => {
8
- const handleClick = useCallback(
9
- (event: any): void => {
10
- if (
11
- !checkTarget ||
12
- (targetElement?.current && !targetElement.current.contains(event.target))
13
- ) {
14
- callback?.();
15
- }
16
- },
17
- [checkTarget, targetElement, callback]
18
- );
19
-
20
- useEffect(() => {
21
- window.addEventListener('click', handleClick);
22
-
23
- return () => {
24
- window.removeEventListener('click', handleClick);
25
- };
26
- });
27
- };
28
-
29
- export default useOutsideClick;
@@ -1,128 +0,0 @@
1
- import { merge, size } from 'lodash';
2
- import { useEffect, useMemo } from 'react';
3
- import { useUpdateEffect } from 'react-use';
4
- import usePagination, { usePaginationReturn } from 'react-use-pagination-hook';
5
-
6
- export interface IReqorePageChangeData {
7
- isFirst?: boolean;
8
- isLast?: boolean;
9
- }
10
-
11
- export interface IReqorePagingOptions<T> {
12
- items: T[];
13
- startPage?: number;
14
- pagesToShow?: number;
15
- itemsPerPage?: number;
16
- infinite?: boolean;
17
- enabled?: boolean;
18
- onPageChange?: (page: number, info: IReqorePageChangeData) => void;
19
- }
20
-
21
- export interface IReqorePagingResult<T>
22
- extends Pick<usePaginationReturn, 'setPage' | 'currentPage'> {
23
- pages: number[];
24
- allPages: number[];
25
- items: T[];
26
- itemsPerPage: number;
27
- itemsLeft: number;
28
- isLastPage: boolean;
29
- isFirstPage: boolean;
30
- next: usePaginationReturn['goNext'];
31
- back: usePaginationReturn['goBefore'];
32
- first: () => void;
33
- last: () => void;
34
- pageCount: number;
35
- infinite: boolean;
36
- renderControls: boolean;
37
- }
38
-
39
- export const defaultPagingOptions: IReqorePagingOptions<any> = {
40
- items: [],
41
- itemsPerPage: 10,
42
- infinite: false,
43
- };
44
-
45
- export const useReqorePaging = <T>(
46
- options: IReqorePagingOptions<T> = defaultPagingOptions
47
- ): IReqorePagingResult<T> => {
48
- const {
49
- items,
50
- itemsPerPage,
51
- infinite,
52
- pagesToShow,
53
- startPage,
54
- enabled = true,
55
- onPageChange,
56
- }: IReqorePagingOptions<T> = merge({}, defaultPagingOptions, options);
57
- const allPageCount = useMemo(() => Math.ceil(size(items) / itemsPerPage), [items, itemsPerPage]);
58
- const { pagelist, currentPage, setPage, setTotalPage, goNext, goBefore } = usePagination({
59
- numOfPage: allPageCount,
60
- totalPage: allPageCount,
61
- });
62
-
63
- useEffect(() => {
64
- setPage(startPage || 1);
65
- }, [startPage]);
66
-
67
- useUpdateEffect(() => {
68
- onPageChange?.(currentPage, {
69
- isFirst: currentPage === 1,
70
- isLast: currentPage === allPageCount,
71
- });
72
- }, [currentPage]);
73
-
74
- useUpdateEffect(() => {
75
- setPage(1);
76
- setTotalPage(Math.ceil(size(items) / itemsPerPage));
77
- }, [size(items)]);
78
-
79
- const slicedItems: T[] = useMemo(() => {
80
- return items.slice(infinite ? 0 : (currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
81
- }, [items, currentPage, itemsPerPage, infinite]);
82
-
83
- const pages: number[] = useMemo(() => {
84
- if (!pagesToShow || pagesToShow >= allPageCount) {
85
- return pagelist;
86
- }
87
- // Get the middle of the desired page count
88
- const middle = Math.ceil(pagesToShow / 2);
89
- // Get the start number of the pages to show
90
- // If the current page is the last page, we need to subtract the number of pages to show from the total number of pages
91
- const start =
92
- currentPage === allPageCount ? allPageCount - pagesToShow : Math.max(currentPage - middle, 0);
93
- // Get the end number of the pages to show
94
- // If the start number is 0, we need to add the number of pages to show to the total number of pages
95
- const end = Math.min(start + pagesToShow, allPageCount);
96
-
97
- let newPages = pagelist.slice(start, end);
98
- // Always remove the first page
99
- newPages = newPages.filter((page) => page !== 1);
100
- // Always remove the last page
101
- newPages = newPages.filter((page) => page !== allPageCount);
102
- // Add the first and last page
103
- newPages = [1, ...newPages, allPageCount];
104
-
105
- return newPages;
106
- }, [pagesToShow, allPageCount, currentPage, pagelist]);
107
-
108
- return {
109
- pages,
110
- allPages: pagelist,
111
- pageCount: allPageCount,
112
- items: enabled ? slicedItems : items,
113
- itemsPerPage,
114
- itemsLeft: items.length - slicedItems.length,
115
- infinite,
116
- setPage,
117
- currentPage,
118
- next: goNext,
119
- back: goBefore,
120
- renderControls:
121
- enabled &&
122
- !(allPageCount === 1 || allPageCount === 0 || (infinite && currentPage === allPageCount)),
123
- isLastPage: currentPage === allPageCount,
124
- isFirstPage: currentPage === 1,
125
- first: () => setPage(1),
126
- last: () => setPage(allPageCount),
127
- };
128
- };
@@ -1,220 +0,0 @@
1
- import { Placement } from '@popperjs/core';
2
- import { MutableRefObject, useEffect, useMemo, useRef } from 'react';
3
- import { useUnmount, useUpdateEffect } from 'react-use';
4
- import shortid from 'shortid';
5
- import { useContext } from 'use-context-selector';
6
- import { useReqoreProperty } from '..';
7
- import { IPopoverData } from '../containers/PopoverProvider';
8
- import { IReqoreOptions } from '../containers/UIProvider';
9
- import PopoverContext from '../context/PopoverContext';
10
- import {
11
- IReqoreIntent,
12
- IWithReqoreEffect,
13
- IWithReqoreFlat,
14
- IWithReqoreMinimal,
15
- } from '../types/global';
16
- import { IReqoreIconName } from '../types/icons';
17
-
18
- const startEvents = {
19
- hover: 'mouseenter',
20
- hoverStay: 'mouseenter',
21
- click: 'click',
22
- focus: 'focusin',
23
- };
24
-
25
- const endEvents = {
26
- hover: 'mouseleave',
27
- hoverStay: null,
28
- click: null,
29
- focus: null,
30
- };
31
-
32
- export interface IPopoverControls {
33
- open: () => void;
34
- close: () => void;
35
- isOpen: () => boolean;
36
- id: string;
37
- }
38
-
39
- export interface IPopover
40
- extends IReqoreIntent,
41
- IWithReqoreMinimal,
42
- IWithReqoreEffect,
43
- IWithReqoreFlat {
44
- content?: JSX.Element | string | undefined;
45
- handler?: 'hover' | 'click' | 'focus' | 'hoverStay';
46
- placement?: Placement;
47
- show?: boolean;
48
- openOnMount?: boolean;
49
- noArrow?: boolean;
50
- noWrapper?: boolean;
51
- useTargetWidth?: boolean;
52
- closeOnOutsideClick?: boolean;
53
- closeOnAnyClick?: boolean;
54
- delay?: number;
55
- blur?: boolean;
56
- transparent?: boolean;
57
- maxWidth?: string;
58
- maxHeight?: string;
59
- icon?: IReqoreIconName;
60
- title?: string;
61
- updater?: string | number;
62
- uiScale?: IReqoreOptions['uiScale'];
63
- }
64
-
65
- export interface IPopoverOptions extends IPopover {
66
- targetElement?: HTMLElement;
67
- passPopoverData?: (data: IPopoverControls) => void;
68
- }
69
-
70
- const usePopover = ({
71
- targetElement,
72
- content,
73
- handler = 'hover',
74
- placement,
75
- show = true,
76
- noArrow,
77
- useTargetWidth,
78
- closeOnOutsideClick = true,
79
- openOnMount = false,
80
- delay,
81
- ...rest
82
- }: IPopoverOptions): IPopoverControls => {
83
- const { addPopover, removePopover, updatePopover, popovers, isPopoverOpen } =
84
- useContext(PopoverContext);
85
- const tooltips = useReqoreProperty('tooltips');
86
- const { current }: MutableRefObject<string> = useRef(shortid.generate());
87
- let { current: timeout }: MutableRefObject<any> = useRef(0);
88
-
89
- const startEvent = startEvents[handler];
90
- const endEvent = endEvents[handler];
91
- const currentPopover: IPopoverData = useMemo(
92
- () => popovers?.find((p) => p.id === current),
93
- [popovers, current]
94
- );
95
-
96
- const openPopover = () => {
97
- addPopover?.({
98
- id: current,
99
- content,
100
- targetElement,
101
- placement,
102
- noArrow,
103
- useTargetWidth,
104
- closeOnOutsideClick,
105
- closeOnAnyClick: handler === 'hover',
106
- ...rest,
107
- });
108
-
109
- if (rest.blur) {
110
- // Create a div and prepend before the targetElement
111
- const blurDiv = document.createElement('div');
112
-
113
- blurDiv.id = `reqore-blur-${current}`;
114
- blurDiv.classList.add('reqore-blur-wrapper');
115
-
116
- // Add the blur div before the target element
117
- targetElement.before(blurDiv);
118
-
119
- // Add the highest z-index to the target element
120
- targetElement.classList.add('reqore-blur-z-index');
121
- }
122
- };
123
-
124
- const _addPopover = () => {
125
- if (currentPopover) {
126
- if (handler !== 'hoverStay' && handler !== 'focus') {
127
- _removePopover();
128
- }
129
- } else if (show) {
130
- if (delay || tooltips.delay) {
131
- timeout = setTimeout(() => {
132
- openPopover();
133
- }, delay || tooltips.delay);
134
- } else {
135
- openPopover();
136
- }
137
- }
138
- };
139
-
140
- const _removePopover = () => {
141
- cancelTimeout();
142
- removePopover?.(current);
143
- };
144
-
145
- const cancelTimeout = () => {
146
- clearTimeout(timeout);
147
- timeout = null;
148
- };
149
-
150
- useUpdateEffect(() => {
151
- if (content && show) {
152
- updatePopover?.(current, {
153
- id: current,
154
- content,
155
- targetElement,
156
- placement,
157
- noArrow,
158
- useTargetWidth,
159
- closeOnOutsideClick,
160
- closeOnAnyClick: handler === 'hover',
161
- ...rest,
162
- });
163
- }
164
- }, [content]);
165
-
166
- useEffect(() => {
167
- if (openOnMount && targetElement) {
168
- _addPopover();
169
- }
170
- }, [targetElement?.outerHTML]);
171
-
172
- useEffect(() => {
173
- if (targetElement && content) {
174
- targetElement.addEventListener(startEvent, _addPopover);
175
-
176
- if (endEvent) {
177
- targetElement.addEventListener(endEvent, _removePopover);
178
- }
179
-
180
- if (handler === 'hoverStay') {
181
- targetElement.addEventListener('mouseleave', cancelTimeout);
182
- }
183
- }
184
-
185
- if (!content) {
186
- _removePopover();
187
- }
188
-
189
- return () => {
190
- cancelTimeout();
191
-
192
- targetElement?.removeEventListener(startEvent, _addPopover);
193
-
194
- if (endEvent) {
195
- targetElement?.removeEventListener(endEvent, _removePopover);
196
- }
197
-
198
- if (handler === 'hoverStay') {
199
- targetElement?.removeEventListener('mouseleave', cancelTimeout);
200
- }
201
- };
202
- }, [targetElement?.toString(), content, current, currentPopover]);
203
-
204
- useUnmount(() => {
205
- cancelTimeout();
206
- });
207
-
208
- return {
209
- id: current,
210
- open: () => {
211
- if (!isPopoverOpen(current)) {
212
- openPopover();
213
- }
214
- },
215
- close: () => _removePopover(),
216
- isOpen: () => isPopoverOpen(current),
217
- };
218
- };
219
-
220
- export default usePopover;
@@ -1,30 +0,0 @@
1
- import { useState } from 'react';
2
- import { useDebounce, useUpdateEffect } from 'react-use';
3
-
4
- export const useQueryWithDelay = (
5
- defaultQuery: string = '',
6
- delay: number = 300,
7
- onQueryChange?: (query: string | number) => void
8
- ) => {
9
- const [query, setQuery] = useState<string>(defaultQuery);
10
- const [preQuery, setPreQuery] = useState<string>(defaultQuery);
11
-
12
- useUpdateEffect(() => {
13
- onQueryChange?.(query);
14
- }, [query]);
15
-
16
- useDebounce(
17
- () => {
18
- setQuery(preQuery);
19
- },
20
- delay,
21
- [preQuery]
22
- );
23
-
24
- return {
25
- query,
26
- setQuery,
27
- setPreQuery,
28
- preQuery,
29
- };
30
- };
@@ -1,12 +0,0 @@
1
- import { useContext } from 'use-context-selector';
2
- import ReqoreContext, { IReqoreContext } from '../context/ReqoreContext';
3
-
4
- export const useReqore = (): IReqoreContext => {
5
- const reqore = useContext(ReqoreContext);
6
-
7
- if (!reqore) {
8
- throw new Error('Reqore context is not defined');
9
- }
10
-
11
- return reqore;
12
- };
@@ -1,16 +0,0 @@
1
- import { useContextSelector } from 'use-context-selector';
2
- import ReqoreContext, { IReqoreContext } from '../context/ReqoreContext';
3
-
4
- export const useReqoreProperty = <T extends keyof IReqoreContext>(
5
- property: T
6
- ): IReqoreContext[T] => {
7
- const contextProperty = useContextSelector(ReqoreContext, (value) => {
8
- if (!(property in value)) {
9
- throw new Error(`Reqore context property ${property} not found`);
10
- }
11
-
12
- return value[property];
13
- });
14
-
15
- return contextProperty;
16
- };
@@ -1,49 +0,0 @@
1
- import { useMemo } from 'react';
2
- import {
3
- IReqoreEffect,
4
- TReqoreEffectGradientAnimationTrigger,
5
- TReqoreHexColor,
6
- } from '../components/Effect';
7
- import { IReqoreTheme } from '../constants/theme';
8
- import { useReqoreTheme } from './useTheme';
9
-
10
- export const useReqoreEffect = (
11
- component: 'buttons',
12
- theme: IReqoreTheme,
13
- effect?: IReqoreEffect
14
- ): IReqoreEffect => {
15
- let _theme: IReqoreTheme = useReqoreTheme();
16
-
17
- // Return the effect if the component is not defined in the theme
18
- if (!theme[component]) {
19
- return effect;
20
- }
21
-
22
- if (theme) {
23
- // No other way to conditionally use a hook
24
- _theme = theme;
25
- }
26
-
27
- const colors: TReqoreHexColor = useMemo(() => {
28
- return _theme[component].gradient ? _theme.main : undefined;
29
- }, [_theme, effect]);
30
-
31
- const animate: TReqoreEffectGradientAnimationTrigger = useMemo(() => {
32
- return _theme[component].animate;
33
- }, [_theme, effect]);
34
-
35
- const _effect = useMemo(() => {
36
- return {
37
- ...effect,
38
- gradient: {
39
- colors,
40
- animate,
41
-
42
- // If the user has defined a gradient, we don't want to override it
43
- ...effect?.gradient,
44
- },
45
- };
46
- }, [colors, animate, effect]);
47
-
48
- return _effect;
49
- };
@@ -1,22 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- // Updates the height of a <textarea> when the value changes.
4
- const useAutosizeTextArea = (
5
- textAreaRef: HTMLTextAreaElement | null,
6
- value: string,
7
- scaleWithContent?: boolean
8
- ) => {
9
- useEffect(() => {
10
- if (textAreaRef && scaleWithContent) {
11
- // We need to reset the height momentarily to get the correct scrollHeight for the textarea
12
- textAreaRef.style.height = '0px';
13
- const scrollHeight = textAreaRef.scrollHeight;
14
-
15
- // We then set the height directly, outside of the render loop
16
- // Trying to set this with state or a ref will product an incorrect value.
17
- textAreaRef.style.height = scrollHeight + 'px';
18
- }
19
- }, [textAreaRef, value]);
20
- };
21
-
22
- export default useAutosizeTextArea;
@@ -1,48 +0,0 @@
1
- import { cloneDeep } from 'lodash';
2
- import { useMemo } from 'react';
3
- import { TReqoreEffectColor } from '../components/Effect';
4
- import { IReqoreTheme, TReqoreIntent } from '../constants/theme';
5
- import { getColorFromMaybeString, mergeThemes } from '../helpers/colors';
6
- import { useReqoreProperty } from './useReqoreContext';
7
-
8
- export interface IReqoreCustomTheme extends Partial<Omit<IReqoreTheme, 'main' | 'text'>> {
9
- main?: TReqoreEffectColor;
10
- text?: {
11
- color?: TReqoreEffectColor;
12
- dim?: boolean;
13
- };
14
- gradient?: boolean;
15
- }
16
-
17
- export const useReqoreTheme = (
18
- element?: string,
19
- customTheme: IReqoreCustomTheme = {},
20
- intent?: TReqoreIntent,
21
- intentsKey: 'intents' | 'notifications' = 'intents'
22
- ): IReqoreTheme => {
23
- const theme: IReqoreTheme = useReqoreProperty('theme');
24
-
25
- const finalTheme = useMemo(() => {
26
- if (!element) {
27
- return theme;
28
- }
29
-
30
- const _customTheme: IReqoreCustomTheme = cloneDeep(customTheme);
31
-
32
- if (_customTheme.main) {
33
- _customTheme.main = getColorFromMaybeString(theme, customTheme.main);
34
- }
35
-
36
- if (_customTheme.text?.color) {
37
- _customTheme.text.color = getColorFromMaybeString(theme, customTheme.text.color);
38
- }
39
-
40
- if (element === 'main' && intent) {
41
- _customTheme.main = theme[intentsKey][intent];
42
- }
43
-
44
- return mergeThemes(element, theme, _customTheme) as IReqoreTheme;
45
- }, [JSON.stringify(theme), element, JSON.stringify(customTheme), intent, intentsKey]);
46
-
47
- return finalTheme;
48
- };
@@ -1,40 +0,0 @@
1
- import { useEffect, useMemo, useState } from 'react';
2
- import { IReqoreTooltip, TReqoreTooltipProp } from '../types/global';
3
- import usePopover from './usePopover';
4
-
5
- export const useTooltip = (
6
- targetElement: HTMLElement | undefined,
7
- tooltip?: TReqoreTooltipProp
8
- ): void => {
9
- const [element, setElement] = useState<HTMLElement | undefined>(undefined);
10
- const [data, setData] = useState<string | IReqoreTooltip | undefined>(undefined);
11
- const content = useMemo(
12
- () => (typeof tooltip === 'object' ? tooltip?.content : tooltip),
13
- [tooltip]
14
- );
15
-
16
- useEffect(() => {
17
- if (!content) {
18
- setElement(targetElement);
19
- setData(undefined);
20
- } else {
21
- setElement(targetElement);
22
- setData(tooltip);
23
- }
24
- }, [content]);
25
-
26
- useEffect(() => {
27
- if (targetElement) {
28
- setElement(targetElement);
29
- setData(tooltip);
30
- }
31
- }, [targetElement]);
32
-
33
- const popoverData = typeof data === 'string' ? { content: data } : data;
34
-
35
- usePopover({
36
- ...popoverData,
37
- targetElement: element,
38
- show: !!popoverData?.content,
39
- });
40
- };
@@ -1,32 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
-
3
- export function useWhyDidYouUpdate(name, props) {
4
- // Get a mutable ref object where we can store props ...
5
- // ... for comparison next time this hook runs.
6
- const previousProps: any = useRef();
7
- useEffect(() => {
8
- if (previousProps.current) {
9
- // Get all keys from previous and current props
10
- const allKeys = Object.keys({ ...previousProps.current, ...props });
11
- // Use this object to keep track of changed props
12
- const changesObj = {};
13
- // Iterate through keys
14
- allKeys.forEach((key) => {
15
- // If previous is different from current
16
- if (previousProps.current[key] !== props[key]) {
17
- // Add to changesObj
18
- changesObj[key] = {
19
- from: previousProps.current[key],
20
- to: props[key],
21
- };
22
- }
23
- });
24
- // If changesObj not empty then output to console
25
- if (Object.keys(changesObj).length) {
26
- console.warn('[why-did-you-update]', name, changesObj);
27
- }
28
- }
29
- // Finally update previousProps with current props for next hook call
30
- previousProps.current = props;
31
- });
32
- }