@datarobot/design-system 28.9.2 → 28.10.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/cjs/floating-panel/constants.d.ts +21 -0
- package/cjs/floating-panel/constants.js +94 -0
- package/cjs/floating-panel/draggable-area.d.ts +12 -0
- package/cjs/floating-panel/draggable-area.js +72 -0
- package/cjs/floating-panel/floating-panel-dock-button.d.ts +5 -0
- package/cjs/floating-panel/floating-panel-dock-button.js +37 -0
- package/cjs/floating-panel/floating-panel-drag-handle.d.ts +5 -0
- package/cjs/floating-panel/floating-panel-drag-handle.js +51 -0
- package/cjs/floating-panel/floating-panel-header.d.ts +11 -0
- package/cjs/floating-panel/floating-panel-header.js +46 -0
- package/cjs/floating-panel/floating-panel.d.ts +66 -0
- package/cjs/floating-panel/floating-panel.js +140 -0
- package/cjs/floating-panel/index.d.ts +4 -0
- package/cjs/floating-panel/index.js +19 -0
- package/cjs/floating-panel/types.d.ts +21 -0
- package/cjs/floating-panel/types.js +5 -0
- package/cjs/floating-panel/use-floating-panel-root.d.ts +6 -0
- package/cjs/floating-panel/use-floating-panel-root.js +31 -0
- package/cjs/floating-panel/use-floating-panel-state.d.ts +27 -0
- package/cjs/floating-panel/use-floating-panel-state.js +316 -0
- package/cjs/floating-panel/use-floating-panel.d.ts +4 -0
- package/cjs/floating-panel/use-floating-panel.js +14 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +11 -0
- package/cjs/table-react/hooks/useColumns.js +13 -5
- package/esm/floating-panel/constants.d.ts +21 -0
- package/esm/floating-panel/constants.js +86 -0
- package/esm/floating-panel/draggable-area.d.ts +12 -0
- package/esm/floating-panel/draggable-area.js +65 -0
- package/esm/floating-panel/floating-panel-dock-button.d.ts +5 -0
- package/esm/floating-panel/floating-panel-dock-button.js +30 -0
- package/esm/floating-panel/floating-panel-drag-handle.d.ts +5 -0
- package/esm/floating-panel/floating-panel-drag-handle.js +44 -0
- package/esm/floating-panel/floating-panel-header.d.ts +11 -0
- package/esm/floating-panel/floating-panel-header.js +39 -0
- package/esm/floating-panel/floating-panel.d.ts +66 -0
- package/esm/floating-panel/floating-panel.js +132 -0
- package/esm/floating-panel/index.d.ts +4 -0
- package/esm/floating-panel/index.js +2 -0
- package/esm/floating-panel/types.d.ts +21 -0
- package/esm/floating-panel/types.js +1 -0
- package/esm/floating-panel/use-floating-panel-root.d.ts +6 -0
- package/esm/floating-panel/use-floating-panel-root.js +24 -0
- package/esm/floating-panel/use-floating-panel-state.d.ts +27 -0
- package/esm/floating-panel/use-floating-panel-state.js +310 -0
- package/esm/floating-panel/use-floating-panel.d.ts +4 -0
- package/esm/floating-panel/use-floating-panel.js +9 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/table-react/hooks/useColumns.js +13 -5
- package/floating-panel/package.json +7 -0
- package/js/bundle/bundle.js +1351 -332
- package/js/bundle/bundle.min.js +1 -1
- package/js/bundle/index.d.ts +94 -1
- package/package.json +1 -1
- package/styles/index.css +150 -0
- package/styles/index.min.css +1 -1
- package/styles/themes/alpine-light.css +12 -0
- package/styles/themes/alpine-light.min.css +1 -1
- package/styles/themes/midnight-gray.css +12 -0
- package/styles/themes/midnight-gray.min.css +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FloatingPanelContextType } from './types';
|
|
3
|
+
export declare const FloatingPanelContext: import("react").Context<FloatingPanelContextType>;
|
|
4
|
+
export declare const MOVE_KEYS: {
|
|
5
|
+
readonly UP: "ArrowUp";
|
|
6
|
+
readonly DOWN: "ArrowDown";
|
|
7
|
+
readonly RIGHT: "ArrowRight";
|
|
8
|
+
readonly LEFT: "ArrowLeft";
|
|
9
|
+
};
|
|
10
|
+
export declare const MOVE_KEYS_VALUES: ("ArrowUp" | "ArrowDown" | "ArrowRight" | "ArrowLeft")[];
|
|
11
|
+
export declare const HIGHLIGHTED_CLASSNAME = "highlighted";
|
|
12
|
+
export type ResizeHandle = {
|
|
13
|
+
id: string;
|
|
14
|
+
left: boolean;
|
|
15
|
+
top: boolean;
|
|
16
|
+
bottom: boolean;
|
|
17
|
+
right: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const resizeHandles: readonly ResizeHandle[];
|
|
20
|
+
export declare const resizeHandlesMap: Map<string, ResizeHandle>;
|
|
21
|
+
export declare function getHtmlElement(anchorEl: any): HTMLElement | null;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MOVE_KEYS_VALUES = exports.MOVE_KEYS = exports.HIGHLIGHTED_CLASSNAME = exports.FloatingPanelContext = void 0;
|
|
7
|
+
exports.getHtmlElement = getHtmlElement;
|
|
8
|
+
exports.resizeHandlesMap = exports.resizeHandles = void 0;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
const FloatingPanelContext = exports.FloatingPanelContext = /*#__PURE__*/(0, _react.createContext)({
|
|
11
|
+
onDrag: () => {},
|
|
12
|
+
onDragStart: () => {},
|
|
13
|
+
onDragEnd: () => {},
|
|
14
|
+
isDocked: false,
|
|
15
|
+
isMoving: false,
|
|
16
|
+
setIsDocked: () => {},
|
|
17
|
+
onMoveWithArrows: () => {},
|
|
18
|
+
getPosition: () => ({
|
|
19
|
+
left: 0,
|
|
20
|
+
top: 0,
|
|
21
|
+
width: 0,
|
|
22
|
+
height: 0
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
const MOVE_KEYS = exports.MOVE_KEYS = {
|
|
26
|
+
UP: 'ArrowUp',
|
|
27
|
+
DOWN: 'ArrowDown',
|
|
28
|
+
RIGHT: 'ArrowRight',
|
|
29
|
+
LEFT: 'ArrowLeft'
|
|
30
|
+
};
|
|
31
|
+
const MOVE_KEYS_VALUES = exports.MOVE_KEYS_VALUES = Object.values(MOVE_KEYS);
|
|
32
|
+
const HIGHLIGHTED_CLASSNAME = exports.HIGHLIGHTED_CLASSNAME = 'highlighted';
|
|
33
|
+
const resizeHandles = exports.resizeHandles = [{
|
|
34
|
+
id: 'top-left',
|
|
35
|
+
left: true,
|
|
36
|
+
top: true,
|
|
37
|
+
bottom: false,
|
|
38
|
+
right: false
|
|
39
|
+
}, {
|
|
40
|
+
id: 'top',
|
|
41
|
+
left: false,
|
|
42
|
+
top: true,
|
|
43
|
+
bottom: false,
|
|
44
|
+
right: false
|
|
45
|
+
}, {
|
|
46
|
+
id: 'top-right',
|
|
47
|
+
left: false,
|
|
48
|
+
top: true,
|
|
49
|
+
bottom: false,
|
|
50
|
+
right: true
|
|
51
|
+
}, {
|
|
52
|
+
id: 'right',
|
|
53
|
+
left: false,
|
|
54
|
+
top: false,
|
|
55
|
+
bottom: false,
|
|
56
|
+
right: true
|
|
57
|
+
}, {
|
|
58
|
+
id: 'bottom-right',
|
|
59
|
+
left: false,
|
|
60
|
+
top: false,
|
|
61
|
+
bottom: true,
|
|
62
|
+
right: true
|
|
63
|
+
}, {
|
|
64
|
+
id: 'bottom',
|
|
65
|
+
left: false,
|
|
66
|
+
top: false,
|
|
67
|
+
bottom: true,
|
|
68
|
+
right: false
|
|
69
|
+
}, {
|
|
70
|
+
id: 'bottom-left',
|
|
71
|
+
left: true,
|
|
72
|
+
top: false,
|
|
73
|
+
bottom: true,
|
|
74
|
+
right: false
|
|
75
|
+
}, {
|
|
76
|
+
id: 'left',
|
|
77
|
+
left: true,
|
|
78
|
+
top: false,
|
|
79
|
+
bottom: false,
|
|
80
|
+
right: false
|
|
81
|
+
}];
|
|
82
|
+
const resizeHandlesMap = exports.resizeHandlesMap = new Map(resizeHandles.map(handle => [handle.id, handle]));
|
|
83
|
+
function getHtmlElement(anchorEl) {
|
|
84
|
+
if (typeof anchorEl === 'function') {
|
|
85
|
+
return anchorEl();
|
|
86
|
+
}
|
|
87
|
+
if (anchorEl?.ref?.current) {
|
|
88
|
+
return anchorEl.ref.current;
|
|
89
|
+
}
|
|
90
|
+
if (anchorEl?.current) {
|
|
91
|
+
return anchorEl.current;
|
|
92
|
+
}
|
|
93
|
+
return anchorEl;
|
|
94
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
|
+
import { DraggableEvent } from './types';
|
|
3
|
+
export type DraggableAreaProps = {
|
|
4
|
+
areaId: string;
|
|
5
|
+
className: string;
|
|
6
|
+
onDragStart?: (event: DraggableEvent) => void;
|
|
7
|
+
onDrag: (event: DraggableEvent) => void;
|
|
8
|
+
onDragEnd?: (event: DraggableEvent | string) => void;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
testId?: string;
|
|
11
|
+
} & Omit<HTMLAttributes<HTMLDivElement>, 'onDragEnd' | 'onDrag' | 'onDragStart'>;
|
|
12
|
+
export declare function DraggableArea({ areaId, testId, className, onDragStart, onDrag, onDragEnd, children, ...props }: DraggableAreaProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DraggableArea = DraggableArea;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
function DraggableArea({
|
|
11
|
+
areaId,
|
|
12
|
+
testId,
|
|
13
|
+
className,
|
|
14
|
+
onDragStart = () => {},
|
|
15
|
+
onDrag,
|
|
16
|
+
onDragEnd = () => {},
|
|
17
|
+
children = null,
|
|
18
|
+
...props
|
|
19
|
+
}) {
|
|
20
|
+
const [isDragging, setIsDragging] = (0, _react.useState)(false);
|
|
21
|
+
const onStart = (0, _react.useCallback)(e => {
|
|
22
|
+
const draggableEvent = Object.assign(e, {
|
|
23
|
+
areaId
|
|
24
|
+
});
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
setIsDragging(true);
|
|
27
|
+
onDragStart(draggableEvent);
|
|
28
|
+
}, []);
|
|
29
|
+
(0, _react.useEffect)(() => {
|
|
30
|
+
if (!isDragging) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
function onDragHandler(e) {
|
|
34
|
+
const draggableEvent = Object.assign(e, {
|
|
35
|
+
areaId
|
|
36
|
+
});
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
onDrag(draggableEvent);
|
|
39
|
+
}
|
|
40
|
+
function onDragEndHandler(e) {
|
|
41
|
+
const draggableEvent = Object.assign(e, {
|
|
42
|
+
areaId
|
|
43
|
+
});
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
removeListeners();
|
|
46
|
+
setIsDragging(false);
|
|
47
|
+
onDragEnd(draggableEvent);
|
|
48
|
+
}
|
|
49
|
+
function onDragBlurHandler() {
|
|
50
|
+
setIsDragging(false);
|
|
51
|
+
onDragEnd(areaId);
|
|
52
|
+
removeListeners();
|
|
53
|
+
}
|
|
54
|
+
window.addEventListener('mousemove', onDragHandler);
|
|
55
|
+
window.addEventListener('mouseup', onDragEndHandler);
|
|
56
|
+
window.addEventListener('blur', onDragBlurHandler);
|
|
57
|
+
function removeListeners() {
|
|
58
|
+
window.removeEventListener('mousemove', onDragHandler);
|
|
59
|
+
window.removeEventListener('mouseup', onDragEndHandler);
|
|
60
|
+
window.removeEventListener('blur', onDragBlurHandler);
|
|
61
|
+
}
|
|
62
|
+
return removeListeners;
|
|
63
|
+
}, [isDragging, onDragStart, onDrag, onDragEnd, areaId]);
|
|
64
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
65
|
+
className: className,
|
|
66
|
+
onMouseDown: onStart,
|
|
67
|
+
"test-id": testId,
|
|
68
|
+
role: "none",
|
|
69
|
+
...props,
|
|
70
|
+
children: children
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FloatingPanelDockButton = FloatingPanelDockButton;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _faThumbtackSlash = require("@fortawesome/pro-solid-svg-icons/faThumbtackSlash");
|
|
9
|
+
var _faThumbtack = require("@fortawesome/free-solid-svg-icons/faThumbtack");
|
|
10
|
+
var _button = require("../button");
|
|
11
|
+
var _hooks = require("../hooks");
|
|
12
|
+
var _fontAwesomeIcon = require("../font-awesome-icon");
|
|
13
|
+
var _tooltip = require("../tooltip");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
function FloatingPanelDockButton({
|
|
17
|
+
isDocked,
|
|
18
|
+
setIsDocked
|
|
19
|
+
}) {
|
|
20
|
+
const {
|
|
21
|
+
t
|
|
22
|
+
} = (0, _hooks.useTranslation)();
|
|
23
|
+
const ariaLabel = isDocked ? t('Unlock from sidebar') : t('Dock to sidebar');
|
|
24
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
|
|
25
|
+
testId: "floating-panel-dock-button",
|
|
26
|
+
accentType: _button.ACCENT_TYPES.ROUND_ICON,
|
|
27
|
+
onClick: () => setIsDocked(!isDocked),
|
|
28
|
+
"aria-label": ariaLabel,
|
|
29
|
+
tooltipText: ariaLabel,
|
|
30
|
+
tooltipPlacement: _tooltip.TOOLTIP_PLACEMENT_TYPES.TOP,
|
|
31
|
+
children: isDocked ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
|
|
32
|
+
icon: _faThumbtackSlash.faThumbtackSlash
|
|
33
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
|
|
34
|
+
icon: _faThumbtack.faThumbtack
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FloatingPanelDragHandle = FloatingPanelDragHandle;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _faGripDotsVertical = require("@fortawesome/pro-solid-svg-icons/faGripDotsVertical");
|
|
9
|
+
var _fontAwesomeIcon = require("../font-awesome-icon");
|
|
10
|
+
var _hooks = require("../hooks");
|
|
11
|
+
var _constants = require("./constants");
|
|
12
|
+
var _draggableArea = require("./draggable-area");
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
+
function FloatingPanelDragHandle({
|
|
16
|
+
children
|
|
17
|
+
}) {
|
|
18
|
+
const content = children || /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
|
|
19
|
+
icon: _faGripDotsVertical.faGripDotsVertical
|
|
20
|
+
});
|
|
21
|
+
const {
|
|
22
|
+
t
|
|
23
|
+
} = (0, _hooks.useTranslation)();
|
|
24
|
+
const {
|
|
25
|
+
onDrag,
|
|
26
|
+
onDragStart,
|
|
27
|
+
onDragEnd,
|
|
28
|
+
onMoveWithArrows,
|
|
29
|
+
isDocked
|
|
30
|
+
} = (0, _react.useContext)(_constants.FloatingPanelContext);
|
|
31
|
+
if (isDocked) {
|
|
32
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
33
|
+
className: "drag-handle disabled",
|
|
34
|
+
"test-id": "floating-area-drag-handle",
|
|
35
|
+
children: content
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_draggableArea.DraggableArea, {
|
|
39
|
+
tabIndex: 0,
|
|
40
|
+
testId: "floating-area-drag-handle",
|
|
41
|
+
areaId: "drag-handle",
|
|
42
|
+
className: "drag-handle",
|
|
43
|
+
onDrag: onDrag,
|
|
44
|
+
onDragStart: onDragStart,
|
|
45
|
+
onDragEnd: onDragEnd,
|
|
46
|
+
onKeyDown: onMoveWithArrows,
|
|
47
|
+
"aria-label": t('Draggable handle: use arrows to change position of the panel'),
|
|
48
|
+
role: "button",
|
|
49
|
+
children: content
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PanelState } from './types';
|
|
3
|
+
type FloatingPanelHeaderProps = {
|
|
4
|
+
onClose: (State: PanelState) => void;
|
|
5
|
+
isDocked: boolean;
|
|
6
|
+
setIsDocked: (docked: boolean) => void;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
getPosition: () => PanelState;
|
|
9
|
+
};
|
|
10
|
+
export declare const FloatingPanelHeader: React.ForwardRefExoticComponent<FloatingPanelHeaderProps & React.RefAttributes<HTMLElement>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FloatingPanelHeader = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _faXmark = require("@fortawesome/free-solid-svg-icons/faXmark");
|
|
9
|
+
var _button = require("../button");
|
|
10
|
+
var _fontAwesomeIcon = require("../font-awesome-icon");
|
|
11
|
+
var _useTranslation = require("../hooks/use-translation");
|
|
12
|
+
var _floatingPanelDockButton = require("./floating-panel-dock-button");
|
|
13
|
+
var _floatingPanelDragHandle = require("./floating-panel-drag-handle");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
16
|
+
const FloatingPanelHeader = exports.FloatingPanelHeader = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
17
|
+
actions = null,
|
|
18
|
+
onClose,
|
|
19
|
+
isDocked,
|
|
20
|
+
setIsDocked,
|
|
21
|
+
getPosition
|
|
22
|
+
}, ref) => {
|
|
23
|
+
const {
|
|
24
|
+
t
|
|
25
|
+
} = (0, _useTranslation.useTranslation)();
|
|
26
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("header", {
|
|
27
|
+
ref: ref,
|
|
28
|
+
className: "floating-panel-header",
|
|
29
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelDragHandle.FloatingPanelDragHandle, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
30
|
+
className: "actions",
|
|
31
|
+
children: [actions, /*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelDockButton.FloatingPanelDockButton, {
|
|
32
|
+
isDocked: isDocked,
|
|
33
|
+
setIsDocked: setIsDocked
|
|
34
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
|
|
35
|
+
testId: "floating-panel-close-action",
|
|
36
|
+
accentType: _button.ACCENT_TYPES.ROUND_ICON,
|
|
37
|
+
onClick: () => onClose(getPosition()),
|
|
38
|
+
"aria-label": t('Close'),
|
|
39
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
|
|
40
|
+
icon: _faXmark.faXmark
|
|
41
|
+
})
|
|
42
|
+
})]
|
|
43
|
+
})]
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
FloatingPanelHeader.displayName = 'FloatingPanelHeader';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { Modifier, Placement } from '@popperjs/core';
|
|
3
|
+
import './floating-panel.less';
|
|
4
|
+
import type { ElementReference, PanelState } from './types';
|
|
5
|
+
export type FloatingPanelProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Panel's content
|
|
8
|
+
*/
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* Pass custom header action buttons here
|
|
12
|
+
*/
|
|
13
|
+
actions?: React.ReactNode;
|
|
14
|
+
minHeight?: number;
|
|
15
|
+
minWidth?: number;
|
|
16
|
+
maxWidth?: number;
|
|
17
|
+
maxHeight?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Position panel relative to this element. Alternative use `initialState`
|
|
20
|
+
*/
|
|
21
|
+
anchorEl?: ElementReference;
|
|
22
|
+
/**
|
|
23
|
+
* Dock element. It should be placed after id="full-screen-modal-root"
|
|
24
|
+
*/
|
|
25
|
+
dockEl?: ElementReference;
|
|
26
|
+
/**
|
|
27
|
+
* Pass an element where the main page content is rendered, this will help calculate the header size
|
|
28
|
+
*/
|
|
29
|
+
pageContentEl?: ElementReference;
|
|
30
|
+
/**
|
|
31
|
+
* Popper's placement, used for initial position if `initialState` is not defined
|
|
32
|
+
*/
|
|
33
|
+
placement?: Placement;
|
|
34
|
+
/**
|
|
35
|
+
* Popper modifies which will override default set of modifiers
|
|
36
|
+
*/
|
|
37
|
+
popperModifiers?: Partial<Modifier<any, any>>[];
|
|
38
|
+
testId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use this to set initial state. Update it in `onClose` handler to preserve last position.
|
|
41
|
+
*/
|
|
42
|
+
initialState?: PanelState;
|
|
43
|
+
/**
|
|
44
|
+
* Use this to control docked state outside the component
|
|
45
|
+
*/
|
|
46
|
+
isDocked?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Use this to sync up the docked state with consumer when controlled outside
|
|
49
|
+
*/
|
|
50
|
+
setIsDocked?: Dispatch<SetStateAction<boolean>>;
|
|
51
|
+
/**
|
|
52
|
+
* Use this in consumer to update `initialState` in order to preserve last position
|
|
53
|
+
*/
|
|
54
|
+
onClose?: (State: PanelState) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Aria label for the floating panel
|
|
57
|
+
*/
|
|
58
|
+
ariaLabel?: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Floating panel
|
|
62
|
+
* @midnight-gray-supported
|
|
63
|
+
* @uxr-only-supported
|
|
64
|
+
* @alpine-light-supported
|
|
65
|
+
*/
|
|
66
|
+
export declare function FloatingPanel({ children, minHeight, minWidth, maxWidth, maxHeight, anchorEl, dockEl, pageContentEl, initialState, testId, placement, popperModifiers, onClose, actions, ...props }: FloatingPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FloatingPanel = FloatingPanel;
|
|
7
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _core = require("@popperjs/core");
|
|
11
|
+
var _reactPopper = require("../react-popper");
|
|
12
|
+
var _hooks = require("../hooks");
|
|
13
|
+
var _constants = require("./constants");
|
|
14
|
+
var _useFloatingPanelState = require("./use-floating-panel-state");
|
|
15
|
+
var _draggableArea = require("./draggable-area");
|
|
16
|
+
var _floatingPanelHeader = require("./floating-panel-header");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
const noop = () => false;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Floating panel
|
|
24
|
+
* @midnight-gray-supported
|
|
25
|
+
* @uxr-only-supported
|
|
26
|
+
* @alpine-light-supported
|
|
27
|
+
*/
|
|
28
|
+
function FloatingPanel({
|
|
29
|
+
children,
|
|
30
|
+
minHeight = 648,
|
|
31
|
+
minWidth = 380,
|
|
32
|
+
maxWidth = 900,
|
|
33
|
+
maxHeight = 800,
|
|
34
|
+
anchorEl,
|
|
35
|
+
dockEl,
|
|
36
|
+
pageContentEl,
|
|
37
|
+
initialState,
|
|
38
|
+
testId = 'floating-panel',
|
|
39
|
+
placement = 'bottom',
|
|
40
|
+
popperModifiers = [_reactPopper.OFFSET_MODIFIER],
|
|
41
|
+
onClose = noop,
|
|
42
|
+
actions,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
const containerElement = (0, _constants.getHtmlElement)(dockEl) || document.getElementById('floating-panel-root') || document.body;
|
|
46
|
+
const initialStateAppliedOnce = (0, _react.useRef)(false);
|
|
47
|
+
const {
|
|
48
|
+
t
|
|
49
|
+
} = (0, _hooks.useTranslation)();
|
|
50
|
+
const {
|
|
51
|
+
panelRef,
|
|
52
|
+
headerRef,
|
|
53
|
+
style,
|
|
54
|
+
onResize,
|
|
55
|
+
onMovementStart,
|
|
56
|
+
onResizeEnd,
|
|
57
|
+
setState,
|
|
58
|
+
isDocked,
|
|
59
|
+
setIsDocked,
|
|
60
|
+
getPosition,
|
|
61
|
+
context
|
|
62
|
+
} = (0, _useFloatingPanelState.useFloatingPanelState)({
|
|
63
|
+
minHeight,
|
|
64
|
+
minWidth,
|
|
65
|
+
maxWidth,
|
|
66
|
+
maxHeight,
|
|
67
|
+
initialState,
|
|
68
|
+
isDocked: props.isDocked ?? false,
|
|
69
|
+
setIsDocked: props.setIsDocked ?? noop,
|
|
70
|
+
containerElement,
|
|
71
|
+
pageContentElement: (0, _constants.getHtmlElement)(pageContentEl)
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// use @popperjs/core to set initial position for the panel
|
|
75
|
+
(0, _react.useLayoutEffect)(() => {
|
|
76
|
+
if (!panelRef.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
panelRef.current.focus();
|
|
80
|
+
if (initialState && !initialStateAppliedOnce.current) {
|
|
81
|
+
initialStateAppliedOnce.current = true;
|
|
82
|
+
return setState(initialState);
|
|
83
|
+
}
|
|
84
|
+
if (!anchorEl) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const popperInstance = (0, _core.createPopper)((0, _constants.getHtmlElement)(anchorEl), panelRef.current, {
|
|
88
|
+
placement,
|
|
89
|
+
strategy: 'fixed',
|
|
90
|
+
modifiers: popperModifiers,
|
|
91
|
+
onFirstUpdate: () => {
|
|
92
|
+
const {
|
|
93
|
+
left,
|
|
94
|
+
top
|
|
95
|
+
} = panelRef.current.getBoundingClientRect();
|
|
96
|
+
setState(state => ({
|
|
97
|
+
...state,
|
|
98
|
+
left,
|
|
99
|
+
top
|
|
100
|
+
}));
|
|
101
|
+
popperInstance.destroy();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}, [placement]);
|
|
105
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_constants.FloatingPanelContext.Provider, {
|
|
106
|
+
value: context,
|
|
107
|
+
children: /*#__PURE__*/_reactDom.default.createPortal(/*#__PURE__*/(0, _jsxRuntime.jsxs)("section", {
|
|
108
|
+
ref: panelRef,
|
|
109
|
+
"test-id": testId,
|
|
110
|
+
className: (0, _classnames.default)('floating-panel', {
|
|
111
|
+
docked: isDocked
|
|
112
|
+
})
|
|
113
|
+
/* eslint-disable-next-line react/forbid-dom-props */,
|
|
114
|
+
style: style,
|
|
115
|
+
"aria-modal": "true",
|
|
116
|
+
role: "dialog",
|
|
117
|
+
"aria-label": props.ariaLabel || t('Floating panel'),
|
|
118
|
+
"aria-describedby": "floating-panel-content",
|
|
119
|
+
tabIndex: -1,
|
|
120
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_floatingPanelHeader.FloatingPanelHeader, {
|
|
121
|
+
ref: headerRef,
|
|
122
|
+
onClose: onClose,
|
|
123
|
+
getPosition: getPosition,
|
|
124
|
+
isDocked: isDocked,
|
|
125
|
+
setIsDocked: setIsDocked,
|
|
126
|
+
actions: actions
|
|
127
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
128
|
+
id: "floating-panel-content",
|
|
129
|
+
className: "floating-panel-content",
|
|
130
|
+
children: children
|
|
131
|
+
}), !isDocked && _constants.resizeHandles.map(handle => /*#__PURE__*/(0, _jsxRuntime.jsx)(_draggableArea.DraggableArea, {
|
|
132
|
+
areaId: handle.id,
|
|
133
|
+
className: (0, _classnames.default)('resize-handle', handle.id),
|
|
134
|
+
onDrag: onResize,
|
|
135
|
+
onDragStart: onMovementStart,
|
|
136
|
+
onDragEnd: onResizeEnd
|
|
137
|
+
}, handle.id))]
|
|
138
|
+
}), containerElement)
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FloatingPanel", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _floatingPanel.FloatingPanel;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useFloatingPanel", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useFloatingPanel.useFloatingPanel;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _floatingPanel = require("./floating-panel");
|
|
19
|
+
var _useFloatingPanel = require("./use-floating-panel");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { MutableRefObject } from 'react';
|
|
2
|
+
export type PanelState = {
|
|
3
|
+
top: number;
|
|
4
|
+
left: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export type DraggableEvent = MouseEvent & {
|
|
9
|
+
areaId: string;
|
|
10
|
+
};
|
|
11
|
+
export type FloatingPanelContextType = {
|
|
12
|
+
onDrag: (event: DraggableEvent) => void;
|
|
13
|
+
onDragStart: (event: DraggableEvent) => void;
|
|
14
|
+
onDragEnd: (event: DraggableEvent | string) => void;
|
|
15
|
+
onMoveWithArrows: (event: React.KeyboardEvent) => void;
|
|
16
|
+
isDocked: boolean;
|
|
17
|
+
setIsDocked: (docked: boolean) => void;
|
|
18
|
+
isMoving: boolean;
|
|
19
|
+
getPosition: () => PanelState;
|
|
20
|
+
};
|
|
21
|
+
export type ElementReference = HTMLElement | Element | MutableRefObject<HTMLElement> | (() => HTMLElement) | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFloatingPanelRoot = useFloatingPanelRoot;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _debounce = _interopRequireDefault(require("lodash-es/debounce"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function useFloatingPanelRoot({
|
|
11
|
+
containerElement,
|
|
12
|
+
pageContentElement
|
|
13
|
+
}) {
|
|
14
|
+
(0, _react.useEffect)(() => {
|
|
15
|
+
// this is not an exceptional case: when there is no header this could be omitted
|
|
16
|
+
if (!containerElement || !pageContentElement) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const onResize = (0, _debounce.default)(() => {
|
|
20
|
+
const contentRect = pageContentElement.getBoundingClientRect();
|
|
21
|
+
containerElement.style.top = `${contentRect.top}px`;
|
|
22
|
+
}, 100);
|
|
23
|
+
onResize();
|
|
24
|
+
const resizeObserver = new ResizeObserver(onResize);
|
|
25
|
+
resizeObserver.observe(pageContentElement);
|
|
26
|
+
return () => {
|
|
27
|
+
onResize.cancel();
|
|
28
|
+
resizeObserver.disconnect();
|
|
29
|
+
};
|
|
30
|
+
}, [containerElement, pageContentElement]);
|
|
31
|
+
}
|