@qoretechnologies/reqore 0.44.0 → 0.46.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 (226) hide show
  1. package/dist/constants/theme.d.ts +8 -1
  2. package/dist/constants/theme.d.ts.map +1 -1
  3. package/dist/constants/theme.js +16 -2
  4. package/dist/constants/theme.js.map +1 -1
  5. package/package.json +1 -1
  6. package/tests.json +1 -1
  7. package/.eslintrc.js +0 -40
  8. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  9. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  10. package/.github/ISSUE_TEMPLATE/new-component.md +0 -20
  11. package/.github/ISSUE_TEMPLATE/visual-bug-report.md +0 -38
  12. package/.github/workflows/beta_release.yml +0 -100
  13. package/.github/workflows/tests.yml +0 -84
  14. package/.gitpod.yml +0 -11
  15. package/.jest-test-results.json +0 -1
  16. package/.prettierrc +0 -7
  17. package/.vscode/settings.json +0 -0
  18. package/__tests__/breadcrumbs.test.tsx +0 -75
  19. package/__tests__/button.test.tsx +0 -218
  20. package/__tests__/checkbox.test.tsx +0 -45
  21. package/__tests__/collection.test.tsx +0 -243
  22. package/__tests__/containers/paging.test.tsx +0 -138
  23. package/__tests__/control_group.test.tsx +0 -32
  24. package/__tests__/drawer.test.tsx +0 -140
  25. package/__tests__/dropdown.test.tsx +0 -381
  26. package/__tests__/effect.test.tsx +0 -70
  27. package/__tests__/heading.test.tsx +0 -58
  28. package/__tests__/helpers/colors.test.tsx +0 -18
  29. package/__tests__/helpers/table.test.tsx +0 -67
  30. package/__tests__/hooks/useLatestZIndex.test.tsx +0 -10
  31. package/__tests__/hooks/useReqorePaging.test.tsx +0 -271
  32. package/__tests__/hooks/useTheme.test.tsx +0 -31
  33. package/__tests__/icon.test.tsx +0 -53
  34. package/__tests__/input.test.tsx +0 -482
  35. package/__tests__/layout.test.tsx +0 -37
  36. package/__tests__/menu.test.tsx +0 -65
  37. package/__tests__/messages.test.tsx +0 -79
  38. package/__tests__/modal.test.tsx +0 -204
  39. package/__tests__/multiselect.test.tsx +0 -458
  40. package/__tests__/navbar.test.tsx +0 -31
  41. package/__tests__/notifications.test.tsx +0 -178
  42. package/__tests__/pagination.test.tsx +0 -437
  43. package/__tests__/panel.test.tsx +0 -243
  44. package/__tests__/popover.test.tsx +0 -282
  45. package/__tests__/radiogroup.test.tsx +0 -47
  46. package/__tests__/setup.js +0 -8
  47. package/__tests__/stories/Collection.stories.tsx +0 -0
  48. package/__tests__/table.test.tsx +0 -647
  49. package/__tests__/tabs.test.tsx +0 -321
  50. package/__tests__/tag.test.tsx +0 -160
  51. package/__tests__/textarea.test.tsx +0 -467
  52. package/__tests__/timeAgo.test.tsx +0 -27
  53. package/__tests__/tree.test.tsx +0 -58
  54. package/build-storybook.log +0 -491
  55. package/chromatic.config.json +0 -1
  56. package/icons.ts +0 -1
  57. package/migration-storybook.log +0 -56
  58. package/public/logo-dark.png +0 -0
  59. package/public/logo.png +0 -0
  60. package/public/q-symbol-small.png +0 -0
  61. package/public/q-symbol.png +0 -0
  62. package/public/qoreLogo-dark.png +0 -0
  63. package/public/qoreLogo.png +0 -0
  64. package/src/components/Breadcrumbs/index.tsx +0 -254
  65. package/src/components/Breadcrumbs/item.tsx +0 -44
  66. package/src/components/Button/index.tsx +0 -633
  67. package/src/components/Checkbox/index.tsx +0 -388
  68. package/src/components/Collection/index.tsx +0 -426
  69. package/src/components/Collection/item.tsx +0 -267
  70. package/src/components/Columns/column.tsx +0 -27
  71. package/src/components/Columns/index.tsx +0 -41
  72. package/src/components/Comment/index.tsx +0 -141
  73. package/src/components/CommentFeed/index.tsx +0 -34
  74. package/src/components/Content/index.tsx +0 -34
  75. package/src/components/Content/wrapper.tsx +0 -36
  76. package/src/components/ControlGroup/index.tsx +0 -523
  77. package/src/components/DatePicker/index.tsx +0 -347
  78. package/src/components/Drawer/backdrop.tsx +0 -54
  79. package/src/components/Drawer/index.tsx +0 -365
  80. package/src/components/Dropdown/index.tsx +0 -153
  81. package/src/components/Dropdown/item.tsx +0 -33
  82. package/src/components/Dropdown/list.tsx +0 -222
  83. package/src/components/Effect/index.tsx +0 -464
  84. package/src/components/ExportModal/index.tsx +0 -99
  85. package/src/components/Header/index.tsx +0 -81
  86. package/src/components/Icon/index.tsx +0 -184
  87. package/src/components/Input/index.tsx +0 -295
  88. package/src/components/InputClearButton/index.tsx +0 -59
  89. package/src/components/InternalPopover/index.tsx +0 -303
  90. package/src/components/KeyValueTable/index.tsx +0 -192
  91. package/src/components/Label/index.tsx +0 -10
  92. package/src/components/Layout/content.tsx +0 -31
  93. package/src/components/Layout/index.tsx +0 -55
  94. package/src/components/Menu/divider.tsx +0 -92
  95. package/src/components/Menu/index.tsx +0 -141
  96. package/src/components/Menu/item.tsx +0 -137
  97. package/src/components/Menu/section.tsx +0 -81
  98. package/src/components/Message/index.tsx +0 -220
  99. package/src/components/Modal/index.tsx +0 -26
  100. package/src/components/MultiSelect/index.tsx +0 -288
  101. package/src/components/Navbar/divider.tsx +0 -50
  102. package/src/components/Navbar/group.tsx +0 -53
  103. package/src/components/Navbar/index.tsx +0 -82
  104. package/src/components/Navbar/item.tsx +0 -92
  105. package/src/components/Notifications/index.tsx +0 -57
  106. package/src/components/Notifications/notification.tsx +0 -362
  107. package/src/components/Paging/index.tsx +0 -321
  108. package/src/components/Panel/LabelEditor.tsx +0 -67
  109. package/src/components/Panel/NonResponsiveActions.tsx +0 -79
  110. package/src/components/Panel/__screenshots__/linux/panel-SomePanel.png +0 -0
  111. package/src/components/Panel/index.tsx +0 -912
  112. package/src/components/Panel/panel.screenshot.tsx +0 -29
  113. package/src/components/Paragraph/index.tsx +0 -43
  114. package/src/components/Popover/index.tsx +0 -68
  115. package/src/components/RadioGroup/index.tsx +0 -71
  116. package/src/components/Slider/index.tsx +0 -358
  117. package/src/components/Spacer/index.tsx +0 -142
  118. package/src/components/Spinner/index.tsx +0 -74
  119. package/src/components/Table/body.tsx +0 -109
  120. package/src/components/Table/cell.tsx +0 -136
  121. package/src/components/Table/header.tsx +0 -236
  122. package/src/components/Table/headerCell.tsx +0 -203
  123. package/src/components/Table/helpers.ts +0 -308
  124. package/src/components/Table/index.tsx +0 -797
  125. package/src/components/Table/row.tsx +0 -288
  126. package/src/components/Table/value.tsx +0 -28
  127. package/src/components/Tabs/content.tsx +0 -68
  128. package/src/components/Tabs/index.tsx +0 -124
  129. package/src/components/Tabs/item.tsx +0 -198
  130. package/src/components/Tabs/list.tsx +0 -381
  131. package/src/components/Tag/group.tsx +0 -73
  132. package/src/components/Tag/index.tsx +0 -463
  133. package/src/components/Textarea/index.tsx +0 -277
  134. package/src/components/TimeAgo/index.tsx +0 -15
  135. package/src/components/Tree/index.tsx +0 -271
  136. package/src/constants/animations.ts +0 -9
  137. package/src/constants/colors.ts +0 -13
  138. package/src/constants/paging.ts +0 -93
  139. package/src/constants/sizes.ts +0 -185
  140. package/src/constants/theme.ts +0 -122
  141. package/src/containers/Paging.tsx +0 -136
  142. package/src/containers/PopoverProvider.tsx +0 -124
  143. package/src/containers/ReqoreProvider.tsx +0 -289
  144. package/src/containers/ThemeProvider.tsx +0 -12
  145. package/src/containers/UIProvider.tsx +0 -101
  146. package/src/context/PopoverContext.tsx +0 -11
  147. package/src/context/ReqoreContext.tsx +0 -47
  148. package/src/context/ThemeContext.tsx +0 -4
  149. package/src/helpers/animations.ts +0 -13
  150. package/src/helpers/colors.ts +0 -335
  151. package/src/helpers/time.ts +0 -21
  152. package/src/helpers/utils.ts +0 -152
  153. package/src/hooks/useAutoFocus.ts +0 -106
  154. package/src/hooks/useCloneThroughFragments.ts +0 -39
  155. package/src/hooks/useCombinedRefs.ts +0 -26
  156. package/src/hooks/useLatestZIndex.ts +0 -13
  157. package/src/hooks/useOutsideClick.ts +0 -29
  158. package/src/hooks/usePaging.ts +0 -128
  159. package/src/hooks/usePopover.tsx +0 -220
  160. package/src/hooks/useQueryWithDelay.ts +0 -30
  161. package/src/hooks/useReqore.ts +0 -12
  162. package/src/hooks/useReqoreContext.ts +0 -16
  163. package/src/hooks/useReqoreEffect.ts +0 -49
  164. package/src/hooks/useTextareaAutoSize.ts +0 -22
  165. package/src/hooks/useTheme.ts +0 -48
  166. package/src/hooks/useTooltip.ts +0 -40
  167. package/src/hooks/useWhyDidYouUpdate.ts +0 -32
  168. package/src/icons.json +0 -2295
  169. package/src/index.tsx +0 -80
  170. package/src/mock/breadcrumbs.ts +0 -146
  171. package/src/mock/collectionData.tsx +0 -380
  172. package/src/mock/data.json +0 -11000
  173. package/src/mock/icons.ts +0 -32
  174. package/src/mock/menu.ts +0 -93
  175. package/src/mock/multiSelect.ts +0 -71
  176. package/src/mock/object.json +0 -317
  177. package/src/mock/styleMock.js +0 -1
  178. package/src/mock/tableData.ts +0 -64
  179. package/src/stories/Breadcrumbs/Breadcrumbs.stories.tsx +0 -27
  180. package/src/stories/Button/Button.stories.tsx +0 -405
  181. package/src/stories/Checkbox/Checkbox.stories.tsx +0 -75
  182. package/src/stories/Collection/Collection.stories.tsx +0 -317
  183. package/src/stories/Columns/Columns.stories.tsx +0 -158
  184. package/src/stories/Comment/Comment.stories.tsx +0 -136
  185. package/src/stories/ControlGroup/ControlGroup.stories.tsx +0 -399
  186. package/src/stories/DatePicker/DatePicker.stories.tsx +0 -348
  187. package/src/stories/Drawer/Drawer.stories.tsx +0 -294
  188. package/src/stories/Dropdown/Dropdown.stories.tsx +0 -375
  189. package/src/stories/Dropdown/DropdownTests.stories.tsx +0 -111
  190. package/src/stories/ExportModal/ExportModal.stories.tsx +0 -18
  191. package/src/stories/Header/Header.stories.tsx +0 -108
  192. package/src/stories/Icon/Icon.stories.tsx +0 -162
  193. package/src/stories/Input/Input.stories.tsx +0 -220
  194. package/src/stories/KeyValueTable/KeyValueTable.stories.tsx +0 -346
  195. package/src/stories/Label/Label.stories.tsx +0 -33
  196. package/src/stories/Menu/Menu.stories.tsx +0 -367
  197. package/src/stories/Message/Message.stories.tsx +0 -167
  198. package/src/stories/Modal/Manager.stories.tsx +0 -192
  199. package/src/stories/Modal/Modal.stories.tsx +0 -252
  200. package/src/stories/MultiSelect/MultiSelect.stories.tsx +0 -140
  201. package/src/stories/Navbar/Navbar.stories.tsx +0 -119
  202. package/src/stories/Notifications/Interactive.stories.tsx +0 -117
  203. package/src/stories/Notifications/Notification.stories.tsx +0 -216
  204. package/src/stories/Notifications/Notifications.stories.tsx +0 -81
  205. package/src/stories/Paging/Paging.stories.tsx +0 -255
  206. package/src/stories/Panel/Panel.stories.tsx +0 -753
  207. package/src/stories/Paragraph/Paragraph.stories.tsx +0 -108
  208. package/src/stories/Popover/Popover.stories.tsx +0 -510
  209. package/src/stories/RadioGroup/RadioGroup.stories.tsx +0 -212
  210. package/src/stories/Slider/Slider.stories.tsx +0 -173
  211. package/src/stories/Spacer/Spacer.stories.tsx +0 -100
  212. package/src/stories/Spinner/Spinner.stories.tsx +0 -82
  213. package/src/stories/Table/Table.stories.tsx +0 -571
  214. package/src/stories/Tabs/Tabs.stories.tsx +0 -346
  215. package/src/stories/Tag/Tag.stories.tsx +0 -381
  216. package/src/stories/Tag/TagGroup.stories.tsx +0 -307
  217. package/src/stories/TextArea/TextArea.stories.tsx +0 -287
  218. package/src/stories/TextArea/TextAreaTests.stories.tsx +0 -108
  219. package/src/stories/Tree/Tree.stories.tsx +0 -124
  220. package/src/stories/Wrapper.tsx +0 -13
  221. package/src/stories/utils/args.ts +0 -151
  222. package/src/stories/utils.ts +0 -39
  223. package/src/styles.ts +0 -124
  224. package/src/types/global.ts +0 -211
  225. package/src/types/icons.ts +0 -2272
  226. package/tsconfig.prod.json +0 -26
@@ -1,633 +0,0 @@
1
- import { size } from 'lodash';
2
- import { rgba } from 'polished';
3
- import React, { forwardRef, memo, useCallback, useMemo, useState } from 'react';
4
- import styled, { css } from 'styled-components';
5
- import {
6
- CONTROL_TEXT_FROM_SIZE,
7
- ICON_FROM_SIZE,
8
- PADDING_FROM_SIZE,
9
- PILL_RADIUS_MODIFIER,
10
- RADIUS_FROM_SIZE,
11
- SIZE_TO_PX,
12
- TSizes,
13
- } from '../../constants/sizes';
14
- import { IReqoreCustomTheme, IReqoreTheme } from '../../constants/theme';
15
- import { changeLightness, getReadableColor, getReadableColorFrom } from '../../helpers/colors';
16
- import { alignToFlexAlign, getOneLessSize } from '../../helpers/utils';
17
- import { useCombinedRefs } from '../../hooks/useCombinedRefs';
18
- import { useReqoreProperty } from '../../hooks/useReqoreContext';
19
- import { useReqoreEffect } from '../../hooks/useReqoreEffect';
20
- import { useReqoreTheme } from '../../hooks/useTheme';
21
- import { useTooltip } from '../../hooks/useTooltip';
22
- import {
23
- ActiveIconScale,
24
- DisabledElement,
25
- InactiveIconScale,
26
- ReadOnlyElement,
27
- ScaleIconOnHover,
28
- StyledActiveContent,
29
- StyledContent,
30
- StyledInActiveContent,
31
- StyledInvisibleContent,
32
- } from '../../styles';
33
- import {
34
- IReqoreDisabled,
35
- IReqoreIntent,
36
- IReqoreReadOnly,
37
- IWithReqoreEffect,
38
- IWithReqoreSize,
39
- TReqoreTooltipProp,
40
- } from '../../types/global';
41
- import { IReqoreIconName } from '../../types/icons';
42
- import {
43
- IReqoreEffect,
44
- ReqoreTextEffect,
45
- StyledEffect,
46
- TReqoreEffectColor,
47
- TReqoreHexColor,
48
- } from '../Effect';
49
- import ReqoreIcon, { IReqoreIconProps } from '../Icon';
50
- import { ReqoreHorizontalSpacer, ReqoreSpacer } from '../Spacer';
51
- import ReqoreTag, { IReqoreTagProps } from '../Tag';
52
- import ReqoreTagGroup from '../Tag/group';
53
-
54
- export type TReqoreBadge = string | number | IReqoreTagProps;
55
-
56
- export interface IReqoreButtonProps
57
- extends React.HTMLAttributes<HTMLButtonElement>,
58
- IReqoreDisabled,
59
- IReqoreIntent,
60
- IReqoreReadOnly,
61
- IWithReqoreEffect {
62
- icon?: IReqoreIconName;
63
- size?: TSizes;
64
- minimal?: boolean;
65
- tooltip?: TReqoreTooltipProp;
66
- fluid?: boolean;
67
- fixed?: boolean;
68
- active?: boolean;
69
- flat?: boolean;
70
- animated?: boolean;
71
-
72
- compact?: boolean;
73
- verticalPadding?: TSizes;
74
-
75
- rightIcon?: IReqoreIconName;
76
- customTheme?: IReqoreCustomTheme;
77
- wrap?: boolean;
78
- badge?: TReqoreBadge | TReqoreBadge[];
79
-
80
- description?: string | number;
81
- maxWidth?: string;
82
- textAlign?: 'left' | 'center' | 'right';
83
- iconsAlign?: 'center' | 'sides';
84
- iconColor?: TReqoreEffectColor;
85
- leftIconColor?: TReqoreEffectColor;
86
- rightIconColor?: TReqoreEffectColor;
87
- leftIconProps?: IReqoreIconProps;
88
- rightIconProps?: IReqoreIconProps;
89
- labelEffect?: IReqoreEffect;
90
- descriptionEffect?: IReqoreEffect;
91
- label?: React.HTMLAttributes<HTMLButtonElement>['children'];
92
- as?: string | React.ElementType;
93
- grow?: 0 | 1 | 2 | 3 | 4;
94
- shrink?: 0 | 1 | 2 | 3 | 4;
95
- rounded?: boolean;
96
-
97
- pill?: boolean;
98
- circle?: boolean;
99
- }
100
-
101
- export interface IReqoreButtonStyle extends Omit<IReqoreButtonProps, 'intent'> {
102
- theme: IReqoreTheme;
103
- animate?: boolean;
104
- color?: TReqoreHexColor;
105
- }
106
-
107
- const getButtonMainColor = (theme: IReqoreTheme, color?: TReqoreHexColor) => {
108
- if (color) {
109
- return color;
110
- }
111
-
112
- return theme.main;
113
- };
114
-
115
- export const StyledAnimatedTextWrapper = styled.span`
116
- min-width: 5px;
117
- overflow: hidden;
118
- position: relative;
119
- text-align: ${({ textAlign }) => textAlign};
120
- display: flex;
121
- flex-flow: column;
122
- align-items: ${({ textAlign }) => alignToFlexAlign(textAlign)};
123
- `;
124
-
125
- export const StyledButton = styled(StyledEffect)<IReqoreButtonStyle>`
126
- display: flex;
127
- flex-flow: column;
128
- justify-content: center;
129
- margin: 0;
130
- font-weight: 600;
131
- position: relative;
132
- overflow: hidden;
133
- vertical-align: middle;
134
- border: ${({ theme, color, flat }) =>
135
- !flat ? `1px solid ${changeLightness(getButtonMainColor(theme, color), 0.2)}` : 0};
136
- padding: ${({ size, compact, verticalPadding }) =>
137
- `${verticalPadding ? PADDING_FROM_SIZE[verticalPadding] : 0}px ${
138
- compact ? PADDING_FROM_SIZE[size] / 2 : PADDING_FROM_SIZE[size]
139
- }px`};
140
- font-size: ${({ size }) => CONTROL_TEXT_FROM_SIZE[size]}px;
141
-
142
- min-height: ${({ size }) => SIZE_TO_PX[size]}px;
143
- min-width: ${({ size }) => SIZE_TO_PX[size]}px;
144
- max-width: ${({ maxWidth, fluid, fixed }) => maxWidth || (fluid && !fixed ? '100%' : undefined)};
145
-
146
- ${({ wrap, description }) =>
147
- !wrap && !description
148
- ? css`
149
- max-height: ${({ size, verticalPadding }) =>
150
- SIZE_TO_PX[size] + (verticalPadding ? PADDING_FROM_SIZE[verticalPadding] * 2 : 0)}px;
151
- `
152
- : null}
153
-
154
- flex: ${({ fluid, fixed }) => (fixed ? '0 0 auto' : fluid ? '1 auto' : '0 0 auto')};
155
- flex-shrink: ${({ shrink }) => shrink};
156
- flex-grow: ${({ grow }) => grow};
157
- align-self: ${({ fixed, fluid }) => (fixed ? 'flex-start' : fluid ? 'stretch' : undefined)};
158
-
159
- border-radius: ${({ size, rounded, pill, circle }) =>
160
- rounded === false
161
- ? undefined
162
- : circle
163
- ? 9999
164
- : RADIUS_FROM_SIZE[size] * (pill ? PILL_RADIUS_MODIFIER : 1)}px;
165
-
166
- background-color: ${({ minimal, color }) => {
167
- if (minimal) {
168
- return 'transparent';
169
- }
170
-
171
- return color;
172
- }};
173
-
174
- color: ${({ theme, color, minimal }) =>
175
- color
176
- ? minimal
177
- ? getReadableColor(theme, undefined, undefined, true, theme.originalMain)
178
- : getReadableColorFrom(color, true)
179
- : getReadableColor(theme, undefined, undefined, true)};
180
-
181
- ${InactiveIconScale}
182
-
183
- ${({ readOnly, animate, active }) =>
184
- !readOnly && !active
185
- ? css`
186
- &:not(:disabled) {
187
- ${ScaleIconOnHover}
188
-
189
- cursor: pointer;
190
- transition: all 0.2s ease-out;
191
-
192
- &:active {
193
- transform: scale(0.97);
194
- }
195
-
196
- &:hover,
197
- &:active,
198
- &:focus {
199
- background-color: ${({ theme, color, minimal }: IReqoreButtonStyle) =>
200
- minimal
201
- ? rgba(changeLightness(getButtonMainColor(theme, color), 0.05), 0.2)
202
- : changeLightness(getButtonMainColor(theme, color), 0.05)};
203
- color: ${({ theme, color, minimal }) =>
204
- getReadableColor(
205
- { main: minimal ? theme.originalMain : getButtonMainColor(theme, color) },
206
- undefined,
207
- undefined
208
- )};
209
- border-color: ${({ flat, theme, color }) =>
210
- flat ? undefined : changeLightness(getButtonMainColor(theme, color), 0.35)};
211
-
212
- ${animate &&
213
- css`
214
- ${StyledActiveContent} {
215
- transform: translateY(0px);
216
- filter: blur(0);
217
- opacity: 1;
218
- }
219
-
220
- ${StyledInActiveContent} {
221
- transform: translateY(150%);
222
- filter: blur(10px);
223
- opacity: 0;
224
- }
225
- `}
226
- }
227
- }
228
- `
229
- : readOnly
230
- ? css`
231
- ${ReadOnlyElement};
232
- `
233
- : undefined}
234
-
235
- ${({ active, flat, theme, color }: IReqoreButtonStyle) => {
236
- if (active) {
237
- return css`
238
- cursor: pointer;
239
- background-color: ${changeLightness(getButtonMainColor(theme, color), 0.1)};
240
- color: ${getReadableColor(
241
- { main: changeLightness(getButtonMainColor(theme, color), 0.1) },
242
- undefined,
243
- undefined
244
- )};
245
- border-color: ${flat
246
- ? undefined
247
- : changeLightness(getButtonMainColor(theme, color), 0.175)};
248
-
249
- &:hover,
250
- &:active,
251
- &:focus {
252
- border-color: ${flat
253
- ? undefined
254
- : changeLightness(getButtonMainColor(theme, color), 0.275)};
255
- }
256
-
257
- ${ActiveIconScale}
258
- `;
259
- }
260
- }}
261
-
262
- &:disabled {
263
- ${DisabledElement};
264
- }
265
-
266
- &:focus,
267
- &:active {
268
- outline: none;
269
- }
270
-
271
- &:focus {
272
- border-color: ${({ minimal, theme, color }) =>
273
- minimal ? undefined : changeLightness(getButtonMainColor(theme, color), 0.4)};
274
- }
275
-
276
- .reqore-button-description {
277
- padding-bottom: ${({ size }) => PADDING_FROM_SIZE[size] / 2}px;
278
- }
279
- `;
280
-
281
- export const StyledButtonContent = styled.div`
282
- display: flex;
283
- align-items: center;
284
- width: 100%;
285
- height: 100%;
286
- min-width: ${({ size }) => ICON_FROM_SIZE[size]}px;
287
- flex: 1;
288
- flex-shrink: 0;
289
- padding: ${({ size, flat }) => PADDING_FROM_SIZE[size] / 2 - (!flat ? 1 : 0)}px 0;
290
-
291
- ${({ wrap, description }) =>
292
- !wrap && !description
293
- ? css`
294
- max-height: ${({ size }) => SIZE_TO_PX[size]}px;
295
- `
296
- : null}
297
- `;
298
-
299
- export interface IReqoreButtonBadgeProps extends IWithReqoreSize {
300
- color?: TReqoreEffectColor;
301
- theme?: IReqoreTheme;
302
- content?: TReqoreBadge | TReqoreBadge[];
303
- wrap?: boolean;
304
- wrapGroup?: boolean;
305
- compact?: boolean;
306
- }
307
-
308
- export const ButtonBadge = memo(({ wrapGroup, compact, ...props }: IReqoreButtonBadgeProps) => {
309
- const renderTag = useCallback(
310
- ({ size, color, theme, content, key }: IReqoreButtonBadgeProps & { key: number }) => (
311
- <ReqoreTag
312
- key={key}
313
- size={getOneLessSize(size)}
314
- asBadge
315
- color={color}
316
- customTheme={theme}
317
- className='reqore-button-badge'
318
- minimal={!(content as IReqoreTagProps)?.effect?.gradient}
319
- {...(typeof content === 'string' || typeof content === 'number'
320
- ? { label: content }
321
- : content)}
322
- />
323
- ),
324
- [props]
325
- );
326
-
327
- const content = Array.isArray(props.content) ? props.content : [props.content];
328
-
329
- const leftBadges = content.filter(
330
- (badge) => typeof badge === 'string' || typeof badge === 'number' || !badge?.align
331
- );
332
- const rightBadges = content.filter(
333
- (badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'right'
334
- );
335
- const middleBadges = content.filter(
336
- (badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'center'
337
- );
338
-
339
- const buildContent = (badge: TReqoreBadge) => {
340
- if (typeof badge === 'string' || typeof badge === 'number') {
341
- return { label: badge, align: undefined };
342
- }
343
-
344
- return { ...badge, align: undefined };
345
- };
346
-
347
- return (
348
- <>
349
- <ReqoreSpacer
350
- width={props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / (compact ? 2 : 1)}
351
- height={!props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / 2}
352
- />
353
- {size(leftBadges) ? (
354
- <ReqoreTagGroup wrap={wrapGroup} align='left'>
355
- {leftBadges.map((badge, index) =>
356
- renderTag({ ...props, content: buildContent(badge), key: index })
357
- )}
358
- </ReqoreTagGroup>
359
- ) : null}
360
- {size(middleBadges) ? (
361
- <ReqoreTagGroup wrap={wrapGroup} fluid align='center'>
362
- {middleBadges.map((badge, index) =>
363
- renderTag({ ...props, content: buildContent(badge), key: index })
364
- )}
365
- </ReqoreTagGroup>
366
- ) : null}
367
- {size(rightBadges) ? (
368
- <ReqoreTagGroup wrap={wrapGroup} align='right'>
369
- {rightBadges.map((badge, index) =>
370
- renderTag({ ...props, content: buildContent(badge), key: index })
371
- )}
372
- </ReqoreTagGroup>
373
- ) : null}
374
- </>
375
- );
376
- });
377
-
378
- const ReqoreButton = memo(
379
- forwardRef<HTMLButtonElement, IReqoreButtonProps>(
380
- (
381
- {
382
- icon,
383
- size = 'normal',
384
- minimal,
385
- children,
386
- tooltip,
387
- className,
388
- fluid,
389
- fixed,
390
- intent,
391
- active,
392
- flat,
393
- rightIcon,
394
- customTheme,
395
- wrap,
396
- readOnly,
397
- badge,
398
- description,
399
- maxWidth,
400
- textAlign = 'left',
401
- effect,
402
- labelEffect,
403
- descriptionEffect,
404
- leftIconColor,
405
- rightIconColor,
406
- iconColor,
407
- iconsAlign,
408
- leftIconProps,
409
- rightIconProps,
410
- label,
411
- compact,
412
- as,
413
- animated,
414
- ...rest
415
- }: IReqoreButtonProps,
416
- ref
417
- ) => {
418
- const { targetRef } = useCombinedRefs(ref);
419
- const [buttonRef, setButtonRef] = useState<HTMLButtonElement>(undefined);
420
- const animations = useReqoreProperty('animations');
421
- const theme = useReqoreTheme('main', customTheme, intent);
422
- const fixedEffect = useReqoreEffect('buttons', theme, effect);
423
-
424
- /* A custom hook that is used to add a tooltip to the button. */
425
- useTooltip(buttonRef, tooltip);
426
-
427
- // If color or intent was specified, set the color
428
- const customColor = intent ? theme.main : changeLightness(theme.main, 0.07);
429
- const _flat = minimal ? flat : flat !== false;
430
- const color: TReqoreHexColor = customColor
431
- ? minimal
432
- ? getReadableColor(theme, undefined, undefined, true, theme.originalMain)
433
- : getReadableColorFrom(customColor, true)
434
- : getReadableColor(theme, undefined, undefined, true);
435
-
436
- const _children = useMemo(() => label || children, [label, children]);
437
- const hasLeftIcon = icon || leftIconProps?.image;
438
- const hasRightIcon = rightIcon || rightIconProps?.image;
439
-
440
- const hasRightAlignedBadge = useMemo(() => {
441
- if (Array.isArray(badge)) {
442
- return badge.some(
443
- (badge) =>
444
- typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'right'
445
- );
446
- }
447
-
448
- return typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'right';
449
- }, [badge]);
450
-
451
- const animate = animated === true || (animations.buttons && animated !== false);
452
-
453
- return (
454
- <StyledButton
455
- {...rest}
456
- effect={{
457
- interactive: !readOnly && !rest.disabled,
458
- ...fixedEffect,
459
- gradient: intent ? undefined : fixedEffect?.gradient,
460
- }}
461
- tabindex={rest.disabled ? -1 : 0}
462
- as={as || 'button'}
463
- theme={theme}
464
- ref={(ref) => {
465
- targetRef.current = ref;
466
- setButtonRef(ref);
467
- }}
468
- fluid={fluid}
469
- fixed={fixed}
470
- maxWidth={maxWidth}
471
- minimal={minimal}
472
- size={size}
473
- color={customColor}
474
- animate={animate}
475
- flat={_flat}
476
- active={active}
477
- readOnly={readOnly}
478
- wrap={wrap}
479
- description={description}
480
- className={`${className || ''} reqore-control reqore-button`}
481
- compact={compact}
482
- >
483
- <StyledButtonContent size={size} wrap={wrap} description={description} flat={_flat}>
484
- {hasLeftIcon ? (
485
- <>
486
- <ReqoreIcon
487
- icon={icon}
488
- size={size}
489
- color={leftIconColor || iconColor}
490
- compact={compact}
491
- {...leftIconProps}
492
- style={
493
- textAlign !== 'left' || iconsAlign === 'center'
494
- ? {
495
- marginRight: iconsAlign !== 'center' || !children ? 'auto' : undefined,
496
- marginLeft:
497
- iconsAlign === 'center' || (textAlign === 'center' && !_children)
498
- ? 'auto'
499
- : undefined,
500
- }
501
- : undefined
502
- }
503
- />
504
- {_children || hasRightIcon ? (
505
- <ReqoreSpacer width={PADDING_FROM_SIZE[size] / (compact ? 2 : 1)} />
506
- ) : null}
507
- </>
508
- ) : _children ? (
509
- <ReqoreHorizontalSpacer
510
- width={1}
511
- style={textAlign !== 'left' ? { marginRight: 'auto' } : undefined}
512
- />
513
- ) : null}
514
- {_children && (
515
- <StyledAnimatedTextWrapper
516
- textAlign={textAlign}
517
- style={
518
- textAlign === 'center' && iconsAlign !== 'center' ? { margin: 'auto' } : undefined
519
- }
520
- >
521
- {!animate && (
522
- <StyledContent
523
- wrap={wrap}
524
- effect={labelEffect}
525
- className='reqore-button-text-content'
526
- >
527
- {_children}
528
- </StyledContent>
529
- )}
530
- {animate && (
531
- <StyledActiveContent
532
- wrap={wrap}
533
- effect={labelEffect}
534
- className='reqore-button-text-content reqore-animated'
535
- >
536
- {_children}
537
- </StyledActiveContent>
538
- )}
539
- {animate && (
540
- <StyledInActiveContent
541
- wrap={wrap}
542
- effect={labelEffect}
543
- className='reqore-button-text-content reqore-animated'
544
- >
545
- {_children}
546
- </StyledInActiveContent>
547
- )}
548
- {animate && (
549
- <StyledInvisibleContent
550
- wrap={wrap}
551
- effect={labelEffect}
552
- className='reqore-button-text-content reqore-animated'
553
- >
554
- {_children}
555
- </StyledInvisibleContent>
556
- )}
557
- {(badge || badge === 0) && wrap ? (
558
- <ButtonBadge content={badge} size={size} theme={theme} wrap />
559
- ) : null}
560
- </StyledAnimatedTextWrapper>
561
- )}
562
- {(badge || badge === 0) && !wrap ? (
563
- <ButtonBadge
564
- content={badge}
565
- size={size}
566
- theme={theme}
567
- compact={compact}
568
- wrapGroup={false}
569
- wrap={false}
570
- />
571
- ) : null}
572
- {!hasRightIcon ? (
573
- _children ? (
574
- <ReqoreHorizontalSpacer
575
- width={1}
576
- style={
577
- textAlign !== 'right' && !hasRightAlignedBadge
578
- ? { marginLeft: 'auto' }
579
- : undefined
580
- }
581
- />
582
- ) : null
583
- ) : (
584
- <>
585
- {_children || badge ? (
586
- <ReqoreSpacer width={PADDING_FROM_SIZE[size] / (compact ? 2 : 1)} />
587
- ) : null}
588
- <ReqoreIcon
589
- icon={rightIcon}
590
- size={size}
591
- color={rightIconColor || iconColor}
592
- compact={compact}
593
- {...rightIconProps}
594
- style={
595
- textAlign !== 'right' || iconsAlign === 'center'
596
- ? {
597
- marginLeft:
598
- !hasRightAlignedBadge && (iconsAlign !== 'center' || !_children)
599
- ? 'auto'
600
- : undefined,
601
- marginRight:
602
- iconsAlign === 'center' || (textAlign === 'center' && !_children)
603
- ? 'auto'
604
- : undefined,
605
- }
606
- : undefined
607
- }
608
- />
609
- </>
610
- )}
611
- </StyledButtonContent>
612
-
613
- {description && (
614
- <ReqoreTextEffect
615
- className='reqore-button-description'
616
- effect={{
617
- textSize: getOneLessSize(size),
618
- weight: 'light',
619
- color: `${color}90`,
620
- textAlign,
621
- ...descriptionEffect,
622
- }}
623
- >
624
- {description}
625
- </ReqoreTextEffect>
626
- )}
627
- </StyledButton>
628
- );
629
- }
630
- )
631
- );
632
-
633
- export default ReqoreButton;