@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.
- package/package.json +1 -1
- package/tests.json +1 -1
- package/.eslintrc.js +0 -40
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/ISSUE_TEMPLATE/new-component.md +0 -20
- package/.github/ISSUE_TEMPLATE/visual-bug-report.md +0 -38
- package/.github/workflows/beta_release.yml +0 -100
- package/.github/workflows/tests.yml +0 -84
- package/.gitpod.yml +0 -11
- package/.jest-test-results.json +0 -1
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -0
- package/__tests__/breadcrumbs.test.tsx +0 -75
- package/__tests__/button.test.tsx +0 -218
- package/__tests__/checkbox.test.tsx +0 -45
- package/__tests__/collection.test.tsx +0 -243
- package/__tests__/containers/paging.test.tsx +0 -138
- package/__tests__/control_group.test.tsx +0 -32
- package/__tests__/drawer.test.tsx +0 -140
- package/__tests__/dropdown.test.tsx +0 -381
- package/__tests__/effect.test.tsx +0 -70
- package/__tests__/heading.test.tsx +0 -58
- package/__tests__/helpers/colors.test.tsx +0 -18
- package/__tests__/helpers/table.test.tsx +0 -67
- package/__tests__/hooks/useLatestZIndex.test.tsx +0 -10
- package/__tests__/hooks/useReqorePaging.test.tsx +0 -271
- package/__tests__/hooks/useTheme.test.tsx +0 -31
- package/__tests__/icon.test.tsx +0 -53
- package/__tests__/input.test.tsx +0 -482
- package/__tests__/layout.test.tsx +0 -37
- package/__tests__/menu.test.tsx +0 -65
- package/__tests__/messages.test.tsx +0 -79
- package/__tests__/modal.test.tsx +0 -204
- package/__tests__/multiselect.test.tsx +0 -458
- package/__tests__/navbar.test.tsx +0 -31
- package/__tests__/notifications.test.tsx +0 -178
- package/__tests__/pagination.test.tsx +0 -437
- package/__tests__/panel.test.tsx +0 -243
- package/__tests__/popover.test.tsx +0 -282
- package/__tests__/radiogroup.test.tsx +0 -47
- package/__tests__/setup.js +0 -8
- package/__tests__/stories/Collection.stories.tsx +0 -0
- package/__tests__/table.test.tsx +0 -647
- package/__tests__/tabs.test.tsx +0 -321
- package/__tests__/tag.test.tsx +0 -160
- package/__tests__/textarea.test.tsx +0 -467
- package/__tests__/timeAgo.test.tsx +0 -27
- package/__tests__/tree.test.tsx +0 -58
- package/build-storybook.log +0 -491
- package/chromatic.config.json +0 -1
- package/icons.ts +0 -1
- package/migration-storybook.log +0 -56
- package/public/logo-dark.png +0 -0
- package/public/logo.png +0 -0
- package/public/q-symbol-small.png +0 -0
- package/public/q-symbol.png +0 -0
- package/public/qoreLogo-dark.png +0 -0
- package/public/qoreLogo.png +0 -0
- package/src/components/Breadcrumbs/index.tsx +0 -254
- package/src/components/Breadcrumbs/item.tsx +0 -44
- package/src/components/Button/index.tsx +0 -633
- package/src/components/Checkbox/index.tsx +0 -388
- package/src/components/Collection/index.tsx +0 -426
- package/src/components/Collection/item.tsx +0 -267
- package/src/components/Columns/column.tsx +0 -27
- package/src/components/Columns/index.tsx +0 -41
- package/src/components/Comment/index.tsx +0 -141
- package/src/components/CommentFeed/index.tsx +0 -34
- package/src/components/Content/index.tsx +0 -34
- package/src/components/Content/wrapper.tsx +0 -36
- package/src/components/ControlGroup/index.tsx +0 -523
- package/src/components/DatePicker/index.tsx +0 -347
- package/src/components/Drawer/backdrop.tsx +0 -54
- package/src/components/Drawer/index.tsx +0 -365
- package/src/components/Dropdown/index.tsx +0 -153
- package/src/components/Dropdown/item.tsx +0 -33
- package/src/components/Dropdown/list.tsx +0 -222
- package/src/components/Effect/index.tsx +0 -464
- package/src/components/ExportModal/index.tsx +0 -99
- package/src/components/Header/index.tsx +0 -81
- package/src/components/Icon/index.tsx +0 -184
- package/src/components/Input/index.tsx +0 -295
- package/src/components/InputClearButton/index.tsx +0 -59
- package/src/components/InternalPopover/index.tsx +0 -303
- package/src/components/KeyValueTable/index.tsx +0 -192
- package/src/components/Label/index.tsx +0 -10
- package/src/components/Layout/content.tsx +0 -31
- package/src/components/Layout/index.tsx +0 -55
- package/src/components/Menu/divider.tsx +0 -92
- package/src/components/Menu/index.tsx +0 -141
- package/src/components/Menu/item.tsx +0 -137
- package/src/components/Menu/section.tsx +0 -81
- package/src/components/Message/index.tsx +0 -220
- package/src/components/Modal/index.tsx +0 -26
- package/src/components/MultiSelect/index.tsx +0 -288
- package/src/components/Navbar/divider.tsx +0 -50
- package/src/components/Navbar/group.tsx +0 -53
- package/src/components/Navbar/index.tsx +0 -82
- package/src/components/Navbar/item.tsx +0 -92
- package/src/components/Notifications/index.tsx +0 -57
- package/src/components/Notifications/notification.tsx +0 -362
- package/src/components/Paging/index.tsx +0 -321
- package/src/components/Panel/LabelEditor.tsx +0 -67
- package/src/components/Panel/NonResponsiveActions.tsx +0 -79
- package/src/components/Panel/__screenshots__/linux/panel-SomePanel.png +0 -0
- package/src/components/Panel/index.tsx +0 -912
- package/src/components/Panel/panel.screenshot.tsx +0 -29
- package/src/components/Paragraph/index.tsx +0 -43
- package/src/components/Popover/index.tsx +0 -68
- package/src/components/RadioGroup/index.tsx +0 -71
- package/src/components/Slider/index.tsx +0 -358
- package/src/components/Spacer/index.tsx +0 -142
- package/src/components/Spinner/index.tsx +0 -74
- package/src/components/Table/body.tsx +0 -109
- package/src/components/Table/cell.tsx +0 -136
- package/src/components/Table/header.tsx +0 -236
- package/src/components/Table/headerCell.tsx +0 -203
- package/src/components/Table/helpers.ts +0 -308
- package/src/components/Table/index.tsx +0 -797
- package/src/components/Table/row.tsx +0 -288
- package/src/components/Table/value.tsx +0 -28
- package/src/components/Tabs/content.tsx +0 -68
- package/src/components/Tabs/index.tsx +0 -124
- package/src/components/Tabs/item.tsx +0 -198
- package/src/components/Tabs/list.tsx +0 -381
- package/src/components/Tag/group.tsx +0 -73
- package/src/components/Tag/index.tsx +0 -463
- package/src/components/Textarea/index.tsx +0 -277
- package/src/components/TimeAgo/index.tsx +0 -15
- package/src/components/Tree/index.tsx +0 -271
- package/src/constants/animations.ts +0 -9
- package/src/constants/colors.ts +0 -13
- package/src/constants/paging.ts +0 -93
- package/src/constants/sizes.ts +0 -185
- package/src/constants/theme.ts +0 -122
- package/src/containers/Paging.tsx +0 -136
- package/src/containers/PopoverProvider.tsx +0 -124
- package/src/containers/ReqoreProvider.tsx +0 -289
- package/src/containers/ThemeProvider.tsx +0 -12
- package/src/containers/UIProvider.tsx +0 -101
- package/src/context/PopoverContext.tsx +0 -11
- package/src/context/ReqoreContext.tsx +0 -47
- package/src/context/ThemeContext.tsx +0 -4
- package/src/helpers/animations.ts +0 -13
- package/src/helpers/colors.ts +0 -335
- package/src/helpers/time.ts +0 -21
- package/src/helpers/utils.ts +0 -152
- package/src/hooks/useAutoFocus.ts +0 -106
- package/src/hooks/useCloneThroughFragments.ts +0 -39
- package/src/hooks/useCombinedRefs.ts +0 -26
- package/src/hooks/useLatestZIndex.ts +0 -13
- package/src/hooks/useOutsideClick.ts +0 -29
- package/src/hooks/usePaging.ts +0 -128
- package/src/hooks/usePopover.tsx +0 -220
- package/src/hooks/useQueryWithDelay.ts +0 -30
- package/src/hooks/useReqore.ts +0 -12
- package/src/hooks/useReqoreContext.ts +0 -16
- package/src/hooks/useReqoreEffect.ts +0 -49
- package/src/hooks/useTextareaAutoSize.ts +0 -22
- package/src/hooks/useTheme.ts +0 -48
- package/src/hooks/useTooltip.ts +0 -40
- package/src/hooks/useWhyDidYouUpdate.ts +0 -32
- package/src/icons.json +0 -2295
- package/src/index.tsx +0 -80
- package/src/mock/breadcrumbs.ts +0 -146
- package/src/mock/collectionData.tsx +0 -380
- package/src/mock/data.json +0 -11000
- package/src/mock/icons.ts +0 -32
- package/src/mock/menu.ts +0 -93
- package/src/mock/multiSelect.ts +0 -71
- package/src/mock/object.json +0 -317
- package/src/mock/styleMock.js +0 -1
- package/src/mock/tableData.ts +0 -64
- package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +0 -27
- package/src/stories/Button/Button.stories.tsx +0 -405
- package/src/stories/Checkbox/Checkbox.stories.tsx +0 -75
- package/src/stories/Collection/Collection.stories.tsx +0 -317
- package/src/stories/Columns/Columns.stories.tsx +0 -158
- package/src/stories/Comment/Comment.stories.tsx +0 -136
- package/src/stories/ControlGroup/ControlGroup.stories.tsx +0 -399
- package/src/stories/DatePicker/DatePicker.stories.tsx +0 -348
- package/src/stories/Drawer/Drawer.stories.tsx +0 -294
- package/src/stories/Dropdown/Dropdown.stories.tsx +0 -375
- package/src/stories/Dropdown/DropdownTests.stories.tsx +0 -111
- package/src/stories/ExportModal/ExportModal.stories.tsx +0 -18
- package/src/stories/Header/Header.stories.tsx +0 -108
- package/src/stories/Icon/Icon.stories.tsx +0 -162
- package/src/stories/Input/Input.stories.tsx +0 -220
- package/src/stories/KeyValueTable/KeyValueTable.stories.tsx +0 -346
- package/src/stories/Label/Label.stories.tsx +0 -33
- package/src/stories/Menu/Menu.stories.tsx +0 -367
- package/src/stories/Message/Message.stories.tsx +0 -167
- package/src/stories/Modal/Manager.stories.tsx +0 -192
- package/src/stories/Modal/Modal.stories.tsx +0 -252
- package/src/stories/MultiSelect/MultiSelect.stories.tsx +0 -140
- package/src/stories/Navbar/Navbar.stories.tsx +0 -119
- package/src/stories/Notifications/Interactive.stories.tsx +0 -117
- package/src/stories/Notifications/Notification.stories.tsx +0 -216
- package/src/stories/Notifications/Notifications.stories.tsx +0 -81
- package/src/stories/Paging/Paging.stories.tsx +0 -255
- package/src/stories/Panel/Panel.stories.tsx +0 -753
- package/src/stories/Paragraph/Paragraph.stories.tsx +0 -108
- package/src/stories/Popover/Popover.stories.tsx +0 -510
- package/src/stories/RadioGroup/RadioGroup.stories.tsx +0 -212
- package/src/stories/Slider/Slider.stories.tsx +0 -173
- package/src/stories/Spacer/Spacer.stories.tsx +0 -100
- package/src/stories/Spinner/Spinner.stories.tsx +0 -82
- package/src/stories/Table/Table.stories.tsx +0 -571
- package/src/stories/Tabs/Tabs.stories.tsx +0 -346
- package/src/stories/Tag/Tag.stories.tsx +0 -381
- package/src/stories/Tag/TagGroup.stories.tsx +0 -307
- package/src/stories/TextArea/TextArea.stories.tsx +0 -287
- package/src/stories/TextArea/TextAreaTests.stories.tsx +0 -108
- package/src/stories/Tree/Tree.stories.tsx +0 -124
- package/src/stories/Wrapper.tsx +0 -13
- package/src/stories/utils/args.ts +0 -151
- package/src/stories/utils.ts +0 -39
- package/src/styles.ts +0 -124
- package/src/types/global.ts +0 -211
- package/src/types/icons.ts +0 -2272
- package/tsconfig.prod.json +0 -26
package/src/helpers/colors.ts
DELETED
|
@@ -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
|
-
};
|
package/src/helpers/time.ts
DELETED
|
@@ -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
|
-
};
|
package/src/helpers/utils.ts
DELETED
|
@@ -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;
|