@apple-pie/slice 0.0.1 → 0.0.3
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/dist/cjs/chunks/Avatar-8-wPWe0V.js +68 -0
- package/dist/cjs/chunks/AvatarGroup-CVKmgBbD.js +39 -0
- package/dist/cjs/chunks/Badge-CMapJCij.js +41 -0
- package/dist/cjs/chunks/CheckBox-7AACxrdZ.js +76 -0
- package/dist/cjs/chunks/DivInput-BKKJTFeV.js +204 -0
- package/dist/cjs/chunks/DocIcons-BRWOzK96.js +41 -0
- package/dist/cjs/chunks/Dot-Dnr9M9na.js +80 -0
- package/dist/cjs/chunks/DrggablePanel-C6TPsDB-.js +302 -0
- package/dist/cjs/chunks/DropDown-D9sf_m2I.js +154 -0
- package/dist/cjs/chunks/EditorButtonBar-CUNDgRQd.js +244 -0
- package/dist/cjs/chunks/ErrorSummary-Dv44onsV.js +42 -0
- package/dist/cjs/chunks/FlexDiv-DZBpswHV.js +103 -0
- package/dist/cjs/chunks/Grouper-_kd2nU78.js +50 -0
- package/dist/cjs/chunks/IconButton-BfsPlKTb.js +84 -0
- package/dist/cjs/chunks/Logos-DSlAUz8l.js +119 -0
- package/dist/cjs/chunks/MessageInput-CiHFo2j8.js +399 -0
- package/dist/cjs/chunks/Overlay-DwCPvGB5.js +45 -0
- package/dist/cjs/chunks/Pager-CFtZ0IIW.js +42 -0
- package/dist/cjs/chunks/ProgressIndicator-C5oB7Mky.js +121 -0
- package/dist/cjs/chunks/RadioButton-e_y2qiPE.js +65 -0
- package/dist/cjs/chunks/RadioButtonList-I81UwHmM.js +116 -0
- package/dist/cjs/chunks/Slider-C-gn7Sby.js +285 -0
- package/dist/cjs/chunks/Spacer-BEY2-_PB.js +16 -0
- package/dist/cjs/chunks/Switch-CtkFtogd.js +43 -0
- package/dist/cjs/chunks/TabBar-D3bj4pjj.js +176 -0
- package/dist/cjs/chunks/TextArea-B1oKK3_b.js +153 -0
- package/dist/cjs/chunks/TextField-CiQdPP5E.js +248 -0
- package/dist/cjs/chunks/Tip-C2pzExut.js +91 -0
- package/dist/cjs/chunks/Toast-DrijUwoL.js +141 -0
- package/dist/cjs/chunks/UIButton-CH4p-8yq.js +317 -0
- package/dist/cjs/chunks/UIButtonBar-0fHPB0ww.js +58 -0
- package/dist/cjs/chunks/UICard-DBDSyT7E.js +36 -0
- package/dist/cjs/chunks/UIChip-kjhvRrOV.js +93 -0
- package/dist/cjs/chunks/UIFileIcon-ZrbDIeYz.js +54 -0
- package/dist/cjs/chunks/UILabel-DkBE2AIt.js +116 -0
- package/dist/cjs/chunks/_types-CoWzQFsT.js +714 -0
- package/dist/cjs/chunks/sharedTypes-BvTjh6M5.js +9 -0
- package/dist/cjs/chunks/style-inject.es-XZHJH68X.js +30 -0
- package/dist/cjs/chunks/tipStore-C9oV9SIh.js +23 -0
- package/dist/cjs/chunks/toastStore-C-ETP9H6.js +23 -0
- package/dist/cjs/chunks/tslib.es6-4H29ixHs.js +48 -0
- package/dist/cjs/chunks/utils-CbayehuI.js +126 -0
- package/dist/cjs/hooks/useDoubleClick.js +26 -0
- package/dist/cjs/hooks/useKeyboardShortcuts.js +42 -0
- package/dist/cjs/hooks/useLastUpdated.js +53 -0
- package/dist/cjs/hooks/useLocalStore.js +52 -0
- package/dist/cjs/hooks/useObserveResize.js +56 -0
- package/dist/cjs/hooks/useObserveTheme.js +37 -0
- package/dist/cjs/hooks/useTheme.js +86 -0
- package/dist/cjs/hooks/useToolTip.js +36 -0
- package/dist/cjs/hooks/useTrackRenders.js +38 -0
- package/dist/cjs/hooks/useWindow.js +64 -0
- package/dist/cjs/hooks.js +33 -0
- package/dist/cjs/index.js +124 -0
- package/dist/cjs/providers/ThemeProvider.js +55 -0
- package/dist/cjs/providers.js +14 -0
- package/dist/cjs/stores/tip.js +12 -0
- package/dist/cjs/stores/toast.js +12 -0
- package/dist/cjs/stores.js +18 -0
- package/dist/cjs/theme/colors.js +383 -0
- package/dist/cjs/theme/corners.js +14 -0
- package/dist/cjs/theme/elevations.js +17 -0
- package/dist/cjs/theme/themes.js +26 -0
- package/dist/cjs/theme/type.js +316 -0
- package/dist/cjs/theme.js +16 -0
- package/dist/cjs/uikit/Avatar.js +11 -0
- package/dist/cjs/uikit/AvatarGroup.js +12 -0
- package/dist/cjs/uikit/Badge.js +11 -0
- package/dist/cjs/uikit/CheckBox.js +22 -0
- package/dist/cjs/uikit/DivInput.js +13 -0
- package/dist/cjs/uikit/DocIcon.js +18 -0
- package/dist/cjs/uikit/Dot.js +12 -0
- package/dist/cjs/uikit/DraggablePanel.js +21 -0
- package/dist/cjs/uikit/DropDown.js +21 -0
- package/dist/cjs/uikit/EditorButtonBar.js +28 -0
- package/dist/cjs/uikit/ErrorSummary.js +12 -0
- package/dist/cjs/uikit/FlexDiv.js +12 -0
- package/dist/cjs/uikit/Grouper.js +23 -0
- package/dist/cjs/uikit/Icon.js +23 -0
- package/dist/cjs/uikit/IconButton.js +25 -0
- package/dist/cjs/uikit/Logos.js +18 -0
- package/dist/cjs/uikit/MessageInput.js +30 -0
- package/dist/cjs/uikit/Overlay.js +12 -0
- package/dist/cjs/uikit/Pager.js +12 -0
- package/dist/cjs/uikit/Progress.js +21 -0
- package/dist/cjs/uikit/RadioButton.js +26 -0
- package/dist/cjs/uikit/RadioButtonList.js +27 -0
- package/dist/cjs/uikit/Slider.js +13 -0
- package/dist/cjs/uikit/Spacer.js +10 -0
- package/dist/cjs/uikit/Switch.js +12 -0
- package/dist/cjs/uikit/TabBar.js +26 -0
- package/dist/cjs/uikit/TextArea.js +27 -0
- package/dist/cjs/uikit/Textfield.js +28 -0
- package/dist/cjs/uikit/Tip.js +13 -0
- package/dist/cjs/uikit/Toast.js +26 -0
- package/dist/cjs/uikit/UIButton.js +26 -0
- package/dist/cjs/uikit/UIButtonBar.js +26 -0
- package/dist/cjs/uikit/UICard.js +21 -0
- package/dist/cjs/uikit/UIChip.js +22 -0
- package/dist/cjs/uikit/UIFileIcon.js +18 -0
- package/dist/cjs/uikit/UILabel.js +19 -0
- package/dist/esm/chunks/Avatar-D_muqPrW.js +66 -0
- package/dist/esm/chunks/AvatarGroup-D8Xmrn52.js +37 -0
- package/dist/esm/chunks/Badge-PPf5Uvw3.js +39 -0
- package/dist/esm/chunks/CheckBox-CswFI0Xc.js +74 -0
- package/dist/esm/chunks/DivInput-iKFkeU2F.js +202 -0
- package/dist/esm/chunks/DocIcons-CbOX4n8Y.js +39 -0
- package/dist/esm/chunks/Dot-B84UVs2e.js +78 -0
- package/dist/esm/chunks/DrggablePanel-CYYwTmFd.js +300 -0
- package/dist/esm/chunks/DropDown-D4t6EhKL.js +152 -0
- package/dist/esm/chunks/EditorButtonBar-FnMa8Zv2.js +242 -0
- package/dist/esm/chunks/ErrorSummary-DhU5SKPt.js +40 -0
- package/dist/esm/chunks/FlexDiv-CmMpORgn.js +101 -0
- package/dist/esm/chunks/Grouper-BbreOXI9.js +48 -0
- package/dist/esm/chunks/IconButton-CguHGkBM.js +82 -0
- package/dist/esm/chunks/Logos-DwZP-TR2.js +117 -0
- package/dist/esm/chunks/MessageInput-DMHzCwjO.js +397 -0
- package/dist/esm/chunks/Overlay-CCBy7n7H.js +43 -0
- package/dist/esm/chunks/Pager-BsSti93V.js +40 -0
- package/dist/esm/chunks/ProgressIndicator-BVukxMU6.js +118 -0
- package/dist/esm/chunks/RadioButton-B5BxQI0R.js +63 -0
- package/dist/esm/chunks/RadioButtonList-C2z8McAD.js +114 -0
- package/dist/esm/chunks/Slider-C-PcWqTz.js +283 -0
- package/dist/esm/chunks/Spacer-DbZSG5x3.js +14 -0
- package/dist/esm/chunks/Switch-DjfrSiQz.js +41 -0
- package/dist/esm/chunks/TabBar-BSBcgTbd.js +174 -0
- package/dist/esm/chunks/TextArea-COM0UPo2.js +151 -0
- package/dist/esm/chunks/TextField-Bh24bRWs.js +246 -0
- package/dist/esm/chunks/Tip-Ct19Ljul.js +89 -0
- package/dist/esm/chunks/Toast-BR0oMX6z.js +139 -0
- package/dist/esm/chunks/UIButton-DKx-_O8h.js +315 -0
- package/dist/esm/chunks/UIButtonBar-BNdA5eVq.js +56 -0
- package/dist/esm/chunks/UICard-Dn5f3wg8.js +34 -0
- package/dist/esm/chunks/UIChip-DqnGeVyR.js +91 -0
- package/dist/esm/chunks/UIFileIcon-qGxIPsJJ.js +52 -0
- package/dist/esm/chunks/UILabel-RnbodPCS.js +114 -0
- package/dist/esm/chunks/_types-BaYeLEWK.js +712 -0
- package/dist/esm/chunks/sharedTypes-BfZzG1KX.js +9 -0
- package/dist/esm/chunks/style-inject.es-tgCJW-Cu.js +28 -0
- package/dist/esm/chunks/tipStore-nBYJ6tmE.js +17 -0
- package/dist/esm/chunks/toastStore-r3pvNa28.js +17 -0
- package/dist/esm/chunks/tslib.es6-0pkUdtrF.js +45 -0
- package/dist/esm/chunks/utils-BRZK2Drn.js +119 -0
- package/dist/esm/hooks/useDoubleClick.js +24 -0
- package/dist/esm/hooks/useKeyboardShortcuts.js +40 -0
- package/dist/esm/hooks/useLastUpdated.js +51 -0
- package/dist/esm/hooks/useLocalStore.js +50 -0
- package/dist/esm/hooks/useObserveResize.js +54 -0
- package/dist/esm/hooks/useObserveTheme.js +35 -0
- package/dist/esm/hooks/useTheme.js +84 -0
- package/dist/esm/hooks/useToolTip.js +34 -0
- package/dist/esm/hooks/useTrackRenders.js +36 -0
- package/dist/esm/hooks/useWindow.js +62 -0
- package/dist/esm/hooks.js +15 -0
- package/dist/esm/index.js +58 -0
- package/dist/esm/providers/ThemeProvider.js +53 -0
- package/dist/esm/providers.js +8 -0
- package/dist/esm/stores/tip.js +2 -0
- package/dist/esm/stores/toast.js +2 -0
- package/dist/esm/stores.js +3 -0
- package/dist/esm/theme/colors.js +377 -0
- package/dist/esm/theme/corners.js +12 -0
- package/dist/esm/theme/elevations.js +15 -0
- package/dist/esm/theme/themes.js +23 -0
- package/dist/esm/theme/type.js +312 -0
- package/dist/esm/theme.js +5 -0
- package/dist/esm/uikit/Avatar.js +5 -0
- package/dist/esm/uikit/AvatarGroup.js +6 -0
- package/dist/esm/uikit/Badge.js +5 -0
- package/dist/esm/uikit/CheckBox.js +16 -0
- package/dist/esm/uikit/DivInput.js +7 -0
- package/dist/esm/uikit/DocIcon.js +12 -0
- package/dist/esm/uikit/Dot.js +6 -0
- package/dist/esm/uikit/DraggablePanel.js +15 -0
- package/dist/esm/uikit/DropDown.js +15 -0
- package/dist/esm/uikit/EditorButtonBar.js +22 -0
- package/dist/esm/uikit/ErrorSummary.js +6 -0
- package/dist/esm/uikit/FlexDiv.js +6 -0
- package/dist/esm/uikit/Grouper.js +17 -0
- package/dist/esm/uikit/Icon.js +13 -0
- package/dist/esm/uikit/IconButton.js +19 -0
- package/dist/esm/uikit/Logos.js +12 -0
- package/dist/esm/uikit/MessageInput.js +24 -0
- package/dist/esm/uikit/Overlay.js +6 -0
- package/dist/esm/uikit/Pager.js +6 -0
- package/dist/esm/uikit/Progress.js +14 -0
- package/dist/esm/uikit/RadioButton.js +20 -0
- package/dist/esm/uikit/RadioButtonList.js +21 -0
- package/dist/esm/uikit/Slider.js +7 -0
- package/dist/esm/uikit/Spacer.js +4 -0
- package/dist/esm/uikit/Switch.js +6 -0
- package/dist/esm/uikit/TabBar.js +20 -0
- package/dist/esm/uikit/TextArea.js +21 -0
- package/dist/esm/uikit/Textfield.js +22 -0
- package/dist/esm/uikit/Tip.js +7 -0
- package/dist/esm/uikit/Toast.js +16 -0
- package/dist/esm/uikit/UIButton.js +20 -0
- package/dist/esm/uikit/UIButtonBar.js +20 -0
- package/dist/esm/uikit/UICard.js +15 -0
- package/dist/esm/uikit/UIChip.js +16 -0
- package/dist/esm/uikit/UIFileIcon.js +12 -0
- package/dist/esm/uikit/UILabel.js +13 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/providers/ThemeProvider.d.ts +1 -0
- package/dist/types/stores/index.d.ts +2 -0
- package/dist/types/stores/tip/_types.d.ts +8 -0
- package/dist/types/stores/tip/index.d.ts +2 -0
- package/dist/types/stores/tip/tipStore.d.ts +12 -0
- package/dist/types/stores/toast/_types.d.ts +14 -0
- package/dist/types/stores/toast/index.d.ts +2 -0
- package/dist/types/stores/toast/toastStore.d.ts +12 -0
- package/dist/types/theme/elevations/_types.d.ts +10 -0
- package/dist/types/theme/elevations/elevations.d.ts +5 -0
- package/dist/types/theme/index.d.ts +2 -0
- package/dist/types/theme/themes.d.ts +2 -0
- package/dist/types/uikit/FlexDiv/FlexDiv.d.ts +2 -0
- package/dist/types/uikit/FlexDiv/_types.d.ts +1 -0
- package/dist/types/uikit/Toast/Toast.d.ts +1 -1
- package/dist/types/uikit/Toast/_types.d.ts +7 -1
- package/dist/types/uikit/Toast/index.d.ts +1 -1
- package/package.json +84 -5
- package/dist/index.esm.js +0 -5859
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -5911
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-0pkUdtrF.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useRef, useState, useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { useTheme } from '../hooks/useTheme.js';
|
|
5
|
+
import '../theme/colors.js';
|
|
6
|
+
import '../hooks/useWindow.js';
|
|
7
|
+
import { useObserveResize } from '../hooks/useObserveResize.js';
|
|
8
|
+
import { p as pointerPosition } from './utils-BRZK2Drn.js';
|
|
9
|
+
import { s as styleInject } from './style-inject.es-tgCJW-Cu.js';
|
|
10
|
+
|
|
11
|
+
var css_248z = ".flexBox-module_row__PWxbe {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowBetween__27lKK {\n\tdisplay: flex;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowStart__nJZnW {\n\tdisplay: flex;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowEnd__dHcOU {\n\tdisplay: flex;\n\tjustify-content: flex-end;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_column__MP2Xd {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStart__Kg8cV {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: flex-start;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStartCenter__zcmtk {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnBetween__157yI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnEnd__u2nwI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-end;\n\talign-items: flex-end;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}\n\n.DraggablePanel-module_panel__r-Dm- {\n\tposition: relative;\n\tbackground-color: var(--panel-bg);\n}\n\n.DraggablePanel-module_content__K1gRd {\n\twidth: 100%;\n\theight: 100%;\n\toverflow: hidden;\n}\n\n.DraggablePanel-module_handle__yVrgS {\n\twidth: var(--drag-handle-width);\n\theight: var(--drag-handle-height);\n\tmin-width: var(--drag-handle-width);\n\tmin-height: var(--drag-handle-height);\n\tborder-radius: var(--drag-handle-radius);\n\tborder: var(--drag-handle-border) solid var(--drag-handle-border-color);\n\tbackground: var(--drag-handle-bg);\n\tposition: absolute;\n\ttop: 50%;\n\tleft: 50%;\n\ttransform: translateX(-50%) translateY(-50%);\n\tz-index: 15000;\n}\n";
|
|
12
|
+
var css = {"panel":"DraggablePanel-module_panel__r-Dm- flexBox-module_columnStart__Kg8cV","content":"DraggablePanel-module_content__K1gRd flexBox-module_columnStart__Kg8cV","handle":"DraggablePanel-module_handle__yVrgS"};
|
|
13
|
+
styleInject(css_248z);
|
|
14
|
+
|
|
15
|
+
const MIN_SIZE = 50;
|
|
16
|
+
const DraggablePanel = React.memo((props) => {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const { children, sizeConstraints = { initial: 250, min: 250, max: 500 }, dragsRight = true, isClosed = true, resizeHandle = {
|
|
19
|
+
width: 10,
|
|
20
|
+
color: 'transparent',
|
|
21
|
+
offsetX: true,
|
|
22
|
+
}, borderRight = '1px solid var(--core-outline-primary)', borderLeft = null, bgColor = 'transparent', drags = true, isTouchDevice = false, disableOnContext = true, dragHandle = true, dragHandleStyle, containerRef, onResize = () => null, onResizeStart = () => null, onResizeEnd = () => null } = props, divAttributes = __rest(props, ["children", "sizeConstraints", "dragsRight", "isClosed", "resizeHandle", "borderRight", "borderLeft", "bgColor", "drags", "isTouchDevice", "disableOnContext", "dragHandle", "dragHandleStyle", "containerRef", "onResize", "onResizeStart", "onResizeEnd"]);
|
|
23
|
+
const { id: divId, className, style } = divAttributes, rest = __rest(divAttributes, ["id", "className", "style"]);
|
|
24
|
+
const divStyle = style !== null && style !== void 0 ? style : {};
|
|
25
|
+
const divClass = className ? ` ${className}` : '';
|
|
26
|
+
const handle = useRef(null);
|
|
27
|
+
const div = useRef(null);
|
|
28
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
29
|
+
const isOver = useRef(false);
|
|
30
|
+
const gripper = Object.assign({}, resizeHandle);
|
|
31
|
+
const containerSize = useObserveResize(containerRef);
|
|
32
|
+
const [handleHighlight, setHandleHighlight] = useState(false);
|
|
33
|
+
const [lastWidth, setLastWidth] = useState(null);
|
|
34
|
+
const [panelClosed, setPanelClosed] = useState(isClosed);
|
|
35
|
+
const [constraints, setConstraints] = useState(sizeConstraints);
|
|
36
|
+
const [contWidth, setContWidth] = useState(undefined);
|
|
37
|
+
const timer = useRef(null);
|
|
38
|
+
const startX = useRef(0);
|
|
39
|
+
const startWidth = useRef(0);
|
|
40
|
+
const divWidth = useRef(0);
|
|
41
|
+
const divHeight = useRef(0);
|
|
42
|
+
const deltaWidth = useRef(0);
|
|
43
|
+
// handle window resize call back - use the window object only if containerRef is undefined
|
|
44
|
+
const handleWindowResize = useCallback(() => {
|
|
45
|
+
if (!(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current))
|
|
46
|
+
setContWidth(window.innerWidth);
|
|
47
|
+
}, [containerRef]);
|
|
48
|
+
const handleMouseOver = useCallback(() => {
|
|
49
|
+
isOver.current = true;
|
|
50
|
+
setHighlight(true);
|
|
51
|
+
}, []);
|
|
52
|
+
const handleMouseOut = useCallback(() => {
|
|
53
|
+
isOver.current = false;
|
|
54
|
+
if (!isDragging)
|
|
55
|
+
setHighlight(false);
|
|
56
|
+
}, [isDragging]);
|
|
57
|
+
const handleFocus = useCallback(() => {
|
|
58
|
+
isOver.current = true;
|
|
59
|
+
setHighlight(true);
|
|
60
|
+
}, []);
|
|
61
|
+
const handleBlur = useCallback(() => {
|
|
62
|
+
isOver.current = false;
|
|
63
|
+
if (!isDragging)
|
|
64
|
+
setHighlight(false);
|
|
65
|
+
}, [isDragging]);
|
|
66
|
+
const handleTouchStart = useCallback(() => {
|
|
67
|
+
isOver.current = true;
|
|
68
|
+
setHighlight(true);
|
|
69
|
+
}, []);
|
|
70
|
+
const handleTouchEnd = useCallback(() => {
|
|
71
|
+
isOver.current = false;
|
|
72
|
+
if (!isDragging)
|
|
73
|
+
setHighlight(false);
|
|
74
|
+
}, [isDragging]);
|
|
75
|
+
// handle container resize - if continerRef and width more than 0 use this to set container size
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!containerRef)
|
|
78
|
+
return;
|
|
79
|
+
if (containerSize.width > 0)
|
|
80
|
+
setContWidth(containerSize.width);
|
|
81
|
+
}, [containerSize, containerRef]);
|
|
82
|
+
// listen to then window resize event
|
|
83
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: on mount only
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!contWidth)
|
|
86
|
+
setContWidth(window.innerWidth);
|
|
87
|
+
globalThis.addEventListener('resize', handleWindowResize);
|
|
88
|
+
return () => globalThis.removeEventListener('resize', handleWindowResize);
|
|
89
|
+
}, []);
|
|
90
|
+
// close/open on prop change
|
|
91
|
+
useEffect(() => setPanelClosed(isClosed), [isClosed]);
|
|
92
|
+
// on constraints update, check and adjust div width to not exceed max
|
|
93
|
+
const adjustCurrentWidth = useCallback((relConst) => {
|
|
94
|
+
if ((div === null || div === void 0 ? void 0 : div.current) && relConst.max) {
|
|
95
|
+
const currentWidth = div.current.offsetWidth;
|
|
96
|
+
if (currentWidth > relConst.max) {
|
|
97
|
+
div.current.style.width = `${relConst.max}px`;
|
|
98
|
+
divWidth.current = relConst.max;
|
|
99
|
+
setLastWidth(relConst.max);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, []);
|
|
103
|
+
// reset constraints on prop changes
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!contWidth)
|
|
106
|
+
return;
|
|
107
|
+
const { min, max, initial } = sizeConstraints;
|
|
108
|
+
const relativeConstraints = { min, max, initial };
|
|
109
|
+
for (const [key, value] of Object.entries(sizeConstraints)) {
|
|
110
|
+
let calc = value;
|
|
111
|
+
if (calc <= 1 && calc >= 0)
|
|
112
|
+
calc = contWidth * value; // handle "percent" values
|
|
113
|
+
if (calc > 1 && calc < MIN_SIZE)
|
|
114
|
+
calc = MIN_SIZE; // ensure values no smaller than MIN_SIZE
|
|
115
|
+
relativeConstraints[key] = calc;
|
|
116
|
+
}
|
|
117
|
+
if (relativeConstraints.min < relativeConstraints.initial) {
|
|
118
|
+
relativeConstraints.initial = relativeConstraints.min; // ensure "initial" is not smaller than "min"
|
|
119
|
+
}
|
|
120
|
+
setConstraints(relativeConstraints);
|
|
121
|
+
adjustCurrentWidth(relativeConstraints);
|
|
122
|
+
}, [sizeConstraints, contWidth, adjustCurrentWidth]);
|
|
123
|
+
// callback for hilight when hovering over the resize handle
|
|
124
|
+
const setHighlight = useCallback((state) => {
|
|
125
|
+
if (timer.current)
|
|
126
|
+
clearTimeout(timer.current);
|
|
127
|
+
if (state) {
|
|
128
|
+
timer.current = setTimeout(() => {
|
|
129
|
+
setHandleHighlight(state);
|
|
130
|
+
}, isTouchDevice ? 0 : 350);
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
setHandleHighlight(false);
|
|
134
|
+
}, [isTouchDevice]);
|
|
135
|
+
// get the current mouse X position using touch or mouse event
|
|
136
|
+
const getClientX = useCallback((e) => {
|
|
137
|
+
return pointerPosition(e);
|
|
138
|
+
}, []);
|
|
139
|
+
// calculate the drag amount based on starting point and new client x point
|
|
140
|
+
const getNewWidth = useCallback((clientX) => {
|
|
141
|
+
return dragsRight
|
|
142
|
+
? startWidth.current + clientX - startX.current
|
|
143
|
+
: startWidth.current - clientX + startX.current;
|
|
144
|
+
}, [dragsRight]);
|
|
145
|
+
// check constraints to prevent over dragging
|
|
146
|
+
const canDrag = useCallback((newWidth, clientX) => {
|
|
147
|
+
if (constraints === null || constraints === void 0 ? void 0 : constraints.min) {
|
|
148
|
+
if (newWidth <= constraints.min)
|
|
149
|
+
return false;
|
|
150
|
+
if (newWidth < constraints.min)
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
if (constraints === null || constraints === void 0 ? void 0 : constraints.max) {
|
|
154
|
+
if (newWidth >= constraints.max) {
|
|
155
|
+
if (clientX - startX.current > 0)
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}, [constraints]);
|
|
161
|
+
// process drag
|
|
162
|
+
const doDrag = useCallback((e) => {
|
|
163
|
+
if (div === null || div === void 0 ? void 0 : div.current) {
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
const el = div.current;
|
|
167
|
+
const clientX = getClientX(e);
|
|
168
|
+
const newWidth = getNewWidth(clientX);
|
|
169
|
+
if (!canDrag(newWidth, clientX))
|
|
170
|
+
return;
|
|
171
|
+
el.style.width = `${newWidth}px`;
|
|
172
|
+
divWidth.current = newWidth;
|
|
173
|
+
deltaWidth.current = clientX - startX.current;
|
|
174
|
+
onResize({
|
|
175
|
+
div,
|
|
176
|
+
divWidth: divWidth.current,
|
|
177
|
+
divHeight: divHeight.current,
|
|
178
|
+
deltaWidth: deltaWidth.current,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}, [onResize, canDrag, getNewWidth, getClientX]);
|
|
183
|
+
// handle stopping drag
|
|
184
|
+
const stopDrag = useCallback(() => {
|
|
185
|
+
setIsDragging(false);
|
|
186
|
+
document.documentElement.removeEventListener('mousemove', doDrag, false);
|
|
187
|
+
document.documentElement.removeEventListener('mouseup', stopDrag, false);
|
|
188
|
+
document.documentElement.removeEventListener('touchmove', doDrag, false);
|
|
189
|
+
document.documentElement.removeEventListener('touchend', stopDrag, false);
|
|
190
|
+
document.documentElement.style.userSelect = 'auto';
|
|
191
|
+
// noinspection JSDeprecatedSymbols
|
|
192
|
+
document.documentElement.style.webkitUserSelect = 'auto'; // reuqired for safari / iOS
|
|
193
|
+
if (div === null || div === void 0 ? void 0 : div.current) {
|
|
194
|
+
divWidth.current = div.current.offsetWidth;
|
|
195
|
+
divHeight.current = div.current.offsetHeight;
|
|
196
|
+
deltaWidth.current = 0;
|
|
197
|
+
const update = {
|
|
198
|
+
div,
|
|
199
|
+
divWidth: divWidth.current,
|
|
200
|
+
divHeight: divHeight.current,
|
|
201
|
+
deltaWidth: deltaWidth.current,
|
|
202
|
+
};
|
|
203
|
+
onResize(update);
|
|
204
|
+
onResizeEnd(update);
|
|
205
|
+
}
|
|
206
|
+
setLastWidth(divWidth.current);
|
|
207
|
+
if (!isOver.current)
|
|
208
|
+
setHighlight(false);
|
|
209
|
+
}, [doDrag, onResizeEnd, onResize, setHighlight]);
|
|
210
|
+
// handle starting drag
|
|
211
|
+
const initDrag = useCallback((e) => {
|
|
212
|
+
if ((div === null || div === void 0 ? void 0 : div.current) && document.defaultView) {
|
|
213
|
+
setIsDragging(true);
|
|
214
|
+
const el = div.current;
|
|
215
|
+
divWidth.current = div.current.offsetWidth;
|
|
216
|
+
divHeight.current = div.current.offsetHeight;
|
|
217
|
+
deltaWidth.current = 0;
|
|
218
|
+
startX.current = pointerPosition(e);
|
|
219
|
+
startWidth.current = Number.parseInt(document.defaultView.getComputedStyle(el).width, 10);
|
|
220
|
+
document.documentElement.addEventListener('mousemove', doDrag, false);
|
|
221
|
+
document.documentElement.addEventListener('mouseup', stopDrag, false);
|
|
222
|
+
document.documentElement.addEventListener('touchmove', doDrag, false);
|
|
223
|
+
document.documentElement.addEventListener('touchend', stopDrag, false);
|
|
224
|
+
document.documentElement.style.userSelect = 'none';
|
|
225
|
+
// noinspection JSDeprecatedSymbols
|
|
226
|
+
document.documentElement.style.webkitUserSelect = 'none'; // reuqired for safari / iOS
|
|
227
|
+
const update = {
|
|
228
|
+
div,
|
|
229
|
+
divWidth: divWidth.current,
|
|
230
|
+
divHeight: divHeight.current,
|
|
231
|
+
deltaWidth: deltaWidth.current,
|
|
232
|
+
};
|
|
233
|
+
onResize(update);
|
|
234
|
+
onResizeStart(update);
|
|
235
|
+
}
|
|
236
|
+
}, [doDrag, stopDrag, onResize, onResizeStart]);
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
const hl = handle === null || handle === void 0 ? void 0 : handle.current;
|
|
239
|
+
if (hl && drags) {
|
|
240
|
+
hl.addEventListener('mousedown', initDrag, false);
|
|
241
|
+
hl.addEventListener('touchstart', initDrag, { passive: true });
|
|
242
|
+
}
|
|
243
|
+
return () => {
|
|
244
|
+
if (hl) {
|
|
245
|
+
hl.removeEventListener('mousedown', initDrag, false);
|
|
246
|
+
hl.removeEventListener('touchstart', initDrag);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}, [drags, initDrag]);
|
|
250
|
+
const leftRightStyle = useMemo(() => {
|
|
251
|
+
if (dragsRight) {
|
|
252
|
+
return { right: isTouchDevice ? -22 : -((gripper.width || 10) / 2) };
|
|
253
|
+
}
|
|
254
|
+
return { left: isTouchDevice ? -22 : -((gripper.width || 10) / 2) };
|
|
255
|
+
}, [dragsRight, isTouchDevice, gripper.width]);
|
|
256
|
+
const width = useMemo(() => {
|
|
257
|
+
if (!drags)
|
|
258
|
+
return '100%';
|
|
259
|
+
if (panelClosed)
|
|
260
|
+
return 0;
|
|
261
|
+
if (lastWidth)
|
|
262
|
+
return lastWidth;
|
|
263
|
+
return constraints.initial;
|
|
264
|
+
}, [drags, panelClosed, lastWidth, constraints.initial]);
|
|
265
|
+
const cssVars = useMemo(() => {
|
|
266
|
+
return {
|
|
267
|
+
'--panel-bg': bgColor !== null && bgColor !== void 0 ? bgColor : 'transparent',
|
|
268
|
+
};
|
|
269
|
+
}, [bgColor]);
|
|
270
|
+
return (jsxs("div", Object.assign({ id: divId, className: `${css.panel}${divClass}`, ref: div, onContextMenu: (e) => {
|
|
271
|
+
if (disableOnContext)
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
return true;
|
|
274
|
+
}, style: Object.assign(Object.assign(Object.assign({}, divStyle), cssVars), { overflow: 'visible', width: width, height: '100%', maxWidth: drags ? constraints.max : 'unset', transition: isDragging ? '' : 'width 0.2s ease', borderRight: panelClosed || !borderRight || !drags ? 'none' : borderRight, borderLeft: panelClosed || !borderLeft || !drags ? 'none' : borderLeft }) }, rest, { children: [jsxs("div", { ref: handle, style: Object.assign(Object.assign({ position: 'absolute', boxSizing: 'border-box', display: panelClosed || !drags ? 'none' : 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 1, top: 0 }, leftRightStyle), { bottom: 0, width: isTouchDevice ? 44 : gripper.width, backgroundColor: resizeHandle.color, cursor: 'col-resize', overflow: 'visible' }), onMouseOver: handleMouseOver, onMouseOut: handleMouseOut, onFocus: handleFocus, onBlur: handleBlur, onTouchStart: handleTouchStart, onTouchEnd: handleTouchEnd, children: [dragHandle && !panelClosed && (jsx(DragHandle, Object.assign({}, (dragHandleStyle !== null && dragHandleStyle !== void 0 ? dragHandleStyle : {})))), jsx("div", { style: {
|
|
275
|
+
backgroundColor: handleHighlight
|
|
276
|
+
? theme.current.colors['core-outline-primary']
|
|
277
|
+
: 'transparent',
|
|
278
|
+
flex: 1,
|
|
279
|
+
maxWidth: 3,
|
|
280
|
+
height: '100%',
|
|
281
|
+
pointerEvents: 'none',
|
|
282
|
+
transition: 'background-color 0.2s ease',
|
|
283
|
+
} })] }), jsx("div", { className: css.content, children: children })] })));
|
|
284
|
+
});
|
|
285
|
+
const DragHandle = React.memo((props) => {
|
|
286
|
+
const { width = 6, height = 6, radius = 100, stroke = 1, color = 'var(--core-surface-primary)', strokeColor = 'var(--core-outline-primary)', } = props;
|
|
287
|
+
const cssVars = useMemo(() => {
|
|
288
|
+
return {
|
|
289
|
+
'--drag-handle-width': `${width}px`,
|
|
290
|
+
'--drag-handle-height': `${height}px`,
|
|
291
|
+
'--drag-handle-radius': `${radius}px`,
|
|
292
|
+
'--drag-handle-border': `${stroke}px`,
|
|
293
|
+
'--drag-handle-border-color': `${strokeColor}`,
|
|
294
|
+
'--drag-handle-bg': `${color}`,
|
|
295
|
+
};
|
|
296
|
+
}, [width, height, radius, stroke, color, strokeColor]);
|
|
297
|
+
return jsx("div", { className: css.handle, style: cssVars });
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
export { DraggablePanel as D };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-0pkUdtrF.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
+
import { useTheme } from '../hooks/useTheme.js';
|
|
5
|
+
import '../theme/colors.js';
|
|
6
|
+
import '../hooks/useWindow.js';
|
|
7
|
+
import { I as Icon } from './_types-BaYeLEWK.js';
|
|
8
|
+
import { s as styleInject } from './style-inject.es-tgCJW-Cu.js';
|
|
9
|
+
|
|
10
|
+
var css_248z = ".flexBox-module_row__PWxbe {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowBetween__27lKK {\n\tdisplay: flex;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowStart__nJZnW {\n\tdisplay: flex;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_rowEnd__dHcOU {\n\tdisplay: flex;\n\tjustify-content: flex-end;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_column__MP2Xd {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: center;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStart__Kg8cV {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: flex-start;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnStartCenter__zcmtk {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-start;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnBetween__157yI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: space-between;\n\talign-items: center;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.flexBox-module_columnEnd__u2nwI {\n\tdisplay: flex;\n\tflex-direction: column;\n\tjustify-content: flex-end;\n\talign-items: flex-end;\n\tbox-sizing: border-box;\n\tpadding: 0;\n\tmargin: 0;\n}.type-module_body-xs-regular__QWEzl {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-medium__FxEAv {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-xs-bold__rf7AV {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-xs);\n\tline-height: 133.33%;\n\ttext-decoration: none;\n\tletter-spacing: 0.25px;\n}.type-module_body-s-regular__8-FO- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-medium__qyYq- {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-s-bold__7GQ5Z {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-s);\n\tline-height: 142.86%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-m-regular__Qtp5G {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-medium__Ieh9K {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_body-m-bold__0lZ3I {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-m);\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_body-l-regular__Ar4d3 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-regular);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-medium__6tV1n {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-medium);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.1px;\n}.type-module_body-l-bold__I8Q1v {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: var(--font-weight-bold);\n\tfont-size: var(--font-size-l);\n\tline-height: 162.5%;\n\ttext-decoration: none;\n\tletter-spacing: 0.15px;\n}.type-module_heading-s-bold__QFgN8 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-s-medium__jGIb2 {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 20px;\n\tline-height: 140%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-bold__tdBSi {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-m-medium__-7Uyu {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 24px;\n\tline-height: 116.67%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-medium__8hGYF {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 560;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}.type-module_heading-l-bold__Cryjg {\n\tfont-family: var(--font-family), sans-serif;\n\tfont-weight: 650;\n\tfont-size: 28px;\n\tline-height: 128.57%;\n\ttext-decoration: none;\n\tletter-spacing: 0.2px;\n}\n\n.DropDown-module_wrapper__56asG {\n\tposition: relative;\n\tgap: var(--dd-gap);\n\tmin-width: var(--dd-width);\n\twidth: var(--dd-width);\n\tborder-radius: var(--dd-border-radius);\n\tbackground-color: var(--dd-bg-color);\n\tbox-shadow: 0 0 0 var(--dd-box-shadow-size) var(--dd-border-color);\n\tpadding: var(--dd-padding-tops) var(--dd-padding-left) var(--dd-padding-tops)\n\t\tvar(--dd-padding-right) !important;\n\ttransition: all 0.2s ease-in-out 0s;\n}\n\n.DropDown-module_face__kF56R {\n\tflex: 1;\n\toverflow: hidden;\n\tdisplay: -webkit-box;\n\t-webkit-line-clamp: 1;\n\t-webkit-box-orient: vertical;\n\ttext-overflow: ellipsis;\n\tword-break: break-all;\n\tcolor: var(--dd-color);\n}\n\n.DropDown-module_small__QYoM4 {\n}\n\n.DropDown-module_medium__FrKVH {\n}\n\n.DropDown-module_large__O1hDm {\n}\n\n.DropDown-module_chevron__upYr7 {\n\tmin-height: var(--dd-icon-size);\n\tmax-height: var(--dd-icon-size);\n\tmin-width: var(--dd-icon-size);\n\tmax-width: var(--dd-icon-size);\n}\n\n.DropDown-module_select__1rQRA {\n\tposition: absolute;\n\topacity: 0;\n\twidth: 100%;\n\theight: 100%;\n\tfont-size: 14px;\n\tbackground-color: #1f99cd;\n\tbackground-position: right 10px center;\n\tbackground-repeat: no-repeat;\n\tbackground-size: auto 50%;\n\tborder: none;\n\toutline: none;\n\t-moz-appearance: none;\n\t-webkit-appearance: none;\n\tappearance: none;\n\t&::-ms-expand {\n\t\tdisplay: none;\n\t}\n}\n";
|
|
11
|
+
var css = {"wrapper":"DropDown-module_wrapper__56asG flexBox-module_rowStart__nJZnW","face":"DropDown-module_face__kF56R flexBox-module_rowStart__nJZnW","small":"DropDown-module_small__QYoM4 type-module_body-s-regular__8-FO-","medium":"DropDown-module_medium__FrKVH type-module_body-m-regular__Qtp5G","large":"DropDown-module_large__O1hDm type-module_body-l-regular__Ar4d3","chevron":"DropDown-module_chevron__upYr7 flexBox-module_rowStart__nJZnW","select":"DropDown-module_select__1rQRA"};
|
|
12
|
+
styleInject(css_248z);
|
|
13
|
+
|
|
14
|
+
const DropDown = React.memo((props) => {
|
|
15
|
+
const theme = useTheme();
|
|
16
|
+
const { name = 'Select', width = '100%', height = 'auto', selectedIndex = 0, selectedValue = '', options = [], placeholder = true, validate = true, borderRadius = 4, bgColor = 'transparent', iconColor = theme.current.colors['core-icon-primary'], paddingLeft = '8px', paddingRight = '12px', paddingTops = '8px', iconSize = 20, disabled = false, unframed = false, focused = false, gap = 0, size = 'medium', onChange = () => null, onValidate = () => null, onFocus = () => null, onBlur = () => null } = props, divAttributes = __rest(props, ["name", "width", "height", "selectedIndex", "selectedValue", "options", "placeholder", "validate", "borderRadius", "bgColor", "iconColor", "paddingLeft", "paddingRight", "paddingTops", "iconSize", "disabled", "unframed", "focused", "gap", "size", "onChange", "onValidate", "onFocus", "onBlur"]);
|
|
17
|
+
const { id: divId, className, style } = divAttributes, rest = __rest(divAttributes, ["id", "className", "style"]);
|
|
18
|
+
const divStyle = style !== null && style !== void 0 ? style : {};
|
|
19
|
+
const divClass = className ? ` ${className}` : '';
|
|
20
|
+
const [index, setIndex] = useState(selectedIndex);
|
|
21
|
+
const [selectedText, setSelectedText] = useState('Select an option');
|
|
22
|
+
const [initiated, setInitiated] = useState(false);
|
|
23
|
+
const [color, setColor] = useState(iconColor);
|
|
24
|
+
const ref = useRef(null);
|
|
25
|
+
useEffect(() => setColor(theme.current.colors['core-icon-primary']), [theme]);
|
|
26
|
+
// validate selection and if there's a placeholder
|
|
27
|
+
// with a validate flag, set error state and event error
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
let valid = true;
|
|
30
|
+
if (validate && placeholder && index === 0)
|
|
31
|
+
valid = false;
|
|
32
|
+
if (!initiated)
|
|
33
|
+
valid = true;
|
|
34
|
+
onValidate(valid);
|
|
35
|
+
}, [index, validate, placeholder, initiated, onValidate]);
|
|
36
|
+
// set focus
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (focused && (ref === null || ref === void 0 ? void 0 : ref.current)) {
|
|
39
|
+
setInitiated(true);
|
|
40
|
+
ref.current.click();
|
|
41
|
+
}
|
|
42
|
+
}, [focused]);
|
|
43
|
+
// set selected by index
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (ref === null || ref === void 0 ? void 0 : ref.current) {
|
|
46
|
+
if (!(options === null || options === void 0 ? void 0 : options[selectedIndex]))
|
|
47
|
+
return;
|
|
48
|
+
const label = options[selectedIndex].label || 'Select an option';
|
|
49
|
+
setIndex(selectedIndex);
|
|
50
|
+
setSelectedText(label);
|
|
51
|
+
ref.current.selectedIndex = selectedIndex;
|
|
52
|
+
}
|
|
53
|
+
}, [selectedIndex, options]);
|
|
54
|
+
// set selected by value - FIXED: potential infinite loop
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!options || options.length === 0 || selectedValue === '')
|
|
57
|
+
return;
|
|
58
|
+
const foundIndex = options.findIndex((option) => {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
return ((_a = option === null || option === void 0 ? void 0 : option.value) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ===
|
|
61
|
+
selectedValue.toString().toLowerCase() ||
|
|
62
|
+
((_b = option === null || option === void 0 ? void 0 : option.label) === null || _b === void 0 ? void 0 : _b.toLowerCase()) ===
|
|
63
|
+
selectedValue.toString().toLowerCase() ||
|
|
64
|
+
((_c = option === null || option === void 0 ? void 0 : option.alt) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === selectedValue.toString().toLowerCase();
|
|
65
|
+
});
|
|
66
|
+
if (foundIndex !== -1) {
|
|
67
|
+
const label = options[foundIndex].label || 'Select an option';
|
|
68
|
+
setSelectedText(label);
|
|
69
|
+
setIndex(foundIndex);
|
|
70
|
+
if (ref.current)
|
|
71
|
+
ref.current.selectedIndex = foundIndex;
|
|
72
|
+
}
|
|
73
|
+
}, [selectedValue, options]);
|
|
74
|
+
// memo on change
|
|
75
|
+
const handleChange = useCallback((i) => {
|
|
76
|
+
if (!options)
|
|
77
|
+
return;
|
|
78
|
+
const label = options[i].label || 'Select an option';
|
|
79
|
+
setIndex(i);
|
|
80
|
+
setSelectedText(label);
|
|
81
|
+
if (index !== i)
|
|
82
|
+
onChange(i, options[i]);
|
|
83
|
+
onBlur(options[i].label || '');
|
|
84
|
+
}, [options, index, onChange, onBlur]);
|
|
85
|
+
// memo focus
|
|
86
|
+
const handleFocus = useCallback(() => {
|
|
87
|
+
setInitiated(true);
|
|
88
|
+
onFocus();
|
|
89
|
+
}, [onFocus]);
|
|
90
|
+
// Memoize renderOptions
|
|
91
|
+
const renderedOptions = useMemo(() => {
|
|
92
|
+
if (!options)
|
|
93
|
+
return null;
|
|
94
|
+
return options.map((option, i) => (jsx("option", { value: option === null || option === void 0 ? void 0 : option.value, onMouseUp: () => handleChange(i), children: option === null || option === void 0 ? void 0 : option.label }, `${option === null || option === void 0 ? void 0 : option.value}_${i}`)));
|
|
95
|
+
}, [options, handleChange]);
|
|
96
|
+
// Memoize displayed text
|
|
97
|
+
const displayText = useMemo(() => selectedText.replace('-- ', ''), [selectedText]);
|
|
98
|
+
// Memoize handleMouseDown
|
|
99
|
+
const handleMouseDown = useCallback((e) => {
|
|
100
|
+
if (disabled)
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
handleFocus();
|
|
103
|
+
}, [disabled, handleFocus]);
|
|
104
|
+
// Memoize onChange handler
|
|
105
|
+
const handleSelectChange = useCallback((e) => {
|
|
106
|
+
handleChange(e.target.selectedIndex);
|
|
107
|
+
}, [handleChange]);
|
|
108
|
+
const getSize = useCallback((value) => {
|
|
109
|
+
if (typeof value === 'string')
|
|
110
|
+
return value;
|
|
111
|
+
return `${value}px`;
|
|
112
|
+
}, []);
|
|
113
|
+
const cssVars = useMemo(() => {
|
|
114
|
+
return {
|
|
115
|
+
'--dd-gap': `${gap}px`,
|
|
116
|
+
'--dd-height': `${getSize(height)}`,
|
|
117
|
+
'--dd-width': `${getSize(width)}`,
|
|
118
|
+
'--dd-margin': '8px',
|
|
119
|
+
'--dd-border-radius': borderRadius ? `${borderRadius}px` : '4px',
|
|
120
|
+
'--dd-box-shadow-size': unframed ? '0' : '1px',
|
|
121
|
+
'--dd-border-color': unframed
|
|
122
|
+
? 'transparent'
|
|
123
|
+
: 'var(--core-outline-primary)',
|
|
124
|
+
'--dd-bg-color': bgColor !== null && bgColor !== void 0 ? bgColor : 'transparent',
|
|
125
|
+
'--dd-padding-left': unframed ? '0' : `${getSize(paddingLeft)}`,
|
|
126
|
+
'--dd-padding-right': unframed ? '0' : `${getSize(paddingRight)}`,
|
|
127
|
+
'--dd-padding-tops': unframed ? '0' : `${getSize(paddingTops)}`,
|
|
128
|
+
'--dd-icon-size': `${iconSize}px`,
|
|
129
|
+
'--dd-color': placeholder && index === 0
|
|
130
|
+
? 'var(--core-text-tertiary)'
|
|
131
|
+
: 'var(--core-text-primary)',
|
|
132
|
+
};
|
|
133
|
+
}, [
|
|
134
|
+
gap,
|
|
135
|
+
height,
|
|
136
|
+
width,
|
|
137
|
+
borderRadius,
|
|
138
|
+
bgColor,
|
|
139
|
+
paddingLeft,
|
|
140
|
+
paddingRight,
|
|
141
|
+
paddingTops,
|
|
142
|
+
unframed,
|
|
143
|
+
placeholder,
|
|
144
|
+
iconSize,
|
|
145
|
+
index,
|
|
146
|
+
getSize,
|
|
147
|
+
]);
|
|
148
|
+
return (jsxs("div", Object.assign({ id: divId, className: `${css.wrapper}${divClass}`, style: Object.assign(Object.assign({}, divStyle), cssVars) }, rest, { children: [jsx("div", { className: `${css.face} ${css[size]}`, children: displayText }), jsx("div", { className: css.chevron, children: jsx(Icon, { name: "chevron down", size: iconSize, strokeColor: color }) }), jsx("select", { className: css.select, defaultValue: index, ref: ref, onFocus: handleFocus, onMouseDown: handleMouseDown, onChange: handleSelectChange, "aria-label": name, children: renderedOptions })] })));
|
|
149
|
+
});
|
|
150
|
+
DropDown.displayName = 'DropDown';
|
|
151
|
+
|
|
152
|
+
export { DropDown as D };
|