@synerise/ds-sidebar 1.0.16 → 1.0.18

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 CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.18](https://github.com/Synerise/synerise-design/compare/@synerise/ds-sidebar@1.0.17...@synerise/ds-sidebar@1.0.18) (2025-07-15)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-sidebar
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.0.17](https://github.com/Synerise/synerise-design/compare/@synerise/ds-sidebar@1.0.16...@synerise/ds-sidebar@1.0.17) (2025-07-08)
15
+
16
+ **Note:** Version bump only for package @synerise/ds-sidebar
17
+
18
+
19
+
20
+
21
+
6
22
  ## [1.0.16](https://github.com/Synerise/synerise-design/compare/@synerise/ds-sidebar@1.0.15...@synerise/ds-sidebar@1.0.16) (2025-07-01)
7
23
 
8
24
  **Note:** Version bump only for package @synerise/ds-sidebar
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
 
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { type PanelProps } from '../Sidebar.types';
3
+ export declare const DragOverlayPanel: ({ header, children, id, isActive, forceRender, }: PanelProps) => React.JSX.Element;
@@ -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,3 @@
1
+ import React from 'react';
2
+ import { type PanelProps } from '../Sidebar.types';
3
+ export declare const DraggablePanel: ({ id, ...props }: PanelProps) => React.JSX.Element;
@@ -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
+ };
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { type PanelProps } from '../Sidebar.types';
3
- export declare const Panel: ({ header, children, id, ...props }: PanelProps) => React.JSX.Element;
3
+ export declare const Panel: (props: PanelProps) => React.JSX.Element;
4
4
  export default Panel;
@@ -1,101 +1,11 @@
1
- var _excluded = ["header", "children", "id"];
2
- 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; }
3
- 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); }
4
- import React, { useContext, useMemo, useRef } from 'react';
5
- import { useDrag, useDrop } from 'react-dnd';
6
- import { theme } from '@synerise/ds-core';
7
- import Icon, { DragHandleM } from '@synerise/ds-icon';
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
- import * as S from '../Sidebar.styles';
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 _ref3 = context || {},
81
- order = _ref3.order;
82
- var isDragDrop = context && !!order;
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,3 @@
1
+ import React from 'react';
2
+ import { type PanelProps } from '../Sidebar.types';
3
+ export declare const PanelContent: ({ header, children, id, draggable, dragHandleProps, ...props }: PanelProps) => React.JSX.Element;
@@ -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 { Panel } from './Panel/Panel';
3
- import { type SidebarProps } from './Sidebar.types';
2
+ import { type PanelProps, type SidebarProps } from './Sidebar.types';
4
3
  import './style/index.less';
5
- declare const Sidebar: React.FC<SidebarProps> & {
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 update from 'immutability-helper';
5
- import React from 'react';
6
- import { DndProvider } from 'react-dnd';
7
- import HTML5Backend from 'react-dnd-html5-backend';
8
- import { theme } from '@synerise/ds-core';
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';
9
8
  import Icon, { AngleDownS, AngleUpS } from '@synerise/ds-icon';
9
+ import { DragOverlay, SortableContainer } from '@synerise/ds-sortable';
10
+ import { DragOverlayPanel } from './DragOverlayPanel/DragOverlayPanel';
10
11
  import { Panel } from './Panel/Panel';
11
12
  import { SidebarContext } from './Sidebar.context';
12
13
  import * as S from './Sidebar.styles';
13
14
  import "./style/index.css";
14
- var prependDots = function prependDots(keys) {
15
- return keys && Array.isArray(keys) ? keys.map(function (el) {
16
- return "." + el;
17
- }) : "." + keys;
18
- };
19
- var Sidebar = function Sidebar(_ref) {
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 isDragDrop = Array.isArray(order) && order.length > 0;
29
- var isActive = function isActive(checkActive) {
30
- return /*#__PURE__*/React.createElement(Icon, {
31
- color: theme.palette['grey-600'],
32
- component: checkActive ? /*#__PURE__*/React.createElement(AngleUpS, null) : /*#__PURE__*/React.createElement(AngleDownS, null)
33
- });
34
- };
35
- var compareByPositionOfKey = React.useCallback(function (a, b) {
36
- if (!isDragDrop) {
37
- return 1;
38
- }
39
- return Array.isArray(order) && order.indexOf(a.props.id) > order.indexOf(b.props.id) ? 1 : -1;
40
- }, [isDragDrop, order]);
41
- var changeOrder = function changeOrder(dragIndex, hoverIndex) {
42
- var dragItemBlock = order[dragIndex];
43
- var orderedItems = update(order, {
44
- $splice: [[dragIndex, 1], [hoverIndex, 0, dragItemBlock]]
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
- onChangeOrder && onChangeOrder(orderedItems);
47
- };
48
- var handleOnChange = React.useCallback(function (keys) {
49
- var finalKeys = isDragDrop ? (Array.isArray(keys) ? keys : [keys]).map(function (key) {
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
- onChange && onChange(finalKeys);
53
- }, [isDragDrop, onChange]);
54
- var antdActiveKey = isDragDrop && activeKey ? prependDots(activeKey) : activeKey;
55
- var antdDefaultActiveKey = isDragDrop && defaultActiveKey ? prependDots(defaultActiveKey) : defaultActiveKey;
56
- var collapseContent = React.useMemo(function () {
57
- var activeKeysProp = {};
58
- if (antdDefaultActiveKey !== undefined) {
59
- activeKeysProp = {
60
- defaultActiveKey: antdDefaultActiveKey
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 (antdActiveKey !== undefined) {
63
- activeKeysProp = {
64
- activeKey: antdActiveKey
77
+ } else if (prependedActiveKey !== undefined) {
78
+ keyProp = {
79
+ activeKey: prependedActiveKey
65
80
  };
66
81
  }
67
- return /*#__PURE__*/React.createElement(S.AntdCollapse, _extends({}, activeKeysProp, {
68
- className: isDragDrop ? 'is-drag-drop' : '',
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(panelProps) {
71
- var checkActive = panelProps.isActive;
72
- return isActive(checkActive);
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), isDragDrop ? React.Children.toArray(children).sort(compareByPositionOfKey) : children);
76
- }, [antdDefaultActiveKey, antdActiveKey, isDragDrop, handleOnChange, collapseProps, children, compareByPositionOfKey]);
77
- return isDragDrop ?
78
- /*#__PURE__*/
79
- // @ts-expect-error Property 'children' does not exist on type 'IntrinsicAttributes & DndProviderProps<any, any>'.
80
- React.createElement(DndProvider, {
81
- backend: HTML5Backend
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
- order: order,
85
- setOrder: changeOrder
138
+ isSortable: isSortable
86
139
  }
87
140
  }, collapseContent)) : collapseContent;
88
141
  };
@@ -1,9 +1,15 @@
1
- import { type CollapseProps } from 'antd/lib/collapse';
2
- import type 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 PanelWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
6
- export declare const AntdCollapse: import("styled-components").StyledComponent<React.ComponentType<CollapseProps>, any, {}, never>;
7
- export declare const AntdPanel: import("styled-components").StyledComponent<React.FC<import("antd/lib/collapse").CollapsePanelProps>, any, {}, never>;
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 SidebarContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
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>;
@@ -1,46 +1,63 @@
1
1
  import Collapse from 'antd/lib/collapse';
2
- import styled from 'styled-components';
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;span{order:1;}"]);
27
- export var PanelWrapper = styled.div.withConfig({
28
- displayName: "Sidebarstyles__PanelWrapper",
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;"]);
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
+ });
31
22
  export var AntdCollapse = styled(Collapse).withConfig({
32
23
  displayName: "Sidebarstyles__AntdCollapse",
33
24
  componentId: "sc-19um1hw-3"
34
- })(["&.ant-collapse{background-color:", ";border:none;.ant-collapse-header{padding:19px 24px;color:", ";font-weight:500;font-size:14px;background:white;&:hover{color:", ";}&:active{box-shadow:0px 16px 32px 0px rgba(35,41,54,0.1);}}> ", " > .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;.drag-handle-m:hover{cursor:grabbing;}}}.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{right:24px;position:absolute;}}&.ant-collapse-icon-position-end.is-drag-drop > ", " > .ant-collapse-item > .ant-collapse-header{padding:18px 24px 18px 0;cursor:pointer;&:hover,&:active{color:", ";box-shadow:0 16px 32px 0 rgba(35,41,54,0.1);}}"], themePaletteBlue050, themePaletteGrey700, themePaletteGrey800, PanelWrapper, SidebarHeader, SidebarHandle, themePaletteGrey700, themePaletteGrey800, themePaletteGrey200, SidebarHandle, PanelWrapper, PanelWrapper, themePaletteGrey800);
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
+ });
35
36
  export var AntdPanel = styled(Panel).withConfig({
36
37
  displayName: "Sidebarstyles__AntdPanel",
37
38
  componentId: "sc-19um1hw-4"
38
- })([".ant-collapse-content{background-color:white;border-radius:0;border-color:", ";}"], themePaletteGrey800);
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
+ });
39
42
  export var SidebarContentWrapper = styled.div.withConfig({
40
43
  displayName: "Sidebarstyles__SidebarContentWrapper",
41
44
  componentId: "sc-19um1hw-5"
42
- })(["display:flex;flex-wrap:wrap;"]);
43
- export var SidebarContainer = styled.div.withConfig({
44
- displayName: "Sidebarstyles__SidebarContainer",
45
+ })([""]);
46
+ export var DragOverlay = styled.div.withConfig({
47
+ displayName: "Sidebarstyles__DragOverlay",
45
48
  componentId: "sc-19um1hw-6"
46
- })(["flex-direction:row;align-items:flex-start;justify-content:flex-start;width:100%;min-width:588px;.ds-card-tags-sortable{gap:16px 12px;margin-bottom:16px;display:flex;flex-direction:row;align-items:flex-start;justify-content:flex-start;flex-wrap:wrap;}.sortable-chosen,.sortable-drag,.sortable-card-ghost-element{cursor:grabbing;box-shadow:0 16px 32px 0 rgba(35,41,54,0.1);opacity:1;&.sortable-card-ghost-element{border:dashed 1px ", ";background-color:", ";*{visibility:hidden;}}}"], themePaletteBlue600, themePaletteBlue050);
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);
@@ -1,24 +1,22 @@
1
1
  import { type CollapseProps } from 'antd/lib/collapse';
2
- import type { ReactElement, ReactNode } from 'react';
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
- export type DraggablePanelProps = {
14
- id: string;
15
- order?: Order;
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
- order: Order;
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;
@@ -0,0 +1 @@
1
+ export declare const prefixKeys: (keys: string | number | (string | number)[]) => string | string[];
@@ -0,0 +1,5 @@
1
+ export var prefixKeys = function prefixKeys(keys) {
2
+ return keys && Array.isArray(keys) ? keys.map(function (el) {
3
+ return ".$" + el;
4
+ }) : ".$" + keys;
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-sidebar",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Sidebar UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -34,15 +34,13 @@
34
34
  ],
35
35
  "types": "dist/index.d.ts",
36
36
  "dependencies": {
37
- "@synerise/ds-button": "^1.4.2",
38
- "@synerise/ds-dropdown": "^1.0.15",
39
- "@synerise/ds-icon": "^1.5.4",
40
- "@synerise/ds-menu": "^1.0.14",
37
+ "@synerise/ds-button": "^1.4.4",
38
+ "@synerise/ds-dropdown": "^1.0.17",
39
+ "@synerise/ds-icon": "^1.6.0",
40
+ "@synerise/ds-menu": "^1.0.16",
41
+ "@synerise/ds-sortable": "^1.3.1",
41
42
  "@synerise/ds-utils": "^1.3.1",
42
- "dnd-core": "10.0.2",
43
- "immutability-helper": "^3.0.1",
44
- "react-dnd": "^10.0.2",
45
- "react-dnd-html5-backend": "^10.0.2"
43
+ "classnames": "^2.5.1"
46
44
  },
47
45
  "peerDependencies": {
48
46
  "@synerise/ds-core": "*",
@@ -50,5 +48,5 @@
50
48
  "react": ">=16.9.0 <= 18.3.1",
51
49
  "styled-components": "^5.3.3"
52
50
  },
53
- "gitHead": "4512641033ba3581a3df208143c547fcfed45895"
51
+ "gitHead": "f7c362a4f370d86b51df9aba9e91ac8f7fe4ed8f"
54
52
  }