orcs-design-system 3.3.39 → 3.3.41
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/es/components/Divider/index.js +1 -1
- package/es/components/Icon/index.js +45 -27
- package/es/components/Popover/index.js +9 -1
- package/es/components/SideNavV2/NavItem.js +231 -0
- package/es/components/SideNavV2/SideNav.js +295 -0
- package/es/components/SideNavV2/SideNavV2.stories.js +382 -0
- package/es/components/SideNavV2/__tests__/resize.test.js +129 -0
- package/es/components/SideNavV2/__tests__/sections.test.js +333 -0
- package/es/components/SideNavV2/components/BaseSection.js +178 -0
- package/es/components/SideNavV2/components/CurrentViewSectionPortalTarget.js +35 -0
- package/es/components/SideNavV2/components/ExpandedPanel.js +161 -0
- package/es/components/SideNavV2/components/ItemSection.js +156 -0
- package/es/components/SideNavV2/components/PanelControl.js +128 -0
- package/es/components/SideNavV2/components/RenderCurrentViewSection.js +39 -0
- package/es/components/SideNavV2/components/index.js +4 -0
- package/es/components/SideNavV2/constants/sideNav.js +21 -0
- package/es/components/SideNavV2/context/SideNavStateProvider.js +57 -0
- package/es/components/SideNavV2/hooks/index.js +3 -0
- package/es/components/SideNavV2/hooks/useResize.js +70 -0
- package/es/components/SideNavV2/hooks/useResponsive.js +32 -0
- package/es/components/SideNavV2/hooks/useSideNavState.js +88 -0
- package/es/components/SideNavV2/index.js +3 -0
- package/es/components/SideNavV2/sections/SideNavCurrentViewSection.js +124 -0
- package/es/components/SideNavV2/sections/SideNavPinnedSection.js +125 -0
- package/es/components/SideNavV2/sections/SideNavTeamsSection.js +91 -0
- package/es/components/SideNavV2/styles/SideNavV2.styles.js +156 -0
- package/es/components/SideNavV2/types/sideNav.js +53 -0
- package/es/components/SideNavV2/utils/index.js +2 -0
- package/es/components/SideNavV2/utils/itemUtils.js +51 -0
- package/es/components/SideNavV2/utils/resizeUtils.js +57 -0
- package/es/components/StatusDot/StatusDot.stories.js +59 -72
- package/es/components/StatusDot/index.js +14 -5
- package/es/components.test.js +4 -0
- package/es/index.js +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { action } from "@storybook/addon-actions";
|
|
4
|
+
import SideNavV2, { SideNavStateProvider } from "./index";
|
|
5
|
+
import { BrowserRouter as Router, Route, Link, useLocation, matchPath, Switch, Redirect, useParams } from "react-router-dom";
|
|
6
|
+
import { H5, P } from "../Typography";
|
|
7
|
+
import Box from "../Box";
|
|
8
|
+
import { far } from "@fortawesome/free-regular-svg-icons";
|
|
9
|
+
import { library } from "@fortawesome/fontawesome-svg-core";
|
|
10
|
+
import Flex from "../Flex";
|
|
11
|
+
import Spacer from "../Spacer/index";
|
|
12
|
+
import Card from "../Card/index";
|
|
13
|
+
import Badge from "../Badge/index";
|
|
14
|
+
import RenderCurrentViewSection from "./components/RenderCurrentViewSection";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
|
+
library.add(far);
|
|
17
|
+
export default {
|
|
18
|
+
title: "Components/SideNavV2",
|
|
19
|
+
decorators: [storyFn => /*#__PURE__*/_jsx(Box, {
|
|
20
|
+
minHeight: "100vh",
|
|
21
|
+
bg: "greyLightest",
|
|
22
|
+
boxBorder: "default",
|
|
23
|
+
children: storyFn()
|
|
24
|
+
})],
|
|
25
|
+
component: SideNavV2
|
|
26
|
+
};
|
|
27
|
+
const makeLinkComponent = path => _ref => {
|
|
28
|
+
let {
|
|
29
|
+
children,
|
|
30
|
+
item
|
|
31
|
+
} = _ref;
|
|
32
|
+
return /*#__PURE__*/_jsx(Link, {
|
|
33
|
+
to: path,
|
|
34
|
+
"aria-label": item.name,
|
|
35
|
+
children: children
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const makePanelComponent = (name, children) => () => {
|
|
39
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
40
|
+
children: [/*#__PURE__*/_jsx(H5, {
|
|
41
|
+
fontWeight: "bold",
|
|
42
|
+
mb: "r",
|
|
43
|
+
children: name
|
|
44
|
+
}), /*#__PURE__*/_jsxs(P, {
|
|
45
|
+
children: [name, " content"]
|
|
46
|
+
}), children]
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const teams = {
|
|
50
|
+
"nebula-ui": {
|
|
51
|
+
name: "Nebula UI",
|
|
52
|
+
avatar: "https://images.unsplash.com/photo-1688413399498-e35ed74b554f?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OHx8c3BhY2VzaGlwJTIwZGlnaXRhbCUyMHNjcmVlbnxlbnwwfHwwfHx8MA%3D%3D",
|
|
53
|
+
shape: "square",
|
|
54
|
+
type: "Team"
|
|
55
|
+
},
|
|
56
|
+
design: {
|
|
57
|
+
name: "Design",
|
|
58
|
+
avatar: "https://images.unsplash.com/photo-1602576666092-bf6447a729fc?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8dWklMjBkZXNpZ258ZW58MHx8MHx8fDA%3D",
|
|
59
|
+
shape: "square",
|
|
60
|
+
type: "Team"
|
|
61
|
+
},
|
|
62
|
+
blackhole: {
|
|
63
|
+
name: "Blackhole",
|
|
64
|
+
avatar: "https://plus.unsplash.com/premium_photo-1690571200236-0f9098fc6ca9?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8YmxhY2tob2xlfGVufDB8fDB8fHww",
|
|
65
|
+
shape: "square",
|
|
66
|
+
type: "Team"
|
|
67
|
+
},
|
|
68
|
+
engineering: {
|
|
69
|
+
name: "Engineering",
|
|
70
|
+
avatar: "https://images.unsplash.com/photo-1515879218367-8466d910aaa4?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHx8MA%3D%3D",
|
|
71
|
+
shape: "square",
|
|
72
|
+
type: "Team"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const getViewingState = teamId => {
|
|
76
|
+
return {
|
|
77
|
+
name: teams[teamId].name,
|
|
78
|
+
avatar: teams[teamId].avatar,
|
|
79
|
+
shape: teams[teamId].shape,
|
|
80
|
+
badge: teams[teamId].type && /*#__PURE__*/_jsx(Badge, {
|
|
81
|
+
variant: "success",
|
|
82
|
+
children: teams[teamId].type
|
|
83
|
+
}),
|
|
84
|
+
subNav: [{
|
|
85
|
+
name: "Overview",
|
|
86
|
+
link: `/teams/${teamId}/overview`
|
|
87
|
+
}, {
|
|
88
|
+
name: "Org chart",
|
|
89
|
+
link: `/teams/${teamId}/org-chart`
|
|
90
|
+
}, {
|
|
91
|
+
name: "Strategy",
|
|
92
|
+
link: `/teams/${teamId}/strategy`
|
|
93
|
+
}, {
|
|
94
|
+
name: "Allocations",
|
|
95
|
+
link: `/teams/${teamId}/allocations`
|
|
96
|
+
}, {
|
|
97
|
+
name: "Planning",
|
|
98
|
+
link: `/teams/${teamId}/planning`
|
|
99
|
+
}, {
|
|
100
|
+
name: "Forecast",
|
|
101
|
+
link: `/teams/${teamId}/forecast`
|
|
102
|
+
}, {
|
|
103
|
+
name: "Team interactions",
|
|
104
|
+
link: `/teams/${teamId}/interactions`
|
|
105
|
+
}, {
|
|
106
|
+
name: "History",
|
|
107
|
+
link: `/teams/${teamId}/history`
|
|
108
|
+
}]
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const getPeopleState = personId => {
|
|
112
|
+
return {
|
|
113
|
+
name: "James Merrit",
|
|
114
|
+
badge: /*#__PURE__*/_jsx(Badge, {
|
|
115
|
+
variant: "success",
|
|
116
|
+
children: "Engineer"
|
|
117
|
+
}),
|
|
118
|
+
avatar: "https://randomuser.me/api/portraits/men/24.jpg",
|
|
119
|
+
shape: "circle",
|
|
120
|
+
subNav: [{
|
|
121
|
+
name: "Details",
|
|
122
|
+
link: `/people/${personId}/details`
|
|
123
|
+
}, {
|
|
124
|
+
name: "Allocations",
|
|
125
|
+
link: `/people/${personId}/allocations`
|
|
126
|
+
}, {
|
|
127
|
+
name: "History",
|
|
128
|
+
link: `/people/${personId}/history`
|
|
129
|
+
}]
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const Teams = () => {
|
|
133
|
+
const params = useParams();
|
|
134
|
+
const viewing = useMemo(() => getViewingState(params.teamId), [params.teamId]);
|
|
135
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
136
|
+
children: ["Team ", params.teamId, " route", /*#__PURE__*/_jsx(RenderCurrentViewSection, {
|
|
137
|
+
viewingState: viewing
|
|
138
|
+
}), /*#__PURE__*/_jsx(Switch, {
|
|
139
|
+
children: /*#__PURE__*/_jsx(Route, {
|
|
140
|
+
path: "/teams/:teamId/:subRoute",
|
|
141
|
+
render: routeProps => /*#__PURE__*/_jsxs("div", {
|
|
142
|
+
children: ["SUB ROUTE ", routeProps.match.params.subRoute, " route"]
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})]
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const People = () => {
|
|
149
|
+
const params = useParams();
|
|
150
|
+
const viewing = useMemo(() => getPeopleState(params.personId), [params.personId]);
|
|
151
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
152
|
+
children: ["People ", params.personId, " route", /*#__PURE__*/_jsx(RenderCurrentViewSection, {
|
|
153
|
+
viewingState: viewing
|
|
154
|
+
}), /*#__PURE__*/_jsx(Switch, {
|
|
155
|
+
children: /*#__PURE__*/_jsx(Route, {
|
|
156
|
+
path: "/people/:personId/:subRoute",
|
|
157
|
+
render: routeProps => /*#__PURE__*/_jsxs("div", {
|
|
158
|
+
children: ["SUB ROUTE ", routeProps.match.params.subRoute, " route", /*#__PURE__*/_jsx(Switch, {
|
|
159
|
+
children: /*#__PURE__*/_jsx(Route, {
|
|
160
|
+
path: "/details",
|
|
161
|
+
render: () => /*#__PURE__*/_jsx("div", {
|
|
162
|
+
children: "Details route"
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
})]
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
})]
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const PinnedItem = () => {
|
|
172
|
+
const params = useParams();
|
|
173
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
174
|
+
children: ["Pinned Item: ", params.itemId, " route"]
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
const PageCard = _ref2 => {
|
|
178
|
+
let {
|
|
179
|
+
children
|
|
180
|
+
} = _ref2;
|
|
181
|
+
return /*#__PURE__*/_jsx(Spacer, {
|
|
182
|
+
px: "r",
|
|
183
|
+
children: /*#__PURE__*/_jsx(Card, {
|
|
184
|
+
children: children
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
const yourTeams = [{
|
|
189
|
+
avatar: "https://plus.unsplash.com/premium_photo-1690571200236-0f9098fc6ca9?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8YmxhY2tob2xlfGVufDB8fDB8fHww",
|
|
190
|
+
name: "Blackhole",
|
|
191
|
+
link: "/teams/blackhole/overview"
|
|
192
|
+
}, {
|
|
193
|
+
avatar: "https://images.unsplash.com/photo-1602576666092-bf6447a729fc?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8dWklMjBkZXNpZ258ZW58MHx8MHx8fDA%3D",
|
|
194
|
+
name: "Design",
|
|
195
|
+
link: "/teams/design/overview"
|
|
196
|
+
}];
|
|
197
|
+
const pinnedItems = [{
|
|
198
|
+
avatar: "https://images.unsplash.com/photo-1515879218367-8466d910aaa4?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8Y29kZXxlbnwwfHwwfHx8MA%3D%3D",
|
|
199
|
+
name: "Engineering",
|
|
200
|
+
link: "/teams/engineering/overview",
|
|
201
|
+
shape: "square",
|
|
202
|
+
onUnpin: action("unpin-engineering")
|
|
203
|
+
}, {
|
|
204
|
+
avatar: "https://images.unsplash.com/photo-1556741533-e228ee50f8b8?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDF8MHxzZWFyY2h8MXx8Y3VzdG9tZXJ8ZW58MHx8MHx8fDA%3D",
|
|
205
|
+
name: "Customer Journey",
|
|
206
|
+
link: "/pinned/new-account",
|
|
207
|
+
shape: "hexagon",
|
|
208
|
+
onUnpin: action("unpin-customer-journey")
|
|
209
|
+
}, {
|
|
210
|
+
avatar: "https://randomuser.me/api/portraits/men/24.jpg",
|
|
211
|
+
name: "James Merrit",
|
|
212
|
+
link: "/people/james-merrit/details",
|
|
213
|
+
onUnpin: action("unpin-james-merrit"),
|
|
214
|
+
shape: "circle"
|
|
215
|
+
}];
|
|
216
|
+
const SideBarWithConfig = () => {
|
|
217
|
+
const location = useLocation();
|
|
218
|
+
const items = [{
|
|
219
|
+
iconName: "building",
|
|
220
|
+
name: "Home",
|
|
221
|
+
component: makeLinkComponent("/"),
|
|
222
|
+
actionType: "link",
|
|
223
|
+
isActive: matchPath(location.pathname, {
|
|
224
|
+
path: "/",
|
|
225
|
+
exact: true
|
|
226
|
+
})
|
|
227
|
+
}, {
|
|
228
|
+
iconName: "user",
|
|
229
|
+
name: "My profile",
|
|
230
|
+
component: makeLinkComponent("/profile"),
|
|
231
|
+
actionType: "link",
|
|
232
|
+
isActive: matchPath(location.pathname, {
|
|
233
|
+
path: "/profile"
|
|
234
|
+
})
|
|
235
|
+
}, {
|
|
236
|
+
iconName: "id-card",
|
|
237
|
+
name: "Search Page",
|
|
238
|
+
component: makeLinkComponent("/search"),
|
|
239
|
+
actionType: "link",
|
|
240
|
+
isActive: matchPath(location.pathname, {
|
|
241
|
+
path: "/search"
|
|
242
|
+
})
|
|
243
|
+
}, {
|
|
244
|
+
iconName: "snowflake",
|
|
245
|
+
name: "Filter",
|
|
246
|
+
hide: !matchPath(location.pathname, {
|
|
247
|
+
path: "/search"
|
|
248
|
+
}),
|
|
249
|
+
// Specify hide if you want to hide this item
|
|
250
|
+
component: makePanelComponent("Filter"),
|
|
251
|
+
actionType: "component",
|
|
252
|
+
// Use 'component' for a component
|
|
253
|
+
pageSpecific: matchPath(location.pathname, {
|
|
254
|
+
path: "/search"
|
|
255
|
+
}),
|
|
256
|
+
isExpandedByDefault: true
|
|
257
|
+
}, {
|
|
258
|
+
iconName: "sun",
|
|
259
|
+
name: "People",
|
|
260
|
+
hide: !matchPath(location.pathname, {
|
|
261
|
+
path: "/profile"
|
|
262
|
+
}),
|
|
263
|
+
// Specify hide if you want to hide this item
|
|
264
|
+
component: makePanelComponent("People"),
|
|
265
|
+
actionType: "component",
|
|
266
|
+
// Use 'component' for a component
|
|
267
|
+
pageSpecific: matchPath(location.pathname, {
|
|
268
|
+
path: "/profile"
|
|
269
|
+
}),
|
|
270
|
+
isExpandedByDefault: true
|
|
271
|
+
}, {
|
|
272
|
+
iconName: "bell",
|
|
273
|
+
name: "Notifications",
|
|
274
|
+
badgeNumber: "3",
|
|
275
|
+
// Specify a badgeNumber if you want to have a count on this item
|
|
276
|
+
component: makePanelComponent("Notifications"),
|
|
277
|
+
actionType: "component" // Use 'component' for a component
|
|
278
|
+
}, {
|
|
279
|
+
iconName: "chart-bar",
|
|
280
|
+
name: "Browse teams",
|
|
281
|
+
large: true,
|
|
282
|
+
// Specify large if you want the expanded sidebar to be wider
|
|
283
|
+
component: makePanelComponent("BrowseTeams", /*#__PURE__*/_jsx(Flex, {
|
|
284
|
+
flexDirection: "column",
|
|
285
|
+
children: Object.keys(teams).map(team => /*#__PURE__*/_jsx(Link, {
|
|
286
|
+
to: `/teams/${team}/overview`,
|
|
287
|
+
children: team
|
|
288
|
+
}, team))
|
|
289
|
+
})),
|
|
290
|
+
actionType: "component" // Use 'component' for a component
|
|
291
|
+
}, {
|
|
292
|
+
iconName: "cog",
|
|
293
|
+
name: "Settings",
|
|
294
|
+
hide: true,
|
|
295
|
+
// Specify hide if you want to hide this item
|
|
296
|
+
bottomAligned: true,
|
|
297
|
+
component: makePanelComponent("Settings"),
|
|
298
|
+
actionType: "component" // Use 'component' for a component
|
|
299
|
+
}, {
|
|
300
|
+
iconName: "calendar-alt",
|
|
301
|
+
name: "Calendar",
|
|
302
|
+
pageSpecific: true,
|
|
303
|
+
// Specify pageSpecific if you want this item to appear below a divider line separating common nav items from page/route specific items
|
|
304
|
+
component: makePanelComponent("Calendar"),
|
|
305
|
+
actionType: "component" // Use 'component' for a component
|
|
306
|
+
}, {
|
|
307
|
+
iconName: "star",
|
|
308
|
+
name: "Announcements",
|
|
309
|
+
badgeDot: true,
|
|
310
|
+
// Specify if you want to have a blue notification dot on this item
|
|
311
|
+
bottomAligned: true,
|
|
312
|
+
// Specify bottomAligned if this item should appear at bottom of SideNav
|
|
313
|
+
component: makePanelComponent("Announcements"),
|
|
314
|
+
actionType: "component" // Use 'component' for a component
|
|
315
|
+
}, {
|
|
316
|
+
iconName: "times-circle",
|
|
317
|
+
name: "Logout",
|
|
318
|
+
bottomAligned: true,
|
|
319
|
+
// Specify bottomAligned if this item should appear at bottom of SideNav
|
|
320
|
+
onClick: () => alert("Logout function"),
|
|
321
|
+
// Specify the onClick function for the button
|
|
322
|
+
actionType: "button" // Use 'button' for a button with onClick event
|
|
323
|
+
}
|
|
324
|
+
// Add more items as needed...
|
|
325
|
+
];
|
|
326
|
+
return /*#__PURE__*/_jsx(Flex, {
|
|
327
|
+
height: "100vh",
|
|
328
|
+
children: /*#__PURE__*/_jsxs(SideNavStateProvider, {
|
|
329
|
+
children: [/*#__PURE__*/_jsx(SideNavV2, {
|
|
330
|
+
items: items,
|
|
331
|
+
yourTeams: yourTeams,
|
|
332
|
+
pinnedItems: pinnedItems
|
|
333
|
+
}), /*#__PURE__*/_jsxs(Switch, {
|
|
334
|
+
children: [/*#__PURE__*/_jsx(Route, {
|
|
335
|
+
exact: true,
|
|
336
|
+
path: "/",
|
|
337
|
+
children: /*#__PURE__*/_jsx(PageCard, {
|
|
338
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
339
|
+
children: "Home"
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
343
|
+
path: "/profile",
|
|
344
|
+
children: /*#__PURE__*/_jsx(PageCard, {
|
|
345
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
346
|
+
children: "Profile route"
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
350
|
+
path: "/teams/:teamId",
|
|
351
|
+
children: /*#__PURE__*/_jsx(PageCard, {
|
|
352
|
+
children: /*#__PURE__*/_jsx(Teams, {})
|
|
353
|
+
})
|
|
354
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
355
|
+
path: "/pinned/:itemId",
|
|
356
|
+
children: /*#__PURE__*/_jsx(PageCard, {
|
|
357
|
+
children: /*#__PURE__*/_jsx(PinnedItem, {})
|
|
358
|
+
})
|
|
359
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
360
|
+
path: "/people/:personId",
|
|
361
|
+
children: /*#__PURE__*/_jsx(PageCard, {
|
|
362
|
+
children: /*#__PURE__*/_jsx(People, {})
|
|
363
|
+
})
|
|
364
|
+
}), /*#__PURE__*/_jsx(Redirect, {
|
|
365
|
+
from: "/iframe.html",
|
|
366
|
+
to: "/"
|
|
367
|
+
})]
|
|
368
|
+
})]
|
|
369
|
+
})
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
export const SidebarNavigationV2 = () => {
|
|
373
|
+
return /*#__PURE__*/_jsx(Router, {
|
|
374
|
+
children: /*#__PURE__*/_jsx(SideBarWithConfig, {})
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
SidebarNavigationV2.storyName = "Sidebar Navigation";
|
|
378
|
+
SidebarNavigationV2.__docgenInfo = {
|
|
379
|
+
"description": "",
|
|
380
|
+
"methods": [],
|
|
381
|
+
"displayName": "SidebarNavigationV2"
|
|
382
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
import useResize from "../hooks/useResize";
|
|
5
|
+
import { calculateDesktopWidth, calculateMobileHeight } from "../utils/resizeUtils";
|
|
6
|
+
|
|
7
|
+
// Mock the resize utilities
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
jest.mock("../utils/resizeUtils", () => ({
|
|
10
|
+
calculateDesktopWidth: jest.fn(),
|
|
11
|
+
calculateMobileHeight: jest.fn(),
|
|
12
|
+
applyResizeCursor: jest.fn(),
|
|
13
|
+
removeResizeCursor: jest.fn()
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
// Test component to use the hook
|
|
17
|
+
const TestComponent = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
expandedRef,
|
|
20
|
+
isSmallScreen,
|
|
21
|
+
expandedItem,
|
|
22
|
+
onWidthChange
|
|
23
|
+
} = _ref;
|
|
24
|
+
const resizeHandlers = useResize(expandedRef, isSmallScreen, expandedItem, onWidthChange);
|
|
25
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
26
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
27
|
+
"data-testid": "resize-handle",
|
|
28
|
+
onMouseDown: resizeHandlers.handleResizeStart
|
|
29
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
30
|
+
"data-testid": "resize-status",
|
|
31
|
+
children: resizeHandlers.isResizing ? "resizing" : "not-resizing"
|
|
32
|
+
})]
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
describe("useResize hook", () => {
|
|
36
|
+
let mockExpandedRef;
|
|
37
|
+
let mockOnWidthChange;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
mockExpandedRef = {
|
|
40
|
+
current: {
|
|
41
|
+
style: {
|
|
42
|
+
height: "300px"
|
|
43
|
+
},
|
|
44
|
+
offsetHeight: 300,
|
|
45
|
+
parentElement: {
|
|
46
|
+
querySelector: jest.fn().mockReturnValue({
|
|
47
|
+
getBoundingClientRect: () => ({
|
|
48
|
+
right: 200
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
mockOnWidthChange = jest.fn();
|
|
55
|
+
|
|
56
|
+
// Reset mocks
|
|
57
|
+
jest.clearAllMocks();
|
|
58
|
+
});
|
|
59
|
+
it("should initialize with correct default state", () => {
|
|
60
|
+
const {
|
|
61
|
+
getByTestId
|
|
62
|
+
} = render(/*#__PURE__*/_jsx(TestComponent, {
|
|
63
|
+
expandedRef: mockExpandedRef,
|
|
64
|
+
isSmallScreen: false,
|
|
65
|
+
expandedItem: 0,
|
|
66
|
+
onWidthChange: mockOnWidthChange
|
|
67
|
+
}));
|
|
68
|
+
expect(getByTestId("resize-status")).toHaveTextContent("not-resizing");
|
|
69
|
+
});
|
|
70
|
+
it("should handle resize start correctly", () => {
|
|
71
|
+
const {
|
|
72
|
+
getByTestId
|
|
73
|
+
} = render(/*#__PURE__*/_jsx(TestComponent, {
|
|
74
|
+
expandedRef: mockExpandedRef,
|
|
75
|
+
isSmallScreen: false,
|
|
76
|
+
expandedItem: 0,
|
|
77
|
+
onWidthChange: mockOnWidthChange
|
|
78
|
+
}));
|
|
79
|
+
const resizeHandle = getByTestId("resize-handle");
|
|
80
|
+
fireEvent.mouseDown(resizeHandle);
|
|
81
|
+
expect(getByTestId("resize-status")).toHaveTextContent("resizing");
|
|
82
|
+
});
|
|
83
|
+
it("should call onWidthChange when resizing on desktop", () => {
|
|
84
|
+
calculateDesktopWidth.mockReturnValue(400);
|
|
85
|
+
const {
|
|
86
|
+
getByTestId
|
|
87
|
+
} = render(/*#__PURE__*/_jsx(TestComponent, {
|
|
88
|
+
expandedRef: mockExpandedRef,
|
|
89
|
+
isSmallScreen: false,
|
|
90
|
+
expandedItem: 0,
|
|
91
|
+
onWidthChange: mockOnWidthChange
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
// Start resizing
|
|
95
|
+
const resizeHandle = getByTestId("resize-handle");
|
|
96
|
+
fireEvent.mouseDown(resizeHandle);
|
|
97
|
+
|
|
98
|
+
// Simulate mouse move
|
|
99
|
+
fireEvent.mouseMove(document, {
|
|
100
|
+
clientX: 600
|
|
101
|
+
});
|
|
102
|
+
expect(calculateDesktopWidth).toHaveBeenCalledWith(600, expect.any(Object));
|
|
103
|
+
expect(mockOnWidthChange).toHaveBeenCalledWith(400);
|
|
104
|
+
});
|
|
105
|
+
it("should handle mobile resize correctly", () => {
|
|
106
|
+
calculateMobileHeight.mockReturnValue(250);
|
|
107
|
+
const {
|
|
108
|
+
getByTestId
|
|
109
|
+
} = render(/*#__PURE__*/_jsx(TestComponent, {
|
|
110
|
+
expandedRef: mockExpandedRef,
|
|
111
|
+
isSmallScreen: true,
|
|
112
|
+
expandedItem: 0,
|
|
113
|
+
onWidthChange: mockOnWidthChange
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
// Start resizing
|
|
117
|
+
const resizeHandle = getByTestId("resize-handle");
|
|
118
|
+
fireEvent.mouseDown(resizeHandle, {
|
|
119
|
+
clientY: 100
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Simulate mouse move
|
|
123
|
+
fireEvent.mouseMove(document, {
|
|
124
|
+
clientY: 150
|
|
125
|
+
});
|
|
126
|
+
expect(calculateMobileHeight).toHaveBeenCalledWith(150, 100, 300);
|
|
127
|
+
expect(mockExpandedRef.current.style.height).toBe("250px");
|
|
128
|
+
});
|
|
129
|
+
});
|