@chayns-components/navigation 5.0.64 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/navigation-layout/NavigationLayout.constants.js +14 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.constants.js.map +1 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.context.js +26 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.context.js.map +1 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.js +105 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.js.map +1 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.styles.js +74 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.types.js +6 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.types.js.map +1 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.utils.js +261 -0
- package/lib/cjs/components/navigation-layout/NavigationLayout.utils.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.js +31 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.styles.js +30 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.types.js +6 -0
- package/lib/cjs/components/navigation-layout/navigation-header/NavigationHeader.types.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.js +71 -0
- package/lib/cjs/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.styles.js +19 -0
- package/lib/cjs/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.context.js +26 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.context.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.js +140 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.js +89 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.js +6 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.js +83 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.js +17 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.js +19 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.js +26 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.js +129 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.js +79 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.styles.js +69 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.hooks.js +265 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.hooks.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.js +193 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.styles.js +132 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.styles.js.map +1 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.utils.js +78 -0
- package/lib/cjs/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.utils.js.map +1 -0
- package/lib/cjs/components/split-layout/SplitLayout.js +90 -0
- package/lib/cjs/components/split-layout/SplitLayout.js.map +1 -0
- package/lib/cjs/components/split-layout/SplitLayout.styles.js +44 -0
- package/lib/cjs/components/split-layout/SplitLayout.styles.js.map +1 -0
- package/lib/cjs/components/split-layout/SplitLayout.types.js +12 -0
- package/lib/cjs/components/split-layout/SplitLayout.types.js.map +1 -0
- package/lib/cjs/components/split-layout/SplitLayout.utils.js +25 -0
- package/lib/cjs/components/split-layout/SplitLayout.utils.js.map +1 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.hooks.js +63 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.hooks.js.map +1 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.js +34 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.js.map +1 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.styles.js +58 -0
- package/lib/cjs/components/split-layout/resize-handle/ResizeHandle.styles.js.map +1 -0
- package/lib/cjs/components/user-image/UserImage.js +38 -0
- package/lib/cjs/components/user-image/UserImage.js.map +1 -0
- package/lib/cjs/components/user-image/UserImage.types.js +6 -0
- package/lib/cjs/components/user-image/UserImage.types.js.map +1 -0
- package/lib/cjs/components/user-image/userImage.styles.js +27 -0
- package/lib/cjs/components/user-image/userImage.styles.js.map +1 -0
- package/lib/cjs/index.js +49 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/components/navigation-layout/NavigationLayout.constants.js +8 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.constants.js.map +1 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.context.js +17 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.context.js.map +1 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.js +97 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.js.map +1 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.styles.js +67 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.types.js +2 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.types.js.map +1 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.utils.js +251 -0
- package/lib/esm/components/navigation-layout/NavigationLayout.utils.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.js +24 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.styles.js +23 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.types.js +2 -0
- package/lib/esm/components/navigation-layout/navigation-header/NavigationHeader.types.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.js +64 -0
- package/lib/esm/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.styles.js +12 -0
- package/lib/esm/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.context.js +17 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.context.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.js +132 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.js +82 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.js +2 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.js +73 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.js +10 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.js +12 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.js +17 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.js +119 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.js +71 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.styles.js +62 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.hooks.js +257 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.hooks.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.js +186 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.styles.js +126 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.styles.js.map +1 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.utils.js +67 -0
- package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.utils.js.map +1 -0
- package/lib/esm/components/split-layout/SplitLayout.js +80 -0
- package/lib/esm/components/split-layout/SplitLayout.js.map +1 -0
- package/lib/esm/components/split-layout/SplitLayout.styles.js +37 -0
- package/lib/esm/components/split-layout/SplitLayout.styles.js.map +1 -0
- package/lib/esm/components/split-layout/SplitLayout.types.js +6 -0
- package/lib/esm/components/split-layout/SplitLayout.types.js.map +1 -0
- package/lib/esm/components/split-layout/SplitLayout.utils.js +17 -0
- package/lib/esm/components/split-layout/SplitLayout.utils.js.map +1 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.hooks.js +54 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.hooks.js.map +1 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.js +27 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.js.map +1 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.styles.js +52 -0
- package/lib/esm/components/split-layout/resize-handle/ResizeHandle.styles.js.map +1 -0
- package/lib/esm/components/user-image/UserImage.js +31 -0
- package/lib/esm/components/user-image/UserImage.js.map +1 -0
- package/lib/esm/components/user-image/UserImage.types.js +2 -0
- package/lib/esm/components/user-image/UserImage.types.js.map +1 -0
- package/lib/esm/components/user-image/userImage.styles.js +20 -0
- package/lib/esm/components/user-image/userImage.styles.js.map +1 -0
- package/lib/esm/index.js +15 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/types/components/navigation-layout/NavigationLayout.constants.d.ts +7 -0
- package/lib/types/components/navigation-layout/NavigationLayout.context.d.ts +15 -0
- package/lib/types/components/navigation-layout/NavigationLayout.d.ts +4 -0
- package/lib/types/components/navigation-layout/NavigationLayout.styles.d.ts +19 -0
- package/lib/types/components/navigation-layout/NavigationLayout.types.d.ts +125 -0
- package/lib/types/components/navigation-layout/NavigationLayout.utils.d.ts +22 -0
- package/lib/types/components/navigation-layout/navigation-header/NavigationHeader.d.ts +4 -0
- package/lib/types/components/navigation-layout/navigation-header/NavigationHeader.styles.d.ts +9 -0
- package/lib/types/components/navigation-layout/navigation-header/NavigationHeader.types.d.ts +10 -0
- package/lib/types/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.d.ts +8 -0
- package/lib/types/components/navigation-layout/navigation-header/menu-toggle/MenuToggle.styles.d.ts +3 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/NavigationSidebar.context.d.ts +19 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/NavigationSidebar.d.ts +4 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.d.ts +27 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.d.ts +54 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.d.ts +22 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.d.ts +6 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.d.ts +6 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.d.ts +22 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.d.ts +9 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.d.ts +26 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.styles.d.ts +9 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.d.ts +10 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.hooks.d.ts +51 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.styles.d.ts +24 -0
- package/lib/types/components/navigation-layout/navigation-sidebar/sidebar-group/sidebar-item/SidebarItem.utils.d.ts +23 -0
- package/lib/types/components/split-layout/SplitLayout.d.ts +4 -0
- package/lib/types/components/split-layout/SplitLayout.styles.d.ts +12 -0
- package/lib/types/components/split-layout/SplitLayout.types.d.ts +19 -0
- package/lib/types/components/split-layout/SplitLayout.utils.d.ts +8 -0
- package/lib/types/components/split-layout/resize-handle/ResizeHandle.d.ts +11 -0
- package/lib/types/components/split-layout/resize-handle/ResizeHandle.hooks.d.ts +9 -0
- package/lib/types/components/split-layout/resize-handle/ResizeHandle.styles.d.ts +15 -0
- package/lib/types/components/user-image/UserImage.d.ts +4 -0
- package/lib/types/components/user-image/UserImage.types.d.ts +8 -0
- package/lib/types/components/user-image/userImage.styles.d.ts +10 -0
- package/lib/types/index.d.ts +10 -2
- package/package.json +3 -3
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useRef, useState, Fragment } from 'react';
|
|
2
|
+
import { StyledMotionNavigationSidebar, StyledMotionNavigationSidebarContentList, StyledMotionNavigationSidebarContent, StyledNavigationSidebarResizeHandle, StyledMotionNavigationSidebarContentWrapper, StyledMotionNavigationSidebarExternalContent } from './NavigationSidebar.styles';
|
|
3
|
+
import { clampSideBarWidth, getNearestSideBarWidth, getSideBarCompactBreakpoint, useGlobalUserSelect } from './NavigationSidebar.utils';
|
|
4
|
+
import SidebarGroup from './sidebar-group/SidebarGroup';
|
|
5
|
+
import SidebarDivider from './sidebar-divider/SidebarDivider';
|
|
6
|
+
import { NavigationSidebarProvider } from './NavigationSidebar.context';
|
|
7
|
+
const NavigationSidebar = ({
|
|
8
|
+
color,
|
|
9
|
+
minWidth,
|
|
10
|
+
maxWidth,
|
|
11
|
+
topContent,
|
|
12
|
+
bottomContent,
|
|
13
|
+
groups,
|
|
14
|
+
selectedItemId,
|
|
15
|
+
onItemClick,
|
|
16
|
+
onSidebarOpen,
|
|
17
|
+
onSidebarClose,
|
|
18
|
+
shouldShowCollapsedLabel,
|
|
19
|
+
isMobile
|
|
20
|
+
}) => {
|
|
21
|
+
const [width, setWidth] = useState(minWidth);
|
|
22
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
23
|
+
const dragStartWidthRef = useRef(minWidth);
|
|
24
|
+
useGlobalUserSelect({
|
|
25
|
+
isDisabled: isDragging
|
|
26
|
+
});
|
|
27
|
+
const isCompact = useMemo(() => isMobile ? false : width < getSideBarCompactBreakpoint({
|
|
28
|
+
minWidth,
|
|
29
|
+
maxWidth
|
|
30
|
+
}), [isMobile, maxWidth, minWidth, width]);
|
|
31
|
+
const handlePanStart = useCallback(() => {
|
|
32
|
+
dragStartWidthRef.current = width;
|
|
33
|
+
setIsDragging(true);
|
|
34
|
+
}, [width]);
|
|
35
|
+
const handlePointerDown = useCallback(event => {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
}, []);
|
|
39
|
+
const handlePan = useCallback((_, info) => {
|
|
40
|
+
setWidth(clampSideBarWidth({
|
|
41
|
+
width: dragStartWidthRef.current + info.offset.x,
|
|
42
|
+
minWidth,
|
|
43
|
+
maxWidth
|
|
44
|
+
}));
|
|
45
|
+
}, [maxWidth, minWidth]);
|
|
46
|
+
const handlePanEnd = useCallback((_, info) => {
|
|
47
|
+
const nextWidth = clampSideBarWidth({
|
|
48
|
+
width: dragStartWidthRef.current + info.offset.x,
|
|
49
|
+
minWidth,
|
|
50
|
+
maxWidth
|
|
51
|
+
});
|
|
52
|
+
const nearestWidth = getNearestSideBarWidth({
|
|
53
|
+
width: nextWidth,
|
|
54
|
+
minWidth,
|
|
55
|
+
maxWidth
|
|
56
|
+
});
|
|
57
|
+
setIsDragging(false);
|
|
58
|
+
setWidth(nearestWidth);
|
|
59
|
+
dragStartWidthRef.current = nearestWidth;
|
|
60
|
+
if (typeof onSidebarOpen === 'function' && nearestWidth === maxWidth) {
|
|
61
|
+
onSidebarOpen();
|
|
62
|
+
}
|
|
63
|
+
if (typeof onSidebarClose === 'function' && nearestWidth === minWidth) {
|
|
64
|
+
onSidebarClose();
|
|
65
|
+
}
|
|
66
|
+
}, [maxWidth, minWidth, onSidebarClose, onSidebarOpen]);
|
|
67
|
+
const {
|
|
68
|
+
pinnedGroups,
|
|
69
|
+
scrollableGroups
|
|
70
|
+
} = useMemo(() => ({
|
|
71
|
+
pinnedGroups: groups.filter(({
|
|
72
|
+
isPinned
|
|
73
|
+
}) => isPinned),
|
|
74
|
+
scrollableGroups: groups.filter(({
|
|
75
|
+
isPinned
|
|
76
|
+
}) => !isPinned)
|
|
77
|
+
}), [groups]);
|
|
78
|
+
const hasPinnedGroups = pinnedGroups.length > 0;
|
|
79
|
+
const hasScrollableGroups = scrollableGroups.length > 0;
|
|
80
|
+
const shouldShowCollapsedSidebarLabel = shouldShowCollapsedLabel && width === minWidth;
|
|
81
|
+
const contextValue = useMemo(() => ({
|
|
82
|
+
color,
|
|
83
|
+
isCompact,
|
|
84
|
+
onItemClick,
|
|
85
|
+
selectedItemId,
|
|
86
|
+
shouldShowCollapsedLabel: shouldShowCollapsedSidebarLabel
|
|
87
|
+
}), [color, isCompact, onItemClick, selectedItemId, shouldShowCollapsedSidebarLabel]);
|
|
88
|
+
const renderGroups = useCallback(groupsToRender => groupsToRender.map(({
|
|
89
|
+
items,
|
|
90
|
+
id,
|
|
91
|
+
isReorderable
|
|
92
|
+
}, index) => /*#__PURE__*/React.createElement(Fragment, {
|
|
93
|
+
key: id
|
|
94
|
+
}, /*#__PURE__*/React.createElement(SidebarGroup, {
|
|
95
|
+
groupId: id,
|
|
96
|
+
items: items,
|
|
97
|
+
isReorderable: isReorderable
|
|
98
|
+
}), index < groupsToRender.length - 1 && /*#__PURE__*/React.createElement(SidebarDivider, {
|
|
99
|
+
color: color
|
|
100
|
+
}))), [color]);
|
|
101
|
+
return /*#__PURE__*/React.createElement(StyledMotionNavigationSidebar, {
|
|
102
|
+
$color: color,
|
|
103
|
+
$isMobile: isMobile,
|
|
104
|
+
initial: false,
|
|
105
|
+
animate: !isMobile ? {
|
|
106
|
+
width
|
|
107
|
+
} : {},
|
|
108
|
+
transition: isDragging ? {
|
|
109
|
+
duration: 0
|
|
110
|
+
} : {
|
|
111
|
+
type: 'spring',
|
|
112
|
+
stiffness: 320,
|
|
113
|
+
damping: 30
|
|
114
|
+
},
|
|
115
|
+
id: "sidebar",
|
|
116
|
+
"data-navigation-sidebar-root": "true"
|
|
117
|
+
}, /*#__PURE__*/React.createElement(NavigationSidebarProvider, {
|
|
118
|
+
value: contextValue
|
|
119
|
+
}, /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarContent, null, !!topContent && /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarExternalContent, null, topContent), /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarContentWrapper, null, hasPinnedGroups && /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarContentList, {
|
|
120
|
+
$isPinned: true
|
|
121
|
+
}, renderGroups(pinnedGroups)), hasPinnedGroups && hasScrollableGroups && /*#__PURE__*/React.createElement(SidebarDivider, {
|
|
122
|
+
color: color
|
|
123
|
+
}), hasScrollableGroups && /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarContentList, null, renderGroups(scrollableGroups))), !!bottomContent && /*#__PURE__*/React.createElement(StyledMotionNavigationSidebarExternalContent, null, bottomContent))), !isMobile && /*#__PURE__*/React.createElement(StyledNavigationSidebarResizeHandle, {
|
|
124
|
+
onPointerDown: handlePointerDown,
|
|
125
|
+
onPanStart: handlePanStart,
|
|
126
|
+
onPan: handlePan,
|
|
127
|
+
onPanEnd: handlePanEnd
|
|
128
|
+
}));
|
|
129
|
+
};
|
|
130
|
+
NavigationSidebar.displayName = 'NavigationSidebar';
|
|
131
|
+
export default NavigationSidebar;
|
|
132
|
+
//# sourceMappingURL=NavigationSidebar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationSidebar.js","names":["React","useCallback","useMemo","useRef","useState","Fragment","StyledMotionNavigationSidebar","StyledMotionNavigationSidebarContentList","StyledMotionNavigationSidebarContent","StyledNavigationSidebarResizeHandle","StyledMotionNavigationSidebarContentWrapper","StyledMotionNavigationSidebarExternalContent","clampSideBarWidth","getNearestSideBarWidth","getSideBarCompactBreakpoint","useGlobalUserSelect","SidebarGroup","SidebarDivider","NavigationSidebarProvider","NavigationSidebar","color","minWidth","maxWidth","topContent","bottomContent","groups","selectedItemId","onItemClick","onSidebarOpen","onSidebarClose","shouldShowCollapsedLabel","isMobile","width","setWidth","isDragging","setIsDragging","dragStartWidthRef","isDisabled","isCompact","handlePanStart","current","handlePointerDown","event","preventDefault","stopPropagation","handlePan","_","info","offset","x","handlePanEnd","nextWidth","nearestWidth","pinnedGroups","scrollableGroups","filter","isPinned","hasPinnedGroups","length","hasScrollableGroups","shouldShowCollapsedSidebarLabel","contextValue","renderGroups","groupsToRender","map","items","id","isReorderable","index","createElement","key","groupId","$color","$isMobile","initial","animate","transition","duration","type","stiffness","damping","value","$isPinned","onPointerDown","onPanStart","onPan","onPanEnd","displayName"],"sources":["../../../../../src/components/navigation-layout/navigation-sidebar/NavigationSidebar.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useMemo,\n useRef,\n useState,\n PointerEvent as ReactPointerEvent,\n Fragment,\n} from 'react';\nimport {\n StyledMotionNavigationSidebar,\n StyledMotionNavigationSidebarContentList,\n StyledMotionNavigationSidebarContent,\n StyledNavigationSidebarResizeHandle,\n StyledMotionNavigationSidebarContentWrapper,\n StyledMotionNavigationSidebarExternalContent,\n} from './NavigationSidebar.styles';\nimport { NavigationSidebarProps } from './NavigationSidebar.types';\nimport {\n clampSideBarWidth,\n getNearestSideBarWidth,\n getSideBarCompactBreakpoint,\n useGlobalUserSelect,\n} from './NavigationSidebar.utils';\nimport { PanInfo } from 'motion';\nimport SidebarGroup from './sidebar-group/SidebarGroup';\nimport SidebarDivider from './sidebar-divider/SidebarDivider';\nimport { NavigationLayoutGroup } from '../NavigationLayout.types';\nimport { NavigationSidebarProvider } from './NavigationSidebar.context';\n\nconst NavigationSidebar: FC<NavigationSidebarProps> = ({\n color,\n minWidth,\n maxWidth,\n topContent,\n bottomContent,\n groups,\n selectedItemId,\n onItemClick,\n onSidebarOpen,\n onSidebarClose,\n shouldShowCollapsedLabel,\n isMobile,\n}) => {\n const [width, setWidth] = useState<number>(minWidth);\n const [isDragging, setIsDragging] = useState<boolean>(false);\n const dragStartWidthRef = useRef<number>(minWidth);\n\n useGlobalUserSelect({ isDisabled: isDragging });\n\n const isCompact = useMemo(\n () => (isMobile ? false : width < getSideBarCompactBreakpoint({ minWidth, maxWidth })),\n [isMobile, maxWidth, minWidth, width],\n );\n\n const handlePanStart = useCallback((): void => {\n dragStartWidthRef.current = width;\n setIsDragging(true);\n }, [width]);\n\n const handlePointerDown = useCallback((event: ReactPointerEvent<HTMLDivElement>): void => {\n event.preventDefault();\n event.stopPropagation();\n }, []);\n\n const handlePan = useCallback(\n (_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void => {\n setWidth(\n clampSideBarWidth({\n width: dragStartWidthRef.current + info.offset.x,\n minWidth,\n maxWidth,\n }),\n );\n },\n [maxWidth, minWidth],\n );\n\n const handlePanEnd = useCallback(\n (_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo): void => {\n const nextWidth = clampSideBarWidth({\n width: dragStartWidthRef.current + info.offset.x,\n minWidth,\n maxWidth,\n });\n\n const nearestWidth = getNearestSideBarWidth({\n width: nextWidth,\n minWidth,\n maxWidth,\n });\n\n setIsDragging(false);\n setWidth(nearestWidth);\n\n dragStartWidthRef.current = nearestWidth;\n\n if (typeof onSidebarOpen === 'function' && nearestWidth === maxWidth) {\n onSidebarOpen();\n }\n\n if (typeof onSidebarClose === 'function' && nearestWidth === minWidth) {\n onSidebarClose();\n }\n },\n [maxWidth, minWidth, onSidebarClose, onSidebarOpen],\n );\n\n const { pinnedGroups, scrollableGroups } = useMemo(\n () => ({\n pinnedGroups: groups.filter(({ isPinned }) => isPinned),\n scrollableGroups: groups.filter(({ isPinned }) => !isPinned),\n }),\n [groups],\n );\n\n const hasPinnedGroups = pinnedGroups.length > 0;\n const hasScrollableGroups = scrollableGroups.length > 0;\n const shouldShowCollapsedSidebarLabel = shouldShowCollapsedLabel && width === minWidth;\n\n const contextValue = useMemo(\n () => ({\n color,\n isCompact,\n onItemClick,\n selectedItemId,\n shouldShowCollapsedLabel: shouldShowCollapsedSidebarLabel,\n }),\n [color, isCompact, onItemClick, selectedItemId, shouldShowCollapsedSidebarLabel],\n );\n\n const renderGroups = useCallback(\n (groupsToRender: NavigationLayoutGroup[]) =>\n groupsToRender.map(({ items, id, isReorderable }, index) => (\n <Fragment key={id}>\n <SidebarGroup groupId={id} items={items} isReorderable={isReorderable} />\n\n {index < groupsToRender.length - 1 && <SidebarDivider color={color} />}\n </Fragment>\n )),\n [color],\n );\n\n return (\n <StyledMotionNavigationSidebar\n $color={color}\n $isMobile={isMobile}\n initial={false}\n animate={!isMobile ? { width } : {}}\n transition={\n isDragging\n ? {\n duration: 0,\n }\n : {\n type: 'spring',\n stiffness: 320,\n damping: 30,\n }\n }\n id=\"sidebar\"\n data-navigation-sidebar-root=\"true\"\n >\n <NavigationSidebarProvider value={contextValue}>\n <StyledMotionNavigationSidebarContent>\n {!!topContent && (\n <StyledMotionNavigationSidebarExternalContent>\n {topContent}\n </StyledMotionNavigationSidebarExternalContent>\n )}\n <StyledMotionNavigationSidebarContentWrapper>\n {hasPinnedGroups && (\n <StyledMotionNavigationSidebarContentList $isPinned>\n {renderGroups(pinnedGroups)}\n </StyledMotionNavigationSidebarContentList>\n )}\n {hasPinnedGroups && hasScrollableGroups && <SidebarDivider color={color} />}\n {hasScrollableGroups && (\n <StyledMotionNavigationSidebarContentList>\n {renderGroups(scrollableGroups)}\n </StyledMotionNavigationSidebarContentList>\n )}\n </StyledMotionNavigationSidebarContentWrapper>\n {!!bottomContent && (\n <StyledMotionNavigationSidebarExternalContent>\n {bottomContent}\n </StyledMotionNavigationSidebarExternalContent>\n )}\n </StyledMotionNavigationSidebarContent>\n </NavigationSidebarProvider>\n {!isMobile && (\n <StyledNavigationSidebarResizeHandle\n onPointerDown={handlePointerDown}\n onPanStart={handlePanStart}\n onPan={handlePan}\n onPanEnd={handlePanEnd}\n />\n )}\n </StyledMotionNavigationSidebar>\n );\n};\n\nNavigationSidebar.displayName = 'NavigationSidebar';\n\nexport default NavigationSidebar;\n"],"mappings":"AAAA,OAAOA,KAAK,IAERC,WAAW,EACXC,OAAO,EACPC,MAAM,EACNC,QAAQ,EAERC,QAAQ,QACL,OAAO;AACd,SACIC,6BAA6B,EAC7BC,wCAAwC,EACxCC,oCAAoC,EACpCC,mCAAmC,EACnCC,2CAA2C,EAC3CC,4CAA4C,QACzC,4BAA4B;AAEnC,SACIC,iBAAiB,EACjBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,mBAAmB,QAChB,2BAA2B;AAElC,OAAOC,YAAY,MAAM,8BAA8B;AACvD,OAAOC,cAAc,MAAM,kCAAkC;AAE7D,SAASC,yBAAyB,QAAQ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,gCAA6B;EAAM,gBAEnClE,KAAA,CAAAqE,aAAA,CAACnD,yBAAyB;IAAC+D,KAAK,EAAEpB;EAAa,gBAC3C7D,KAAA,CAAAqE,aAAA,CAAC7D,oCAAoC,QAChC,CAAC,CAACe,UAAU,iBACTvB,KAAA,CAAAqE,aAAA,CAAC1D,4CAA4C,QACxCY,UACyC,CACjD,eACDvB,KAAA,CAAAqE,aAAA,CAAC3D,2CAA2C,QACvC+C,eAAe,iBACZzD,KAAA,CAAAqE,aAAA,CAAC9D,wCAAwC;IAAC2E,SAAS;EAAA,GAC9CpB,YAAY,CAACT,YAAY,CACY,CAC7C,EACAI,eAAe,IAAIE,mBAAmB,iBAAI3D,KAAA,CAAAqE,aAAA,CAACpD,cAAc;IAACG,KAAK,EAAEA;EAAM,CAAE,CAAC,EAC1EuC,mBAAmB,iBAChB3D,KAAA,CAAAqE,aAAA,CAAC9D,wCAAwC,QACpCuD,YAAY,CAACR,gBAAgB,CACQ,CAEL,CAAC,EAC7C,CAAC,CAAC9B,aAAa,iBACZxB,KAAA,CAAAqE,aAAA,CAAC1D,4CAA4C,QACxCa,aACyC,CAEhB,CACf,CAAC,EAC3B,CAACO,QAAQ,iBACN/B,KAAA,CAAAqE,aAAA,CAAC5D,mCAAmC;IAChC0E,aAAa,EAAE1C,iBAAkB;IACjC2C,UAAU,EAAE7C,cAAe;IAC3B8C,KAAK,EAAExC,SAAU;IACjByC,QAAQ,EAAEpC;EAAa,CAC1B,CAEsB,CAAC;AAExC,CAAC;AAED/B,iBAAiB,CAACoE,WAAW,GAAG,mBAAmB;AAEnD,eAAepE,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
import { motion } from 'motion/react';
|
|
3
|
+
const SCROLLABLE_GROUPS_MIN_HEIGHT = 120;
|
|
4
|
+
export const StyledMotionNavigationSidebar = styled(motion.div)`
|
|
5
|
+
height: 100%;
|
|
6
|
+
color: ${({
|
|
7
|
+
$color
|
|
8
|
+
}) => $color};
|
|
9
|
+
|
|
10
|
+
position: relative;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-shrink: 0;
|
|
13
|
+
min-height: 0;
|
|
14
|
+
overflow: visible;
|
|
15
|
+
z-index: 1;
|
|
16
|
+
padding: 10px;
|
|
17
|
+
|
|
18
|
+
${({
|
|
19
|
+
$isMobile
|
|
20
|
+
}) => $isMobile && css`
|
|
21
|
+
width: 70vw;
|
|
22
|
+
min-width: 70vw;
|
|
23
|
+
max-width: 70vw;
|
|
24
|
+
`}
|
|
25
|
+
`;
|
|
26
|
+
export const StyledMotionNavigationSidebarContent = styled(motion.div)`
|
|
27
|
+
width: 100%;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex: 1 1 auto;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: 2px;
|
|
32
|
+
min-height: 0;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
`;
|
|
35
|
+
export const StyledMotionNavigationSidebarContentWrapper = styled(motion.div)`
|
|
36
|
+
display: flex;
|
|
37
|
+
flex: 1 1 auto;
|
|
38
|
+
flex-direction: column;
|
|
39
|
+
min-height: 0;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
`;
|
|
42
|
+
export const StyledMotionNavigationSidebarExternalContent = styled(motion.div)`
|
|
43
|
+
flex-shrink: 0;
|
|
44
|
+
margin: 4px 0;
|
|
45
|
+
`;
|
|
46
|
+
export const StyledMotionNavigationSidebarContentList = styled(motion.div)`
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-direction: column;
|
|
49
|
+
min-height: 0;
|
|
50
|
+
overflow-x: hidden;
|
|
51
|
+
|
|
52
|
+
${({
|
|
53
|
+
$isPinned
|
|
54
|
+
}) => $isPinned ? css`
|
|
55
|
+
flex: 0 0 auto;
|
|
56
|
+
overflow-y: auto;
|
|
57
|
+
` : css`
|
|
58
|
+
flex: 1 1 auto;
|
|
59
|
+
min-height: min(${SCROLLABLE_GROUPS_MIN_HEIGHT}px, 100%);
|
|
60
|
+
overflow-y: auto;
|
|
61
|
+
`}
|
|
62
|
+
|
|
63
|
+
&::-webkit-scrollbar {
|
|
64
|
+
width: 0;
|
|
65
|
+
height: 0;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
export const StyledNavigationSidebarResizeHandle = styled(motion.div)`
|
|
69
|
+
position: absolute;
|
|
70
|
+
right: -10px;
|
|
71
|
+
top: 0;
|
|
72
|
+
width: 20px;
|
|
73
|
+
height: 100%;
|
|
74
|
+
cursor: col-resize;
|
|
75
|
+
opacity: 0;
|
|
76
|
+
z-index: 20;
|
|
77
|
+
pointer-events: auto;
|
|
78
|
+
touch-action: none;
|
|
79
|
+
user-select: none;
|
|
80
|
+
-webkit-user-select: none;
|
|
81
|
+
`;
|
|
82
|
+
//# sourceMappingURL=NavigationSidebar.styles.js.map
|
package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationSidebar.styles.js","names":["styled","css","motion","SCROLLABLE_GROUPS_MIN_HEIGHT","StyledMotionNavigationSidebar","div","$color","$isMobile","StyledMotionNavigationSidebarContent","StyledMotionNavigationSidebarContentWrapper","StyledMotionNavigationSidebarExternalContent","StyledMotionNavigationSidebarContentList","$isPinned","StyledNavigationSidebarResizeHandle"],"sources":["../../../../../src/components/navigation-layout/navigation-sidebar/NavigationSidebar.styles.ts"],"sourcesContent":["import styled, { css } from 'styled-components';\nimport { WithTheme } from '@chayns-components/core';\nimport { motion } from 'motion/react';\n\nconst SCROLLABLE_GROUPS_MIN_HEIGHT = 120;\n\ntype StyledNavigationSidebarProps = WithTheme<{ $color: string; $isMobile?: boolean }>;\n\nexport const StyledMotionNavigationSidebar = styled(motion.div)<StyledNavigationSidebarProps>`\n height: 100%;\n color: ${({ $color }) => $color};\n\n position: relative;\n display: flex;\n flex-shrink: 0;\n min-height: 0;\n overflow: visible;\n z-index: 1;\n padding: 10px;\n\n ${({ $isMobile }) =>\n $isMobile &&\n css`\n width: 70vw;\n min-width: 70vw;\n max-width: 70vw;\n `}\n`;\n\nexport const StyledMotionNavigationSidebarContent = styled(motion.div)`\n width: 100%;\n display: flex;\n flex: 1 1 auto;\n flex-direction: column;\n gap: 2px;\n min-height: 0;\n overflow: hidden;\n`;\n\nexport const StyledMotionNavigationSidebarContentWrapper = styled(motion.div)`\n display: flex;\n flex: 1 1 auto;\n flex-direction: column;\n min-height: 0;\n overflow: hidden;\n`;\n\nexport const StyledMotionNavigationSidebarExternalContent = styled(motion.div)`\n flex-shrink: 0;\n margin: 4px 0;\n`;\n\ntype StyledMotionNavigationSidebarContentListProps = WithTheme<{ $isPinned?: boolean }>;\n\nexport const StyledMotionNavigationSidebarContentList = styled(\n motion.div,\n)<StyledMotionNavigationSidebarContentListProps>`\n display: flex;\n flex-direction: column;\n min-height: 0;\n overflow-x: hidden;\n\n ${({ $isPinned }) =>\n $isPinned\n ? css`\n flex: 0 0 auto;\n overflow-y: auto;\n `\n : css`\n flex: 1 1 auto;\n min-height: min(${SCROLLABLE_GROUPS_MIN_HEIGHT}px, 100%);\n overflow-y: auto;\n `}\n\n &::-webkit-scrollbar {\n width: 0;\n height: 0;\n }\n`;\n\nexport const StyledNavigationSidebarResizeHandle = styled(motion.div)`\n position: absolute;\n right: -10px;\n top: 0;\n width: 20px;\n height: 100%;\n cursor: col-resize;\n opacity: 0;\n z-index: 20;\n pointer-events: auto;\n touch-action: none;\n user-select: none;\n -webkit-user-select: none;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAE/C,SAASC,MAAM,QAAQ,cAAc;AAErC,MAAMC,4BAA4B,GAAG,GAAG;AAIxC,OAAO,MAAMC,6BAA6B,GAAGJ,MAAM,CAACE,MAAM,CAACG,GAAG,CAA+B;AAC7F;AACA,aAAa,CAAC;EAAEC;AAAO,CAAC,KAAKA,MAAM;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,CAAC;EAAEC;AAAU,CAAC,KACZA,SAAS,IACTN,GAAG;AACX;AACA;AACA;AACA,SAAS;AACT,CAAC;AAED,OAAO,MAAMO,oCAAoC,GAAGR,MAAM,CAACE,MAAM,CAACG,GAAG,CAAC;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMI,2CAA2C,GAAGT,MAAM,CAACE,MAAM,CAACG,GAAG,CAAC;AAC7E;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMK,4CAA4C,GAAGV,MAAM,CAACE,MAAM,CAACG,GAAG,CAAC;AAC9E;AACA;AACA,CAAC;AAID,OAAO,MAAMM,wCAAwC,GAAGX,MAAM,CAC1DE,MAAM,CAACG,GACX,CAAgD;AAChD;AACA;AACA;AACA;AACA;AACA,MAAM,CAAC;EAAEO;AAAU,CAAC,KACZA,SAAS,GACHX,GAAG;AACjB;AACA;AACA,eAAe,GACDA,GAAG;AACjB;AACA,oCAAoCE,4BAA4B;AAChE;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMU,mCAAmC,GAAGb,MAAM,CAACE,MAAM,CAACG,GAAG,CAAC;AACrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationSidebar.types.js","names":[],"sources":["../../../../../src/components/navigation-layout/navigation-sidebar/NavigationSidebar.types.ts"],"sourcesContent":["import { NavigationLayoutProps } from '../NavigationLayout.types';\n\n/**\n * Internal props used to render the navigation sidebar.\n */\nexport interface NavigationSidebarProps {\n /**\n * Color used for icons, text highlights and separators.\n */\n color: string;\n /**\n * Optional content rendered above the item groups.\n */\n topContent: NavigationLayoutProps['sidebarTopContent'];\n /**\n * Optional content rendered below the item groups.\n */\n bottomContent: NavigationLayoutProps['sidebarBottomContent'];\n /**\n * Collapsed sidebar width.\n */\n minWidth: number;\n /**\n * Expanded sidebar width.\n */\n maxWidth: number;\n /**\n * Grouped navigation items shown in the sidebar.\n */\n groups: NavigationLayoutProps['groups'];\n /**\n * Currently selected item id.\n */\n selectedItemId?: NavigationLayoutProps['selectedItemId'];\n /**\n * Called when an item is clicked.\n */\n onItemClick?: NavigationLayoutProps['onItemClick'];\n /**\n * Called when the sidebar snaps open.\n */\n onSidebarOpen?: NavigationLayoutProps['onSidebarOpen'];\n /**\n * Called when the sidebar snaps closed.\n */\n onSidebarClose?: NavigationLayoutProps['onSidebarClose'];\n /**\n * Enables collapsed labels for top-level items.\n */\n shouldShowCollapsedLabel?: NavigationLayoutProps['shouldShowCollapsedLabel'];\n /**\n * Enables the mobile layout behaviour.\n */\n isMobile?: NavigationLayoutProps['isMobile'];\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export const useGlobalUserSelect = ({
|
|
3
|
+
isDisabled
|
|
4
|
+
}) => {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (!isDisabled || typeof document === 'undefined') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const elements = [document.documentElement, document.body];
|
|
10
|
+
const previousStyles = elements.map(element => ({
|
|
11
|
+
element,
|
|
12
|
+
userSelect: element.style.userSelect,
|
|
13
|
+
webkitUserSelect: element.style.getPropertyValue('-webkit-user-select')
|
|
14
|
+
}));
|
|
15
|
+
previousStyles.forEach(({
|
|
16
|
+
element
|
|
17
|
+
}) => {
|
|
18
|
+
const {
|
|
19
|
+
style
|
|
20
|
+
} = element;
|
|
21
|
+
style.userSelect = 'none';
|
|
22
|
+
style.setProperty('-webkit-user-select', 'none');
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
previousStyles.forEach(({
|
|
26
|
+
element,
|
|
27
|
+
userSelect,
|
|
28
|
+
webkitUserSelect
|
|
29
|
+
}) => {
|
|
30
|
+
const {
|
|
31
|
+
style
|
|
32
|
+
} = element;
|
|
33
|
+
style.userSelect = userSelect;
|
|
34
|
+
if (webkitUserSelect) {
|
|
35
|
+
style.setProperty('-webkit-user-select', webkitUserSelect);
|
|
36
|
+
} else {
|
|
37
|
+
style.removeProperty('-webkit-user-select');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}, [isDisabled]);
|
|
42
|
+
};
|
|
43
|
+
export const clampSideBarWidth = ({
|
|
44
|
+
width,
|
|
45
|
+
minWidth,
|
|
46
|
+
maxWidth
|
|
47
|
+
}) => {
|
|
48
|
+
const normalizedMinWidth = Math.min(minWidth, maxWidth);
|
|
49
|
+
const normalizedMaxWidth = Math.max(minWidth, maxWidth);
|
|
50
|
+
return Math.min(Math.max(width, normalizedMinWidth), normalizedMaxWidth);
|
|
51
|
+
};
|
|
52
|
+
export const getNearestSideBarWidth = ({
|
|
53
|
+
width,
|
|
54
|
+
minWidth,
|
|
55
|
+
maxWidth
|
|
56
|
+
}) => {
|
|
57
|
+
const normalizedMinWidth = Math.min(minWidth, maxWidth);
|
|
58
|
+
const normalizedMaxWidth = Math.max(minWidth, maxWidth);
|
|
59
|
+
const halfWidth = getSideBarCompactBreakpoint({
|
|
60
|
+
minWidth,
|
|
61
|
+
maxWidth
|
|
62
|
+
});
|
|
63
|
+
return width < halfWidth ? normalizedMinWidth : normalizedMaxWidth;
|
|
64
|
+
};
|
|
65
|
+
export const getSideBarCompactBreakpoint = ({
|
|
66
|
+
minWidth,
|
|
67
|
+
maxWidth
|
|
68
|
+
}) => {
|
|
69
|
+
const normalizedMinWidth = Math.min(minWidth, maxWidth);
|
|
70
|
+
const normalizedMaxWidth = Math.max(minWidth, maxWidth);
|
|
71
|
+
return normalizedMinWidth + (normalizedMaxWidth - normalizedMinWidth) / 2;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=NavigationSidebar.utils.js.map
|
package/lib/esm/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationSidebar.utils.js","names":["useEffect","useGlobalUserSelect","isDisabled","document","undefined","elements","documentElement","body","previousStyles","map","element","userSelect","style","webkitUserSelect","getPropertyValue","forEach","setProperty","removeProperty","clampSideBarWidth","width","minWidth","maxWidth","normalizedMinWidth","Math","min","normalizedMaxWidth","max","getNearestSideBarWidth","halfWidth","getSideBarCompactBreakpoint"],"sources":["../../../../../src/components/navigation-layout/navigation-sidebar/NavigationSidebar.utils.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport interface UseGlobalUserSelectOptions {\n isDisabled: boolean;\n}\n\nexport const useGlobalUserSelect = ({ isDisabled }: UseGlobalUserSelectOptions): void => {\n useEffect(() => {\n if (!isDisabled || typeof document === 'undefined') {\n return undefined;\n }\n\n const elements = [document.documentElement, document.body];\n const previousStyles = elements.map((element) => ({\n element,\n userSelect: element.style.userSelect,\n webkitUserSelect: element.style.getPropertyValue('-webkit-user-select'),\n }));\n\n previousStyles.forEach(({ element }) => {\n const { style } = element;\n\n style.userSelect = 'none';\n style.setProperty('-webkit-user-select', 'none');\n });\n\n return () => {\n previousStyles.forEach(({ element, userSelect, webkitUserSelect }) => {\n const { style } = element;\n\n style.userSelect = userSelect;\n\n if (webkitUserSelect) {\n style.setProperty('-webkit-user-select', webkitUserSelect);\n } else {\n style.removeProperty('-webkit-user-select');\n }\n });\n };\n }, [isDisabled]);\n};\n\ninterface ClampSideBarWidthOptions {\n width: number;\n minWidth: number;\n maxWidth: number;\n}\n\nexport const clampSideBarWidth = ({\n width,\n minWidth,\n maxWidth,\n}: ClampSideBarWidthOptions): number => {\n const normalizedMinWidth = Math.min(minWidth, maxWidth);\n const normalizedMaxWidth = Math.max(minWidth, maxWidth);\n\n return Math.min(Math.max(width, normalizedMinWidth), normalizedMaxWidth);\n};\n\ninterface GetNearestSideBarWidthOptions {\n width: number;\n minWidth: number;\n maxWidth: number;\n}\n\ninterface GetSideBarCompactBreakpointOptions {\n minWidth: number;\n maxWidth: number;\n}\n\nexport const getNearestSideBarWidth = ({\n width,\n minWidth,\n maxWidth,\n}: GetNearestSideBarWidthOptions): number => {\n const normalizedMinWidth = Math.min(minWidth, maxWidth);\n const normalizedMaxWidth = Math.max(minWidth, maxWidth);\n const halfWidth = getSideBarCompactBreakpoint({ minWidth, maxWidth });\n\n return width < halfWidth ? normalizedMinWidth : normalizedMaxWidth;\n};\n\nexport const getSideBarCompactBreakpoint = ({\n minWidth,\n maxWidth,\n}: GetSideBarCompactBreakpointOptions): number => {\n const normalizedMinWidth = Math.min(minWidth, maxWidth);\n const normalizedMaxWidth = Math.max(minWidth, maxWidth);\n\n return normalizedMinWidth + (normalizedMaxWidth - normalizedMinWidth) / 2;\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAMjC,OAAO,MAAMC,mBAAmB,GAAGA,CAAC;EAAEC;AAAuC,CAAC,KAAW;EACrFF,SAAS,CAAC,MAAM;IACZ,IAAI,CAACE,UAAU,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;MAChD,OAAOC,SAAS;IACpB;IAEA,MAAMC,QAAQ,GAAG,CAACF,QAAQ,CAACG,eAAe,EAAEH,QAAQ,CAACI,IAAI,CAAC;IAC1D,MAAMC,cAAc,GAAGH,QAAQ,CAACI,GAAG,CAAEC,OAAO,KAAM;MAC9CA,OAAO;MACPC,UAAU,EAAED,OAAO,CAACE,KAAK,CAACD,UAAU;MACpCE,gBAAgB,EAAEH,OAAO,CAACE,KAAK,CAACE,gBAAgB,CAAC,qBAAqB;IAC1E,CAAC,CAAC,CAAC;IAEHN,cAAc,CAACO,OAAO,CAAC,CAAC;MAAEL;IAAQ,CAAC,KAAK;MACpC,MAAM;QAAEE;MAAM,CAAC,GAAGF,OAAO;MAEzBE,KAAK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AAS,CAAC,CAAC;EAErE,OAAOF,KAAK,GAAGS,SAAS,GAAGN,kBAAkB,GAAGG,kBAAkB;AACtE,CAAC;AAED,OAAO,MAAMI,2BAA2B,GAAGA,CAAC;EACxCT,QAAQ;EACRC;AACgC,CAAC,KAAa;EAC9C,MAAMC,kBAAkB,GAAGC,IAAI,CAACC,GAAG,CAACJ,QAAQ,EAAEC,QAAQ,CAAC;EACvD,MAAMI,kBAAkB,GAAGF,IAAI,CAACG,GAAG,CAACN,QAAQ,EAAEC,QAAQ,CAAC;EAEvD,OAAOC,kBAAkB,GAAG,CAACG,kBAAkB,GAAGH,kBAAkB,IAAI,CAAC;AAC7E,CAAC","ignoreList":[]}
|
package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledSidebarDivider } from './SidebarDivider.styles';
|
|
3
|
+
const SidebarDivider = ({
|
|
4
|
+
color
|
|
5
|
+
}) => /*#__PURE__*/React.createElement(StyledSidebarDivider, {
|
|
6
|
+
$color: color
|
|
7
|
+
});
|
|
8
|
+
SidebarDivider.displayName = 'SidebarDivider';
|
|
9
|
+
export default SidebarDivider;
|
|
10
|
+
//# sourceMappingURL=SidebarDivider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidebarDivider.js","names":["React","StyledSidebarDivider","SidebarDivider","color","createElement","$color","displayName"],"sources":["../../../../../../src/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.tsx"],"sourcesContent":["import React, { FC } from 'react';\nimport { StyledSidebarDivider } from './SidebarDivider.styles';\n\ninterface SidebarDividerProps {\n color: string;\n}\n\nconst SidebarDivider: FC<SidebarDividerProps> = ({ color }) => (\n <StyledSidebarDivider $color={color} />\n);\n\nSidebarDivider.displayName = 'SidebarDivider';\n\nexport default SidebarDivider;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAc,OAAO;AACjC,SAASC,oBAAoB,QAAQ,yBAAyB;AAM9D,MAAMC,cAAuC,GAAGA,CAAC;EAAEC;AAAM,CAAC,kBACtDH,KAAA,CAAAI,aAAA,CAACH,oBAAoB;EAACI,MAAM,EAAEF;AAAM,CAAE,CACzC;AAEDD,cAAc,CAACI,WAAW,GAAG,gBAAgB;AAE7C,eAAeJ,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export const StyledSidebarDivider = styled.div`
|
|
3
|
+
background-color: ${({
|
|
4
|
+
$color
|
|
5
|
+
}) => $color};
|
|
6
|
+
opacity: 0.35;
|
|
7
|
+
flex: none;
|
|
8
|
+
height: 1px;
|
|
9
|
+
margin: 4px 0;
|
|
10
|
+
width: 100%;
|
|
11
|
+
`;
|
|
12
|
+
//# sourceMappingURL=SidebarDivider.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidebarDivider.styles.js","names":["styled","StyledSidebarDivider","div","$color"],"sources":["../../../../../../src/components/navigation-layout/navigation-sidebar/sidebar-divider/SidebarDivider.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport { WithTheme } from '@chayns-components/core';\n\ntype StyledSidebarDividerProps = WithTheme<{ $color: string }>;\n\nexport const StyledSidebarDivider = styled.div<StyledSidebarDividerProps>`\n background-color: ${({ $color }) => $color};\n opacity: 0.35;\n flex: none;\n height: 1px;\n margin: 4px 0;\n width: 100%;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AAKtC,OAAO,MAAMC,oBAAoB,GAAGD,MAAM,CAACE,GAA8B;AACzE,wBAAwB,CAAC;EAAEC;AAAO,CAAC,KAAKA,MAAM;AAC9C;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
const SidebarGroupReorderContext = /*#__PURE__*/createContext(null);
|
|
3
|
+
export const SidebarGroupReorderProvider = ({
|
|
4
|
+
children,
|
|
5
|
+
value
|
|
6
|
+
}) => /*#__PURE__*/React.createElement(SidebarGroupReorderContext.Provider, {
|
|
7
|
+
value: value
|
|
8
|
+
}, children);
|
|
9
|
+
SidebarGroupReorderProvider.displayName = 'SidebarGroupReorderProvider';
|
|
10
|
+
export const useSidebarGroupReorderContext = () => {
|
|
11
|
+
const context = useContext(SidebarGroupReorderContext);
|
|
12
|
+
if (!context) {
|
|
13
|
+
throw new Error('useSidebarGroupReorderContext must be used within SidebarGroupReorderProvider.');
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=SidebarGroup.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidebarGroup.context.js","names":["React","createContext","useContext","SidebarGroupReorderContext","SidebarGroupReorderProvider","children","value","createElement","Provider","displayName","useSidebarGroupReorderContext","context","Error"],"sources":["../../../../../../src/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.context.tsx"],"sourcesContent":["import React, { ReactNode, createContext, useContext } from 'react';\nimport {\n NavigationLayoutItem,\n NavigationLayoutItemReorderSource,\n NavigationLayoutItemReorderTarget,\n} from '../../NavigationLayout.types';\n\ninterface SidebarGroupReorderContextValue {\n draggedItemId?: NavigationLayoutItem['id'];\n dropTarget: NavigationLayoutItemReorderTarget | null;\n isDragging: boolean;\n isReorderEnabled: boolean;\n onDragEnd: VoidFunction;\n onDragStart: (\n event: React.DragEvent<HTMLDivElement>,\n item: NavigationLayoutItemReorderSource,\n ) => void;\n onDrop: (target: NavigationLayoutItemReorderTarget) => void;\n onDropTargetChange: (target: NavigationLayoutItemReorderTarget) => void;\n}\n\ninterface SidebarGroupReorderProviderProps {\n children: ReactNode;\n value: SidebarGroupReorderContextValue;\n}\n\nconst SidebarGroupReorderContext = createContext<SidebarGroupReorderContextValue | null>(null);\n\nexport const SidebarGroupReorderProvider = ({\n children,\n value,\n}: SidebarGroupReorderProviderProps) => (\n <SidebarGroupReorderContext.Provider value={value}>\n {children}\n </SidebarGroupReorderContext.Provider>\n);\n\nSidebarGroupReorderProvider.displayName = 'SidebarGroupReorderProvider';\n\nexport const useSidebarGroupReorderContext = (): SidebarGroupReorderContextValue => {\n const context = useContext(SidebarGroupReorderContext);\n\n if (!context) {\n throw new Error(\n 'useSidebarGroupReorderContext must be used within SidebarGroupReorderProvider.',\n );\n }\n\n return context;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAeC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AA0BnE,MAAMC,0BAA0B,gBAAGF,aAAa,CAAyC,IAAI,CAAC;AAE9F,OAAO,MAAMG,2BAA2B,GAAGA,CAAC;EACxCC,QAAQ;EACRC;AAC8B,CAAC,kBAC/BN,KAAA,CAAAO,aAAA,CAACJ,0BAA0B,CAACK,QAAQ;EAACF,KAAK,EAAEA;AAAM,GAC7CD,QACgC,CACxC;AAEDD,2BAA2B,CAACK,WAAW,GAAG,6BAA6B;AAEvE,OAAO,MAAMC,6BAA6B,GAAGA,CAAA,KAAuC;EAChF,MAAMC,OAAO,GAAGT,UAAU,CAACC,0BAA0B,CAAC;EAEtD,IAAI,CAACQ,OAAO,EAAE;IACV,MAAM,IAAIC,KAAK,CACX,gFACJ,CAAC;EACL;EAEA,OAAOD,OAAO;AAClB,CAAC","ignoreList":[]}
|
package/lib/esm/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { isNavigationLayoutItemReorderEventValid, isNavigationLayoutReorderTargetEqual } from '../../NavigationLayout.utils';
|
|
3
|
+
const setDragMoveEffect = event => {
|
|
4
|
+
const {
|
|
5
|
+
dataTransfer
|
|
6
|
+
} = event;
|
|
7
|
+
dataTransfer.dropEffect = 'move';
|
|
8
|
+
};
|
|
9
|
+
export const useSidebarGroupReorder = ({
|
|
10
|
+
groupId,
|
|
11
|
+
isCompact,
|
|
12
|
+
isReorderable,
|
|
13
|
+
items,
|
|
14
|
+
onItemReorder
|
|
15
|
+
}) => {
|
|
16
|
+
const [draggedItem, setDraggedItem] = useState(null);
|
|
17
|
+
const [dropTarget, setDropTarget] = useState(null);
|
|
18
|
+
const isReorderEnabled = useMemo(() => Boolean(isReorderable && !isCompact && typeof onItemReorder === 'function'), [isCompact, isReorderable, onItemReorder]);
|
|
19
|
+
const resetDragState = useCallback(() => {
|
|
20
|
+
setDraggedItem(null);
|
|
21
|
+
setDropTarget(null);
|
|
22
|
+
}, []);
|
|
23
|
+
const createReorderEvent = useCallback(target => {
|
|
24
|
+
if (!draggedItem) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
groupId,
|
|
29
|
+
itemId: draggedItem.itemId,
|
|
30
|
+
source: draggedItem,
|
|
31
|
+
target
|
|
32
|
+
};
|
|
33
|
+
}, [draggedItem, groupId]);
|
|
34
|
+
const handleDragStart = useCallback((event, item) => {
|
|
35
|
+
if (!isReorderEnabled) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const {
|
|
39
|
+
dataTransfer
|
|
40
|
+
} = event;
|
|
41
|
+
dataTransfer.effectAllowed = 'move';
|
|
42
|
+
dataTransfer.setData('text/plain', item.itemId);
|
|
43
|
+
setDraggedItem(item);
|
|
44
|
+
setDropTarget(null);
|
|
45
|
+
}, [isReorderEnabled]);
|
|
46
|
+
const handleDropTargetChange = useCallback(target => {
|
|
47
|
+
const nextEvent = createReorderEvent(target);
|
|
48
|
+
if (!nextEvent || !isNavigationLayoutItemReorderEventValid({
|
|
49
|
+
items,
|
|
50
|
+
event: nextEvent
|
|
51
|
+
})) {
|
|
52
|
+
setDropTarget(null);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
setDropTarget(target);
|
|
56
|
+
}, [createReorderEvent, items]);
|
|
57
|
+
const handleDrop = useCallback(target => {
|
|
58
|
+
const nextEvent = createReorderEvent(target);
|
|
59
|
+
if (!nextEvent || typeof onItemReorder !== 'function' || !isNavigationLayoutItemReorderEventValid({
|
|
60
|
+
items,
|
|
61
|
+
event: nextEvent
|
|
62
|
+
})) {
|
|
63
|
+
resetDragState();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
onItemReorder(nextEvent);
|
|
67
|
+
resetDragState();
|
|
68
|
+
}, [createReorderEvent, items, onItemReorder, resetDragState]);
|
|
69
|
+
const groupEndTarget = useMemo(() => ({
|
|
70
|
+
itemId: items[items.length - 1]?.id,
|
|
71
|
+
parentIds: [],
|
|
72
|
+
index: items.length,
|
|
73
|
+
placement: 'after'
|
|
74
|
+
}), [items]);
|
|
75
|
+
const isGroupEndTargetActive = useMemo(() => isNavigationLayoutReorderTargetEqual({
|
|
76
|
+
targetA: dropTarget,
|
|
77
|
+
targetB: groupEndTarget
|
|
78
|
+
}), [dropTarget, groupEndTarget]);
|
|
79
|
+
const handleGroupEndDragOver = useCallback(event => {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
setDragMoveEffect(event);
|
|
82
|
+
handleDropTargetChange(groupEndTarget);
|
|
83
|
+
}, [groupEndTarget, handleDropTargetChange]);
|
|
84
|
+
const handleGroupEndDrop = useCallback(event => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
event.stopPropagation();
|
|
87
|
+
handleDrop(groupEndTarget);
|
|
88
|
+
}, [groupEndTarget, handleDrop]);
|
|
89
|
+
const handleGroupDragOver = useCallback(event => {
|
|
90
|
+
if (!dropTarget) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
setDragMoveEffect(event);
|
|
95
|
+
}, [dropTarget]);
|
|
96
|
+
const handleGroupDrop = useCallback(event => {
|
|
97
|
+
if (!dropTarget) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
handleDrop(dropTarget);
|
|
102
|
+
}, [dropTarget, handleDrop]);
|
|
103
|
+
return {
|
|
104
|
+
draggedItemId: draggedItem?.itemId,
|
|
105
|
+
dropTarget,
|
|
106
|
+
isDragging: draggedItem !== null,
|
|
107
|
+
isGroupEndTargetActive,
|
|
108
|
+
isReorderEnabled,
|
|
109
|
+
handleDragEnd: resetDragState,
|
|
110
|
+
handleDragStart,
|
|
111
|
+
handleDrop,
|
|
112
|
+
handleDropTargetChange,
|
|
113
|
+
handleGroupDragOver,
|
|
114
|
+
handleGroupDrop,
|
|
115
|
+
handleGroupEndDragOver,
|
|
116
|
+
handleGroupEndDrop
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=SidebarGroup.hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidebarGroup.hooks.js","names":["useCallback","useMemo","useState","isNavigationLayoutItemReorderEventValid","isNavigationLayoutReorderTargetEqual","setDragMoveEffect","event","dataTransfer","dropEffect","useSidebarGroupReorder","groupId","isCompact","isReorderable","items","onItemReorder","draggedItem","setDraggedItem","dropTarget","setDropTarget","isReorderEnabled","Boolean","resetDragState","createReorderEvent","target","itemId","source","handleDragStart","item","effectAllowed","setData","handleDropTargetChange","nextEvent","handleDrop","groupEndTarget","length","id","parentIds","index","placement","isGroupEndTargetActive","targetA","targetB","handleGroupEndDragOver","preventDefault","handleGroupEndDrop","stopPropagation","handleGroupDragOver","handleGroupDrop","draggedItemId","isDragging","handleDragEnd"],"sources":["../../../../../../src/components/navigation-layout/navigation-sidebar/sidebar-group/SidebarGroup.hooks.ts"],"sourcesContent":["import React, { useCallback, useMemo, useState } from 'react';\nimport {\n NavigationLayoutGroup,\n NavigationLayoutItem,\n NavigationLayoutItemReorderEvent,\n NavigationLayoutItemReorderSource,\n NavigationLayoutItemReorderTarget,\n NavigationLayoutProps,\n} from '../../NavigationLayout.types';\nimport {\n isNavigationLayoutItemReorderEventValid,\n isNavigationLayoutReorderTargetEqual,\n} from '../../NavigationLayout.utils';\n\ninterface UseSidebarGroupReorderOptions {\n groupId: NavigationLayoutGroup['id'];\n isCompact: boolean;\n isReorderable?: NavigationLayoutGroup['isReorderable'];\n items: NavigationLayoutItem[];\n onItemReorder?: NavigationLayoutProps['onItemReorder'];\n}\n\ninterface UseSidebarGroupReorderResult {\n draggedItemId?: NavigationLayoutItem['id'];\n dropTarget: NavigationLayoutItemReorderTarget | null;\n isDragging: boolean;\n isGroupEndTargetActive: boolean;\n isReorderEnabled: boolean;\n handleDragEnd: VoidFunction;\n handleDragStart: (\n event: React.DragEvent<HTMLDivElement>,\n item: NavigationLayoutItemReorderSource,\n ) => void;\n handleDrop: (target: NavigationLayoutItemReorderTarget) => void;\n handleDropTargetChange: (target: NavigationLayoutItemReorderTarget) => void;\n handleGroupDragOver: (event: React.DragEvent<HTMLDivElement>) => void;\n handleGroupDrop: (event: React.DragEvent<HTMLDivElement>) => void;\n handleGroupEndDragOver: (event: React.DragEvent<HTMLDivElement>) => void;\n handleGroupEndDrop: (event: React.DragEvent<HTMLDivElement>) => void;\n}\n\nconst setDragMoveEffect = (event: React.DragEvent<HTMLDivElement>): void => {\n const { dataTransfer } = event;\n\n dataTransfer.dropEffect = 'move';\n};\n\nexport const useSidebarGroupReorder = ({\n groupId,\n isCompact,\n isReorderable,\n items,\n onItemReorder,\n}: UseSidebarGroupReorderOptions): UseSidebarGroupReorderResult => {\n const [draggedItem, setDraggedItem] = useState<NavigationLayoutItemReorderSource | null>(null);\n const [dropTarget, setDropTarget] = useState<NavigationLayoutItemReorderTarget | null>(null);\n\n const isReorderEnabled = useMemo(\n () => Boolean(isReorderable && !isCompact && typeof onItemReorder === 'function'),\n [isCompact, isReorderable, onItemReorder],\n );\n\n const resetDragState = useCallback((): void => {\n setDraggedItem(null);\n setDropTarget(null);\n }, []);\n\n const createReorderEvent = useCallback(\n (target: NavigationLayoutItemReorderTarget): NavigationLayoutItemReorderEvent | null => {\n if (!draggedItem) {\n return null;\n }\n\n return {\n groupId,\n itemId: draggedItem.itemId,\n source: draggedItem,\n target,\n };\n },\n [draggedItem, groupId],\n );\n\n const handleDragStart = useCallback(\n (event: React.DragEvent<HTMLDivElement>, item: NavigationLayoutItemReorderSource): void => {\n if (!isReorderEnabled) {\n return;\n }\n\n const { dataTransfer } = event;\n\n dataTransfer.effectAllowed = 'move';\n dataTransfer.setData('text/plain', item.itemId);\n\n setDraggedItem(item);\n setDropTarget(null);\n },\n [isReorderEnabled],\n );\n\n const handleDropTargetChange = useCallback(\n (target: NavigationLayoutItemReorderTarget): void => {\n const nextEvent = createReorderEvent(target);\n\n if (\n !nextEvent ||\n !isNavigationLayoutItemReorderEventValid({ items, event: nextEvent })\n ) {\n setDropTarget(null);\n\n return;\n }\n\n setDropTarget(target);\n },\n [createReorderEvent, items],\n );\n\n const handleDrop = useCallback(\n (target: NavigationLayoutItemReorderTarget): void => {\n const nextEvent = createReorderEvent(target);\n\n if (\n !nextEvent ||\n typeof onItemReorder !== 'function' ||\n !isNavigationLayoutItemReorderEventValid({ items, event: nextEvent })\n ) {\n resetDragState();\n\n return;\n }\n\n onItemReorder(nextEvent);\n resetDragState();\n },\n [createReorderEvent, items, onItemReorder, resetDragState],\n );\n\n const groupEndTarget = useMemo<NavigationLayoutItemReorderTarget>(\n () => ({\n itemId: items[items.length - 1]?.id,\n parentIds: [],\n index: items.length,\n placement: 'after',\n }),\n [items],\n );\n\n const isGroupEndTargetActive = useMemo(\n () =>\n isNavigationLayoutReorderTargetEqual({\n targetA: dropTarget,\n targetB: groupEndTarget,\n }),\n [dropTarget, groupEndTarget],\n );\n\n const handleGroupEndDragOver = useCallback(\n (event: React.DragEvent<HTMLDivElement>): void => {\n event.preventDefault();\n setDragMoveEffect(event);\n handleDropTargetChange(groupEndTarget);\n },\n [groupEndTarget, handleDropTargetChange],\n );\n\n const handleGroupEndDrop = useCallback(\n (event: React.DragEvent<HTMLDivElement>): void => {\n event.preventDefault();\n event.stopPropagation();\n handleDrop(groupEndTarget);\n },\n [groupEndTarget, handleDrop],\n );\n\n const handleGroupDragOver = useCallback(\n (event: React.DragEvent<HTMLDivElement>): void => {\n if (!dropTarget) {\n return;\n }\n\n event.preventDefault();\n setDragMoveEffect(event);\n },\n [dropTarget],\n );\n\n const handleGroupDrop = useCallback(\n (event: React.DragEvent<HTMLDivElement>): void => {\n if (!dropTarget) {\n return;\n }\n\n event.preventDefault();\n handleDrop(dropTarget);\n },\n [dropTarget, handleDrop],\n );\n\n return {\n draggedItemId: draggedItem?.itemId,\n dropTarget,\n isDragging: draggedItem !== null,\n isGroupEndTargetActive,\n isReorderEnabled,\n handleDragEnd: resetDragState,\n handleDragStart,\n handleDrop,\n handleDropTargetChange,\n handleGroupDragOver,\n handleGroupDrop,\n handleGroupEndDragOver,\n handleGroupEndDrop,\n };\n};\n"],"mappings":"AAAA,SAAgBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAS7D,SACIC,uCAAuC,EACvCC,oCAAoC,QACjC,8BAA8B;AA6BrC,MAAMC,iBAAiB,GAAIC,KAAsC,IAAW;EACxE,MAAM;IAAEC;EAAa,CAAC,GAAGD,KAAK;EAE9BC,YAAY,CAACC,UAAU,GAAG,MAAM;AACpC,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAGA,CAAC;EACnCC,OAAO;EACPC,SAAS;EACTC,aAAa;EACbC,KAAK;EACLC;AAC2B,CAAC,KAAmC;EAC/D,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGd,QAAQ,CAA2C,IAAI,CAAC;EAC9F,MAAM,CAACe,UAAU,EAAEC,aAAa,CAAC,GAAGhB,QAAQ,CAA2C,IAAI,CAAC;EAE5F,MAAMiB,gBAAgB,GAAGlB,OAAO,CAC5B,MAAMmB,OAAO,CAACR,aAAa,IAAI,CAACD,SAAS,IAAI,OAAOG,aAAa,KAAK,UAAU,CAAC,EACjF,CAACH,SAAS,EAAEC,aAAa,EAAEE,aAAa,CAC5C,CA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MAAMc,mBAAmB,GAAG9C,WAAW,CAClCM,KAAsC,IAAW;IAC9C,IAAI,CAACW,UAAU,EAAE;MACb;IACJ;IAEAX,KAAK,CAACqC,cAAc,CAAC,CAAC;IACtBtC,iBAAiB,CAACC,KAAK,CAAC;EAC5B,CAAC,EACD,CAACW,UAAU,CACf,CAAC;EAED,MAAM8B,eAAe,GAAG/C,WAAW,CAC9BM,KAAsC,IAAW;IAC9C,IAAI,CAACW,UAAU,EAAE;MACb;IACJ;IAEAX,KAAK,CAACqC,cAAc,CAAC,CAAC;IACtBX,UAAU,CAACf,UAAU,CAAC;EAC1B,CAAC,EACD,CAACA,UAAU,EAAEe,UAAU,CAC3B,CAAC;EAED,OAAO;IACHgB,aAAa,EAAEjC,WAAW,EAAES,MAAM;IAClCP,UAAU;IACVgC,UAAU,EAAElC,WAAW,KAAK,IAAI;IAChCwB,sBAAsB;IACtBpB,gBAAgB;IAChB+B,aAAa,EAAE7B,cAAc;IAC7BK,eAAe;IACfM,UAAU;IACVF,sBAAsB;IACtBgB,mBAAmB;IACnBC,eAAe;IACfL,sBAAsB;IACtBE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { StyledSidebarDropZone, StyledSidebarGroup } from './SidebarGroup.styles';
|
|
3
|
+
import SidebarItem from './sidebar-item/SidebarItem';
|
|
4
|
+
import { SidebarGroupReorderProvider } from './SidebarGroup.context';
|
|
5
|
+
import { useSidebarGroupReorder } from './SidebarGroup.hooks';
|
|
6
|
+
import { useNavigationSidebarContext } from '../NavigationSidebar.context';
|
|
7
|
+
import { useNavigationLayoutContext } from '../../NavigationLayout.context';
|
|
8
|
+
const SidebarGroup = ({
|
|
9
|
+
groupId,
|
|
10
|
+
items,
|
|
11
|
+
isReorderable
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
isCompact
|
|
15
|
+
} = useNavigationSidebarContext();
|
|
16
|
+
const {
|
|
17
|
+
onItemReorder
|
|
18
|
+
} = useNavigationLayoutContext();
|
|
19
|
+
const {
|
|
20
|
+
draggedItemId,
|
|
21
|
+
dropTarget,
|
|
22
|
+
isDragging,
|
|
23
|
+
isGroupEndTargetActive,
|
|
24
|
+
isReorderEnabled,
|
|
25
|
+
handleDragEnd,
|
|
26
|
+
handleDragStart,
|
|
27
|
+
handleDrop,
|
|
28
|
+
handleDropTargetChange,
|
|
29
|
+
handleGroupDragOver,
|
|
30
|
+
handleGroupDrop,
|
|
31
|
+
handleGroupEndDragOver,
|
|
32
|
+
handleGroupEndDrop
|
|
33
|
+
} = useSidebarGroupReorder({
|
|
34
|
+
groupId,
|
|
35
|
+
isCompact,
|
|
36
|
+
isReorderable,
|
|
37
|
+
items,
|
|
38
|
+
onItemReorder
|
|
39
|
+
});
|
|
40
|
+
const contextValue = useMemo(() => ({
|
|
41
|
+
draggedItemId,
|
|
42
|
+
dropTarget,
|
|
43
|
+
isDragging,
|
|
44
|
+
isReorderEnabled,
|
|
45
|
+
onDragEnd: handleDragEnd,
|
|
46
|
+
onDragStart: handleDragStart,
|
|
47
|
+
onDrop: handleDrop,
|
|
48
|
+
onDropTargetChange: handleDropTargetChange
|
|
49
|
+
}), [draggedItemId, dropTarget, handleDragEnd, handleDragStart, handleDrop, handleDropTargetChange, isDragging, isReorderEnabled]);
|
|
50
|
+
const content = useMemo(() => items.map((item, index) => /*#__PURE__*/React.createElement(SidebarItem, {
|
|
51
|
+
key: item.id,
|
|
52
|
+
item: item,
|
|
53
|
+
index: index,
|
|
54
|
+
parentIds: []
|
|
55
|
+
})), [items]);
|
|
56
|
+
return /*#__PURE__*/React.createElement(SidebarGroupReorderProvider, {
|
|
57
|
+
value: contextValue
|
|
58
|
+
}, /*#__PURE__*/React.createElement(StyledSidebarGroup, {
|
|
59
|
+
onDragOver: handleGroupDragOver,
|
|
60
|
+
onDrop: handleGroupDrop
|
|
61
|
+
}, content, isReorderEnabled && /*#__PURE__*/React.createElement(StyledSidebarDropZone, {
|
|
62
|
+
$isActive: isGroupEndTargetActive,
|
|
63
|
+
$isDragging: isDragging,
|
|
64
|
+
$placement: "after",
|
|
65
|
+
onDragOver: handleGroupEndDragOver,
|
|
66
|
+
onDrop: handleGroupEndDrop
|
|
67
|
+
})));
|
|
68
|
+
};
|
|
69
|
+
SidebarGroup.displayName = 'SidebarGroup';
|
|
70
|
+
export default /*#__PURE__*/memo(SidebarGroup);
|
|
71
|
+
//# sourceMappingURL=SidebarGroup.js.map
|