@qoretechnologies/reqore 0.39.0 → 0.40.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 (35) hide show
  1. package/dist/components/ControlGroup/index.d.ts +4 -2
  2. package/dist/components/ControlGroup/index.d.ts.map +1 -1
  3. package/dist/components/ControlGroup/index.js.map +1 -1
  4. package/dist/components/Menu/section.d.ts +12 -0
  5. package/dist/components/Menu/section.d.ts.map +1 -0
  6. package/dist/components/Menu/section.js +87 -0
  7. package/dist/components/Menu/section.js.map +1 -0
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +3 -3
  11. package/dist/index.js.map +1 -1
  12. package/package.json +1 -1
  13. package/src/components/ControlGroup/index.tsx +8 -4
  14. package/src/components/Menu/section.tsx +82 -0
  15. package/src/index.tsx +1 -1
  16. package/src/mock/menu.ts +46 -48
  17. package/src/stories/Menu/Menu.stories.tsx +161 -108
  18. package/tests.json +1 -1
  19. package/__tests__/sidebar.test.tsx +0 -225
  20. package/dist/components/Sidebar/index.d.ts +0 -60
  21. package/dist/components/Sidebar/index.d.ts.map +0 -1
  22. package/dist/components/Sidebar/index.js +0 -266
  23. package/dist/components/Sidebar/index.js.map +0 -1
  24. package/dist/components/Sidebar/item.d.ts +0 -35
  25. package/dist/components/Sidebar/item.d.ts.map +0 -1
  26. package/dist/components/Sidebar/item.js +0 -98
  27. package/dist/components/Sidebar/item.js.map +0 -1
  28. package/dist/helpers/sidebar.d.ts +0 -5
  29. package/dist/helpers/sidebar.d.ts.map +0 -1
  30. package/dist/helpers/sidebar.js +0 -92
  31. package/dist/helpers/sidebar.js.map +0 -1
  32. package/src/components/Sidebar/index.tsx +0 -536
  33. package/src/components/Sidebar/item.tsx +0 -264
  34. package/src/helpers/sidebar.ts +0 -89
  35. package/src/stories/Sidebar/Sidebar.stories.tsx +0 -97
@@ -1,264 +0,0 @@
1
- import classnames from 'classnames';
2
- import map from 'lodash/map';
3
- import { useMount } from 'react-use';
4
- import { IQorusSidebarItem } from '.';
5
- import { ReqorePopover, useReqoreTheme } from '../..';
6
- import { IReqoreTheme } from '../../constants/theme';
7
- import { getMainColor, getReadableColor } from '../../helpers/colors';
8
- import { isActiveMulti } from '../../helpers/sidebar';
9
- import ReqoreIcon from '../Icon';
10
-
11
- export interface SidebarItemProps {
12
- itemData: IQorusSidebarItem;
13
- isCollapsed?: boolean;
14
- subItem?: boolean;
15
- onSectionToggle?: (sectionId: string) => any;
16
- isExpanded?: boolean;
17
- isActive?: boolean;
18
- tooltip?: string;
19
- children?: any;
20
- expandedSection?: string;
21
- onFavoriteClick?: (id: string) => void;
22
- onUnfavoriteClick?: (id: string) => void;
23
- favoriteItems?: any;
24
- formatItemName?: (itemName: string) => string;
25
- currentPath?: string;
26
- sectionName?: string;
27
- hasFavorites?: boolean;
28
- useNativeTitle?: boolean;
29
- bookmarks?: string[];
30
- onClick(): void;
31
- }
32
-
33
- export interface ISidebarTooltipProps {
34
- isCollapsed?: boolean;
35
- children: any;
36
- itemData: IQorusSidebarItem;
37
- isActive?: boolean;
38
- isSubcategory?: boolean;
39
- isSubitem?: boolean;
40
- onClick?: any;
41
- useNativeTitle?: boolean;
42
- }
43
-
44
- const SidebarItemTooltip = ({
45
- isCollapsed,
46
- children,
47
- itemData,
48
- isActive,
49
- isSubitem,
50
- isSubcategory,
51
- onClick,
52
- useNativeTitle,
53
- }: ISidebarTooltipProps) => {
54
- const Element = itemData.as || 'div';
55
-
56
- if (useNativeTitle) {
57
- return (
58
- <Element
59
- {...itemData.props}
60
- onClick={(e) => {
61
- itemData.props?.onClick?.(e);
62
- onClick?.(e);
63
- }}
64
- className={classnames('sidebarItem', 'sidebarLink', {
65
- sidebarSubItem: isSubitem,
66
- active: isActive,
67
- submenuCategory: isSubcategory,
68
- })}
69
- title={itemData.name}
70
- >
71
- {children}
72
- </Element>
73
- );
74
- }
75
-
76
- return (
77
- <ReqorePopover
78
- component={Element}
79
- componentProps={{
80
- ...itemData.props,
81
- onClick: (e) => {
82
- itemData.props?.onClick?.(e);
83
- onClick?.(e);
84
- },
85
- className: classnames('sidebarItem', 'sidebarLink', {
86
- sidebarSubItem: isSubitem,
87
- active: isActive,
88
- submenuCategory: isSubcategory,
89
- }),
90
- }}
91
- content={itemData.name}
92
- placement='right'
93
- isReqoreComponent
94
- show={isCollapsed}
95
- >
96
- {children}
97
- </ReqorePopover>
98
- );
99
- };
100
-
101
- const SidebarItem = ({
102
- itemData,
103
- isCollapsed,
104
- subItem,
105
- onSectionToggle,
106
- isExpanded,
107
- onFavoriteClick,
108
- onUnfavoriteClick,
109
- formatItemName,
110
- currentPath,
111
- sectionName,
112
- hasFavorites,
113
- useNativeTitle,
114
- onClick,
115
- }: SidebarItemProps) => {
116
- const handleFavoriteClick = (event) => {
117
- event.persist();
118
- event.stopPropagation();
119
- event.preventDefault();
120
-
121
- if (onFavoriteClick) {
122
- onFavoriteClick(itemData.id);
123
- }
124
- };
125
-
126
- const handleUnfavoriteClick = (event) => {
127
- event.persist();
128
- event.stopPropagation();
129
- event.preventDefault();
130
-
131
- if (onUnfavoriteClick) {
132
- onUnfavoriteClick(itemData.id);
133
- }
134
- };
135
-
136
- const isActive = isActiveMulti(
137
- itemData.activePaths || [itemData.props?.href],
138
- currentPath,
139
- itemData.exact
140
- );
141
-
142
- const getItemName: (itemName: string) => string = (itemName) =>
143
- formatItemName ? formatItemName(itemName) : itemName;
144
-
145
- return (
146
- <>
147
- <SidebarItemTooltip
148
- isCollapsed={isCollapsed}
149
- itemData={itemData}
150
- isActive={isActive}
151
- isSubitem={subItem}
152
- useNativeTitle={useNativeTitle}
153
- onClick={
154
- onSectionToggle
155
- ? () => {
156
- onSectionToggle(itemData.name);
157
- }
158
- : () => void onClick?.()
159
- }
160
- >
161
- <ReqoreIcon icon={itemData.icon} margin={isCollapsed ? undefined : 'right'} />{' '}
162
- {!isCollapsed && getItemName(itemData.name)}
163
- {itemData.submenu && (
164
- <ReqoreIcon
165
- icon={isExpanded ? 'ArrowUpSFill' : 'ArrowDownSFill'}
166
- className='submenuExpand'
167
- />
168
- )}
169
- {!itemData.submenu && !isCollapsed && hasFavorites ? (
170
- <>
171
- {sectionName === '_qorusBookmarks' ? (
172
- <ReqoreIcon
173
- icon='Bookmark3Fill'
174
- className='favorite'
175
- onClick={handleUnfavoriteClick}
176
- />
177
- ) : (
178
- <ReqoreIcon icon='Bookmark3Line' className='favorite' onClick={handleFavoriteClick} />
179
- )}
180
- </>
181
- ) : null}
182
- </SidebarItemTooltip>
183
- </>
184
- );
185
- };
186
-
187
- const SidebarItemWrapper = ({
188
- itemData,
189
- isCollapsed,
190
- onSectionToggle,
191
- expandedSection,
192
- favoriteItems,
193
- currentPath,
194
- onFavoriteClick,
195
- onUnfavoriteClick,
196
- hasFavorites,
197
- sectionName,
198
- useNativeTitle,
199
- onClick,
200
- }: SidebarItemProps) => {
201
- const theme: IReqoreTheme = useReqoreTheme();
202
-
203
- useMount(() => {
204
- if (
205
- !itemData.element &&
206
- isActiveMulti(itemData.activePaths || [itemData.props?.href], currentPath, itemData.exact)
207
- ) {
208
- onSectionToggle(itemData.name);
209
- }
210
- });
211
-
212
- if (itemData.element) {
213
- const { element: Element } = itemData;
214
-
215
- return (
216
- <Element
217
- isCollapsed={isCollapsed}
218
- backgroundColor={theme.sidebar?.main || theme.main}
219
- textColor={
220
- theme.sidebar?.color ||
221
- getReadableColor(theme, undefined, undefined, true, getMainColor(theme, 'sidebar'))
222
- }
223
- />
224
- );
225
- }
226
-
227
- return (
228
- <>
229
- <SidebarItem
230
- itemData={itemData}
231
- isCollapsed={isCollapsed}
232
- onSectionToggle={itemData.submenu && onSectionToggle}
233
- isExpanded={expandedSection === itemData.name}
234
- currentPath={currentPath}
235
- favoriteItems={favoriteItems}
236
- onFavoriteClick={onFavoriteClick}
237
- onUnfavoriteClick={onUnfavoriteClick}
238
- sectionName={sectionName}
239
- hasFavorites={hasFavorites}
240
- useNativeTitle={useNativeTitle}
241
- onClick={onClick}
242
- />
243
- {expandedSection === itemData.name &&
244
- map(itemData.submenu, (subItemData: any, key: number) => (
245
- <SidebarItem
246
- itemData={subItemData}
247
- key={key}
248
- isCollapsed={isCollapsed}
249
- subItem
250
- currentPath={currentPath}
251
- favoriteItems={favoriteItems}
252
- onFavoriteClick={onFavoriteClick}
253
- onUnfavoriteClick={onUnfavoriteClick}
254
- sectionName={sectionName}
255
- hasFavorites={hasFavorites}
256
- useNativeTitle={useNativeTitle}
257
- onClick={onClick}
258
- />
259
- ))}
260
- </>
261
- );
262
- };
263
-
264
- export default SidebarItemWrapper;
@@ -1,89 +0,0 @@
1
- import { reduce, size } from 'lodash';
2
- import { IQorusSidebarCustomItem, IQorusSidebarItems } from '../components/Sidebar';
3
-
4
- export const transformMenu = (
5
- menu: IQorusSidebarItems,
6
- bookmarks: string[],
7
- customItems?: IQorusSidebarCustomItem[]
8
- ) => {
9
- let newMenu: IQorusSidebarItems = { ...menu };
10
- let _qorusCustomElements;
11
- let _qorusBookmarks;
12
-
13
- if (size(bookmarks)) {
14
- _qorusBookmarks = {
15
- title: 'Bookmarks',
16
- items: [],
17
- };
18
-
19
- newMenu = reduce(
20
- newMenu,
21
- (cur, menuSection, name: string) => {
22
- const newSection = { ...menuSection };
23
-
24
- newSection.items = [...newSection.items]
25
- .map((newSectionItem) => {
26
- const copySectionItem = { ...newSectionItem };
27
-
28
- if (copySectionItem.submenu) {
29
- copySectionItem.submenu = copySectionItem.submenu.filter((submenuItem) => {
30
- const isItemInSubmenu = bookmarks.find(
31
- (favoriteItem) => favoriteItem === submenuItem.id
32
- );
33
-
34
- if (isItemInSubmenu) {
35
- _qorusBookmarks.items.push(submenuItem);
36
- }
37
-
38
- return !isItemInSubmenu;
39
- });
40
-
41
- if (size(copySectionItem.submenu)) {
42
- return copySectionItem;
43
- } else {
44
- return undefined;
45
- }
46
- } else {
47
- if (!bookmarks.find((favoriteItem) => favoriteItem === copySectionItem.id)) {
48
- return copySectionItem;
49
- } else {
50
- _qorusBookmarks.items.push(copySectionItem);
51
- return undefined;
52
- }
53
- }
54
- })
55
- .filter((newSectionItem) => newSectionItem);
56
-
57
- return { ...cur, [name]: newSection };
58
- },
59
- {}
60
- );
61
-
62
- newMenu = { _qorusBookmarks, ...newMenu };
63
- }
64
-
65
- if (size(customItems)) {
66
- _qorusCustomElements = {
67
- items: customItems,
68
- };
69
-
70
- newMenu = { _qorusCustomElements, ...newMenu };
71
- }
72
-
73
- return newMenu;
74
- };
75
-
76
- export const isActive = (to: string, currentPath: string, exact?: boolean): boolean =>
77
- exact ? currentPath === to : currentPath.startsWith(to);
78
-
79
- export const isActiveMulti = (to: string[], currentPath: string, exact?: boolean): boolean => {
80
- let active: boolean = false;
81
-
82
- to.forEach((path: string) => {
83
- if (isActive(path, currentPath, exact)) {
84
- active = true;
85
- }
86
- });
87
-
88
- return active;
89
- };
@@ -1,97 +0,0 @@
1
- import { StoryFn, StoryObj } from '@storybook/react';
2
- import { noop } from 'lodash';
3
- import { IQorusSidebarProps } from '../../components/Sidebar';
4
- import { ReqorePanel, ReqoreSidebar } from '../../index';
5
- import { qorusSidebarItems } from '../../mock/menu';
6
- import { StoryMeta } from '../utils';
7
- import { FlatArg, NoContentArg, argManager } from '../utils/args';
8
-
9
- const { disableArg, createArg } = argManager<IQorusSidebarProps>();
10
-
11
- const meta = {
12
- title: 'Navigation/Sidebar/Stories',
13
- component: ReqoreSidebar,
14
- args: {
15
- path: '/',
16
- floating: false,
17
- bordered: false,
18
- isOpen: false,
19
- position: 'left',
20
- withoutContent: true,
21
- },
22
- argTypes: {
23
- ...disableArg('items'),
24
- ...FlatArg,
25
- ...createArg('path', {
26
- defaultValue: '/',
27
- name: 'Path',
28
- description: 'Mock location path',
29
- type: 'string',
30
- }),
31
- ...createArg('floating', {
32
- control: 'boolean',
33
- defaultValue: false,
34
- name: 'Floating',
35
- description: 'If the sidebar should be floating',
36
- }),
37
- ...createArg('bordered', {
38
- control: 'boolean',
39
- defaultValue: false,
40
- name: 'Bordered',
41
- description: 'If the sidebar should be bordered',
42
- }),
43
- ...createArg('isOpen', {
44
- control: 'boolean',
45
- defaultValue: false,
46
- name: 'Is Open',
47
- description: 'If the sidebar should be shown when floating',
48
- }),
49
- ...createArg('position', {
50
- control: 'select',
51
- options: ['left', 'right'],
52
- defaultValue: 'left',
53
- name: 'Sidebar position',
54
- description: 'Sidebar positions - this decides which border is drawn',
55
- }),
56
- ...NoContentArg,
57
- },
58
- } as StoryMeta<typeof ReqoreSidebar>;
59
-
60
- export default meta;
61
- type Story = StoryObj<typeof meta>;
62
-
63
- const Template: StoryFn<IQorusSidebarProps> = (args: IQorusSidebarProps) => {
64
- return (
65
- <ReqoreSidebar
66
- {...args}
67
- items={qorusSidebarItems}
68
- bookmarks={['submenu-item-2', 'another-item-1']}
69
- onBookmarksChange={noop}
70
- customItems={[
71
- {
72
- element: () => (
73
- <div style={{ padding: '10px' }}>
74
- <ReqorePanel intent='info' flat opacity={0.5}>
75
- Hello I am a custom element!
76
- </ReqorePanel>
77
- </div>
78
- ),
79
- },
80
- ]}
81
- />
82
- );
83
- };
84
-
85
- export const Basic: Story = {
86
- render: Template,
87
- };
88
-
89
- export const Floating: Story = {
90
- render: Template,
91
-
92
- args: {
93
- floating: true,
94
- isOpen: true,
95
- hasFloatingBackdrop: true,
96
- },
97
- };