@synerise/ds-sidebar 1.0.15 → 1.0.17
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/CHANGELOG.md +455 -1715
- package/README.md +12 -11
- package/dist/DragOverlayPanel/DragOverlayPanel.d.ts +3 -0
- package/dist/DragOverlayPanel/DragOverlayPanel.js +22 -0
- package/dist/DraggablePanel/DraggablePanel.d.ts +3 -0
- package/dist/DraggablePanel/DraggablePanel.js +32 -0
- package/dist/Panel/Panel.d.ts +2 -2
- package/dist/Panel/Panel.js +7 -97
- package/dist/PanelContent/PanelContent.d.ts +3 -0
- package/dist/PanelContent/PanelContent.js +27 -0
- package/dist/Sidebar.context.d.ts +1 -1
- package/dist/Sidebar.d.ts +4 -4
- package/dist/Sidebar.js +115 -62
- package/dist/Sidebar.styles.d.ts +12 -6
- package/dist/Sidebar.styles.js +43 -28
- package/dist/Sidebar.types.d.ts +8 -10
- package/dist/SidebarWithButton/SidebarWithButton.d.ts +2 -2
- package/dist/SidebarWithButton/SidebarWithButton.js +2 -2
- package/dist/SidebarWithButton/SidebarWithButton.types.d.ts +1 -1
- package/dist/utils/prefixKeys.d.ts +1 -0
- package/dist/utils/prefixKeys.js +5 -0
- package/package.json +9 -11
package/README.md
CHANGED
|
@@ -29,13 +29,14 @@ import Sidebar from '@synerise/ds-sidebar'
|
|
|
29
29
|
## API
|
|
30
30
|
|
|
31
31
|
#### Sidebar
|
|
32
|
+
| Property | Description | Type | Default |
|
|
33
|
+
|-------------------|---------------------------------------------|---------------------------------------|---------|
|
|
34
|
+
| children | Place for Panel element | React.ReactNode | - |
|
|
35
|
+
| order | Place for optional Array with render order | string[] | - |
|
|
36
|
+
| onChangeOrder | Called on drag and drop fired | (order: string / string[])=>void | - |
|
|
37
|
+
| defaultActiveKey | Place for optional default active panel | string[] | - |
|
|
38
|
+
| getPopupContainer | Determines where to render the drag overlay | (elem: HTMLDivElement) => HTMLElement | - |
|
|
32
39
|
|
|
33
|
-
| Property | Description | Type | Default |
|
|
34
|
-
| ---------------- | ------------------------------------------ | -------------------------------- | ------- |
|
|
35
|
-
| children | Place for Panel element | React.ReactNode | - |
|
|
36
|
-
| order | Place for optional Array with render order | string[] | - |
|
|
37
|
-
| onChangeOrder | Called on drag and drop fired | (order: string / string[])=>void | - |
|
|
38
|
-
| defaultActiveKey | Place for optional default active panel | string[] | - |
|
|
39
40
|
|
|
40
41
|
#### Panel
|
|
41
42
|
|
|
@@ -47,8 +48,8 @@ import Sidebar from '@synerise/ds-sidebar'
|
|
|
47
48
|
|
|
48
49
|
#### SidebarButton
|
|
49
50
|
|
|
50
|
-
| Property
|
|
51
|
-
|
|
|
52
|
-
| buttonLabel
|
|
53
|
-
| title
|
|
54
|
-
| dataSource
|
|
51
|
+
| Property | Description | Type | Default |
|
|
52
|
+
| ----------- | ----------------------------- | ---------------------- | ------- |
|
|
53
|
+
| buttonLabel | prop to show text of button | string | - |
|
|
54
|
+
| title | prop to show title | string | - |
|
|
55
|
+
| dataSource | data of all items in dropdown | string / MenuItemProps | - |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { theme } from '@synerise/ds-core';
|
|
3
|
+
import Icon, { AngleDownS, AngleUpS, DragHandleM } from '@synerise/ds-icon';
|
|
4
|
+
import * as S from '../Sidebar.styles';
|
|
5
|
+
export var DragOverlayPanel = function DragOverlayPanel(_ref) {
|
|
6
|
+
var header = _ref.header,
|
|
7
|
+
children = _ref.children,
|
|
8
|
+
id = _ref.id,
|
|
9
|
+
isActive = _ref.isActive,
|
|
10
|
+
forceRender = _ref.forceRender;
|
|
11
|
+
return /*#__PURE__*/React.createElement(S.DragOverlay, {
|
|
12
|
+
key: "sidebar-drag-overlay-" + id
|
|
13
|
+
}, /*#__PURE__*/React.createElement(S.DragOverlayHeader, null, /*#__PURE__*/React.createElement(S.SidebarHeader, null, /*#__PURE__*/React.createElement("span", null, header), /*#__PURE__*/React.createElement(S.SidebarHandle, {
|
|
14
|
+
"data-testid": "ds-sidebar-header-handle"
|
|
15
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
16
|
+
color: theme.palette['grey-400'],
|
|
17
|
+
component: /*#__PURE__*/React.createElement(DragHandleM, null)
|
|
18
|
+
})), /*#__PURE__*/React.createElement(S.ExpandIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
19
|
+
color: theme.palette['grey-600'],
|
|
20
|
+
component: isActive ? /*#__PURE__*/React.createElement(AngleUpS, null) : /*#__PURE__*/React.createElement(AngleDownS, null)
|
|
21
|
+
})))), (isActive || forceRender) && /*#__PURE__*/React.createElement(S.DragOverlayContent, null, /*#__PURE__*/React.createElement(S.SidebarContentWrapper, null, children)));
|
|
22
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var _excluded = ["id"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { CSS, useSortable } from '@synerise/ds-sortable';
|
|
6
|
+
import { PanelContent } from '../PanelContent/PanelContent';
|
|
7
|
+
import * as S from '../Sidebar.styles';
|
|
8
|
+
export var DraggablePanel = function DraggablePanel(_ref) {
|
|
9
|
+
var id = _ref.id,
|
|
10
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
11
|
+
var _useSortable = useSortable({
|
|
12
|
+
id: id
|
|
13
|
+
}),
|
|
14
|
+
attributes = _useSortable.attributes,
|
|
15
|
+
listeners = _useSortable.listeners,
|
|
16
|
+
setNodeRef = _useSortable.setNodeRef,
|
|
17
|
+
transform = _useSortable.transform,
|
|
18
|
+
transition = _useSortable.transition;
|
|
19
|
+
var dragStyle = {
|
|
20
|
+
transform: CSS.Transform.toString(transform),
|
|
21
|
+
transition: transition
|
|
22
|
+
};
|
|
23
|
+
return /*#__PURE__*/React.createElement(S.DraggablePanelWrapper, {
|
|
24
|
+
ref: setNodeRef,
|
|
25
|
+
style: dragStyle
|
|
26
|
+
}, /*#__PURE__*/React.createElement(PanelContent, _extends({
|
|
27
|
+
id: id
|
|
28
|
+
}, props, {
|
|
29
|
+
draggable: true,
|
|
30
|
+
dragHandleProps: _extends({}, attributes, listeners)
|
|
31
|
+
})));
|
|
32
|
+
};
|
package/dist/Panel/Panel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { PanelProps } from '../Sidebar.types';
|
|
3
|
-
export declare const Panel: (
|
|
2
|
+
import { type PanelProps } from '../Sidebar.types';
|
|
3
|
+
export declare const Panel: (props: PanelProps) => React.JSX.Element;
|
|
4
4
|
export default Panel;
|
package/dist/Panel/Panel.js
CHANGED
|
@@ -1,101 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import React, { useContext, useMemo, useRef } from 'react';
|
|
5
|
-
import { useDrag, useDrop } from 'react-dnd';
|
|
6
|
-
import Icon, { DragHandleM } from '@synerise/ds-icon';
|
|
7
|
-
import { theme } from '@synerise/ds-core';
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { DraggablePanel } from '../DraggablePanel/DraggablePanel';
|
|
3
|
+
import { PanelContent } from '../PanelContent/PanelContent';
|
|
8
4
|
import { SidebarContext } from '../Sidebar.context';
|
|
9
|
-
|
|
10
|
-
var DraggablePanel = function DraggablePanel(_ref) {
|
|
11
|
-
var id = _ref.id,
|
|
12
|
-
context = _ref.context,
|
|
13
|
-
order = _ref.order,
|
|
14
|
-
children = _ref.children;
|
|
15
|
-
var ref = useRef(null);
|
|
16
|
-
var index = order ? order.indexOf(id) : 0;
|
|
17
|
-
var _useDrop = useDrop({
|
|
18
|
-
accept: 'PANEL',
|
|
19
|
-
hover: function hover(prop, monitor) {
|
|
20
|
-
if (!ref.current) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
var dragIndex = prop.index;
|
|
24
|
-
var hoverIndex = index;
|
|
25
|
-
if (dragIndex === hoverIndex) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
var hoverMonitor = monitor;
|
|
29
|
-
var hoverBoundingRect = ref.current.getBoundingClientRect();
|
|
30
|
-
var hoverMiddleY = hoverBoundingRect.bottom - hoverBoundingRect.top;
|
|
31
|
-
var clientOffset = hoverMonitor.getClientOffset();
|
|
32
|
-
var hoverClientY = clientOffset.y - hoverBoundingRect.top;
|
|
33
|
-
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
context && context.setOrder(dragIndex, hoverIndex);
|
|
40
|
-
hoverMonitor.getItem().index = hoverIndex;
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
drop = _useDrop[1];
|
|
44
|
-
var _useDrag = useDrag({
|
|
45
|
-
item: {
|
|
46
|
-
type: 'PANEL',
|
|
47
|
-
index: index
|
|
48
|
-
},
|
|
49
|
-
begin: function begin() {
|
|
50
|
-
return _extends({}, {
|
|
51
|
-
type: 'PANEL',
|
|
52
|
-
index: index
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
isDragging: function isDragging(monitor) {
|
|
56
|
-
return monitor.getItem().index === index;
|
|
57
|
-
},
|
|
58
|
-
collect: function collect(monitor) {
|
|
59
|
-
return {
|
|
60
|
-
isDragging: monitor.isDragging()
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}),
|
|
64
|
-
isDragging = _useDrag[0].isDragging,
|
|
65
|
-
drag = _useDrag[1];
|
|
66
|
-
drag(drop(ref));
|
|
67
|
-
return /*#__PURE__*/React.createElement(S.PanelWrapper, {
|
|
68
|
-
ref: ref,
|
|
69
|
-
style: {
|
|
70
|
-
opacity: isDragging ? '0' : '1'
|
|
71
|
-
}
|
|
72
|
-
}, children);
|
|
73
|
-
};
|
|
74
|
-
export var Panel = function Panel(_ref2) {
|
|
75
|
-
var header = _ref2.header,
|
|
76
|
-
children = _ref2.children,
|
|
77
|
-
id = _ref2.id,
|
|
78
|
-
props = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
5
|
+
export var Panel = function Panel(props) {
|
|
79
6
|
var context = useContext(SidebarContext);
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
var panelContent = useMemo(function () {
|
|
84
|
-
return /*#__PURE__*/React.createElement(S.AntdPanel, _extends({
|
|
85
|
-
header: /*#__PURE__*/React.createElement(S.SidebarHeader, null, /*#__PURE__*/React.createElement("span", {
|
|
86
|
-
"data-testid": "header-" + id
|
|
87
|
-
}, header), isDragDrop && /*#__PURE__*/React.createElement(S.SidebarHandle, null, /*#__PURE__*/React.createElement(Icon, {
|
|
88
|
-
color: theme.palette['grey-400'],
|
|
89
|
-
component: /*#__PURE__*/React.createElement(DragHandleM, null)
|
|
90
|
-
})))
|
|
91
|
-
}, props, {
|
|
92
|
-
key: id
|
|
93
|
-
}), /*#__PURE__*/React.createElement(S.SidebarContentWrapper, null, children));
|
|
94
|
-
}, [header, isDragDrop, id, props, children]);
|
|
95
|
-
return isDragDrop ? /*#__PURE__*/React.createElement(DraggablePanel, {
|
|
96
|
-
id: id,
|
|
97
|
-
order: order,
|
|
98
|
-
context: context
|
|
99
|
-
}, panelContent) : panelContent;
|
|
7
|
+
var _ref = context || {},
|
|
8
|
+
isSortable = _ref.isSortable;
|
|
9
|
+
return isSortable ? /*#__PURE__*/React.createElement(DraggablePanel, props) : /*#__PURE__*/React.createElement(PanelContent, props);
|
|
100
10
|
};
|
|
101
11
|
export default Panel;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var _excluded = ["header", "children", "id", "draggable", "dragHandleProps"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { theme } from '@synerise/ds-core';
|
|
6
|
+
import Icon, { DragHandleM } from '@synerise/ds-icon';
|
|
7
|
+
import * as S from '../Sidebar.styles';
|
|
8
|
+
export var PanelContent = function PanelContent(_ref) {
|
|
9
|
+
var header = _ref.header,
|
|
10
|
+
children = _ref.children,
|
|
11
|
+
id = _ref.id,
|
|
12
|
+
draggable = _ref.draggable,
|
|
13
|
+
dragHandleProps = _ref.dragHandleProps,
|
|
14
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
15
|
+
return /*#__PURE__*/React.createElement(S.AntdPanel, _extends({
|
|
16
|
+
header: /*#__PURE__*/React.createElement(S.SidebarHeader, null, /*#__PURE__*/React.createElement("span", {
|
|
17
|
+
"data-testid": "header-" + id
|
|
18
|
+
}, header), draggable && /*#__PURE__*/React.createElement(S.SidebarHandle, _extends({
|
|
19
|
+
"data-testid": "ds-sidebar-header-handle"
|
|
20
|
+
}, dragHandleProps), /*#__PURE__*/React.createElement(Icon, {
|
|
21
|
+
color: theme.palette['grey-400'],
|
|
22
|
+
component: /*#__PURE__*/React.createElement(DragHandleM, null)
|
|
23
|
+
}))),
|
|
24
|
+
key: id,
|
|
25
|
+
isDragOverlay: id === '-1'
|
|
26
|
+
}, props), /*#__PURE__*/React.createElement(S.SidebarContentWrapper, null, children));
|
|
27
|
+
};
|
package/dist/Sidebar.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type PanelProps, type SidebarProps } from './Sidebar.types';
|
|
2
3
|
import './style/index.less';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Panel: typeof Panel;
|
|
4
|
+
export declare const Sidebar: {
|
|
5
|
+
({ children, order, onChangeOrder, defaultActiveKey, activeKey, onChange, className, getPopupContainer, ...collapseProps }: SidebarProps): React.JSX.Element;
|
|
6
|
+
Panel: (props: PanelProps) => React.JSX.Element;
|
|
7
7
|
};
|
|
8
8
|
export default Sidebar;
|
package/dist/Sidebar.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
var _excluded = ["children", "order", "onChangeOrder", "defaultActiveKey", "activeKey", "onChange"];
|
|
1
|
+
var _excluded = ["children", "order", "onChangeOrder", "defaultActiveKey", "activeKey", "onChange", "className", "getPopupContainer"];
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import React, { Children, useCallback, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
import { useTheme } from '@synerise/ds-core';
|
|
7
8
|
import Icon, { AngleDownS, AngleUpS } from '@synerise/ds-icon';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import update from 'immutability-helper';
|
|
11
|
-
import * as S from './Sidebar.styles';
|
|
9
|
+
import { DragOverlay, SortableContainer } from '@synerise/ds-sortable';
|
|
10
|
+
import { DragOverlayPanel } from './DragOverlayPanel/DragOverlayPanel';
|
|
12
11
|
import { Panel } from './Panel/Panel';
|
|
13
12
|
import { SidebarContext } from './Sidebar.context';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
var Sidebar = function Sidebar(_ref) {
|
|
13
|
+
import * as S from './Sidebar.styles';
|
|
14
|
+
import "./style/index.css";
|
|
15
|
+
import { prefixKeys } from './utils/prefixKeys';
|
|
16
|
+
export var Sidebar = function Sidebar(_ref) {
|
|
20
17
|
var children = _ref.children,
|
|
21
18
|
_ref$order = _ref.order,
|
|
22
19
|
order = _ref$order === void 0 ? [] : _ref$order,
|
|
@@ -24,65 +21,121 @@ var Sidebar = function Sidebar(_ref) {
|
|
|
24
21
|
defaultActiveKey = _ref.defaultActiveKey,
|
|
25
22
|
activeKey = _ref.activeKey,
|
|
26
23
|
onChange = _ref.onChange,
|
|
24
|
+
className = _ref.className,
|
|
25
|
+
getPopupContainer = _ref.getPopupContainer,
|
|
27
26
|
collapseProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
var _useState = useState(),
|
|
28
|
+
draggedItem = _useState[0],
|
|
29
|
+
setDraggedItem = _useState[1];
|
|
30
|
+
var isSortable = Array.isArray(order) && order.length > 0 && !!onChangeOrder;
|
|
31
|
+
var theme = useTheme();
|
|
32
|
+
var wrapperRef = useRef(null);
|
|
33
|
+
var _useState2 = useState(function () {
|
|
34
|
+
if (!activeKey && !defaultActiveKey) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
if (activeKey) {
|
|
38
|
+
return Array.isArray(activeKey) ? activeKey : [activeKey];
|
|
39
|
+
}
|
|
40
|
+
if (defaultActiveKey) {
|
|
41
|
+
return Array.isArray(defaultActiveKey) ? defaultActiveKey : [defaultActiveKey];
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}),
|
|
45
|
+
activeKeys = _useState2[0],
|
|
46
|
+
setActiveKeys = _useState2[1];
|
|
47
|
+
var sortableItems = useMemo(function () {
|
|
48
|
+
return order.map(function (id) {
|
|
49
|
+
return {
|
|
50
|
+
id: id
|
|
51
|
+
};
|
|
45
52
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return key.startsWith('.') ? key.substring(1) : key;
|
|
53
|
+
}, [order]);
|
|
54
|
+
var handleOnChange = useCallback(function (keys) {
|
|
55
|
+
var finalKeys = isSortable ? (Array.isArray(keys) ? keys : [keys]).map(function (key) {
|
|
56
|
+
return key.startsWith('.$') ? key.substring(2) : key;
|
|
51
57
|
}) : keys;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
setActiveKeys(Array.isArray(finalKeys) ? finalKeys : [finalKeys]);
|
|
59
|
+
onChange == null || onChange(finalKeys);
|
|
60
|
+
}, [isSortable, onChange]);
|
|
61
|
+
var sortedChildren = useMemo(function () {
|
|
62
|
+
return Children.toArray(children).sort(function (a, b) {
|
|
63
|
+
if (!isSortable) {
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
return Array.isArray(order) && order.indexOf(a.props.id) > order.indexOf(b.props.id) ? 1 : -1;
|
|
67
|
+
});
|
|
68
|
+
}, [children, isSortable, order]);
|
|
69
|
+
var activeKeysProp = useMemo(function () {
|
|
70
|
+
var prependedActiveKey = isSortable && activeKey ? prefixKeys(activeKey) : activeKey;
|
|
71
|
+
var prependedDefaultActiveKey = isSortable && defaultActiveKey ? prefixKeys(defaultActiveKey) : defaultActiveKey;
|
|
72
|
+
var keyProp = {};
|
|
73
|
+
if (prependedDefaultActiveKey !== undefined) {
|
|
74
|
+
keyProp = {
|
|
75
|
+
defaultActiveKey: prependedDefaultActiveKey
|
|
61
76
|
};
|
|
62
|
-
} else if (
|
|
63
|
-
|
|
64
|
-
activeKey:
|
|
77
|
+
} else if (prependedActiveKey !== undefined) {
|
|
78
|
+
keyProp = {
|
|
79
|
+
activeKey: prependedActiveKey
|
|
65
80
|
};
|
|
66
81
|
}
|
|
67
|
-
return
|
|
68
|
-
|
|
82
|
+
return keyProp;
|
|
83
|
+
}, [isSortable, activeKey, defaultActiveKey]);
|
|
84
|
+
var isDraggedPanelActive = useCallback(function (id) {
|
|
85
|
+
return activeKeys.indexOf(id) > -1;
|
|
86
|
+
}, [activeKeys]);
|
|
87
|
+
var handleDragStart = useCallback(function (_ref2) {
|
|
88
|
+
var active = _ref2.active;
|
|
89
|
+
var activePanel = sortedChildren.find(function (child) {
|
|
90
|
+
return child.props.id === active.id;
|
|
91
|
+
});
|
|
92
|
+
setDraggedItem(activePanel == null ? void 0 : activePanel.props);
|
|
93
|
+
}, [sortedChildren]);
|
|
94
|
+
var handleDragEnd = useCallback(function () {
|
|
95
|
+
setDraggedItem(undefined);
|
|
96
|
+
}, []);
|
|
97
|
+
var handleOrderChange = function handleOrderChange(newOrder) {
|
|
98
|
+
onChangeOrder == null || onChangeOrder(newOrder.map(function (item) {
|
|
99
|
+
return item.id;
|
|
100
|
+
}));
|
|
101
|
+
};
|
|
102
|
+
var collapseContent = useMemo(function () {
|
|
103
|
+
var dragOverlay = /*#__PURE__*/React.createElement(DragOverlay, null, draggedItem && /*#__PURE__*/React.createElement(DragOverlayPanel, _extends({
|
|
104
|
+
isActive: isDraggedPanelActive(draggedItem.id),
|
|
105
|
+
forceRender: isDraggedPanelActive(draggedItem.id)
|
|
106
|
+
}, draggedItem, {
|
|
107
|
+
draggable: true,
|
|
108
|
+
id: "-1",
|
|
109
|
+
key: "-1"
|
|
110
|
+
})));
|
|
111
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
112
|
+
ref: wrapperRef
|
|
113
|
+
}, /*#__PURE__*/React.createElement(S.AntdCollapse, _extends({}, activeKeysProp, {
|
|
114
|
+
className: classNames({
|
|
115
|
+
'is-drag-drop': isSortable,
|
|
116
|
+
className: className
|
|
117
|
+
}),
|
|
69
118
|
expandIconPosition: "end",
|
|
70
|
-
expandIcon: function expandIcon(
|
|
71
|
-
var
|
|
72
|
-
return
|
|
119
|
+
expandIcon: function expandIcon(_ref3) {
|
|
120
|
+
var isActive = _ref3.isActive;
|
|
121
|
+
return /*#__PURE__*/React.createElement(Icon, {
|
|
122
|
+
color: theme.palette['grey-600'],
|
|
123
|
+
component: isActive ? /*#__PURE__*/React.createElement(AngleUpS, null) : /*#__PURE__*/React.createElement(AngleDownS, null)
|
|
124
|
+
});
|
|
73
125
|
},
|
|
74
126
|
onChange: handleOnChange
|
|
75
|
-
}, collapseProps),
|
|
76
|
-
}, [
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
127
|
+
}, collapseProps), isSortable ? sortedChildren : children), wrapperRef.current && getPopupContainer ? /*#__PURE__*/createPortal(dragOverlay, getPopupContainer(wrapperRef.current)) : dragOverlay);
|
|
128
|
+
}, [draggedItem, isDraggedPanelActive, activeKeysProp, isSortable, className, handleOnChange, collapseProps, sortedChildren, children, getPopupContainer, theme.palette]);
|
|
129
|
+
return isSortable ? /*#__PURE__*/React.createElement(SortableContainer, {
|
|
130
|
+
axis: "y",
|
|
131
|
+
items: sortableItems,
|
|
132
|
+
onDragStart: handleDragStart,
|
|
133
|
+
onDragEnd: handleDragEnd,
|
|
134
|
+
onDragCancel: handleDragEnd,
|
|
135
|
+
onOrderChange: handleOrderChange
|
|
82
136
|
}, /*#__PURE__*/React.createElement(SidebarContext.Provider, {
|
|
83
137
|
value: {
|
|
84
|
-
|
|
85
|
-
setOrder: changeOrder
|
|
138
|
+
isSortable: isSortable
|
|
86
139
|
}
|
|
87
140
|
}, collapseContent)) : collapseContent;
|
|
88
141
|
};
|
package/dist/Sidebar.styles.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import React from 'react';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
export declare const SidebarHandle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
3
|
export declare const SidebarHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const AntdCollapse: import("styled-components").StyledComponent<
|
|
7
|
-
|
|
4
|
+
export declare const DraggablePanelWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
export declare const AntdCollapse: import("styled-components").StyledComponent<import("react").FC<import("antd/lib/collapse").CollapseProps> & {
|
|
6
|
+
Panel: import("react").FC<import("antd/lib/collapse").CollapsePanelProps>;
|
|
7
|
+
}, any, {}, never>;
|
|
8
|
+
export declare const AntdPanel: import("styled-components").StyledComponent<import("react").FC<import("antd/lib/collapse").CollapsePanelProps>, any, {
|
|
9
|
+
isDragOverlay?: boolean | undefined;
|
|
10
|
+
}, never>;
|
|
8
11
|
export declare const SidebarContentWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
9
|
-
export declare const
|
|
12
|
+
export declare const DragOverlay: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
13
|
+
export declare const DragOverlayHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
14
|
+
export declare const DragOverlayContent: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
15
|
+
export declare const ExpandIcon: import("styled-components").StyledComponent<"div", any, {}, never>;
|
package/dist/Sidebar.styles.js
CHANGED
|
@@ -1,48 +1,63 @@
|
|
|
1
|
-
import styled from 'styled-components';
|
|
2
1
|
import Collapse from 'antd/lib/collapse';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
3
|
var Panel = Collapse.Panel;
|
|
4
|
-
var themePaletteGrey700 = function themePaletteGrey700(props) {
|
|
5
|
-
return props.theme.palette['grey-700'];
|
|
6
|
-
};
|
|
7
|
-
var themePaletteGrey800 = function themePaletteGrey800(props) {
|
|
8
|
-
return props.theme.palette['grey-800'];
|
|
9
|
-
};
|
|
10
|
-
var themePaletteBlue050 = function themePaletteBlue050(props) {
|
|
11
|
-
return props.theme.palette['blue-050'];
|
|
12
|
-
};
|
|
13
|
-
var themePaletteGrey200 = function themePaletteGrey200(props) {
|
|
14
|
-
return props.theme.palette['grey-200'];
|
|
15
|
-
};
|
|
16
|
-
var themePaletteBlue600 = function themePaletteBlue600(props) {
|
|
17
|
-
return props.theme.palette['blue-600'];
|
|
18
|
-
};
|
|
19
4
|
export var SidebarHandle = styled.div.withConfig({
|
|
20
5
|
displayName: "Sidebarstyles__SidebarHandle",
|
|
21
6
|
componentId: "sc-19um1hw-0"
|
|
22
|
-
})(["display:flex;opacity:1;transition:0.2s ease-in-out;&::before{content:'';position:absolute;width:100%;height:100%;left:0;top:0;pointer-events:none;}"]);
|
|
7
|
+
})(["display:flex;opacity:1;transition:0.2s ease-in-out;cursor:grabbing;position:absolute;left:0;top:50%;transform:translateY(-50%);&::before{content:'';position:absolute;width:100%;height:100%;left:0;top:0;pointer-events:none;}"]);
|
|
23
8
|
export var SidebarHeader = styled.div.withConfig({
|
|
24
9
|
displayName: "Sidebarstyles__SidebarHeader",
|
|
25
10
|
componentId: "sc-19um1hw-1"
|
|
26
|
-
})(["display:flex;align-items:center;max-height:20px;
|
|
27
|
-
export var
|
|
28
|
-
displayName: "
|
|
11
|
+
})(["display:flex;align-items:center;max-height:20px;"]);
|
|
12
|
+
export var DraggablePanelWrapper = styled.div.withConfig({
|
|
13
|
+
displayName: "Sidebarstyles__DraggablePanelWrapper",
|
|
29
14
|
componentId: "sc-19um1hw-2"
|
|
30
15
|
})(["position:relative;"]);
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
var expandIconStyles = css(["right:24px;top:50%;transform:translateY(-50%);position:absolute;"]);
|
|
17
|
+
var headerStyle = css(["padding:18px 24px;color:", ";font-weight:500;font-size:14px;background:white;position:relative;cursor:pointer;&:hover{color:", ";}"], function (props) {
|
|
18
|
+
return props.theme.palette['grey-700'];
|
|
19
|
+
}, function (props) {
|
|
20
|
+
return props.theme.palette['grey-800'];
|
|
21
|
+
});
|
|
33
22
|
export var AntdCollapse = styled(Collapse).withConfig({
|
|
34
23
|
displayName: "Sidebarstyles__AntdCollapse",
|
|
35
24
|
componentId: "sc-19um1hw-3"
|
|
36
|
-
})(["&.ant-collapse{background-color:", ";border:none;.ant-collapse-
|
|
25
|
+
})(["&.ant-collapse{background-color:", ";border:none;.ant-collapse-arrow{position:static !important;vertical-align:0 !important;transform:none !important;display:block;}.ant-collapse-header{", "}", " > .ant-collapse-item > .ant-collapse-header{transition:0.2s ease-in-out;display:flex;align-items:center;justify-content:flex-start;}.ant-collapse-content-active,.ant-collapse-item-active{border-top:0;", ",", "{color:", ";&:hover{color:", ";}}}.ant-collapse-content-box{padding:16px 24px;}.ant-collapse-item{position:relative;border-top:solid 1px ", ";border-bottom:none;}}.ant-collapse-item:hover ", "{opacity:1;}&.ant-collapse-icon-position-end{.ant-collapse-item > .ant-collapse-header{padding:18px 24px;user-select:none;.ant-collapse-expand-icon{", "}}&.ant-collapse-icon-position-end.is-drag-drop ", " > .ant-collapse-item{&:hover{color:", ";}}}"], function (props) {
|
|
26
|
+
return props.theme.palette['blue-050'];
|
|
27
|
+
}, headerStyle, DraggablePanelWrapper, SidebarHeader, SidebarHandle, function (props) {
|
|
28
|
+
return props.theme.palette['grey-700'];
|
|
29
|
+
}, function (props) {
|
|
30
|
+
return props.theme.palette['grey-800'];
|
|
31
|
+
}, function (props) {
|
|
32
|
+
return props.theme.palette['grey-200'];
|
|
33
|
+
}, SidebarHandle, expandIconStyles, DraggablePanelWrapper, function (props) {
|
|
34
|
+
return props.theme.palette['grey-800'];
|
|
35
|
+
});
|
|
37
36
|
export var AntdPanel = styled(Panel).withConfig({
|
|
38
37
|
displayName: "Sidebarstyles__AntdPanel",
|
|
39
38
|
componentId: "sc-19um1hw-4"
|
|
40
|
-
})([".ant-collapse-content{background-color:white;border-radius:0;border
|
|
39
|
+
})(["", " .ant-collapse-content{background-color:white;border-radius:0;border:none;}"], function (props) {
|
|
40
|
+
return props.isDragOverlay && css(["box-shadow:", ";z-index:10;"], props.theme.variables['box-shadow-2']);
|
|
41
|
+
});
|
|
41
42
|
export var SidebarContentWrapper = styled.div.withConfig({
|
|
42
43
|
displayName: "Sidebarstyles__SidebarContentWrapper",
|
|
43
44
|
componentId: "sc-19um1hw-5"
|
|
44
|
-
})(["
|
|
45
|
-
export var
|
|
46
|
-
displayName: "
|
|
45
|
+
})([""]);
|
|
46
|
+
export var DragOverlay = styled.div.withConfig({
|
|
47
|
+
displayName: "Sidebarstyles__DragOverlay",
|
|
47
48
|
componentId: "sc-19um1hw-6"
|
|
48
|
-
})(["
|
|
49
|
+
})([""]);
|
|
50
|
+
export var DragOverlayHeader = styled.div.withConfig({
|
|
51
|
+
displayName: "Sidebarstyles__DragOverlayHeader",
|
|
52
|
+
componentId: "sc-19um1hw-7"
|
|
53
|
+
})(["border-top:1px solid ", ";padding:18px 24px;user-select:none;", ""], function (props) {
|
|
54
|
+
return props.theme.palette['grey-200'];
|
|
55
|
+
}, headerStyle);
|
|
56
|
+
export var DragOverlayContent = styled.div.withConfig({
|
|
57
|
+
displayName: "Sidebarstyles__DragOverlayContent",
|
|
58
|
+
componentId: "sc-19um1hw-8"
|
|
59
|
+
})(["background-color:white;padding:16px 24px;"]);
|
|
60
|
+
export var ExpandIcon = styled.div.withConfig({
|
|
61
|
+
displayName: "Sidebarstyles__ExpandIcon",
|
|
62
|
+
componentId: "sc-19um1hw-9"
|
|
63
|
+
})(["", ""], expandIconStyles);
|
package/dist/Sidebar.types.d.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { type CollapseProps } from 'antd/lib/collapse';
|
|
2
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
3
3
|
export type SidebarProps = CollapseProps & {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
order?: string[];
|
|
6
6
|
onChangeOrder?: (order: Order) => void;
|
|
7
|
+
getPopupContainer?: (node: HTMLDivElement) => HTMLElement;
|
|
7
8
|
};
|
|
8
9
|
export type PanelProps = {
|
|
9
10
|
header: ReactNode;
|
|
10
11
|
children: ReactNode;
|
|
11
12
|
id: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
children?: ReactNode;
|
|
17
|
-
context?: SidebarContextType;
|
|
13
|
+
draggable?: boolean;
|
|
14
|
+
isActive?: boolean;
|
|
15
|
+
forceRender?: boolean;
|
|
16
|
+
dragHandleProps?: HTMLAttributes<HTMLDivElement>;
|
|
18
17
|
};
|
|
19
18
|
export type SidebarContextType = {
|
|
20
|
-
|
|
21
|
-
setOrder: (dragIndex: number, hoverIndex: number) => void;
|
|
19
|
+
isSortable?: boolean;
|
|
22
20
|
};
|
|
23
21
|
export type Order = string[] | string;
|
|
24
22
|
export type CompareFnType = (a: ReactElement<PanelProps>, b: ReactElement<PanelProps>) => number;
|