@datarobot/design-system 29.1.1 → 29.2.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/datetime-range-picker/datetime-range-picker-panel.d.ts +2 -1
- package/cjs/datetime-range-picker/datetime-range-picker-panel.js +1 -0
- package/cjs/floating-panel/constants.js +3 -1
- package/cjs/floating-panel/draggable-area.d.ts +1 -0
- package/cjs/floating-panel/draggable-area.js +9 -46
- package/cjs/floating-panel/floating-panel-collapse-button.d.ts +5 -0
- package/cjs/floating-panel/floating-panel-collapse-button.js +36 -0
- package/cjs/floating-panel/floating-panel-dock-button.js +1 -0
- package/cjs/floating-panel/floating-panel-drag-handle.js +1 -9
- package/cjs/floating-panel/floating-panel-header.js +49 -20
- package/cjs/floating-panel/floating-panel.d.ts +8 -0
- package/cjs/floating-panel/floating-panel.js +8 -4
- package/cjs/floating-panel/types.d.ts +8 -0
- package/cjs/floating-panel/types.js +9 -1
- package/cjs/floating-panel/use-draggable-area.d.ts +17 -0
- package/cjs/floating-panel/use-draggable-area.js +70 -0
- package/cjs/floating-panel/use-floating-panel-state.d.ts +6 -2
- package/cjs/floating-panel/use-floating-panel-state.js +224 -84
- package/cjs/hooks/use-analytics/use-analytics.test.js +0 -10
- package/esm/datetime-range-picker/datetime-range-picker-panel.d.ts +2 -1
- package/esm/datetime-range-picker/datetime-range-picker-panel.js +1 -0
- package/esm/floating-panel/constants.js +3 -1
- package/esm/floating-panel/draggable-area.d.ts +1 -0
- package/esm/floating-panel/draggable-area.js +8 -45
- package/esm/floating-panel/floating-panel-collapse-button.d.ts +5 -0
- package/esm/floating-panel/floating-panel-collapse-button.js +29 -0
- package/esm/floating-panel/floating-panel-dock-button.js +2 -1
- package/esm/floating-panel/floating-panel-drag-handle.js +1 -9
- package/esm/floating-panel/floating-panel-header.js +50 -21
- package/esm/floating-panel/floating-panel.d.ts +8 -0
- package/esm/floating-panel/floating-panel.js +8 -4
- package/esm/floating-panel/types.d.ts +8 -0
- package/esm/floating-panel/types.js +7 -1
- package/esm/floating-panel/use-draggable-area.d.ts +17 -0
- package/esm/floating-panel/use-draggable-area.js +64 -0
- package/esm/floating-panel/use-floating-panel-state.d.ts +6 -2
- package/esm/floating-panel/use-floating-panel-state.js +226 -86
- package/esm/hooks/use-analytics/use-analytics.test.js +0 -10
- package/js/139/139.min.js +1 -1
- package/js/244/244.min.js +1 -1
- package/js/633/633.min.js +1 -1
- package/js/784/784.min.js +1 -1
- package/js/86/86.min.js +1 -1
- package/js/bundle/bundle.js +467 -191
- package/js/bundle/bundle.min.js +1 -1
- package/js/bundle/index.d.ts +18 -1
- package/js/src_locales_es_419_translation_json/src_locales_es_419_translation_json.js +1 -1
- package/js/src_locales_fr_translation_json/src_locales_fr_translation_json.js +1 -1
- package/js/src_locales_ja_translation_json/src_locales_ja_translation_json.js +1 -1
- package/js/src_locales_ko_translation_json/src_locales_ko_translation_json.js +1 -1
- package/js/src_locales_pt_BR_translation_json/src_locales_pt_BR_translation_json.js +1 -1
- package/locales/es_419/translation.json +5 -1
- package/locales/fr/translation.json +5 -1
- package/locales/ja/translation.json +5 -1
- package/locales/ko/translation.json +5 -1
- package/locales/pt_BR/translation.json +5 -1
- package/package.json +1 -1
- package/styles/index.css +1 -0
- package/styles/index.min.css +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
1
|
+
import React, { forwardRef, useContext } from 'react';
|
|
2
2
|
import { faXmark } from '@fortawesome/free-solid-svg-icons/faXmark';
|
|
3
3
|
import { Button, ACCENT_TYPES } from '../button';
|
|
4
4
|
import { FontAwesomeIcon } from '../font-awesome-icon';
|
|
5
5
|
import { useTranslation } from '../hooks/use-translation';
|
|
6
6
|
import { FloatingPanelDockButton } from './floating-panel-dock-button';
|
|
7
7
|
import { FloatingPanelDragHandle } from './floating-panel-drag-handle';
|
|
8
|
+
import { useDraggableArea } from './use-draggable-area';
|
|
9
|
+
import { FloatingPanelContext } from './constants';
|
|
10
|
+
import { FloatingPanelCollapseButton } from './floating-panel-collapse-button';
|
|
8
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
12
|
export const FloatingPanelHeader = /*#__PURE__*/forwardRef(({
|
|
10
13
|
actions = null,
|
|
@@ -17,26 +20,52 @@ export const FloatingPanelHeader = /*#__PURE__*/forwardRef(({
|
|
|
17
20
|
const {
|
|
18
21
|
t
|
|
19
22
|
} = useTranslation();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
accentType: ACCENT_TYPES.ROUND_ICON,
|
|
33
|
-
onClick: () => onClose(getPosition()),
|
|
34
|
-
"aria-label": t('Close'),
|
|
35
|
-
children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
36
|
-
icon: faXmark
|
|
37
|
-
})
|
|
38
|
-
})]
|
|
39
|
-
})]
|
|
23
|
+
const {
|
|
24
|
+
onDrag,
|
|
25
|
+
onDragStart,
|
|
26
|
+
onDragEnd,
|
|
27
|
+
isCollapsed,
|
|
28
|
+
setIsCollapsed
|
|
29
|
+
} = useContext(FloatingPanelContext);
|
|
30
|
+
const onStart = useDraggableArea({
|
|
31
|
+
areaId: 'drag-header',
|
|
32
|
+
onDrag,
|
|
33
|
+
onDragStart,
|
|
34
|
+
onDragEnd
|
|
40
35
|
});
|
|
36
|
+
return (
|
|
37
|
+
/*#__PURE__*/
|
|
38
|
+
// FloatingPanelDragHandle is responsible for accessibility of the drag handle
|
|
39
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
40
|
+
_jsxs("header", {
|
|
41
|
+
ref: ref,
|
|
42
|
+
className: "floating-panel-header",
|
|
43
|
+
onMouseDown: onStart,
|
|
44
|
+
children: [/*#__PURE__*/_jsx(FloatingPanelDragHandle, {
|
|
45
|
+
dragIcon: dragIcon
|
|
46
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
47
|
+
className: "actions",
|
|
48
|
+
onMouseDown: event => {
|
|
49
|
+
// Prevent dragging when clicking on action buttons
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
},
|
|
52
|
+
children: [actions, /*#__PURE__*/_jsx(FloatingPanelCollapseButton, {
|
|
53
|
+
isCollapsed: isCollapsed,
|
|
54
|
+
setIsCollapsed: setIsCollapsed
|
|
55
|
+
}), /*#__PURE__*/_jsx(FloatingPanelDockButton, {
|
|
56
|
+
isDocked: isDocked,
|
|
57
|
+
setIsDocked: setIsDocked
|
|
58
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
59
|
+
testId: "floating-panel-close-action",
|
|
60
|
+
accentType: ACCENT_TYPES.ROUND_ICON,
|
|
61
|
+
onClick: () => onClose(getPosition()),
|
|
62
|
+
"aria-label": t('Close'),
|
|
63
|
+
children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
|
|
64
|
+
icon: faXmark
|
|
65
|
+
})
|
|
66
|
+
})]
|
|
67
|
+
})]
|
|
68
|
+
})
|
|
69
|
+
);
|
|
41
70
|
});
|
|
42
71
|
FloatingPanelHeader.displayName = 'FloatingPanelHeader';
|
|
@@ -49,6 +49,14 @@ export type FloatingPanelProps = {
|
|
|
49
49
|
* Use this to sync up the docked state with consumer when controlled outside
|
|
50
50
|
*/
|
|
51
51
|
setIsDocked?: Dispatch<SetStateAction<boolean>>;
|
|
52
|
+
/**
|
|
53
|
+
* Use this to control collapsed state outside the component
|
|
54
|
+
*/
|
|
55
|
+
isCollapsed?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Use this to sync up the collapsed state with consumer when controlled outside
|
|
58
|
+
*/
|
|
59
|
+
setIsCollapsed?: Dispatch<SetStateAction<boolean>>;
|
|
52
60
|
/**
|
|
53
61
|
* Use this in consumer to update `initialState` in order to preserve last position
|
|
54
62
|
*/
|
|
@@ -48,8 +48,9 @@ export function FloatingPanel({
|
|
|
48
48
|
onResize,
|
|
49
49
|
onMovementStart,
|
|
50
50
|
onResizeEnd,
|
|
51
|
-
|
|
51
|
+
setPosition,
|
|
52
52
|
isDocked,
|
|
53
|
+
isCollapsed,
|
|
53
54
|
setIsDocked,
|
|
54
55
|
getPosition,
|
|
55
56
|
context
|
|
@@ -61,6 +62,8 @@ export function FloatingPanel({
|
|
|
61
62
|
initialState,
|
|
62
63
|
isDocked: props.isDocked ?? false,
|
|
63
64
|
setIsDocked: props.setIsDocked ?? noop,
|
|
65
|
+
isCollapsed: props.isCollapsed ?? false,
|
|
66
|
+
setIsCollapsed: props.setIsCollapsed ?? noop,
|
|
64
67
|
containerElement,
|
|
65
68
|
pageContentElement: getHtmlElement(pageContentEl)
|
|
66
69
|
});
|
|
@@ -73,7 +76,7 @@ export function FloatingPanel({
|
|
|
73
76
|
panelRef.current.focus();
|
|
74
77
|
if (initialState && !initialStateAppliedOnce.current) {
|
|
75
78
|
initialStateAppliedOnce.current = true;
|
|
76
|
-
return
|
|
79
|
+
return setPosition(initialState);
|
|
77
80
|
}
|
|
78
81
|
if (!anchorEl) {
|
|
79
82
|
return;
|
|
@@ -87,7 +90,7 @@ export function FloatingPanel({
|
|
|
87
90
|
left,
|
|
88
91
|
top
|
|
89
92
|
} = panelRef.current.getBoundingClientRect();
|
|
90
|
-
|
|
93
|
+
setPosition(state => ({
|
|
91
94
|
...state,
|
|
92
95
|
left,
|
|
93
96
|
top
|
|
@@ -102,7 +105,8 @@ export function FloatingPanel({
|
|
|
102
105
|
ref: panelRef,
|
|
103
106
|
"test-id": testId,
|
|
104
107
|
className: classnames('floating-panel', {
|
|
105
|
-
docked: isDocked
|
|
108
|
+
docked: isDocked,
|
|
109
|
+
collapsed: isCollapsed
|
|
106
110
|
})
|
|
107
111
|
/* eslint-disable-next-line react/forbid-dom-props */,
|
|
108
112
|
style: style,
|
|
@@ -8,6 +8,12 @@ export type PanelState = {
|
|
|
8
8
|
export type DraggableEvent = MouseEvent & {
|
|
9
9
|
areaId: string;
|
|
10
10
|
};
|
|
11
|
+
export declare enum PANEL_STATE {
|
|
12
|
+
FLOATING = "floating",
|
|
13
|
+
COLLAPSED = "collapsed",
|
|
14
|
+
DOCKED = "docked",
|
|
15
|
+
TO_BE_DOCKED = "to-be-docked"
|
|
16
|
+
}
|
|
11
17
|
export type FloatingPanelContextType = {
|
|
12
18
|
onDrag: (event: DraggableEvent) => void;
|
|
13
19
|
onDragStart: (event: DraggableEvent) => void;
|
|
@@ -15,6 +21,8 @@ export type FloatingPanelContextType = {
|
|
|
15
21
|
onMoveWithArrows: (event: React.KeyboardEvent) => void;
|
|
16
22
|
isDocked: boolean;
|
|
17
23
|
setIsDocked: (docked: boolean) => void;
|
|
24
|
+
isCollapsed: boolean;
|
|
25
|
+
setIsCollapsed: (docked: boolean) => void;
|
|
18
26
|
isMoving: boolean;
|
|
19
27
|
getPosition: () => PanelState;
|
|
20
28
|
};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export let PANEL_STATE = /*#__PURE__*/function (PANEL_STATE) {
|
|
2
|
+
PANEL_STATE["FLOATING"] = "floating";
|
|
3
|
+
PANEL_STATE["COLLAPSED"] = "collapsed";
|
|
4
|
+
PANEL_STATE["DOCKED"] = "docked";
|
|
5
|
+
PANEL_STATE["TO_BE_DOCKED"] = "to-be-docked";
|
|
6
|
+
return PANEL_STATE;
|
|
7
|
+
}({});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DraggableEvent } from '@datarobot/design-system/floating-panel/types';
|
|
3
|
+
export type DraggableArea = {
|
|
4
|
+
areaId: string;
|
|
5
|
+
onDragStart?: (event: DraggableEvent) => void;
|
|
6
|
+
onDrag: (event: DraggableEvent) => void;
|
|
7
|
+
onDragEnd?: (event: DraggableEvent | string) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param areaId
|
|
12
|
+
* @param onDragStart
|
|
13
|
+
* @param onDrag
|
|
14
|
+
* @param onDragEnd
|
|
15
|
+
* @returns onStart function to be used in onMouseDown event
|
|
16
|
+
*/
|
|
17
|
+
export declare function useDraggableArea({ areaId, onDragStart, onDrag, onDragEnd, }: DraggableArea): (e: React.MouseEvent<Element>) => void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param areaId
|
|
5
|
+
* @param onDragStart
|
|
6
|
+
* @param onDrag
|
|
7
|
+
* @param onDragEnd
|
|
8
|
+
* @returns onStart function to be used in onMouseDown event
|
|
9
|
+
*/
|
|
10
|
+
export function useDraggableArea({
|
|
11
|
+
areaId,
|
|
12
|
+
onDragStart = () => {},
|
|
13
|
+
onDrag,
|
|
14
|
+
onDragEnd = () => {}
|
|
15
|
+
}) {
|
|
16
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
17
|
+
const onStart = e => {
|
|
18
|
+
const draggableEvent = Object.assign(e, {
|
|
19
|
+
areaId
|
|
20
|
+
});
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
setIsDragging(true);
|
|
24
|
+
onDragStart(draggableEvent);
|
|
25
|
+
};
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isDragging) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
function onDragHandler(e) {
|
|
31
|
+
const draggableEvent = Object.assign(e, {
|
|
32
|
+
areaId
|
|
33
|
+
});
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
e.stopPropagation();
|
|
36
|
+
onDrag(draggableEvent);
|
|
37
|
+
}
|
|
38
|
+
function onDragEndHandler(e) {
|
|
39
|
+
const draggableEvent = Object.assign(e, {
|
|
40
|
+
areaId
|
|
41
|
+
});
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
removeListeners();
|
|
45
|
+
setIsDragging(false);
|
|
46
|
+
onDragEnd(draggableEvent);
|
|
47
|
+
}
|
|
48
|
+
function onDragBlurHandler() {
|
|
49
|
+
setIsDragging(false);
|
|
50
|
+
onDragEnd(areaId);
|
|
51
|
+
removeListeners();
|
|
52
|
+
}
|
|
53
|
+
window.addEventListener('mousemove', onDragHandler);
|
|
54
|
+
window.addEventListener('mouseup', onDragEndHandler);
|
|
55
|
+
window.addEventListener('blur', onDragBlurHandler);
|
|
56
|
+
function removeListeners() {
|
|
57
|
+
window.removeEventListener('mousemove', onDragHandler);
|
|
58
|
+
window.removeEventListener('mouseup', onDragEndHandler);
|
|
59
|
+
window.removeEventListener('blur', onDragBlurHandler);
|
|
60
|
+
}
|
|
61
|
+
return removeListeners;
|
|
62
|
+
}, [isDragging, onDragStart, onDrag, onDragEnd, areaId]);
|
|
63
|
+
return onStart;
|
|
64
|
+
}
|
|
@@ -8,9 +8,11 @@ export type UseFloatingPanelHook = {
|
|
|
8
8
|
onResize: (event: DraggableEvent) => void;
|
|
9
9
|
onMovementStart: (event: DraggableEvent) => void;
|
|
10
10
|
onResizeEnd: (event: DraggableEvent | string) => void;
|
|
11
|
-
|
|
11
|
+
setPosition: Dispatch<SetStateAction<PanelState>>;
|
|
12
12
|
isDocked: boolean;
|
|
13
13
|
setIsDocked: (docked: boolean) => void;
|
|
14
|
+
isCollapsed: boolean;
|
|
15
|
+
setIsCollapsed: (collapsed: boolean) => void;
|
|
14
16
|
getPosition: () => PanelState;
|
|
15
17
|
};
|
|
16
18
|
export type UseFloatingPanelParams = {
|
|
@@ -20,8 +22,10 @@ export type UseFloatingPanelParams = {
|
|
|
20
22
|
maxHeight: number;
|
|
21
23
|
isDocked: boolean;
|
|
22
24
|
setIsDocked: Dispatch<SetStateAction<boolean>>;
|
|
25
|
+
isCollapsed: boolean;
|
|
26
|
+
setIsCollapsed: Dispatch<SetStateAction<boolean>>;
|
|
23
27
|
initialState?: PanelState;
|
|
24
28
|
containerElement: HTMLElement;
|
|
25
29
|
pageContentElement?: HTMLElement;
|
|
26
30
|
};
|
|
27
|
-
export declare function useFloatingPanelState({ minWidth, minHeight, maxWidth, maxHeight, isDocked: isDockedExternal, setIsDocked: setIsDockedExternal, initialState, containerElement, pageContentElement, }: UseFloatingPanelParams): UseFloatingPanelHook;
|
|
31
|
+
export declare function useFloatingPanelState({ minWidth, minHeight, maxWidth, maxHeight, isDocked: isDockedExternal, setIsDocked: setIsDockedExternal, isCollapsed: isCollapsedExternal, setIsCollapsed: setIsCollapsedExternal, initialState, containerElement, pageContentElement, }: UseFloatingPanelParams): UseFloatingPanelHook;
|