@qoretechnologies/reqore 0.30.4 → 0.30.6

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 (214) hide show
  1. package/CODE_OF_CONDUCT.md +105 -0
  2. package/CONTRIBUTING.MD +78 -0
  3. package/LICENSE +1 -1
  4. package/README.md +44 -2
  5. package/SECURITY.md +5 -0
  6. package/__tests__/collection.test.tsx +1 -1
  7. package/__tests__/{control_group.test.tsx → control_group.text.tsx} +2 -4
  8. package/__tests__/modal.test.tsx +2 -74
  9. package/__tests__/panel.test.tsx +24 -96
  10. package/__tests__/popover.test.tsx +2 -24
  11. package/__tests__/tabs.test.tsx +0 -75
  12. package/dist/components/Button/index.d.ts +1 -4
  13. package/dist/components/Button/index.d.ts.map +1 -1
  14. package/dist/components/Button/index.js +7 -10
  15. package/dist/components/Button/index.js.map +1 -1
  16. package/dist/components/Checkbox/index.js +1 -1
  17. package/dist/components/Collection/index.d.ts +2 -7
  18. package/dist/components/Collection/index.d.ts.map +1 -1
  19. package/dist/components/Collection/index.js +53 -57
  20. package/dist/components/Collection/index.js.map +1 -1
  21. package/dist/components/Collection/item.d.ts +5 -5
  22. package/dist/components/Collection/item.d.ts.map +1 -1
  23. package/dist/components/Collection/item.js +4 -15
  24. package/dist/components/Collection/item.js.map +1 -1
  25. package/dist/components/Columns/column.d.ts.map +1 -1
  26. package/dist/components/Columns/column.js +1 -1
  27. package/dist/components/Columns/column.js.map +1 -1
  28. package/dist/components/ControlGroup/index.d.ts +4 -20
  29. package/dist/components/ControlGroup/index.d.ts.map +1 -1
  30. package/dist/components/ControlGroup/index.js +55 -241
  31. package/dist/components/ControlGroup/index.js.map +1 -1
  32. package/dist/components/Drawer/index.d.ts +3 -3
  33. package/dist/components/Drawer/index.d.ts.map +1 -1
  34. package/dist/components/Drawer/index.js +16 -27
  35. package/dist/components/Drawer/index.js.map +1 -1
  36. package/dist/components/Dropdown/index.d.ts +0 -1
  37. package/dist/components/Dropdown/index.d.ts.map +1 -1
  38. package/dist/components/Dropdown/index.js +2 -2
  39. package/dist/components/Dropdown/index.js.map +1 -1
  40. package/dist/components/Dropdown/list.d.ts +3 -3
  41. package/dist/components/Dropdown/list.d.ts.map +1 -1
  42. package/dist/components/Effect/index.d.ts +9 -9
  43. package/dist/components/Effect/index.d.ts.map +1 -1
  44. package/dist/components/Effect/index.js +1 -1
  45. package/dist/components/Effect/index.js.map +1 -1
  46. package/dist/components/Icon/index.d.ts +6 -5
  47. package/dist/components/Icon/index.d.ts.map +1 -1
  48. package/dist/components/Icon/index.js +7 -14
  49. package/dist/components/Icon/index.js.map +1 -1
  50. package/dist/components/Input/index.d.ts +0 -2
  51. package/dist/components/Input/index.d.ts.map +1 -1
  52. package/dist/components/Input/index.js +6 -9
  53. package/dist/components/Input/index.js.map +1 -1
  54. package/dist/components/InternalPopover/index.d.ts.map +1 -1
  55. package/dist/components/InternalPopover/index.js +10 -12
  56. package/dist/components/InternalPopover/index.js.map +1 -1
  57. package/dist/components/Menu/index.d.ts.map +1 -1
  58. package/dist/components/Menu/index.js +1 -1
  59. package/dist/components/Menu/index.js.map +1 -1
  60. package/dist/components/Message/index.d.ts +0 -2
  61. package/dist/components/Message/index.d.ts.map +1 -1
  62. package/dist/components/Message/index.js +2 -2
  63. package/dist/components/Message/index.js.map +1 -1
  64. package/dist/components/MultiSelect/index.d.ts +2 -2
  65. package/dist/components/MultiSelect/index.d.ts.map +1 -1
  66. package/dist/components/MultiSelect/index.js +10 -10
  67. package/dist/components/MultiSelect/index.js.map +1 -1
  68. package/dist/components/Notifications/index.d.ts +1 -1
  69. package/dist/components/Notifications/index.d.ts.map +1 -1
  70. package/dist/components/Notifications/notification.d.ts +1 -1
  71. package/dist/components/Notifications/notification.d.ts.map +1 -1
  72. package/dist/components/Panel/index.d.ts +6 -13
  73. package/dist/components/Panel/index.d.ts.map +1 -1
  74. package/dist/components/Panel/index.js +44 -78
  75. package/dist/components/Panel/index.js.map +1 -1
  76. package/dist/components/Popover/index.d.ts +2 -1
  77. package/dist/components/Popover/index.d.ts.map +1 -1
  78. package/dist/components/Popover/index.js +2 -2
  79. package/dist/components/Popover/index.js.map +1 -1
  80. package/dist/components/Spacer/index.d.ts +0 -2
  81. package/dist/components/Spacer/index.d.ts.map +1 -1
  82. package/dist/components/Spacer/index.js +7 -29
  83. package/dist/components/Spacer/index.js.map +1 -1
  84. package/dist/components/Table/helpers.d.ts +2 -3
  85. package/dist/components/Table/helpers.d.ts.map +1 -1
  86. package/dist/components/Table/helpers.js +3 -6
  87. package/dist/components/Table/helpers.js.map +1 -1
  88. package/dist/components/Table/index.d.ts +3 -4
  89. package/dist/components/Table/index.d.ts.map +1 -1
  90. package/dist/components/Table/index.js.map +1 -1
  91. package/dist/components/Tabs/content.d.ts +1 -3
  92. package/dist/components/Tabs/content.d.ts.map +1 -1
  93. package/dist/components/Tabs/content.js +3 -8
  94. package/dist/components/Tabs/content.js.map +1 -1
  95. package/dist/components/Tabs/index.d.ts +1 -4
  96. package/dist/components/Tabs/index.d.ts.map +1 -1
  97. package/dist/components/Tabs/index.js +4 -12
  98. package/dist/components/Tabs/index.js.map +1 -1
  99. package/dist/components/Tabs/item.d.ts +0 -1
  100. package/dist/components/Tabs/item.d.ts.map +1 -1
  101. package/dist/components/Tabs/item.js +7 -7
  102. package/dist/components/Tabs/item.js.map +1 -1
  103. package/dist/components/Tabs/list.d.ts +1 -1
  104. package/dist/components/Tabs/list.d.ts.map +1 -1
  105. package/dist/components/Tabs/list.js +3 -4
  106. package/dist/components/Tabs/list.js.map +1 -1
  107. package/dist/components/Tag/group.d.ts +2 -2
  108. package/dist/components/Tag/group.d.ts.map +1 -1
  109. package/dist/components/Tag/group.js +8 -7
  110. package/dist/components/Tag/group.js.map +1 -1
  111. package/dist/components/Tag/index.d.ts +2 -6
  112. package/dist/components/Tag/index.d.ts.map +1 -1
  113. package/dist/components/Tag/index.js +12 -20
  114. package/dist/components/Tag/index.js.map +1 -1
  115. package/dist/components/Tree/index.js +1 -1
  116. package/dist/components/Tree/index.js.map +1 -1
  117. package/dist/constants/animations.js +1 -1
  118. package/dist/constants/sizes.d.ts +2 -2
  119. package/dist/constants/sizes.d.ts.map +1 -1
  120. package/dist/constants/sizes.js +10 -10
  121. package/dist/constants/sizes.js.map +1 -1
  122. package/dist/constants/theme.d.ts +1 -1
  123. package/dist/constants/theme.d.ts.map +1 -1
  124. package/dist/containers/PopoverProvider.d.ts.map +1 -1
  125. package/dist/containers/PopoverProvider.js +8 -10
  126. package/dist/containers/PopoverProvider.js.map +1 -1
  127. package/dist/containers/ReqoreProvider.d.ts.map +1 -1
  128. package/dist/containers/ReqoreProvider.js +2 -4
  129. package/dist/containers/ReqoreProvider.js.map +1 -1
  130. package/dist/containers/UIProvider.d.ts +0 -7
  131. package/dist/containers/UIProvider.d.ts.map +1 -1
  132. package/dist/containers/UIProvider.js.map +1 -1
  133. package/dist/context/ReqoreContext.d.ts +0 -2
  134. package/dist/context/ReqoreContext.d.ts.map +1 -1
  135. package/dist/context/ReqoreContext.js.map +1 -1
  136. package/dist/helpers/utils.d.ts +0 -2
  137. package/dist/helpers/utils.d.ts.map +1 -1
  138. package/dist/helpers/utils.js +2 -4
  139. package/dist/helpers/utils.js.map +1 -1
  140. package/dist/hooks/useLatestZIndex.js +2 -2
  141. package/dist/hooks/useLatestZIndex.js.map +1 -1
  142. package/dist/hooks/usePopover.d.ts +0 -1
  143. package/dist/hooks/usePopover.d.ts.map +1 -1
  144. package/dist/hooks/usePopover.js +6 -8
  145. package/dist/hooks/usePopover.js.map +1 -1
  146. package/dist/styles.d.ts +0 -1
  147. package/dist/styles.d.ts.map +1 -1
  148. package/dist/styles.js +5 -6
  149. package/dist/styles.js.map +1 -1
  150. package/dist/types/global.d.ts +1 -27
  151. package/dist/types/global.d.ts.map +1 -1
  152. package/dist/types/icons.d.ts +1 -1
  153. package/dist/types/icons.d.ts.map +1 -1
  154. package/package.json +1 -1
  155. package/public/logo-dark.png +0 -0
  156. package/public/logo.png +0 -0
  157. package/public/q-symbol.png +0 -0
  158. package/public/qoreLogo-dark.png +0 -0
  159. package/public/qoreLogo.png +0 -0
  160. package/src/components/Button/index.tsx +5 -17
  161. package/src/components/Checkbox/index.tsx +1 -1
  162. package/src/components/Collection/index.tsx +60 -93
  163. package/src/components/Collection/item.tsx +9 -29
  164. package/src/components/Columns/column.tsx +0 -1
  165. package/src/components/ControlGroup/index.tsx +103 -426
  166. package/src/components/Drawer/index.tsx +27 -28
  167. package/src/components/Dropdown/index.tsx +1 -3
  168. package/src/components/Effect/index.tsx +0 -1
  169. package/src/components/Icon/index.tsx +62 -81
  170. package/src/components/Input/index.tsx +4 -8
  171. package/src/components/InternalPopover/index.tsx +126 -131
  172. package/src/components/Menu/index.tsx +1 -7
  173. package/src/components/Message/index.tsx +1 -9
  174. package/src/components/MultiSelect/index.tsx +188 -180
  175. package/src/components/Panel/index.tsx +100 -227
  176. package/src/components/Popover/index.tsx +3 -1
  177. package/src/components/Spacer/index.tsx +14 -63
  178. package/src/components/Table/helpers.ts +6 -12
  179. package/src/components/Table/index.tsx +0 -1
  180. package/src/components/Tabs/content.tsx +3 -11
  181. package/src/components/Tabs/index.tsx +3 -14
  182. package/src/components/Tabs/item.tsx +5 -28
  183. package/src/components/Tabs/list.tsx +0 -4
  184. package/src/components/Tag/group.tsx +12 -6
  185. package/src/components/Tag/index.tsx +35 -67
  186. package/src/components/Tree/index.tsx +1 -1
  187. package/src/constants/animations.ts +1 -1
  188. package/src/constants/sizes.ts +10 -10
  189. package/src/containers/PopoverProvider.tsx +8 -11
  190. package/src/containers/ReqoreProvider.tsx +35 -40
  191. package/src/containers/UIProvider.tsx +0 -7
  192. package/src/context/ReqoreContext.tsx +0 -2
  193. package/src/helpers/utils.ts +0 -3
  194. package/src/hooks/useLatestZIndex.ts +2 -2
  195. package/src/hooks/usePopover.tsx +6 -9
  196. package/src/mock/collectionData.tsx +2 -33
  197. package/src/stories/Button/Button.stories.tsx +6 -14
  198. package/src/stories/Checkbox/Checkbox.stories.tsx +3 -6
  199. package/src/stories/Collection/Collection.stories.tsx +2 -18
  200. package/src/stories/ControlGroup/ControlGroup.stories.tsx +34 -220
  201. package/src/stories/Drawer/Drawer.stories.tsx +3 -70
  202. package/src/stories/Dropdown/Dropdown.stories.tsx +3 -13
  203. package/src/stories/Icon/Icon.stories.tsx +0 -1
  204. package/src/stories/Input/Input.stories.tsx +3 -5
  205. package/src/stories/Menu/Menu.stories.tsx +0 -2
  206. package/src/stories/Message/Message.stories.tsx +0 -7
  207. package/src/stories/Panel/Panel.stories.tsx +13 -147
  208. package/src/stories/Popover/Popover.stories.tsx +82 -88
  209. package/src/stories/Tabs/Tabs.stories.tsx +15 -32
  210. package/src/stories/Tag/Tag.stories.tsx +3 -23
  211. package/src/stories/TextArea/TextArea.stories.tsx +3 -3
  212. package/src/styles.ts +0 -6
  213. package/src/types/global.ts +0 -28
  214. package/tests.json +1 -1
@@ -1,52 +1,23 @@
1
- import { debounce } from 'lodash';
2
- import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { useMount, useUnmount } from 'react-use';
1
+ import React, { forwardRef } from 'react';
4
2
  import styled, { css } from 'styled-components';
5
- import { ReqoreButton, ReqoreDrawer } from '../..';
6
3
  import { GAP_FROM_SIZE, RADIUS_FROM_SIZE, TSizes } from '../../constants/sizes';
7
4
  import { IReqoreTheme } from '../../constants/theme';
8
- import {
9
- IReqoreIntent,
10
- IWithReqoreCustomTheme,
11
- IWithReqoreFlat,
12
- IWithReqoreFluid,
13
- IWithReqoreMinimal,
14
- IWithReqoreSize,
15
- } from '../../types/global';
5
+ import { IWithReqoreFlat, IWithReqoreMinimal, IWithReqoreSize } from '../../types/global';
16
6
 
17
7
  export interface IReqoreControlGroupProps
18
8
  extends React.HTMLAttributes<HTMLDivElement>,
19
9
  IWithReqoreFlat,
20
10
  IWithReqoreSize,
21
- IWithReqoreMinimal,
22
- IReqoreIntent,
23
- IWithReqoreFluid,
24
- IWithReqoreCustomTheme {
11
+ IWithReqoreMinimal {
25
12
  stack?: boolean;
26
13
  children: any;
27
- fixed?: boolean;
14
+ fluid?: boolean;
28
15
  rounded?: boolean;
29
- responsive?: boolean;
30
16
  gapSize?: TSizes;
31
17
  /*
32
18
  * Whether the contents of the control group should be stacked vertically
33
19
  */
34
20
  vertical?: boolean;
35
- verticalAlign?: 'flex-start' | 'center' | 'flex-end';
36
- horizontalAlign?: 'flex-start' | 'center' | 'flex-end';
37
- wrap?: boolean;
38
- isInsideStackGroup?: boolean;
39
- isInsideVerticalGroup?: boolean;
40
- isFirst?: boolean;
41
- isLast?: boolean;
42
- isLastInFirstGroup?: boolean;
43
- isLastInLastGroup?: boolean;
44
- isFirstInLastGroup?: boolean;
45
- childrenCount?: number;
46
- childId?: number;
47
- isChild?: boolean;
48
- isFirstGroup?: boolean;
49
- isLastGroup?: boolean;
50
21
  }
51
22
 
52
23
  export interface IReqoreControlGroupStyle extends IReqoreControlGroupProps {
@@ -56,415 +27,121 @@ export interface IReqoreControlGroupStyle extends IReqoreControlGroupProps {
56
27
  export const StyledReqoreControlGroup = styled.div<IReqoreControlGroupStyle>`
57
28
  display: flex;
58
29
  flex: 0 auto;
59
- width: ${({ fluid, fixed }) => (fluid && !fixed ? '100%' : undefined)};
60
- justify-content: ${({ fluid, vertical }) => (vertical && fluid ? 'stretch' : undefined)};
61
- align-items: ${({ vertical, fluid, horizontalAlign }) =>
62
- vertical ? (fluid ? 'stretch' : horizontalAlign) : undefined};
30
+ width: ${({ fluid }) => (fluid ? '100%' : undefined)};
31
+ align-items: ${({ fluid }) => (fluid ? 'stretch' : 'flex-start')};
63
32
  flex-flow: ${({ vertical }) => (vertical ? 'column' : 'row')};
64
- gap: ${({ gapSize, stack }) => (!stack ? `${GAP_FROM_SIZE[gapSize]}px` : undefined)};
65
- flex-wrap: ${({ wrap }) => (wrap ? 'wrap' : 'nowrap')};
66
33
 
67
- > * {
68
- margin-top: ${({ verticalAlign }) =>
69
- verticalAlign === 'flex-end' || verticalAlign === 'center' ? 'auto' : undefined};
70
- margin-bottom: ${({ verticalAlign }) =>
71
- verticalAlign === 'flex-start' || verticalAlign === 'center' ? 'auto' : undefined};
72
- margin-right: ${({ horizontalAlign }) => (horizontalAlign === 'center' ? 'auto' : undefined)};
73
-
74
- ${({ vertical }) =>
75
- vertical &&
76
- css`
77
- margin-left: ${({ horizontalAlign }) =>
78
- horizontalAlign === 'flex-end' || horizontalAlign === 'center' ? 'auto' : undefined};
79
- `}
80
- }
81
-
82
- ${({ vertical }) =>
83
- !vertical &&
84
- css`
85
- > *:first-child {
86
- margin-left: ${({ horizontalAlign }) =>
87
- horizontalAlign === 'flex-end' || horizontalAlign === 'center' ? 'auto' : undefined};
88
- }
89
- `}
90
-
91
- > * {
34
+ > .reqore-control-wrapper .reqore-control {
92
35
  border-radius: ${({ stack }) => (!stack ? undefined : 0)};
93
36
  }
94
- `;
95
-
96
- const ReqoreControlGroup = memo(
97
- ({
98
- children,
99
- className,
100
- minimal,
101
- size = 'normal',
102
- gapSize = 'normal',
103
- fluid,
104
- flat,
105
- fixed,
106
- rounded = true,
107
- wrap,
108
- stack,
109
- isInsideStackGroup,
110
- isInsideVerticalGroup,
111
- isFirstInLastGroup,
112
- isLastInFirstGroup,
113
- isLastInLastGroup,
114
- intent,
115
- customTheme,
116
- isFirst,
117
- isLast,
118
- vertical,
119
- childrenCount,
120
- childId,
121
- isChild,
122
- isFirstGroup,
123
- isLastGroup,
124
- verticalAlign = 'center',
125
- horizontalAlign = 'flex-start',
126
- responsive,
127
- ...rest
128
- }: IReqoreControlGroupProps) => {
129
- const isStack = stack || isInsideStackGroup;
130
- const isVertical = vertical || isInsideVerticalGroup;
131
37
 
132
- const [overflowingChildren, setOverflowingChildren] = useState<number | undefined>(0);
133
- const [lastReSize, setLastReSize] = useState<number>(0);
134
- const [isOverflownDialogOpen, setIsOverflownDialogOpen] = useState<boolean>(false);
135
- const observer = useRef<ResizeObserver | null>(null);
136
- const ref = useRef<HTMLDivElement>(null);
137
-
138
- const realChildCount = useMemo((): number => {
139
- let count = 0;
140
-
141
- const countChildren = (children: React.ReactNode) =>
142
- React.Children.forEach(children, (child: any) => {
143
- if (child && React.isValidElement(child)) {
144
- if (child.type === React.Fragment) {
145
- // just compare to `React.Fragment`
146
- countChildren((child.props as any).children);
147
- } else {
148
- count++;
38
+ ${({ vertical }) =>
39
+ vertical
40
+ ? css`
41
+ > .reqore-control,
42
+ > .reqore-control-wrapper,
43
+ > .reqore-tag,
44
+ > * {
45
+ &:not(:last-child) {
46
+ margin-bottom: ${({ stack, gapSize }) =>
47
+ !stack ? `${GAP_FROM_SIZE[gapSize]}px` : undefined};
48
+ border-bottom: ${({ stack }) => (!stack ? undefined : 0)};
149
49
  }
150
- }
151
- });
152
-
153
- countChildren(children);
154
-
155
- return count < 0 ? 0 : count;
156
- }, [children]);
157
-
158
- const checkIfOverflowing = useCallback(() => {
159
- return (
160
- ref.current &&
161
- ref.current.clientWidth > 40 &&
162
- !vertical &&
163
- responsive &&
164
- ref.current.scrollWidth > ref.current.clientWidth
165
- );
166
- }, [vertical, responsive, ref, children]);
167
-
168
- useMount(() => {
169
- if (!vertical && responsive) {
170
- if ('ResizeObserver' in window) {
171
- observer.current = new ResizeObserver(
172
- debounce(() => {
173
- if (ref && ref.current) {
174
- setOverflowingChildren(0);
175
- setLastReSize(ref.current.clientWidth);
176
- }
177
- }, 200)
178
- );
179
-
180
- observer.current.observe(ref.current);
181
- }
182
- }
183
- });
184
-
185
- useUnmount(() => {
186
- if (observer.current) {
187
- observer.current.disconnect();
188
- }
189
- });
190
-
191
- useEffect(() => {
192
- // Is the control group still overflowing?
193
- if ((overflowingChildren || overflowingChildren === 0) && checkIfOverflowing()) {
194
- setOverflowingChildren(overflowingChildren + 1);
195
- }
196
-
197
- // Hide the dialog if the group was resized and the dialog was open
198
- if (overflowingChildren === 0) {
199
- setIsOverflownDialogOpen(false);
200
- }
201
- }, [overflowingChildren, lastReSize]);
202
-
203
- const getIsFirst = (index: number): boolean => {
204
- return !isInsideStackGroup || childrenCount === 1
205
- ? index === 0
206
- : (isFirst || isFirst !== false) && index === 0;
207
- };
208
- const getIsLast = (index: number): boolean => {
209
- return !isInsideStackGroup
210
- ? index === realChildCount - 1
211
- : (isLast || isLast !== false) && index === realChildCount - 1;
212
- };
213
- const getIsLastInFirstGroup = (index: number): boolean => {
214
- return !isInsideStackGroup
215
- ? index === 0
216
- : isFirstGroup && (isLast || isLast !== false) && index === realChildCount - 1;
217
- };
218
- const getIsFirstInLastGroup = (index: number): boolean => {
219
- return !isInsideStackGroup
220
- ? index === realChildCount - 1
221
- : isLastGroup && (isFirst || isFirst !== false) && childId === 1 && index === 0;
222
- };
223
- const getIsLastInLastGroup = (index: number): boolean => {
224
- return !isInsideStackGroup
225
- ? index === realChildCount - 1
226
- : isLastGroup && (isLast || isLast !== false) && index === realChildCount - 1;
227
- };
228
-
229
- const getBorderTopLeftRadius = (index: number): number | undefined => {
230
- const _isFirstGroup =
231
- !isInsideStackGroup || childrenCount === 1 ? true : isChild ? isFirstGroup : index === 0;
232
-
233
- // If this is the first item
234
- if (_isFirstGroup && getIsFirst(index)) {
235
- return RADIUS_FROM_SIZE[size];
236
- }
237
-
238
- return undefined;
239
- };
240
-
241
- const getBorderTopRightRadius = (index: number): number | undefined => {
242
- // If this group is not vertical we need to style the very last item
243
- if (!isVertical || !isStack) {
244
- const _isLastGroup =
245
- !isInsideStackGroup || childrenCount === 1
246
- ? true
247
- : isChild
248
- ? isLastGroup
249
- : index === realChildCount - 1;
250
-
251
- if (_isLastGroup && getIsLast(index)) {
252
- return RADIUS_FROM_SIZE[size];
253
- }
254
-
255
- return undefined;
256
- }
257
50
 
258
- // This border only needs to apply when this group is vertical
259
- // AND this item is the last item of the first group
260
- if (getIsLastInFirstGroup(index)) {
261
- return RADIUS_FROM_SIZE[size];
262
- }
263
-
264
- return undefined;
265
- };
266
-
267
- const getBorderBottomLeftRadius = (index: number): number | undefined => {
268
- // If this group is not vertical we need to style the very first item
269
- if (!isVertical || !isStack) {
270
- const _isFirstGroup =
271
- !isInsideStackGroup || childrenCount === 1 ? true : isChild ? isFirstGroup : index === 0;
272
-
273
- if (_isFirstGroup && getIsFirst(index)) {
274
- return RADIUS_FROM_SIZE[size];
275
- }
276
-
277
- return undefined;
278
- }
279
-
280
- // This border only needs to apply when this group is vertical
281
- // AND this item is the first item of the last group
282
- if (getIsFirstInLastGroup(index)) {
283
- return RADIUS_FROM_SIZE[size];
284
- }
285
-
286
- return undefined;
287
- };
288
-
289
- const getBorderBottomRightRadius = (index: number): number | undefined => {
290
- const _isLastGroup =
291
- !isInsideStackGroup || childrenCount === 1
292
- ? true
293
- : isChild
294
- ? isLastGroup
295
- : index === realChildCount - 1;
296
-
297
- // If this is the last item
298
- if (_isLastGroup && getIsLast(index)) {
299
- return RADIUS_FROM_SIZE[size];
300
- }
301
-
302
- return undefined;
303
- };
304
-
305
- let index = 0;
51
+ border-radius: ${({ stack }) => (!stack ? undefined : 0)};
52
+
53
+ ${({ rounded, size, stack }) =>
54
+ rounded && stack
55
+ ? css`
56
+ &:first-child {
57
+ border-top-left-radius: ${RADIUS_FROM_SIZE[size]}px;
58
+ border-top-right-radius: ${RADIUS_FROM_SIZE[size]}px;
59
+ }
60
+
61
+ &:last-child {
62
+ border-bottom-left-radius: ${RADIUS_FROM_SIZE[size]}px;
63
+ border-bottom-right-radius: ${RADIUS_FROM_SIZE[size]}px;
64
+ }
65
+ `
66
+ : undefined}
67
+ }
306
68
 
307
- const cloneThroughFragments = useCallback(
308
- (children: React.ReactNode): React.ReactNode => {
309
- return React.Children.map(children, (child) => {
310
- if (child && React.isValidElement(child)) {
311
- if (child.type === React.Fragment) {
312
- // just compare to `React.Fragment`
313
- return cloneThroughFragments(child.props.children);
69
+ > .reqore-control-wrapper:not(:last-child) .reqore-control {
70
+ margin-bottom: ${({ stack, gapSize }) =>
71
+ !stack ? `${GAP_FROM_SIZE[gapSize]}px` : undefined};
72
+ border-bottom: ${({ stack }) => (!stack ? undefined : 0)};
73
+ }
74
+ `
75
+ : css`
76
+ > .reqore-control,
77
+ > .reqore-control-wrapper,
78
+ > .reqore-tag,
79
+ > * {
80
+ &:not(:last-child) {
81
+ margin-right: ${({ stack, gapSize }) =>
82
+ !stack ? `${GAP_FROM_SIZE[gapSize]}px` : undefined};
83
+ border-right: ${({ stack }) => (!stack ? undefined : 0)};
314
84
  }
315
85
 
316
- let newProps = {
317
- ...child.props,
318
- key: index,
86
+ border-radius: ${({ stack }) => (!stack ? undefined : 0)};
87
+
88
+ ${({ rounded, size, stack }) =>
89
+ rounded && stack
90
+ ? css`
91
+ &:first-child {
92
+ border-top-left-radius: ${RADIUS_FROM_SIZE[size]}px;
93
+ border-bottom-left-radius: ${RADIUS_FROM_SIZE[size]}px;
94
+ }
95
+
96
+ &:last-child {
97
+ border-top-right-radius: ${RADIUS_FROM_SIZE[size]}px;
98
+ border-bottom-right-radius: ${RADIUS_FROM_SIZE[size]}px;
99
+ }
100
+ `
101
+ : undefined}
102
+ }
103
+ `}
104
+ `;
105
+
106
+ const ReqoreControlGroup = forwardRef<HTMLDivElement, IReqoreControlGroupProps>(
107
+ (
108
+ {
109
+ children,
110
+ className,
111
+ minimal,
112
+ size = 'normal',
113
+ gapSize = 'normal',
114
+ fluid,
115
+ flat,
116
+ rounded = true,
117
+ ...rest
118
+ }: IReqoreControlGroupProps,
119
+ ref
120
+ ) => (
121
+ <StyledReqoreControlGroup
122
+ {...rest}
123
+ size={size}
124
+ gapSize={gapSize}
125
+ ref={ref}
126
+ rounded={rounded}
127
+ fluid={fluid}
128
+ className={`${className || ''} reqore-control-group`}
129
+ >
130
+ {React.Children.map(children, (child) =>
131
+ child
132
+ ? React.cloneElement(child, {
319
133
  minimal:
320
134
  child.props?.minimal || child.props?.minimal === false
321
135
  ? child.props.minimal
322
136
  : minimal,
323
137
  size: child.props?.size || size,
324
138
  flat: child.props?.flat || child.props?.flat === false ? child.props.flat : flat,
325
- fluid: child.props?.fluid || child.props?.fluid === false ? child.props.fluid : fluid,
326
- fixed: child.props?.fixed || child.props?.fixed === false ? child.props.fixed : fixed,
327
- stack:
328
- child.props?.stack || child.props?.stack === false ? child.props.stack : isStack,
329
- intent: child.props?.intent || intent,
330
- customTheme: child.props?.customTheme || customTheme,
331
- };
332
-
333
- if (isStack) {
334
- newProps = {
335
- ...newProps,
336
- style: {
337
- borderTopLeftRadius: getBorderTopLeftRadius(index),
338
- borderBottomLeftRadius: getBorderBottomLeftRadius(index),
339
- borderTopRightRadius: getBorderTopRightRadius(index),
340
- borderBottomRightRadius: getBorderBottomRightRadius(index),
341
- ...(child.props?.style || {}),
342
- },
343
- isChild: true,
344
- rounded: !isStack,
345
- isInsideStackGroup: isStack,
346
- isInsideVerticalGroup: isVertical,
347
- isFirst: isChild ? getIsFirst(index) : undefined,
348
- isLast: isChild ? getIsLast(index) : undefined,
349
- isLastInFirstGroup: getIsLastInFirstGroup(index),
350
- isLastInLastGroup: getIsLastInLastGroup(index),
351
- isFirstInLastGroup: getIsFirstInLastGroup(index),
352
- childrenCount: realChildCount,
353
- childId: index + 1,
354
-
355
- isFirstGroup: isChild ? isFirstGroup : index === 0,
356
- isLastGroup: isChild ? isLastGroup : index === realChildCount - 1,
357
- };
358
- }
359
-
360
- /*
361
- * Because of the way React.Children.map works, we have to
362
- * manually decrement the index for every child that is `null`
363
- * because react maps through null children and returns them in `Count`
364
- * We filter these children out in the `realChildCount` variable,
365
- * but the index is still incremented
366
- * */
367
- index = index + 1;
368
-
369
- return React.cloneElement(child, newProps);
370
- }
371
-
372
- return child;
373
- });
374
- },
375
- [
376
- children,
377
- isStack,
378
- isVertical,
379
- isChild,
380
- isLastGroup,
381
- isFirstGroup,
382
- realChildCount,
383
- index,
384
- fluid,
385
- flat,
386
- minimal,
387
- size,
388
- intent,
389
- ]
390
- );
391
-
392
- // Get the overflown children
393
- const overflownChildren = useMemo(
394
- () =>
395
- overflowingChildren ? React.Children.toArray(children).slice(0, overflowingChildren) : [],
396
- [children, overflowingChildren]
397
- );
398
-
399
- // Remove the overflowing children count from the start of the children array
400
- const _children = useMemo(
401
- () =>
402
- overflowingChildren && responsive
403
- ? [
404
- children.slice(overflowingChildren),
405
- <ReqoreButton
406
- icon='MenuLine'
407
- customTheme={customTheme}
408
- tooltip={{
409
- content: `Show ${React.Children.count(overflownChildren)} hidden items`,
410
- }}
411
- fixed
412
- active={isOverflownDialogOpen}
413
- onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
414
- e.stopPropagation();
415
- setIsOverflownDialogOpen(!isOverflownDialogOpen);
416
- }}
417
- flat
418
- />,
419
- ]
420
- : children,
421
- [children, overflowingChildren, responsive, overflownChildren]
422
- );
423
-
424
- return (
425
- <>
426
- {isOverflownDialogOpen ? (
427
- <ReqoreDrawer
428
- isOpen
429
- onClose={() => setIsOverflownDialogOpen(false)}
430
- flat
431
- floating
432
- minimal
433
- position='bottom'
434
- hasBackdrop={false}
435
- label='Hidden items'
436
- minSize='100px'
437
- size='auto'
438
- >
439
- <ReqoreControlGroup fluid wrap>
440
- {overflownChildren}
441
- </ReqoreControlGroup>
442
- </ReqoreDrawer>
443
- ) : null}
444
- <StyledReqoreControlGroup
445
- {...rest}
446
- vertical={vertical}
447
- style={{
448
- overflowX: responsive ? 'auto' : undefined,
449
- ...rest.style,
450
- }}
451
- size={size}
452
- gapSize={gapSize}
453
- ref={ref}
454
- rounded={rounded}
455
- fluid={fluid}
456
- fixed={fixed}
457
- wrap={wrap}
458
- stack={isStack}
459
- verticalAlign={verticalAlign}
460
- horizontalAlign={horizontalAlign}
461
- className={`${className || ''} reqore-control-group`}
462
- >
463
- {cloneThroughFragments(_children)}
464
- </StyledReqoreControlGroup>
465
- </>
466
- );
467
- }
139
+ fluid,
140
+ })
141
+ : null
142
+ )}
143
+ </StyledReqoreControlGroup>
144
+ )
468
145
  );
469
146
 
470
147
  export default ReqoreControlGroup;