@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,335 +0,0 @@
1
- import { cloneDeep, merge, reduce } from 'lodash';
2
- import { darken, getLuminance, lighten, mix, readableColor, transparentize } from 'polished';
3
- import {
4
- TReqoreEffectColor,
5
- TReqoreEffectColorList,
6
- TReqoreEffectGradientColors,
7
- TReqoreEffectGradientColorsObject,
8
- TReqoreHexColor,
9
- TReqoreMultiTypeColor,
10
- TReqoreRgbaColor,
11
- } from '../components/Effect';
12
- import { Colors } from '../constants/colors';
13
- import { DEFAULT_INTENTS, IReqoreTheme, TReqoreIntent } from '../constants/theme';
14
-
15
- export const getReadableColor: (
16
- theme: Partial<IReqoreTheme>,
17
- ifLight?: TReqoreHexColor,
18
- ifDark?: TReqoreHexColor,
19
- dimmed?: boolean,
20
- fallback?: TReqoreHexColor
21
- ) => TReqoreHexColor = (theme, ifLight, ifDark, dimmed, fallback) => {
22
- if (theme.text?.color) {
23
- return theme.text.dim
24
- ? dimmed
25
- ? changeDarkness(theme.text.color, 0.05)
26
- : theme.text.color
27
- : theme.text.color;
28
- }
29
-
30
- const shouldDim = theme.text?.dim && dimmed;
31
- const from = fallback || theme.main!;
32
-
33
- return getReadableColorFrom(from, shouldDim, ifLight, ifDark);
34
- };
35
-
36
- export const getReadableColorFrom = (
37
- from: TReqoreHexColor,
38
- dim?: boolean,
39
- ifLight?: TReqoreHexColor,
40
- ifDark?: TReqoreHexColor
41
- ): TReqoreHexColor => {
42
- const returnIfLight = ifLight || lighten(dim ? 0.05 : 0, Colors.DARK);
43
- const returnIfDark = ifDark || darken(dim ? 0.05 : 0, Colors.LIGHT);
44
- const fixedColor = hexAToRGBA(from);
45
-
46
- return readableColor(fixedColor, returnIfLight, returnIfDark, false) as TReqoreHexColor;
47
- };
48
-
49
- export const percentToHexAlpha = (p: number) => {
50
- const percent = Math.max(0, Math.min(100, p)); // bound percent from 0 to 100
51
- const intValue = Math.round((percent / 100) * 255); // map percent to nearest integer (0 - 255)
52
- const hexValue = intValue.toString(16); // get hexadecimal representation
53
-
54
- return hexValue.padStart(2, '0').toUpperCase(); // format with leading 0 and upper case characters
55
- };
56
-
57
- export const hexAToRGBA = (hex: TReqoreMultiTypeColor): TReqoreRgbaColor => {
58
- // Check if this color is already in rgba format
59
- if (hex.startsWith('rgb')) {
60
- return hex as TReqoreRgbaColor;
61
- }
62
-
63
- const _hex = hex.length === 4 ? hex + hex.slice(1, 4) : hex;
64
-
65
- const r = parseInt(_hex.slice(1, 3), 16);
66
- const g = parseInt(_hex.slice(3, 5), 16);
67
- const b = parseInt(_hex.slice(5, 7), 16);
68
- const a = parseInt(_hex.slice(7, 9) || 'ff', 16) / 255;
69
-
70
- return `rgba(${r}, ${g}, ${b}, ${a.toFixed(2)})`;
71
- };
72
-
73
- export const RGBAToHexA = (rgba, forceRemoveAlpha = false): TReqoreHexColor => {
74
- if (isValidSixCharHex(rgba)) {
75
- return rgba as TReqoreHexColor;
76
- }
77
-
78
- return ('#' +
79
- rgba
80
- .replace(/^rgba?\(|\s+|\)$/g, '') // Get's rgba / rgb string values
81
- .split(',') // splits them at ","
82
- .filter((_string, index) => !forceRemoveAlpha || index !== 3)
83
- .map((string) => parseFloat(string)) // Converts them to numbers
84
- .map((number, index) => (index === 3 ? Math.round(number * 255) : number)) // Converts alpha to 255 number
85
- .map((number) => number.toString(16)) // Converts numbers to hex
86
- .map((string) => (string.length === 1 ? '0' + string : string)) // Adds 0 when length of one number is 1
87
- .join('')) as TReqoreHexColor; // Puts the array to togehter to a string
88
- };
89
-
90
- export const shouldDarken = (mainColor: TReqoreMultiTypeColor): boolean => {
91
- return getLuminance(hexAToRGBA(mainColor)) > 0.2;
92
- };
93
-
94
- export const getMainColor: (theme: IReqoreTheme, component: string) => TReqoreHexColor = (
95
- theme,
96
- component
97
- ) => theme[component]?.main || theme.main;
98
-
99
- //export const changeBasedOnContrast = (color: string, lightness?: number): string =>
100
-
101
- export const changeLightness = (color: TReqoreHexColor, lightness?: number): TReqoreHexColor => {
102
- const fixedColor = hexAToRGBA(color);
103
-
104
- return lightness
105
- ? shouldDarken(fixedColor)
106
- ? (darken(lightness, fixedColor) as TReqoreHexColor)
107
- : (lighten(lightness, fixedColor) as TReqoreHexColor)
108
- : color;
109
- };
110
-
111
- export const changeDarkness = (color: TReqoreHexColor, lightness?: number): TReqoreHexColor => {
112
- const fixedColor = hexAToRGBA(color);
113
-
114
- return lightness
115
- ? shouldDarken(fixedColor)
116
- ? (lighten(lightness, fixedColor) as TReqoreHexColor)
117
- : (darken(lightness, fixedColor) as TReqoreHexColor)
118
- : color;
119
- };
120
-
121
- export const getColorByBgColor = (bgColor) => {
122
- if (!bgColor) {
123
- return '';
124
- }
125
- return parseInt(bgColor.replace('#', ''), 16) > 0xffffff / 2 ? '#000000' : '#ffffff';
126
- };
127
-
128
- export const isValidSixCharHex = (hex: string): boolean => {
129
- return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/.test(hex);
130
- };
131
-
132
- export const buildTheme = (theme: IReqoreTheme): IReqoreTheme => {
133
- const newTheme: IReqoreTheme = cloneDeep(theme);
134
-
135
- // Check if the main color is a valid hex color
136
- if (!isValidSixCharHex(newTheme.main)) {
137
- newTheme.main = '#333333';
138
- }
139
-
140
- // Add the original theme main color to the theme
141
- newTheme.originalMain = newTheme.main;
142
-
143
- if (!newTheme.notifications?.info) {
144
- newTheme.notifications.info = newTheme.intents.info || DEFAULT_INTENTS.info;
145
- }
146
-
147
- if (!newTheme.notifications?.success) {
148
- newTheme.notifications.success = newTheme.intents.success || DEFAULT_INTENTS.success;
149
- }
150
-
151
- if (!newTheme.notifications?.pending) {
152
- newTheme.notifications.pending = newTheme.intents.pending || DEFAULT_INTENTS.pending;
153
- }
154
-
155
- if (!newTheme.notifications?.warning) {
156
- newTheme.notifications.warning = newTheme.intents.warning || DEFAULT_INTENTS.warning;
157
- }
158
-
159
- if (!newTheme.notifications?.danger) {
160
- newTheme.notifications.danger = newTheme.intents.danger || DEFAULT_INTENTS.danger;
161
- }
162
-
163
- if (!newTheme.notifications?.muted) {
164
- newTheme.notifications.muted = `${newTheme.intents.muted || DEFAULT_INTENTS.muted}30`;
165
- }
166
-
167
- return newTheme;
168
- };
169
-
170
- export const mergeThemes = (element: string, theme: IReqoreTheme, customTheme: any) => {
171
- const clonedTheme = cloneDeep(theme);
172
-
173
- if (!customTheme) {
174
- return clonedTheme;
175
- }
176
-
177
- if (element === 'main') {
178
- merge(clonedTheme, {
179
- main: customTheme.main,
180
- originalMain: clonedTheme.main,
181
- text: customTheme.text,
182
- });
183
- } else {
184
- merge(clonedTheme, { [element]: customTheme, text: customTheme.text });
185
- }
186
-
187
- return clonedTheme;
188
- };
189
-
190
- export const getNotificationIntent = (theme: IReqoreTheme, intent?: TReqoreIntent) => {
191
- if (intent) {
192
- return theme.notifications[intent];
193
- }
194
-
195
- return changeLightness(theme.main, 0.1);
196
- };
197
-
198
- export const getMainBackgroundColor = (theme: IReqoreTheme): TReqoreHexColor =>
199
- changeLightness(theme.main, 0.02);
200
-
201
- export const getColorFromMaybeString = (
202
- theme: IReqoreTheme,
203
- color: TReqoreEffectColor
204
- ): TReqoreHexColor => {
205
- if (!color) {
206
- return undefined;
207
- }
208
-
209
- const [providedColor, shading, multiplier = 1, alpha = 1]: TReqoreEffectColorList = color.split(
210
- ':'
211
- ) as TReqoreEffectColorList;
212
-
213
- if (providedColor === 'transparent') {
214
- return theme.originalMain;
215
- }
216
-
217
- // First we need to get the actual color
218
- let _color: TReqoreHexColor;
219
-
220
- if (!providedColor || providedColor === 'main') {
221
- _color = theme.main;
222
- }
223
-
224
- if (theme.intents[providedColor]) {
225
- _color = theme.intents[providedColor];
226
- }
227
-
228
- if (isValidSixCharHex(providedColor)) {
229
- _color = providedColor as TReqoreHexColor;
230
- }
231
-
232
- if (shading) {
233
- if (shading === 'lighten') {
234
- _color = lighten(0.033 * multiplier, _color) as TReqoreHexColor;
235
- } else if (shading === 'darken') {
236
- _color = darken(0.033 * multiplier, _color) as TReqoreHexColor;
237
- }
238
- }
239
-
240
- if (_color && _color.length === 7 && alpha < 1) {
241
- _color = RGBAToHexA(transparentize(1 - alpha, _color));
242
- }
243
-
244
- return _color;
245
- };
246
-
247
- export const createEffectGradient = (
248
- theme: IReqoreTheme,
249
- colors: TReqoreEffectGradientColors,
250
- lighten: number = 0,
251
- minimal?: boolean,
252
- active?: boolean
253
- ): string => {
254
- let _colors: TReqoreEffectGradientColorsObject;
255
- // Check if the colors are valid
256
- if (!colors) {
257
- throw new Error('You need to provide colors');
258
- }
259
-
260
- if (typeof colors === 'string') {
261
- _colors = buildGradientColorsFromString(theme, colors);
262
- } else {
263
- _colors = colors;
264
- }
265
-
266
- return reduce(
267
- _colors,
268
- (colorsString, color, percentage) => {
269
- return `${colorsString}, ${
270
- minimal
271
- ? active
272
- ? theme.originalMain
273
- : changeLightness(theme.originalMain, lighten)
274
- : changeLightness(getColorFromMaybeString(theme, color), lighten)
275
- } ${percentage}%`;
276
- },
277
- ''
278
- );
279
- };
280
-
281
- export const buildGradientColorsFromString = (
282
- theme: IReqoreTheme,
283
- color: 'main' | TReqoreHexColor | TReqoreIntent
284
- ): TReqoreEffectGradientColorsObject => {
285
- if (!color) {
286
- throw new Error('You need to provide a color or intent');
287
- }
288
-
289
- const colorFrom: TReqoreHexColor = getColorFromMaybeString(theme, `${color}:lighten:1`);
290
- const colorTo: TReqoreHexColor = getColorFromMaybeString(theme, `${color}`);
291
-
292
- return {
293
- 0: colorFrom,
294
- 100: colorTo,
295
- };
296
- };
297
-
298
- export const getNthGradientColor = (
299
- theme: IReqoreTheme,
300
- colors?: TReqoreEffectGradientColors,
301
- nth: number = 1
302
- ): TReqoreHexColor | undefined => {
303
- const _colors =
304
- typeof colors === 'string' ? buildGradientColorsFromString(theme, colors) : colors;
305
-
306
- if (_colors) {
307
- return getColorFromMaybeString(theme, Object.values(_colors)[nth - 1]);
308
- }
309
-
310
- return undefined;
311
- };
312
-
313
- export const getGradientMix = (
314
- theme: IReqoreTheme,
315
- colors: TReqoreEffectGradientColors,
316
- fallback?: TReqoreHexColor
317
- ): TReqoreHexColor | undefined => {
318
- const _colors =
319
- typeof colors === 'string' ? buildGradientColorsFromString(theme, colors) : colors;
320
-
321
- if (colors && Object.keys(colors).length === 2) {
322
- const gradientColor1: TReqoreHexColor = getNthGradientColor(theme, _colors);
323
- const gradientColor2: TReqoreHexColor = getNthGradientColor(theme, _colors, 2);
324
-
325
- return RGBAToHexA(
326
- mix(
327
- 0.5,
328
- gradientColor1 === '#00000000' ? theme.main : gradientColor1,
329
- gradientColor2 === '#00000000' ? theme.main : gradientColor2
330
- ) as TReqoreHexColor
331
- );
332
- }
333
-
334
- return fallback;
335
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * If the time is larger than one day, update once a day. If the time is larger than one hour,
3
- update once an hour. Otherwise update every 5 seconds.
4
- * @param {number} time - the time in milliseconds since the epoch
5
- * @returns The interval ID.
6
- */
7
- export const getTimeAgoIntervalDelay = (time: number): number => {
8
- // If the time is larger than one day
9
- if (Date.now() - time > 60000 * 60 * 24) {
10
- // update once a day
11
- return 60000 * 60 * 24;
12
- }
13
- // If the time is larger than one hour
14
- if (Date.now() - time > 60000 * 60) {
15
- // update once an hour
16
- return 60000 * 60;
17
- }
18
-
19
- // Otherwise update every 5 seconds
20
- return 5000;
21
- };
@@ -1,152 +0,0 @@
1
- import {
2
- isArray,
3
- isBoolean,
4
- isFunction,
5
- isNull,
6
- isNumber,
7
- isObject,
8
- isString,
9
- isUndefined,
10
- } from 'lodash';
11
- import { IReqorePanelAction } from '../components/Panel';
12
- import { NUMBER_TO_SIZE, SIZES, SIZE_TO_NUMBER, TSizes } from '../constants/sizes';
13
-
14
- export const sleep = async (ms: number) => await new Promise((r) => setTimeout(r, ms));
15
-
16
- export const getTypeFromValue = (item: any): string => {
17
- if (isBoolean(item)) {
18
- return 'boolean';
19
- }
20
-
21
- if (isString(item)) {
22
- return 'string';
23
- }
24
-
25
- if (isNumber(item)) {
26
- return 'number';
27
- }
28
-
29
- if (isArray(item)) {
30
- return 'array';
31
- }
32
-
33
- if (isObject(item)) {
34
- return 'object';
35
- }
36
-
37
- if (isFunction(item)) {
38
- return 'function';
39
- }
40
-
41
- if (isNull(item) || isUndefined(item)) {
42
- return 'null';
43
- }
44
-
45
- return 'null';
46
- };
47
-
48
- export const getLineCount = (value: string | null): number => {
49
- try {
50
- return value?.match(/[^\n]*\n[^\n]*/gi)?.length ?? 0;
51
- } catch (e) {
52
- return 0;
53
- }
54
- };
55
-
56
- // A function that takes list of objects and transforms it
57
- // to a CSV string
58
- export const convertToCSV = (objArray: any[]): string => {
59
- const header = Object.keys(objArray[0]).join(',');
60
- const rows = objArray.map((obj) =>
61
- Object.values(obj)
62
- .map((value) => JSON.stringify(value))
63
- .join(',')
64
- );
65
-
66
- return [header, ...rows].join('\n');
67
- };
68
-
69
- export const calculateStringSizeInPixels = (value: string = '', fontSize: number): number => {
70
- const widths = [
71
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72
- 0.2796875, 0.2765625, 0.3546875, 0.5546875, 0.5546875, 0.8890625, 0.665625, 0.190625, 0.3328125,
73
- 0.3328125, 0.3890625, 0.5828125, 0.2765625, 0.3328125, 0.2765625, 0.3015625, 0.5546875,
74
- 0.5546875, 0.5546875, 0.5546875, 0.5546875, 0.5546875, 0.5546875, 0.5546875, 0.5546875,
75
- 0.5546875, 0.2765625, 0.2765625, 0.584375, 0.5828125, 0.584375, 0.5546875, 1.0140625, 0.665625,
76
- 0.665625, 0.721875, 0.721875, 0.665625, 0.609375, 0.7765625, 0.721875, 0.2765625, 0.5, 0.665625,
77
- 0.5546875, 0.8328125, 0.721875, 0.7765625, 0.665625, 0.7765625, 0.721875, 0.665625, 0.609375,
78
- 0.721875, 0.665625, 0.94375, 0.665625, 0.665625, 0.609375, 0.2765625, 0.3546875, 0.2765625,
79
- 0.4765625, 0.5546875, 0.3328125, 0.5546875, 0.5546875, 0.5, 0.5546875, 0.5546875, 0.2765625,
80
- 0.5546875, 0.5546875, 0.221875, 0.240625, 0.5, 0.221875, 0.8328125, 0.5546875, 0.5546875,
81
- 0.5546875, 0.5546875, 0.3328125, 0.5, 0.2765625, 0.5546875, 0.5, 0.721875, 0.5, 0.5, 0.5,
82
- 0.3546875, 0.259375, 0.353125, 0.5890625,
83
- ];
84
- const avg = 0.5279276315789471;
85
-
86
- /* It's calculating the width of a string in pixels. */
87
- return (
88
- Array.from(value).reduce((acc, cur) => acc + (widths[cur.charCodeAt(0)] ?? avg), 0) *
89
- (fontSize * 1.35)
90
- );
91
- };
92
-
93
- export const isStringSize = (value: TSizes | string | number) => {
94
- return SIZES.includes(value as TSizes);
95
- };
96
-
97
- export const getOneLessSize = (size: TSizes): TSizes => {
98
- // Get the initial sizes number
99
- const initialSizeNumber: number = SIZE_TO_NUMBER[size];
100
- // Reduce the size number by one
101
- const oneLessSizeNumber: number = initialSizeNumber - 1 === 0 ? 1 : initialSizeNumber - 1;
102
- // Get the size name from the number
103
- return NUMBER_TO_SIZE[oneLessSizeNumber];
104
- };
105
-
106
- export const getOneHigherSize = (size: TSizes): TSizes => {
107
- // Get the initial sizes number
108
- const initialSizeNumber: number = SIZE_TO_NUMBER[size];
109
- // Reduce the size number by one
110
- const oneHigherSizeNumber: number = initialSizeNumber + 1 === 6 ? 5 : initialSizeNumber + 1;
111
- // Get the size name from the number
112
- return NUMBER_TO_SIZE[oneHigherSizeNumber];
113
- };
114
-
115
- export const isActionShown = (action: IReqorePanelAction) => action.show !== false;
116
-
117
- export const alignToFlexAlign = (
118
- align: 'left' | 'right' | 'center'
119
- ): 'flex-start' | 'center' | 'flex-end' => {
120
- switch (align) {
121
- case 'left':
122
- return 'flex-start';
123
- case 'right':
124
- return 'flex-end';
125
- case 'center':
126
- return 'center';
127
- default:
128
- return 'flex-start';
129
- }
130
- };
131
-
132
- export function decycle(obj, stack = []) {
133
- if (!obj || typeof obj !== 'object') return obj;
134
-
135
- if (stack.includes(obj)) return null;
136
-
137
- const s = stack.concat([obj]);
138
-
139
- return Array.isArray(obj)
140
- ? obj.map((x) => decycle(x, s))
141
- : Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, decycle(v, s)]));
142
- }
143
-
144
- export const stringifyAndDecycleObject = (obj: any): string => {
145
- return JSON.stringify(decycle(obj), (_key, value) => {
146
- if (typeof value === 'function') {
147
- return value.toString();
148
- }
149
-
150
- return value;
151
- });
152
- };
@@ -1,106 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { useUnmount, useUpdateEffect } from 'react-use';
3
-
4
- export type TReqoreAutoFocusType = 'auto' | 'keypress';
5
-
6
- export interface IReqoreAutoFocusRules {
7
- type: TReqoreAutoFocusType;
8
- viewportOnly?: boolean;
9
- viewport?: HTMLElement;
10
- viewportMargin?: string;
11
- shortcut?: 'letters' | 'numbers' | string | ('letters' | 'numbers' | string)[];
12
- clearOnFocus?: boolean;
13
- doNotInsertShortcut?: boolean;
14
- }
15
-
16
- export const useAutoFocus = (
17
- element: HTMLInputElement | HTMLTextAreaElement,
18
- rules?: IReqoreAutoFocusRules,
19
- onChange?: (event: any) => void
20
- ) => {
21
- const isInViewport = useRef<boolean>(false);
22
- const observer = useRef<IntersectionObserver>(null);
23
-
24
- const focus = useCallback(() => {
25
- if (!rules.viewportOnly || isInViewport.current) {
26
- if (rules.clearOnFocus) {
27
- onChange?.({ target: { value: '' } } as any);
28
- }
29
-
30
- element.setSelectionRange(-1, -1);
31
- element.focus();
32
- }
33
- }, [element, rules, isInViewport.current]);
34
-
35
- const handleKeyDown = (e: KeyboardEvent) => {
36
- // Check if this event came from another html input
37
- if (
38
- e.target &&
39
- ((e.target as HTMLElement).tagName === 'INPUT' ||
40
- (e.target as HTMLElement).tagName === 'TEXTAREA')
41
- ) {
42
- return;
43
- }
44
-
45
- const shortcut = Array.isArray(rules?.shortcut) ? rules?.shortcut : [rules?.shortcut];
46
-
47
- if (shortcut.includes('letters') && e.key.length === 1 && e.key.match(/[a-z]/i)) {
48
- focus();
49
- }
50
-
51
- if (shortcut.includes('numbers') && e.key.length === 1 && e.key.match(/[0-9]/i)) {
52
- focus();
53
- }
54
-
55
- if (shortcut.includes(e.key)) {
56
- focus();
57
- }
58
- };
59
-
60
- useUpdateEffect(() => {
61
- if (element && rules) {
62
- if (rules.viewportOnly) {
63
- observer.current = new IntersectionObserver(
64
- (entries: IntersectionObserverEntry[]) => {
65
- entries.forEach((entry) => {
66
- if (entry.isIntersecting) {
67
- isInViewport.current = true;
68
- } else {
69
- isInViewport.current = false;
70
- }
71
- // If the focus type is auto, we focus the element now if its in the viewport
72
- // and set the observer to null so it doesn't run again
73
- if (rules.type === 'auto' && isInViewport.current) {
74
- element.focus();
75
- observer.current?.disconnect();
76
- observer.current = null;
77
- }
78
- });
79
- },
80
- {
81
- root: rules?.viewport,
82
- rootMargin: rules?.viewportMargin,
83
- threshold: 0.8,
84
- }
85
- );
86
-
87
- observer.current.observe(element);
88
- } else if (rules.type === 'auto') {
89
- focus();
90
- }
91
- }
92
- }, [element]);
93
-
94
- useUnmount(() => {
95
- observer.current?.disconnect();
96
- });
97
-
98
- useEffect(() => {
99
- if (element && rules && rules.type === 'keypress') {
100
- window.addEventListener(rules.doNotInsertShortcut ? 'keyup' : 'keydown', handleKeyDown);
101
- }
102
-
103
- return () =>
104
- window.removeEventListener(rules?.doNotInsertShortcut ? 'keyup' : 'keydown', handleKeyDown);
105
- }, [element, rules]);
106
- };
@@ -1,39 +0,0 @@
1
- import React, { useCallback } from 'react';
2
-
3
- export const useCloneThroughFragments = (
4
- propsMapper: (
5
- props: Record<string | number, any>,
6
- reactIndex: number,
7
- realIndex: number
8
- ) => Record<string | number, any>,
9
- deps?: any[]
10
- ) => {
11
- let realIndex = 0;
12
-
13
- const clone = useCallback((children: React.ReactNode): React.ReactNode => {
14
- return React.Children.map(children, (child, reactIndex) => {
15
- if (child && React.isValidElement(child)) {
16
- if (child.type === React.Fragment) {
17
- return clone(child.props.children);
18
- }
19
-
20
- const props = propsMapper(child.props, reactIndex, realIndex);
21
-
22
- /*
23
- * Because of the way React.Children.map works, we have to
24
- * manually decrement the index for every child that is `null`
25
- * because react maps through null children and returns them in `Count`
26
- * We filter these children out in the `realChildCount` variable,
27
- * but the index is still incremented
28
- * */
29
- realIndex = realIndex + 1;
30
-
31
- return React.cloneElement(child, props);
32
- }
33
-
34
- return child;
35
- });
36
- }, deps);
37
-
38
- return { clone };
39
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
-
3
- /**
4
- * It takes a list of refs and returns a single ref that can be used to reference the same underlying
5
- * DOM element
6
- * @param refs - An array of refs to combine.
7
- * @returns A ref object.
8
- */
9
- export function useCombinedRefs<T = any>(...refs) {
10
- const [_innerRef, setInnerRef] = React.useState(null);
11
- const targetRef = React.useRef<T>();
12
-
13
- React.useEffect(() => {
14
- [...refs, setInnerRef].forEach((ref) => {
15
- if (!ref) return;
16
-
17
- if (typeof ref === 'function') {
18
- ref(targetRef.current);
19
- } else {
20
- ref.current = targetRef.current;
21
- }
22
- });
23
- }, [refs]);
24
-
25
- return { _innerRef, targetRef };
26
- }
@@ -1,13 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useReqoreProperty } from './useReqoreContext';
3
-
4
- const useLatestZIndex = (): number => {
5
- const getAndIncreaseZIndex = useReqoreProperty('getAndIncreaseZIndex');
6
- const latestZIndex = useReqoreProperty('latestZIndex');
7
-
8
- const zIndex = useMemo(() => getAndIncreaseZIndex(), [latestZIndex]);
9
-
10
- return zIndex;
11
- };
12
-
13
- export default useLatestZIndex;