@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,277 +0,0 @@
1
- import { rgba } from 'polished';
2
- import React, { forwardRef, useCallback, useEffect, useState } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { ReqoreDropdown } from '../..';
5
- import {
6
- CONTROL_TEXT_FROM_SIZE,
7
- PADDING_FROM_SIZE,
8
- RADIUS_FROM_SIZE,
9
- SIZE_TO_PX,
10
- TSizes,
11
- } from '../../constants/sizes';
12
- import { IReqoreTheme } from '../../constants/theme';
13
- import { changeLightness, getReadableColor } from '../../helpers/colors';
14
- import { IReqoreAutoFocusRules, useAutoFocus } from '../../hooks/useAutoFocus';
15
- import { useCombinedRefs } from '../../hooks/useCombinedRefs';
16
- import useAutosizeTextArea from '../../hooks/useTextareaAutoSize';
17
- import { useReqoreTheme } from '../../hooks/useTheme';
18
- import { useTooltip } from '../../hooks/useTooltip';
19
- import { DisabledElement, ReadOnlyElement } from '../../styles';
20
- import {
21
- IReqoreDisabled,
22
- IReqoreIntent,
23
- IReqoreReadOnly,
24
- IWithReqoreCustomTheme,
25
- IWithReqoreEffect,
26
- IWithReqoreTooltip,
27
- } from '../../types/global';
28
- import { IReqoreDropdownProps } from '../Dropdown';
29
- import { StyledEffect } from '../Effect';
30
- import { IReqoreInputStyle } from '../Input';
31
- import ReqoreInputClearButton from '../InputClearButton';
32
-
33
- export interface IReqoreFormTemplates extends IReqoreDropdownProps {}
34
-
35
- export interface IReqoreTextareaProps
36
- extends React.HTMLAttributes<HTMLTextAreaElement>,
37
- IReqoreReadOnly,
38
- IReqoreDisabled,
39
- IWithReqoreCustomTheme,
40
- IWithReqoreTooltip,
41
- IReqoreIntent,
42
- IWithReqoreEffect {
43
- autoFocus?: boolean;
44
- placeholder?: string;
45
- width?: number;
46
- height?: number;
47
- scaleWithContent?: boolean;
48
- size?: TSizes;
49
- minimal?: boolean;
50
- fluid?: boolean;
51
- value?: string;
52
- rows?: number;
53
- cols?: number;
54
- rounded?: boolean;
55
- flat?: boolean;
56
- fixed?: boolean;
57
- onClearClick?: () => any;
58
- wrapperStyle?: React.CSSProperties;
59
- focusRules?: IReqoreAutoFocusRules;
60
- templates?: IReqoreFormTemplates;
61
- }
62
-
63
- export interface IReqoreTextareaStyle extends IReqoreTextareaProps {
64
- theme: IReqoreTheme;
65
- hasClearButton?: boolean;
66
- _size?: TSizes;
67
- }
68
-
69
- export const StyledTextareaWrapper = styled.div<IReqoreTextareaStyle>`
70
- height: ${({ height }) => (height ? `${height}px` : undefined)};
71
- min-height: ${({ _size }) => SIZE_TO_PX[_size]}px;
72
- max-height: 100%;
73
- width: ${({ width, fluid }) => (fluid ? '100%' : width ? `${width}px` : 'auto')};
74
- flex: ${({ fluid, fixed }) => (fixed ? '0 0 auto' : fluid ? '1 auto' : '0 0 auto')};
75
- align-self: ${({ fixed, fluid }) => (fixed ? 'flex-start' : fluid ? 'stretch' : undefined)};
76
- position: relative;
77
- overflow: hidden;
78
-
79
- &:focus-within {
80
- .reqore-clear-input-button {
81
- display: flex;
82
- }
83
- }
84
- `;
85
-
86
- export const StyledTextarea = styled(StyledEffect)<IReqoreTextareaStyle>`
87
- width: 100%;
88
- max-width: 100%;
89
- max-height: 100%;
90
- font-size: ${({ _size }) => CONTROL_TEXT_FROM_SIZE[_size]}px;
91
- margin: 0;
92
- padding: ${({ _size }) => PADDING_FROM_SIZE[_size] / 2}px;
93
- padding-right: ${({ hasClearButton, _size }) =>
94
- hasClearButton ? `${SIZE_TO_PX[_size]}px` : undefined};
95
- min-height: ${({ _size }) => SIZE_TO_PX[_size]}px;
96
- line-height: ${({ _size }) => SIZE_TO_PX[_size] - CONTROL_TEXT_FROM_SIZE[_size]}px;
97
- vertical-align: middle;
98
-
99
- background-color: ${({ theme, minimal }: IReqoreInputStyle) =>
100
- minimal ? 'transparent' : rgba(theme.main, 0.1)};
101
- color: ${({ theme }: IReqoreInputStyle) =>
102
- getReadableColor(theme, undefined, undefined, true, theme.originalMain)};
103
-
104
- &:active,
105
- &:focus {
106
- background-color: ${({ theme, minimal }: IReqoreInputStyle) =>
107
- minimal ? 'transparent' : rgba(theme.main, 0.15)};
108
- }
109
-
110
- border-radius: ${({ minimal, rounded, _size }) =>
111
- minimal || !rounded ? 0 : RADIUS_FROM_SIZE[_size]}px;
112
- border: ${({ minimal, theme, flat }) =>
113
- !minimal && !flat ? `1px solid ${changeLightness(theme.main, 0.2)}` : 0};
114
- border-bottom: ${({ minimal, theme, flat }) =>
115
- minimal && !flat ? `0.5px solid ${changeLightness(theme.main, 0.2)}` : undefined};
116
-
117
- ${({ disabled, readOnly }) =>
118
- !disabled && !readOnly
119
- ? css`
120
- &:active,
121
- &:focus,
122
- &:hover {
123
- outline: none;
124
- border-color: ${({ theme }) => changeLightness(theme.main, 0.35)};
125
- }
126
- `
127
- : undefined}
128
-
129
- &::placeholder {
130
- color: ${({ theme }) =>
131
- rgba(getReadableColor(theme, undefined, undefined, true, theme.originalMain), 0.3)};
132
- }
133
-
134
- &:focus {
135
- &::placeholder {
136
- color: ${({ theme }) =>
137
- rgba(getReadableColor(theme, undefined, undefined, true, theme.originalMain), 0.5)};
138
- }
139
- }
140
-
141
- ${({ readOnly }) => readOnly && ReadOnlyElement};
142
-
143
- &:disabled {
144
- ${DisabledElement};
145
- }
146
- `;
147
-
148
- const ReqoreInput = forwardRef<HTMLTextAreaElement, IReqoreTextareaProps>(
149
- (
150
- {
151
- width,
152
- height,
153
- scaleWithContent,
154
- size = 'normal',
155
- className,
156
- onClearClick,
157
- fluid,
158
- tooltip,
159
- customTheme,
160
- intent,
161
- rounded = true,
162
- wrapperStyle,
163
- value,
164
- onChange,
165
- fixed,
166
- focusRules,
167
- templates,
168
- ...rest
169
- }: IReqoreTextareaProps,
170
- ref
171
- ) => {
172
- const { targetRef }: any = useCombinedRefs(ref);
173
- const [inputRef, setInputRef] = useState<HTMLTextAreaElement>(null);
174
- const theme = useReqoreTheme('main', customTheme, intent);
175
- const [_value, setValue] = useState(value || '');
176
-
177
- useEffect(() => {
178
- setValue(value || '');
179
- }, [value]);
180
-
181
- useTooltip(inputRef, tooltip);
182
- useAutosizeTextArea(inputRef, _value, scaleWithContent);
183
- useAutoFocus(inputRef, rest.readOnly || rest.disabled ? undefined : focusRules, onChange);
184
-
185
- const handleItemSelect = useCallback(
186
- (item) => {
187
- if (!inputRef || !item || !item.value) {
188
- return;
189
- }
190
- // Add the value of the selected item to the current value at the cursor position
191
- const value = `${_value.slice(0, inputRef.selectionStart)}${item.value}${_value.slice(
192
- inputRef.selectionEnd
193
- )}`;
194
-
195
- setValue(value);
196
- // Trigger the onChange event
197
- onChange?.({ target: { value } } as any);
198
- },
199
- [inputRef, _value]
200
- );
201
-
202
- const renderChildren = () => {
203
- return (
204
- <>
205
- <StyledTextarea
206
- {...rest}
207
- effect={{
208
- interactive: !rest?.disabled && !rest.readOnly,
209
- ...rest?.effect,
210
- }}
211
- onChange={(e) => {
212
- setValue(e.target.value);
213
- onChange?.(e);
214
- }}
215
- as='textarea'
216
- className={`${className || ''} reqore-control reqore-textarea`}
217
- _size={size}
218
- ref={(ref) => setInputRef(ref)}
219
- theme={theme}
220
- rounded={rounded}
221
- rows={1}
222
- value={_value}
223
- readonly={rest?.readOnly}
224
- tabIndex={rest?.disabled ? -1 : 0}
225
- hasClearButton={!rest?.readOnly && !rest?.disabled && !!(onClearClick && onChange)}
226
- />
227
- <ReqoreInputClearButton
228
- enabled={!rest?.readOnly && !rest?.disabled && !!(onClearClick && onChange)}
229
- show={_value && _value !== ''}
230
- onClick={onClearClick}
231
- size={size}
232
- />
233
- </>
234
- );
235
- };
236
-
237
- if (templates) {
238
- return (
239
- <ReqoreDropdown<Omit<IReqoreTextareaStyle & { ref: any }, 'content'>>
240
- component={StyledTextareaWrapper}
241
- className={`${className || ''} reqore-control-wrapper`}
242
- width={width}
243
- filterable
244
- height={height}
245
- fluid={fluid}
246
- fixed={fixed}
247
- _size={size}
248
- theme={theme}
249
- style={wrapperStyle}
250
- ref={targetRef}
251
- onItemSelect={handleItemSelect}
252
- {...templates}
253
- >
254
- {renderChildren()}
255
- </ReqoreDropdown>
256
- );
257
- }
258
-
259
- return (
260
- <StyledTextareaWrapper
261
- className={`${className || ''} reqore-control-wrapper`}
262
- width={width}
263
- height={height}
264
- fluid={fluid}
265
- fixed={fixed}
266
- _size={size}
267
- theme={theme}
268
- style={wrapperStyle}
269
- ref={targetRef}
270
- >
271
- {renderChildren()}
272
- </StyledTextareaWrapper>
273
- );
274
- }
275
- );
276
-
277
- export default ReqoreInput;
@@ -1,15 +0,0 @@
1
- import timeago from 'epoch-timeago';
2
- import { useState } from 'react';
3
- import { useInterval } from 'react-use';
4
- import { getTimeAgoIntervalDelay } from '../../helpers/time';
5
-
6
- export const TimeAgo = ({ time }: { time: number | string }) => {
7
- const setUpdate = useState<number>(Date.now());
8
- const _time = typeof time === 'number' ? time : Date.parse(time);
9
-
10
- useInterval(() => {
11
- setUpdate[1](Date.now());
12
- }, getTimeAgoIntervalDelay(_time));
13
-
14
- return timeago(_time);
15
- };
@@ -1,271 +0,0 @@
1
- import { cloneDeep, size as lodashSize } from 'lodash';
2
- import { useMemo, useState } from 'react';
3
- import styled from 'styled-components';
4
- import { ReqoreHorizontalSpacer, ReqoreIcon, ReqoreP, ReqorePanel, useReqoreProperty } from '../..';
5
- import { GAP_FROM_SIZE, TSizes } from '../../constants/sizes';
6
- import { IReqoreTheme } from '../../constants/theme';
7
- import { getOneLessSize, getTypeFromValue } from '../../helpers/utils';
8
- import { IWithReqoreSize } from '../../types/global';
9
- import ReqoreButton, { IReqoreButtonProps } from '../Button';
10
- import ReqoreControlGroup from '../ControlGroup';
11
- import { ReqoreExportModal } from '../ExportModal';
12
- import { IReqorePanelAction, IReqorePanelProps } from '../Panel';
13
- import { getExportActions, getZoomActions, sizeToZoom, zoomToSize } from '../Table/helpers';
14
-
15
- export interface IReqoreTreeProps extends IReqorePanelProps, IWithReqoreSize {
16
- data: Record<string, unknown> | Array<any>;
17
- mode?: 'tree' | 'copy';
18
- expanded?: boolean;
19
- showTypes?: boolean;
20
- onItemClick?: (value: any, path?: string[]) => void;
21
- withLabelCopy?: boolean;
22
- showControls?: boolean;
23
- zoomable?: boolean;
24
- exportable?: boolean;
25
- defaultZoom?: 0 | 0.5 | 1 | 1.5 | 2;
26
- }
27
-
28
- export interface ITreeStyle {
29
- interactive?: boolean;
30
- theme: IReqoreTheme;
31
- level?: number;
32
- size?: TSizes;
33
- }
34
-
35
- export const StyledTreeLabel = styled(ReqoreP)`
36
- flex-shrink: 1;
37
-
38
- cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')};
39
- `;
40
-
41
- export const StyledTreeWrapper = styled.div<ITreeStyle>`
42
- display: flex;
43
- flex-flow: column;
44
- gap: ${({ size }) => GAP_FROM_SIZE[size]}px;
45
- margin-left: ${({ level, size }) => (level ? level * GAP_FROM_SIZE[size] : 0)}px;
46
- `;
47
-
48
- export const ReqoreTree = ({
49
- data,
50
- size = 'normal',
51
- expanded,
52
- showTypes,
53
- onItemClick,
54
- withLabelCopy,
55
- showControls = true,
56
-
57
- exportable,
58
- zoomable,
59
- defaultZoom,
60
- ...rest
61
- }: IReqoreTreeProps) => {
62
- const [items, setItems] = useState({});
63
- const [allExpanded, setAllExpanded] = useState(expanded || !showControls);
64
- const [_showTypes, setShowTypes] = useState(showTypes);
65
- const addNotification = useReqoreProperty('addNotification');
66
- const [zoom, setZoom] = useState(defaultZoom || sizeToZoom[size]);
67
- const [showExportModal, setShowExportModal] = useState<'full' | 'current' | undefined>(undefined);
68
-
69
- const handleTypesClick = () => {
70
- setShowTypes(!_showTypes);
71
- };
72
-
73
- const handleExpandClick = () => {
74
- setItems({});
75
- setAllExpanded(true);
76
- };
77
-
78
- const handleCollapseClick = () => {
79
- setItems({});
80
- setAllExpanded(false);
81
- };
82
-
83
- const handleItemClick = (key: string, currentState?: boolean) => {
84
- const newItems = cloneDeep(items);
85
-
86
- newItems[key] = !currentState;
87
-
88
- setItems(newItems);
89
- };
90
-
91
- const isDeep = () =>
92
- Object.keys(data).some((key: string): boolean => typeof data[key] === 'object');
93
-
94
- const renderTree = (data, k?: any, level = 1, path: string[] = []) => {
95
- return Object.keys(data).map((key, index) => {
96
- const dataType: string = getTypeFromValue(data[key]);
97
- const displayKey: string = key;
98
- const stateKey = k ? `${k}_${key}` : key;
99
-
100
- let isObject = typeof data[key] === 'object' && data[key] !== null;
101
- let isExpandable =
102
- typeof data[key] !== 'object' ||
103
- items[stateKey] ||
104
- (allExpanded && items[stateKey] !== false);
105
-
106
- if (isObject && lodashSize(data[key]) === 0) {
107
- isObject = false;
108
- isExpandable = false;
109
- }
110
-
111
- const badges: IReqoreButtonProps['badge'] = [`{...} ${lodashSize(data[key])} items`];
112
-
113
- if (_showTypes) {
114
- badges.push({
115
- icon: 'CodeBoxFill',
116
- label: dataType,
117
- });
118
- }
119
-
120
- return (
121
- <StyledTreeWrapper key={index} size={zoomToSize[zoom]} level={level}>
122
- {isObject ? (
123
- <ReqoreControlGroup size={zoomToSize[zoom]}>
124
- {level !== 1 && <ReqoreHorizontalSpacer width={5} />}
125
- <ReqoreButton
126
- compact
127
- minimal
128
- className='reqore-tree-toggle'
129
- icon={isExpandable ? 'ArrowDownSFill' : 'ArrowRightSFill'}
130
- intent={isExpandable ? 'info' : undefined}
131
- onClick={() => handleItemClick(stateKey, isExpandable)}
132
- flat={false}
133
- badge={badges}
134
- >
135
- {displayKey}
136
- </ReqoreButton>
137
- </ReqoreControlGroup>
138
- ) : (
139
- <ReqoreControlGroup verticalAlign='flex-start'>
140
- {level !== 1 && <ReqoreHorizontalSpacer width={5} />}
141
- <ReqoreP
142
- customTheme={{ text: { color: 'info:lighten:3' } }}
143
- style={{ flexShrink: 0 }}
144
- size={zoomToSize[zoom]}
145
- >
146
- {displayKey}:
147
- </ReqoreP>
148
- {withLabelCopy && (
149
- <ReqoreIcon
150
- interactive
151
- icon='ClipboardLine'
152
- size={getOneLessSize(zoomToSize[zoom])}
153
- onClick={() => {
154
- try {
155
- navigator.clipboard.writeText(JSON.stringify(data[key]));
156
- addNotification({
157
- content: 'Successfuly copied to clipboard',
158
- id: Date.now().toString(),
159
- type: 'success',
160
- duration: 3000,
161
- });
162
- } catch (e) {
163
- console.error(e);
164
- }
165
- }}
166
- />
167
- )}
168
- <StyledTreeLabel
169
- flat
170
- onClick={() => onItemClick?.(data[key], [...path, key])}
171
- className='reqore-tree-label'
172
- size={zoomToSize[zoom]}
173
- >
174
- {JSON.stringify(data[key])}
175
- </StyledTreeLabel>
176
- </ReqoreControlGroup>
177
- )}
178
- {isExpandable && isObject
179
- ? renderTree(data[key], stateKey, level + 1, [...path, key])
180
- : null}
181
- </StyledTreeWrapper>
182
- );
183
- });
184
- };
185
-
186
- const actions = useMemo(() => {
187
- let _actions: IReqorePanelAction[] = [];
188
-
189
- if (showControls) {
190
- _actions = [
191
- {
192
- className: 'reqore-tree-expand-all',
193
- icon: 'ArrowDownFill',
194
- onClick: handleExpandClick,
195
- show: !!(isDeep() && !allExpanded),
196
- label: 'Expand all',
197
- },
198
- {
199
- show: !!(isDeep() && (allExpanded || lodashSize(items) > 0)),
200
- className: 'reqore-tree-collapse-all',
201
- icon: 'ArrowUpFill',
202
- onClick: handleCollapseClick,
203
-
204
- label: 'Collapse all',
205
- },
206
- {
207
- className: 'reqore-tree-show-types',
208
- icon: 'CodeBoxFill',
209
- active: _showTypes,
210
- onClick: handleTypesClick,
211
- label: 'Show types',
212
- },
213
- ];
214
- }
215
-
216
- if (zoomable || exportable) {
217
- const moreActions: IReqorePanelAction = {
218
- className: 'reqore-tree-more',
219
- icon: 'MoreLine',
220
- actions: [],
221
- };
222
-
223
- if (zoomable) {
224
- moreActions.actions = [
225
- ...moreActions.actions,
226
- ...getZoomActions('reqore-tree', zoom, setZoom, true),
227
- ];
228
- }
229
-
230
- if (exportable) {
231
- moreActions.actions = [
232
- ...moreActions.actions,
233
- { divider: true, line: true },
234
- ...getExportActions((type) => setShowExportModal(type)),
235
- ];
236
- }
237
-
238
- _actions = [..._actions, moreActions];
239
- }
240
-
241
- return _actions;
242
- }, [allExpanded, items, showControls, _showTypes, isDeep(), zoom]);
243
-
244
- if (!data || !Object.keys(data).length) {
245
- return <p>No data</p>;
246
- }
247
-
248
- return (
249
- <>
250
- {showExportModal && (
251
- <ReqoreExportModal data={data} onClose={() => setShowExportModal(undefined)} />
252
- )}
253
- <ReqorePanel
254
- className='reqore-tree'
255
- minimal
256
- flat
257
- transparent
258
- size={size}
259
- contentStyle={{
260
- display: 'flex',
261
- flexFlow: 'column',
262
- gap: `${GAP_FROM_SIZE[size]}px`,
263
- }}
264
- {...rest}
265
- actions={actions}
266
- >
267
- {renderTree(data, true)}
268
- </ReqorePanel>
269
- </>
270
- );
271
- };
@@ -1,9 +0,0 @@
1
- export const SPRING_CONFIG = {
2
- tension: 180,
3
- friction: 20,
4
- };
5
-
6
- export const SPRING_CONFIG_NO_ANIMATIONS = {
7
- tension: 0,
8
- friction: 0,
9
- };
@@ -1,13 +0,0 @@
1
- import { TReqoreHexColor } from '../components/Effect';
2
-
3
- export const Colors: Record<string, TReqoreHexColor> = {
4
- DARK: '#000000',
5
- DARK_THEME: '#333333',
6
- LIGHT: '#ffffff',
7
- BLUE: '#0776CB',
8
- GREEN: '#0A6640',
9
- YELLOW: '#d1a036',
10
- ORANGE: '#A66321',
11
- RED: '#A82A2A',
12
- GRAY: '#44444450',
13
- };
@@ -1,93 +0,0 @@
1
- import { IReqorePaginationComponentProps, IReqorePaginationProps } from '../components/Paging';
2
- import { IReqorePagingOptions } from '../hooks/usePaging';
3
-
4
- export type TReqorePaginationType<T> =
5
- | 'buttons'
6
- | 'list'
7
- | 'infinite'
8
- | 'auto-load'
9
- | IReqoreComponentPagingOptions<T>;
10
-
11
- export interface IReqoreComponentPagingOptions<T>
12
- extends Omit<IReqorePagingOptions<T>, 'items'>,
13
- IReqorePaginationComponentProps {
14
- pageControlsPosition?: 'top' | 'bottom' | 'both';
15
- includeTopControls?: boolean;
16
- includeBottomControls?: boolean;
17
- }
18
-
19
- export type TReqorePaginationTypeResult<T> = {
20
- pagingOptions?: Omit<IReqorePagingOptions<T>, 'items'>;
21
- componentOptions?: Partial<Omit<IReqorePaginationProps<T>, 'items'>>;
22
- pageControlsPosition?: 'top' | 'bottom' | 'both';
23
- includeTopControls?: boolean;
24
- includeBottomControls?: boolean;
25
- };
26
-
27
- export function getPagingObjectFromType<T>(
28
- type: TReqorePaginationType<T>
29
- ): IReqoreComponentPagingOptions<T> {
30
- if (typeof type === 'object') {
31
- return type;
32
- }
33
-
34
- switch (type) {
35
- case 'buttons':
36
- return {};
37
- case 'list':
38
- return {
39
- showPagesAs: 'list',
40
- };
41
- case 'infinite':
42
- case 'auto-load':
43
- return { infinite: true };
44
- default:
45
- return {};
46
- }
47
- }
48
-
49
- export function getPaginationOptionsFromType<T>(
50
- type: TReqorePaginationType<T>
51
- ): TReqorePaginationTypeResult<T> {
52
- if (!type) return {};
53
-
54
- if (typeof type === 'object') {
55
- const {
56
- infinite,
57
- itemsPerPage,
58
- pagesToShow,
59
- startPage,
60
- enabled,
61
- onPageChange,
62
- pageControlsPosition = 'bottom',
63
- includeBottomControls,
64
- includeTopControls,
65
-
66
- ...componentOptions
67
- } = type;
68
-
69
- return {
70
- pagingOptions: { infinite, itemsPerPage, pagesToShow, startPage, enabled, onPageChange },
71
- pageControlsPosition,
72
- componentOptions,
73
- includeBottomControls,
74
- includeTopControls,
75
- };
76
- }
77
-
78
- switch (type) {
79
- case 'buttons':
80
- return {};
81
- case 'list':
82
- return {
83
- componentOptions: {
84
- showPagesAs: 'list',
85
- },
86
- };
87
- case 'infinite':
88
- case 'auto-load':
89
- return { pagingOptions: { infinite: true } };
90
- default:
91
- return {};
92
- }
93
- }