@infomaximum/ui-kit 0.18.2 → 0.20.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/dist/components/BaseSelect/BaseSelect.d.ts +1 -1
- package/dist/components/BaseSelect/BaseSelect.js +21 -12
- package/dist/components/BaseSelect/BaseSelect.tokens.d.ts +1 -0
- package/dist/components/BaseSelect/BaseSelect.tokens.js +1 -0
- package/dist/components/BaseSelect/BaseSelect.types.d.ts +5 -2
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.d.ts +1 -1
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.js +6 -6
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.styles.d.ts +1 -1
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.types.d.ts +1 -0
- package/dist/components/BaseSelect/hooks/useDefaultCurrentValue.js +2 -1
- package/dist/components/BaseTooltip/BaseTooltip.js +37 -46
- package/dist/components/BaseTooltip/BaseTooltip.styles.d.ts +5 -5
- package/dist/components/BaseTooltip/BaseTooltip.types.d.ts +1 -1
- package/dist/components/BaseTooltip/BaseTooltip.utils.d.ts +1 -3
- package/dist/components/BaseTooltip/BaseTooltip.utils.js +2 -32
- package/dist/components/BaseTooltip/hooks/useCustomFloating.d.ts +2 -1
- package/dist/components/BaseTooltip/hooks/useCustomFloating.js +9 -7
- package/dist/components/BaseTooltip/hooks/useShowTooltipController.d.ts +1 -2
- package/dist/components/BaseTooltip/hooks/useShowTooltipController.js +42 -57
- package/dist/components/Collapse/Collapse.js +7 -3
- package/dist/components/Collapse/components/CollapsePanel/CollapsePanel.js +6 -4
- package/dist/components/ConfigProvider/ConfigProvider.js +7 -2
- package/dist/components/ConfigProvider/ConfigProvider.types.d.ts +1 -0
- package/dist/components/ConfigProvider/ConfigProvider.utils.d.ts +2 -0
- package/dist/components/ConfigProvider/ConfigProvider.utils.js +17 -0
- package/dist/components/ConfigProvider/contexts/ConfigContext.types.d.ts +8 -0
- package/dist/components/ConfigProvider/contexts/index.d.ts +1 -1
- package/dist/components/ConfigProvider/hooks/useComponentTokens/index.d.ts +1 -0
- package/dist/components/ConfigProvider/hooks/useComponentTokens/useComponentTokens.d.ts +2 -0
- package/dist/components/ConfigProvider/hooks/useComponentTokens/useComponentTokens.js +18 -0
- package/dist/components/ConfigProvider/hooks/useComponentTokens/useComponentTokens.types.d.ts +1 -0
- package/dist/components/ConfigProvider/hooks/useConfig/useConfig.d.ts +2 -3
- package/dist/components/ConfigProvider/hooks/useConfig/useConfig.js +1 -1
- package/dist/components/ConfigProvider/hooks/useConfig/useConfig.types.d.ts +2 -0
- package/dist/components/ConfigProvider/index.d.ts +2 -1
- package/dist/components/Dropdown/Dropdown.types.d.ts +1 -0
- package/dist/components/Dropdown/components/SubMenu/SubMenu.js +7 -3
- package/dist/components/InternalPicker/styles/DatePanel.styles.d.ts +596 -596
- package/dist/components/InternalPicker/styles/Popup.styles.d.ts +593 -593
- package/dist/components/NewDropdown/NewDropdown.d.ts +2 -0
- package/dist/components/NewDropdown/NewDropdown.js +180 -0
- package/dist/components/NewDropdown/NewDropdown.styles.d.ts +10 -0
- package/dist/components/NewDropdown/NewDropdown.styles.js +11 -0
- package/dist/components/NewDropdown/NewDropdown.tokens.d.ts +18 -0
- package/dist/components/NewDropdown/NewDropdown.tokens.js +14 -0
- package/dist/components/NewDropdown/NewDropdown.types.d.ts +132 -0
- package/dist/components/NewDropdown/NewDropdown.utils.d.ts +26 -0
- package/dist/components/NewDropdown/NewDropdown.utils.js +55 -0
- package/dist/components/NewDropdown/components/Divider/Divider.d.ts +2 -0
- package/dist/components/NewDropdown/components/Divider/Divider.js +21 -0
- package/dist/components/NewDropdown/components/Divider/Divider.styles.d.ts +10 -0
- package/dist/components/NewDropdown/components/Divider/Divider.styles.js +12 -0
- package/dist/components/NewDropdown/components/Divider/index.d.ts +1 -0
- package/dist/components/NewDropdown/components/GroupItem/GroupItem.d.ts +3 -0
- package/dist/components/NewDropdown/components/GroupItem/GroupItem.js +33 -0
- package/dist/components/NewDropdown/components/GroupItem/GroupItem.styles.d.ts +29 -0
- package/dist/components/NewDropdown/components/GroupItem/GroupItem.styles.js +31 -0
- package/dist/components/NewDropdown/components/GroupItem/GroupItem.types.d.ts +5 -0
- package/dist/components/NewDropdown/components/GroupItem/index.d.ts +1 -0
- package/dist/components/NewDropdown/components/Menu/Menu.d.ts +3 -0
- package/dist/components/NewDropdown/components/Menu/Menu.js +33 -0
- package/dist/components/NewDropdown/components/Menu/Menu.styles.d.ts +2 -0
- package/dist/components/NewDropdown/components/Menu/Menu.styles.js +8 -0
- package/dist/components/NewDropdown/components/Menu/Menu.types.d.ts +11 -0
- package/dist/components/NewDropdown/components/Menu/index.d.ts +1 -0
- package/dist/components/NewDropdown/components/MenuItem/MenuItem.d.ts +3 -0
- package/dist/components/NewDropdown/components/MenuItem/MenuItem.js +75 -0
- package/dist/components/NewDropdown/components/MenuItem/MenuItem.styles.d.ts +42 -0
- package/dist/components/NewDropdown/components/MenuItem/MenuItem.styles.js +67 -0
- package/dist/components/NewDropdown/components/MenuItem/MenuItem.types.d.ts +5 -0
- package/dist/components/NewDropdown/components/MenuItem/index.d.ts +1 -0
- package/dist/components/NewDropdown/components/SubMenuItem/SubMenuItem.d.ts +3 -0
- package/dist/components/NewDropdown/components/SubMenuItem/SubMenuItem.js +170 -0
- package/dist/components/NewDropdown/components/SubMenuItem/SubMenuItem.styles.d.ts +13 -0
- package/dist/components/NewDropdown/components/SubMenuItem/SubMenuItem.styles.js +15 -0
- package/dist/components/NewDropdown/components/SubMenuItem/SubMenuItem.types.d.ts +5 -0
- package/dist/components/NewDropdown/components/SubMenuItem/index.d.ts +1 -0
- package/dist/components/NewDropdown/contexts/NewDropdownContext.d.ts +9 -0
- package/dist/components/NewDropdown/contexts/NewDropdownContext.js +8 -0
- package/dist/components/NewDropdown/contexts/NewDropdownNavigationContext.d.ts +11 -0
- package/dist/components/NewDropdown/contexts/NewDropdownNavigationContext.js +8 -0
- package/dist/components/NewDropdown/hooks/useContextMenu/index.d.ts +2 -0
- package/dist/components/NewDropdown/hooks/useContextMenu/useContextMenu.d.ts +9 -0
- package/dist/components/NewDropdown/hooks/useContextMenu/useContextMenu.js +38 -0
- package/dist/components/NewDropdown/hooks/useContextMenu/useContextMenu.types.d.ts +7 -0
- package/dist/components/NewDropdown/hooks/useNewDropdownTokens/index.d.ts +1 -0
- package/dist/components/NewDropdown/hooks/useNewDropdownTokens/useNewDropdownTokens.d.ts +7 -0
- package/dist/components/NewDropdown/hooks/useNewDropdownTokens/useNewDropdownTokens.js +14 -0
- package/dist/components/NewDropdown/hooks/useNewDropdownTokens/useNewDropdownTokens.types.d.ts +6 -0
- package/dist/components/NewDropdown/index.d.ts +2 -0
- package/dist/components/Segmented/Segmented.js +1 -1
- package/dist/components/Select/Select.d.ts +9 -1
- package/dist/components/Select/Select.js +53 -28
- package/dist/components/Select/Select.types.d.ts +5 -1
- package/dist/components/Select/Select.utils.d.ts +10 -1
- package/dist/components/Select/Select.utils.js +110 -7
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.d.ts +5 -0
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.js +68 -0
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.styles.d.ts +28 -0
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.styles.js +34 -0
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.types.d.ts +21 -0
- package/dist/components/Select/components/SelectGroupOption/SelectGroupOption.types.js +7 -0
- package/dist/components/Select/components/SelectOption/SelectOption.d.ts +3 -2
- package/dist/components/Select/components/SelectOption/SelectOption.js +25 -15
- package/dist/components/Select/components/SelectOption/SelectOption.styles.d.ts +16 -2
- package/dist/components/Select/components/SelectOption/SelectOption.styles.js +18 -2
- package/dist/components/Select/components/SelectOption/SelectOption.types.d.ts +5 -0
- package/dist/components/Select/contexts/DepthContext.d.ts +3 -0
- package/dist/components/Select/contexts/DepthContext.js +9 -0
- package/dist/components/Select/contexts/SelectRenderContext.d.ts +11 -0
- package/dist/components/Select/contexts/SelectRenderContext.js +7 -0
- package/dist/components/Select/forStories/dataForExamples.d.ts +65 -3
- package/dist/components/Select/hooks/useElementSizesController.d.ts +5 -0
- package/dist/components/Select/hooks/useElementSizesController.js +17 -0
- package/dist/components/Select/hooks/useKeyControl.d.ts +4 -4
- package/dist/components/Select/hooks/useKeyControl.js +15 -10
- package/dist/components/Slider/Slider.adapters.d.ts +3 -0
- package/dist/components/Slider/Slider.adapters.js +53 -0
- package/dist/components/Slider/Slider.d.ts +2 -0
- package/dist/components/Slider/Slider.js +13 -0
- package/dist/components/Slider/Slider.styles.d.ts +8 -0
- package/dist/components/Slider/Slider.styles.js +31 -0
- package/dist/components/Slider/Slider.tokens.d.ts +21 -0
- package/dist/components/Slider/Slider.tokens.js +17 -0
- package/dist/components/Slider/Slider.types.d.ts +54 -0
- package/dist/components/Slider/Slider.utils.d.ts +19 -0
- package/dist/components/Slider/Slider.utils.js +62 -0
- package/dist/components/Slider/components/SliderHandle/SliderHandle.d.ts +2 -0
- package/dist/components/Slider/components/SliderHandle/SliderHandle.js +40 -0
- package/dist/components/Slider/components/SliderHandle/SliderHandle.styles.d.ts +10 -0
- package/dist/components/Slider/components/SliderHandle/SliderHandle.styles.js +36 -0
- package/dist/components/Slider/components/SliderHandle/SliderHandle.types.d.ts +16 -0
- package/dist/components/Slider/components/SliderHandle/index.d.ts +1 -0
- package/dist/components/Slider/components/SliderHandleTooltip/SliderHandleTooltip.d.ts +3 -0
- package/dist/components/Slider/components/SliderHandleTooltip/SliderHandleTooltip.js +22 -0
- package/dist/components/Slider/components/SliderHandleTooltip/SliderHandleTooltip.styles.d.ts +7 -0
- package/dist/components/Slider/components/SliderHandleTooltip/SliderHandleTooltip.styles.js +10 -0
- package/dist/components/Slider/components/SliderHandleTooltip/SliderHandleTooltip.types.d.ts +9 -0
- package/dist/components/Slider/components/SliderHandleTooltip/index.d.ts +1 -0
- package/dist/components/Slider/components/SliderInternal/SliderInternal.d.ts +2 -0
- package/dist/components/Slider/components/SliderInternal/SliderInternal.js +121 -0
- package/dist/components/Slider/components/SliderInternal/SliderInternal.types.d.ts +24 -0
- package/dist/components/Slider/components/SliderInternal/SliderInternal.types.js +4 -0
- package/dist/components/Slider/components/SliderInternal/index.d.ts +1 -0
- package/dist/components/Slider/components/SliderRail/SliderRail.d.ts +3 -0
- package/dist/components/Slider/components/SliderRail/SliderRail.js +23 -0
- package/dist/components/Slider/components/SliderRail/SliderRail.styles.d.ts +8 -0
- package/dist/components/Slider/components/SliderRail/SliderRail.styles.js +15 -0
- package/dist/components/Slider/components/SliderRail/SliderRail.types.d.ts +4 -0
- package/dist/components/Slider/components/SliderRail/index.d.ts +1 -0
- package/dist/components/Slider/components/SliderTrack/SliderTrack.d.ts +3 -0
- package/dist/components/Slider/components/SliderTrack/SliderTrack.js +29 -0
- package/dist/components/Slider/components/SliderTrack/SliderTrack.styles.d.ts +11 -0
- package/dist/components/Slider/components/SliderTrack/SliderTrack.styles.js +34 -0
- package/dist/components/Slider/components/SliderTrack/SliderTrack.types.d.ts +7 -0
- package/dist/components/Slider/components/SliderTrack/index.d.ts +1 -0
- package/dist/components/Slider/hooks/useSliderDrag/index.d.ts +1 -0
- package/dist/components/Slider/hooks/useSliderDrag/useSliderDrag.d.ts +2 -0
- package/dist/components/Slider/hooks/useSliderDrag/useSliderDrag.js +148 -0
- package/dist/components/Slider/hooks/useSliderDrag/useSliderDrag.types.d.ts +30 -0
- package/dist/components/Slider/hooks/useSliderDrag/useSliderDrag.utils.d.ts +17 -0
- package/dist/components/Slider/hooks/useSliderDrag/useSliderDrag.utils.js +49 -0
- package/dist/components/Slider/hooks/useSliderInteractionState/index.d.ts +1 -0
- package/dist/components/Slider/hooks/useSliderInteractionState/useSliderInteractionState.d.ts +2 -0
- package/dist/components/Slider/hooks/useSliderInteractionState/useSliderInteractionState.js +43 -0
- package/dist/components/Slider/hooks/useSliderInteractionState/useSliderInteractionState.types.d.ts +16 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/index.d.ts +1 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/useSliderKeyboard.d.ts +2 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/useSliderKeyboard.js +94 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/useSliderKeyboard.types.d.ts +17 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/useSliderKeyboard.utils.d.ts +1 -0
- package/dist/components/Slider/hooks/useSliderKeyboard/useSliderKeyboard.utils.js +16 -0
- package/dist/components/Slider/index.d.ts +3 -0
- package/dist/components/Table/features/tableRowSelection/components/CheckboxCellContentWrapper/CheckboxCellContentWrapper.utils.js +3 -1
- package/dist/components/Table/features/tableRowSelection/hooks/useTableRowSelection/useTableRowSelection.js +1 -1
- package/dist/components/Table/hooks/useTableVisualParamsChange/utils.d.ts +1 -1
- package/dist/components/Tabs/Tabs.utils.d.ts +2 -2
- package/dist/components/Tabs/Tabs.utils.js +11 -24
- package/dist/components/Tabs/components/TabBar/TabBar.js +8 -7
- package/dist/components/Tabs/components/TabBar/TabBar.styles.d.ts +1 -1
- package/dist/components/Tabs/components/TabItem/TabItem.js +7 -5
- package/dist/components/Tabs/components/TabItem/TabItem.styles.d.ts +2 -2
- package/dist/components/Tabs/components/TabItem/TabItem.types.d.ts +1 -0
- package/dist/components/Tabs/hooks/useMoreTabsController.d.ts +2 -1
- package/dist/components/Tabs/hooks/useMoreTabsController.js +10 -6
- package/dist/components/TreeSelect/TreeSelect.js +8 -3
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.types.d.ts +1 -0
- package/dist/components/TreeSelect/hooks/useKeyControl.d.ts +2 -2
- package/dist/components/TreeSelect/hooks/useKeyControl.js +9 -8
- package/dist/hooks/useInputModeDetector/index.d.ts +2 -0
- package/dist/hooks/useInputModeDetector/useInputModeDetector.d.ts +13 -0
- package/dist/hooks/useInputModeDetector/useInputModeDetector.js +50 -0
- package/dist/hooks/useInputModeDetector/useInputModeDetector.types.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/types.d.ts +9 -1
- package/package.json +11 -9
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const getTrackStyle = ({
|
|
2
|
+
tokens,
|
|
3
|
+
startPercent,
|
|
4
|
+
endPercent,
|
|
5
|
+
vertical,
|
|
6
|
+
disabled,
|
|
7
|
+
active
|
|
8
|
+
}) => (theme) => {
|
|
9
|
+
const color = disabled ? tokens.sliderDisabled : active ? tokens.sliderHover : tokens.sliderDefault;
|
|
10
|
+
const base = {
|
|
11
|
+
position: "absolute",
|
|
12
|
+
borderRadius: tokens.sliderBorderRadius,
|
|
13
|
+
background: color
|
|
14
|
+
};
|
|
15
|
+
const size = `${endPercent - startPercent}%`;
|
|
16
|
+
return vertical ? {
|
|
17
|
+
...base,
|
|
18
|
+
width: theme.x1,
|
|
19
|
+
height: size,
|
|
20
|
+
bottom: `${startPercent}%`,
|
|
21
|
+
left: "50%",
|
|
22
|
+
transform: "translateX(-50%)"
|
|
23
|
+
} : {
|
|
24
|
+
...base,
|
|
25
|
+
height: theme.x1,
|
|
26
|
+
width: size,
|
|
27
|
+
left: `${startPercent}%`,
|
|
28
|
+
top: "50%",
|
|
29
|
+
transform: "translateY(-50%)"
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
getTrackStyle
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SliderTrack } from './SliderTrack';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSliderDrag } from './useSliderDrag';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { useState, useRef } from "react";
|
|
2
|
+
import { useEvent } from "../../../../hooks/useEvent/useEvent.js";
|
|
3
|
+
import { validateStep, percentToValue } from "../../Slider.utils.js";
|
|
4
|
+
import { isRangeValues } from "../../components/SliderInternal/SliderInternal.types.js";
|
|
5
|
+
import { parseHandleIndex, getPercentFromPointer, computeRangeNext, getHoveringHandleIndex } from "./useSliderDrag.utils.js";
|
|
6
|
+
function useSliderDrag(params) {
|
|
7
|
+
const {
|
|
8
|
+
containerRef,
|
|
9
|
+
min,
|
|
10
|
+
max,
|
|
11
|
+
step,
|
|
12
|
+
vertical,
|
|
13
|
+
disabled
|
|
14
|
+
} = params;
|
|
15
|
+
const validStep = validateStep(step) ?? 1;
|
|
16
|
+
const [draggingValues, setDraggingValues] = useState(null);
|
|
17
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
18
|
+
const dragStateRef = useRef(null);
|
|
19
|
+
const applyAndEmit = (rawValue, activeIdx) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (isRangeValues(params.value)) {
|
|
22
|
+
const current = params.value;
|
|
23
|
+
const next2 = computeRangeNext({
|
|
24
|
+
rawValue,
|
|
25
|
+
activeIdx,
|
|
26
|
+
current,
|
|
27
|
+
min,
|
|
28
|
+
max,
|
|
29
|
+
step
|
|
30
|
+
});
|
|
31
|
+
setDraggingValues(next2);
|
|
32
|
+
if (next2[0] !== current[0] || next2[1] !== current[1]) {
|
|
33
|
+
(_a = params.onChange) == null ? void 0 : _a.call(params, next2);
|
|
34
|
+
}
|
|
35
|
+
return next2;
|
|
36
|
+
}
|
|
37
|
+
const next = [rawValue];
|
|
38
|
+
setDraggingValues(next);
|
|
39
|
+
if (next[0] !== params.value[0]) {
|
|
40
|
+
(_b = params.onChange) == null ? void 0 : _b.call(params, next);
|
|
41
|
+
}
|
|
42
|
+
return next;
|
|
43
|
+
};
|
|
44
|
+
const onPointerDown = useEvent((event) => {
|
|
45
|
+
var _a;
|
|
46
|
+
if (disabled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const container = containerRef.current;
|
|
50
|
+
if (!container) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (dragStateRef.current !== null) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const target = event.target;
|
|
57
|
+
if (!(target instanceof HTMLElement)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const handleEl = target.closest("[data-handle-index]");
|
|
61
|
+
const isHandle = handleEl !== null && container.contains(handleEl);
|
|
62
|
+
const indexHint = isHandle ? parseHandleIndex(handleEl == null ? void 0 : handleEl.dataset.handleIndex) : null;
|
|
63
|
+
const rect = container.getBoundingClientRect();
|
|
64
|
+
const percent = getPercentFromPointer(rect, event.clientX, event.clientY, vertical);
|
|
65
|
+
const newValue = percentToValue(percent, min, max, validStep);
|
|
66
|
+
let activeIdx;
|
|
67
|
+
if (indexHint !== null) {
|
|
68
|
+
activeIdx = indexHint;
|
|
69
|
+
} else if (isRangeValues(params.value)) {
|
|
70
|
+
const r = params.value;
|
|
71
|
+
activeIdx = Math.abs(newValue - r[0]) <= Math.abs(newValue - r[1]) ? 0 : 1;
|
|
72
|
+
} else {
|
|
73
|
+
activeIdx = 0;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
container.setPointerCapture(event.pointerId);
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
dragStateRef.current = {
|
|
80
|
+
pointerId: event.pointerId,
|
|
81
|
+
rect,
|
|
82
|
+
activeIndex: activeIdx
|
|
83
|
+
};
|
|
84
|
+
setActiveIndex(activeIdx);
|
|
85
|
+
if (indexHint !== null) {
|
|
86
|
+
setDraggingValues([...params.value]);
|
|
87
|
+
} else {
|
|
88
|
+
applyAndEmit(newValue, activeIdx);
|
|
89
|
+
}
|
|
90
|
+
(_a = params.onDragStart) == null ? void 0 : _a.call(params, isHandle ? "handle" : "rail");
|
|
91
|
+
});
|
|
92
|
+
const onPointerMove = useEvent((event) => {
|
|
93
|
+
const state = dragStateRef.current;
|
|
94
|
+
if (!state || state.pointerId !== event.pointerId) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const percent = getPercentFromPointer(state.rect, event.clientX, event.clientY, vertical);
|
|
98
|
+
const rawValue = percentToValue(percent, min, max, validStep);
|
|
99
|
+
applyAndEmit(rawValue, state.activeIndex);
|
|
100
|
+
});
|
|
101
|
+
const finishDrag = (event) => {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
const state = dragStateRef.current;
|
|
104
|
+
if (!state || state.pointerId !== event.pointerId) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const container = containerRef.current;
|
|
108
|
+
try {
|
|
109
|
+
container == null ? void 0 : container.releasePointerCapture(state.pointerId);
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
const percent = getPercentFromPointer(state.rect, event.clientX, event.clientY, vertical);
|
|
113
|
+
const rawValue = percentToValue(percent, min, max, validStep);
|
|
114
|
+
const hoveringHandleIndex = getHoveringHandleIndex(container, event.clientX, event.clientY);
|
|
115
|
+
dragStateRef.current = null;
|
|
116
|
+
setDraggingValues(null);
|
|
117
|
+
setActiveIndex(null);
|
|
118
|
+
(_a = params.onDragEnd) == null ? void 0 : _a.call(params, hoveringHandleIndex);
|
|
119
|
+
if (isRangeValues(params.value)) {
|
|
120
|
+
const next = computeRangeNext({
|
|
121
|
+
rawValue,
|
|
122
|
+
activeIdx: state.activeIndex,
|
|
123
|
+
current: params.value,
|
|
124
|
+
min,
|
|
125
|
+
max,
|
|
126
|
+
step
|
|
127
|
+
});
|
|
128
|
+
(_b = params.onChangeComplete) == null ? void 0 : _b.call(params, next);
|
|
129
|
+
} else {
|
|
130
|
+
(_c = params.onChangeComplete) == null ? void 0 : _c.call(params, [rawValue]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const onPointerUp = useEvent(finishDrag);
|
|
134
|
+
const onPointerCancel = useEvent(finishDrag);
|
|
135
|
+
return {
|
|
136
|
+
draggingValues,
|
|
137
|
+
activeIndex,
|
|
138
|
+
dragHandlers: {
|
|
139
|
+
onPointerDown,
|
|
140
|
+
onPointerMove,
|
|
141
|
+
onPointerUp,
|
|
142
|
+
onPointerCancel
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
useSliderDrag
|
|
148
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { Indices, RequiredDivHandlers } from '../../../../types';
|
|
3
|
+
import { SliderValues } from '../../components/SliderInternal/SliderInternal.types';
|
|
4
|
+
export type HandleIndex = Indices<SliderValues>;
|
|
5
|
+
export interface UseSliderDragParams {
|
|
6
|
+
containerRef: RefObject<HTMLDivElement | null>;
|
|
7
|
+
min: number;
|
|
8
|
+
max: number;
|
|
9
|
+
step: number | null;
|
|
10
|
+
vertical: boolean;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
range: boolean;
|
|
13
|
+
value: SliderValues;
|
|
14
|
+
onChange?: (value: SliderValues) => void;
|
|
15
|
+
onChangeComplete?: (value: SliderValues) => void;
|
|
16
|
+
onDragStart?: (source: "handle" | "rail") => void;
|
|
17
|
+
/** Вызывается в pointerup. Содержит индекс ручки, над которой остался курсор (или null). */
|
|
18
|
+
onDragEnd?: (hoveringHandleIndex: HandleIndex | null) => void;
|
|
19
|
+
}
|
|
20
|
+
export type SliderDragHandlers = RequiredDivHandlers<"onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerCancel">;
|
|
21
|
+
export interface UseSliderDragResult {
|
|
22
|
+
draggingValues: SliderValues | null;
|
|
23
|
+
activeIndex: HandleIndex | null;
|
|
24
|
+
dragHandlers: SliderDragHandlers;
|
|
25
|
+
}
|
|
26
|
+
export interface DragState {
|
|
27
|
+
pointerId: number;
|
|
28
|
+
rect: DOMRect;
|
|
29
|
+
activeIndex: HandleIndex;
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandleIndex } from './useSliderDrag.types';
|
|
2
|
+
export declare const getPercentFromPointer: (rect: DOMRect, clientX: number, clientY: number, vertical: boolean) => number;
|
|
3
|
+
export declare const parseHandleIndex: (raw: string | undefined) => HandleIndex | null;
|
|
4
|
+
export declare const computeRangeNext: ({ rawValue, activeIdx, current, min, max, step, }: {
|
|
5
|
+
rawValue: number;
|
|
6
|
+
activeIdx: HandleIndex;
|
|
7
|
+
current: [number, number];
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
step: number | null;
|
|
11
|
+
}) => [number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Возвращает индекс ручки, над которой сейчас pointer (по координатам), или null.
|
|
14
|
+
* Используется в `finishDrag`: с capture event.target — это контейнер, поэтому
|
|
15
|
+
* для определения hover'а ищем по координатам через `elementFromPoint`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getHoveringHandleIndex: (container: HTMLDivElement | null, clientX: number, clientY: number) => HandleIndex | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { clamp } from "lodash-es";
|
|
2
|
+
import { clampToStepRange } from "../../Slider.utils.js";
|
|
3
|
+
const getPercentFromPointer = (rect, clientX, clientY, vertical) => {
|
|
4
|
+
const rawPercent = vertical ? (rect.bottom - clientY) / rect.height * 100 : (clientX - rect.left) / rect.width * 100;
|
|
5
|
+
return clamp(rawPercent, 0, 100);
|
|
6
|
+
};
|
|
7
|
+
const parseHandleIndex = (raw) => {
|
|
8
|
+
if (raw === "0") {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
if (raw === "1") {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
};
|
|
16
|
+
const computeRangeNext = ({
|
|
17
|
+
rawValue,
|
|
18
|
+
activeIdx,
|
|
19
|
+
current,
|
|
20
|
+
min,
|
|
21
|
+
max,
|
|
22
|
+
step
|
|
23
|
+
}) => {
|
|
24
|
+
const otherValue = current[1 - activeIdx];
|
|
25
|
+
const clamped = clampToStepRange({
|
|
26
|
+
nextValue: rawValue,
|
|
27
|
+
activeIndex: activeIdx,
|
|
28
|
+
otherValue,
|
|
29
|
+
min,
|
|
30
|
+
max,
|
|
31
|
+
step
|
|
32
|
+
});
|
|
33
|
+
return activeIdx === 0 ? [clamped, current[1]] : [current[0], clamped];
|
|
34
|
+
};
|
|
35
|
+
const getHoveringHandleIndex = (container, clientX, clientY) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const elementUnderPointer = (_a = document.elementFromPoint) == null ? void 0 : _a.call(document, clientX, clientY);
|
|
38
|
+
const handleEl = elementUnderPointer instanceof Element ? elementUnderPointer.closest("[data-handle-index]") : null;
|
|
39
|
+
if (!handleEl || !(container == null ? void 0 : container.contains(handleEl))) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return parseHandleIndex(handleEl.dataset.handleIndex);
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
computeRangeNext,
|
|
46
|
+
getHoveringHandleIndex,
|
|
47
|
+
getPercentFromPointer,
|
|
48
|
+
parseHandleIndex
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSliderInteractionState } from './useSliderInteractionState';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
function useSliderInteractionState() {
|
|
3
|
+
const [isRootHovered, setIsRootHovered] = useState(false);
|
|
4
|
+
const [hoverIndex, setHoverIndex] = useState(null);
|
|
5
|
+
const [focusIndex, setFocusIndex] = useState(null);
|
|
6
|
+
const [keyboardFocusIndex, setKeyboardFocusIndex] = useState(null);
|
|
7
|
+
const rootHandlers = {
|
|
8
|
+
onPointerEnter: () => setIsRootHovered(true),
|
|
9
|
+
onPointerLeave: () => setIsRootHovered(false)
|
|
10
|
+
};
|
|
11
|
+
const getHandleHandlers = (index) => ({
|
|
12
|
+
onPointerEnter: () => setHoverIndex(index),
|
|
13
|
+
onPointerLeave: () => setHoverIndex(null),
|
|
14
|
+
onFocus: (event) => {
|
|
15
|
+
setFocusIndex(index);
|
|
16
|
+
if (event.currentTarget.matches(":focus-visible")) {
|
|
17
|
+
setKeyboardFocusIndex(index);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
onBlur: () => {
|
|
21
|
+
setFocusIndex(null);
|
|
22
|
+
setKeyboardFocusIndex(null);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const resetKeyboardFocus = () => {
|
|
26
|
+
setKeyboardFocusIndex(null);
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
state: {
|
|
30
|
+
isRootHovered,
|
|
31
|
+
hoverIndex,
|
|
32
|
+
focusIndex,
|
|
33
|
+
keyboardFocusIndex
|
|
34
|
+
},
|
|
35
|
+
rootHandlers,
|
|
36
|
+
getHandleHandlers,
|
|
37
|
+
resetKeyboardFocus,
|
|
38
|
+
setHoverIndex
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
useSliderInteractionState
|
|
43
|
+
};
|
package/dist/components/Slider/hooks/useSliderInteractionState/useSliderInteractionState.types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RequiredDivHandlers } from '../../../../types';
|
|
2
|
+
export interface SliderInteractionState {
|
|
3
|
+
isRootHovered: boolean;
|
|
4
|
+
hoverIndex: number | null;
|
|
5
|
+
focusIndex: number | null;
|
|
6
|
+
keyboardFocusIndex: number | null;
|
|
7
|
+
}
|
|
8
|
+
export type SliderInteractionRootHandlers = RequiredDivHandlers<"onPointerEnter" | "onPointerLeave">;
|
|
9
|
+
export type SliderInteractionHandleHandlers = RequiredDivHandlers<"onPointerEnter" | "onPointerLeave" | "onFocus" | "onBlur">;
|
|
10
|
+
export interface UseSliderInteractionStateResult {
|
|
11
|
+
state: SliderInteractionState;
|
|
12
|
+
rootHandlers: SliderInteractionRootHandlers;
|
|
13
|
+
getHandleHandlers: (index: number) => SliderInteractionHandleHandlers;
|
|
14
|
+
resetKeyboardFocus: () => void;
|
|
15
|
+
setHoverIndex: (index: number | null) => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSliderKeyboard } from './useSliderKeyboard';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { useEvent } from "../../../../hooks/useEvent/useEvent.js";
|
|
3
|
+
import { validateStep, clampToStep, clampToStepRange } from "../../Slider.utils.js";
|
|
4
|
+
import { isRangeValues } from "../../components/SliderInternal/SliderInternal.types.js";
|
|
5
|
+
import { isRelevantKey } from "./useSliderKeyboard.utils.js";
|
|
6
|
+
function useSliderKeyboard(params) {
|
|
7
|
+
const {
|
|
8
|
+
min,
|
|
9
|
+
max,
|
|
10
|
+
step,
|
|
11
|
+
disabled
|
|
12
|
+
} = params;
|
|
13
|
+
const lastEmittedRef = useRef(null);
|
|
14
|
+
const handleKeyDown = useEvent((event) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
if (disabled) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
key
|
|
21
|
+
} = event;
|
|
22
|
+
if (!isRelevantKey(key)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
const validStep = validateStep(step) ?? 1;
|
|
27
|
+
const delta = key === "ArrowRight" || key === "ArrowUp" ? validStep : -validStep;
|
|
28
|
+
if (isRangeValues(params.value)) {
|
|
29
|
+
const currentRange = params.value;
|
|
30
|
+
const {
|
|
31
|
+
activeIndex
|
|
32
|
+
} = params;
|
|
33
|
+
const currentVal = currentRange[activeIndex];
|
|
34
|
+
const otherValue = currentRange[1 - activeIndex];
|
|
35
|
+
let nextActive;
|
|
36
|
+
if (key === "Home") {
|
|
37
|
+
nextActive = activeIndex === 0 ? min : otherValue + validStep;
|
|
38
|
+
} else if (key === "End") {
|
|
39
|
+
nextActive = activeIndex === 0 ? otherValue - validStep : max;
|
|
40
|
+
} else {
|
|
41
|
+
nextActive = clampToStep(currentVal + delta, min, max, validStep);
|
|
42
|
+
}
|
|
43
|
+
const clamped = clampToStepRange({
|
|
44
|
+
nextValue: nextActive,
|
|
45
|
+
activeIndex,
|
|
46
|
+
otherValue,
|
|
47
|
+
min,
|
|
48
|
+
max,
|
|
49
|
+
step
|
|
50
|
+
});
|
|
51
|
+
const next = activeIndex === 0 ? [clamped, currentRange[1]] : [currentRange[0], clamped];
|
|
52
|
+
lastEmittedRef.current = next;
|
|
53
|
+
(_a = params.onChange) == null ? void 0 : _a.call(params, next);
|
|
54
|
+
} else {
|
|
55
|
+
const currentVal = params.value[0];
|
|
56
|
+
let nextVal;
|
|
57
|
+
if (key === "Home") {
|
|
58
|
+
nextVal = min;
|
|
59
|
+
} else if (key === "End") {
|
|
60
|
+
nextVal = max;
|
|
61
|
+
} else {
|
|
62
|
+
nextVal = clampToStep(currentVal + delta, min, max, validStep);
|
|
63
|
+
}
|
|
64
|
+
const next = [nextVal];
|
|
65
|
+
lastEmittedRef.current = next;
|
|
66
|
+
(_b = params.onChange) == null ? void 0 : _b.call(params, next);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const handleKeyUp = useEvent((event) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (disabled) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!isRelevantKey(event.key)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const last = lastEmittedRef.current;
|
|
78
|
+
lastEmittedRef.current = null;
|
|
79
|
+
if (isRangeValues(params.value)) {
|
|
80
|
+
const final = last && last.length === 2 ? last : params.value;
|
|
81
|
+
(_a = params.onChangeComplete) == null ? void 0 : _a.call(params, final);
|
|
82
|
+
} else {
|
|
83
|
+
const final = last && last.length === 1 ? last : params.value;
|
|
84
|
+
(_b = params.onChangeComplete) == null ? void 0 : _b.call(params, final);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
onKeyDown: handleKeyDown,
|
|
89
|
+
onKeyUp: handleKeyUp
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
useSliderKeyboard
|
|
94
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { SliderValues } from '../../components/SliderInternal/SliderInternal.types';
|
|
3
|
+
import { HandleIndex } from '../useSliderDrag/useSliderDrag.types';
|
|
4
|
+
export interface UseSliderKeyboardParams {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
step: number | null;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
range: boolean;
|
|
10
|
+
value: SliderValues;
|
|
11
|
+
/** Какая ручка обрабатывает keyboard-события (для single всегда 0). */
|
|
12
|
+
activeIndex: HandleIndex;
|
|
13
|
+
onChange?: (value: SliderValues) => void;
|
|
14
|
+
onChangeComplete?: (value: SliderValues) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface UseSliderKeyboardResult extends Required<Pick<HTMLAttributes<HTMLElement>, "onKeyDown" | "onKeyUp">> {
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isRelevantKey: (key: string) => boolean;
|
|
@@ -2,9 +2,9 @@ import { useMemo, useCallback } from "react";
|
|
|
2
2
|
import { useEmitter } from "../../../typedEventBus/hooks.js";
|
|
3
3
|
import { useEvent } from "../../../../../../hooks/useEvent/useEvent.js";
|
|
4
4
|
import { compact } from "lodash-es";
|
|
5
|
+
import { useControlledState } from "../../../../../../hooks/useControlledState/useControlledState.js";
|
|
5
6
|
import { useMultipleSelect } from "../useMultipleSelect/useMultipleSelect.js";
|
|
6
7
|
import { flattenData } from "./useTableRowSelection.utils.js";
|
|
7
|
-
import { useControlledState } from "../../../../../../hooks/useControlledState/useControlledState.js";
|
|
8
8
|
import { getRowKey } from "../../../../utils/getRowKey/getRowKey.js";
|
|
9
9
|
import { useFirstMountLayoutEffect } from "../../../../../../hooks/useFirstMountLayoutEffect/useFirstMountLayoutEffect.js";
|
|
10
10
|
const useTableRowSelection = (options) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const forceScroll: (scrollLeft: number, target: HTMLElement | null) => void;
|
|
2
2
|
export declare const getHorizontalScrollPositionRange: (el: HTMLElement) => readonly [number, number];
|
|
3
3
|
export declare const getVerticalScrollBarWidth: (el: HTMLElement) => number;
|
|
4
|
-
export declare const pickedScrollTargetProps: ("
|
|
4
|
+
export declare const pickedScrollTargetProps: ("clientWidth" | "clientHeight" | "scrollHeight" | "scrollLeft" | "scrollTop" | "scrollWidth")[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DropdownItemKeyType } from 'components/Dropdown/Dropdown.types';
|
|
2
2
|
import { TabItem } from './components/TabItem/TabItem.types';
|
|
3
3
|
import { TabsRect } from './Tabs.types';
|
|
4
|
+
export declare const intersectionThreshold = 0.95;
|
|
4
5
|
export declare const getTabKeysWithoutOrdering: (items: TabItem[]) => DropdownItemKeyType[];
|
|
5
6
|
export declare const getOrderedTabKeys: (currentOrderedTabKeys: DropdownItemKeyType[], newTabKeys: DropdownItemKeyType[]) => DropdownItemKeyType[];
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const intersectionThreshold = 0.95;
|
|
7
|
+
export declare const getHorizontalIntersectionRatio: (targetRect: Pick<TabsRect, "left" | "right">, rootRect: Pick<TabsRect, "left" | "right">) => number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const intersectionThreshold = 0.95;
|
|
1
2
|
const getTabKeysWithoutOrdering = (items) => items.map((item) => item.key);
|
|
2
3
|
const getOrderedTabKeys = (currentOrderedTabKeys, newTabKeys) => {
|
|
3
4
|
const updatedPrev = currentOrderedTabKeys.reduce((acc, key) => {
|
|
@@ -6,34 +7,20 @@ const getOrderedTabKeys = (currentOrderedTabKeys, newTabKeys) => {
|
|
|
6
7
|
const uniqueKeys = /* @__PURE__ */ new Set([...updatedPrev, ...newTabKeys]);
|
|
7
8
|
return Array.from(uniqueKeys);
|
|
8
9
|
};
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
bottom: rootRect.bottom + rootMargin.bottom,
|
|
18
|
-
left: rootRect.left - rootMargin.left,
|
|
19
|
-
right: rootRect.right + rootMargin.right
|
|
20
|
-
};
|
|
21
|
-
const intersect = {
|
|
22
|
-
top: Math.max(targetRect.top, expandedRootRect.top),
|
|
23
|
-
bottom: Math.min(targetRect.bottom, expandedRootRect.bottom),
|
|
24
|
-
left: Math.max(targetRect.left, expandedRootRect.left),
|
|
25
|
-
right: Math.min(targetRect.right, expandedRootRect.right)
|
|
26
|
-
};
|
|
27
|
-
if (intersect.top >= intersect.bottom || intersect.left >= intersect.right) {
|
|
10
|
+
const getHorizontalIntersectionRatio = (targetRect, rootRect) => {
|
|
11
|
+
const intersectLeft = Math.max(targetRect.left, rootRect.left);
|
|
12
|
+
const intersectRight = Math.min(targetRect.right, rootRect.right);
|
|
13
|
+
if (intersectLeft >= intersectRight) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const targetWidth = targetRect.right - targetRect.left;
|
|
17
|
+
if (targetWidth === 0) {
|
|
28
18
|
return 0;
|
|
29
19
|
}
|
|
30
|
-
|
|
31
|
-
const targetArea = (targetRect.bottom - targetRect.top) * (targetRect.right - targetRect.left);
|
|
32
|
-
return intersectArea / targetArea;
|
|
20
|
+
return (intersectRight - intersectLeft) / targetWidth;
|
|
33
21
|
};
|
|
34
|
-
const intersectionThreshold = 0.95;
|
|
35
22
|
export {
|
|
36
|
-
|
|
23
|
+
getHorizontalIntersectionRatio,
|
|
37
24
|
getOrderedTabKeys,
|
|
38
25
|
getTabKeysWithoutOrdering,
|
|
39
26
|
intersectionThreshold
|