@infomaximum/ui-kit 0.18.1 → 0.19.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/components/SelectOptionList/SelectOptionList.styles.d.ts +1 -1
- package/dist/components/BaseTooltip/BaseTooltip.js +13 -4
- package/dist/components/BaseTooltip/BaseTooltip.styles.d.ts +5 -5
- package/dist/components/Collapse/Collapse.js +6 -2
- 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/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/Tabs/components/TabBar/TabBar.styles.d.ts +1 -1
- package/dist/components/Tabs/components/TabItem/TabItem.styles.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -0
- package/dist/types.d.ts +9 -1
- package/package.json +10 -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;
|
|
@@ -27,7 +27,7 @@ export declare const getTabBarStyle: (size: TabsSizeType, border: boolean, iconO
|
|
|
27
27
|
readonly flex: "1 1 auto";
|
|
28
28
|
readonly zIndex: 1;
|
|
29
29
|
readonly overflowY: "hidden";
|
|
30
|
-
readonly overflowX: "
|
|
30
|
+
readonly overflowX: "hidden" | "scroll";
|
|
31
31
|
readonly scrollbarWidth: "none";
|
|
32
32
|
readonly height: number;
|
|
33
33
|
readonly "::-webkit-scrollbar": {
|
|
@@ -33,7 +33,7 @@ export declare const getTabItemStyle: (iconOnly: boolean, disabled: boolean, sel
|
|
|
33
33
|
childrenWrapper: (theme: Theme) => {
|
|
34
34
|
readonly color: "#262626";
|
|
35
35
|
readonly padding: "12px 0";
|
|
36
|
-
readonly visibility: "
|
|
36
|
+
readonly visibility: "hidden" | "visible";
|
|
37
37
|
readonly position: "absolute" | "relative";
|
|
38
38
|
readonly fontFamily: "Roboto";
|
|
39
39
|
readonly fontSize: 14;
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export { Breadcrumb } from './components/Breadcrumb';
|
|
|
39
39
|
export type { BreadcrumbProps } from './components/Breadcrumb';
|
|
40
40
|
export { Tag } from './components/Tag';
|
|
41
41
|
export type { TagProps, CheckableProps } from './components/Tag';
|
|
42
|
-
export { ConfigProvider, useConfig, type Locale } from './components/ConfigProvider';
|
|
42
|
+
export { ConfigProvider, useConfig, type Locale, type Tokens } from './components/ConfigProvider';
|
|
43
43
|
export type { PickerLocale, RangePickerProps } from './components/InternalPicker';
|
|
44
44
|
export { type FormProps, type FormItemProps, Form } from './components/Form';
|
|
45
45
|
export { type PopconfirmProps, Popconfirm } from './components/Popconfirm';
|
|
@@ -51,4 +51,5 @@ export { ContextIsolator } from './components/ContextIsolator';
|
|
|
51
51
|
export { type SpinProps, Spin } from './components/Spin';
|
|
52
52
|
export { type TableProps, type DefaultRecord, type RenderFn, type Column, type ColumnWithChildren, Table, } from './components/Table';
|
|
53
53
|
export { Collapse, type CollapseProps, type CollapseItemType, type CollapseKey, type CollapseExpandIconProps, } from './components/Collapse';
|
|
54
|
+
export { Slider, type SliderProps, type SingleSliderProps, type RangeSliderProps, type SliderTooltipProps, type SliderStyles, type SliderTokens, } from './components/Slider';
|
|
54
55
|
export * from 'react-intersection-observer/test-utils';
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ import { ContextIsolator } from "./components/ContextIsolator/ContextIsolator.js
|
|
|
40
40
|
import { Spin } from "./components/Spin/Spin.js";
|
|
41
41
|
import { Table } from "./components/Table/Table.js";
|
|
42
42
|
import { Collapse } from "./components/Collapse/Collapse.js";
|
|
43
|
+
import { Slider } from "./components/Slider/Slider.js";
|
|
43
44
|
export {
|
|
44
45
|
Alert,
|
|
45
46
|
Avatar,
|
|
@@ -62,6 +63,7 @@ export {
|
|
|
62
63
|
Radio,
|
|
63
64
|
Segmented,
|
|
64
65
|
Select,
|
|
66
|
+
Slider,
|
|
65
67
|
Spin,
|
|
66
68
|
Switch,
|
|
67
69
|
Table,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { Interpolation } from '@emotion/react';
|
|
2
|
+
import { HTMLAttributes } from 'react';
|
|
2
3
|
import { Theme } from './themes';
|
|
3
4
|
type InterpolationWithTheme = Interpolation<Theme>;
|
|
4
|
-
|
|
5
|
+
type PrimitiveWiden<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T extends symbol ? symbol : T;
|
|
6
|
+
type Widen<T> = {
|
|
7
|
+
[K in keyof T]: PrimitiveWiden<T[K]>;
|
|
8
|
+
};
|
|
9
|
+
type Indices<T extends readonly unknown[]> = T extends readonly unknown[] ? Exclude<Partial<T>["length"], T["length"]> : never;
|
|
10
|
+
type RequiredHandlers<E extends HTMLElement, K extends keyof HTMLAttributes<E> & `on${string}`> = Required<Pick<HTMLAttributes<E>, K>>;
|
|
11
|
+
type RequiredDivHandlers<K extends keyof HTMLAttributes<HTMLDivElement> & `on${string}`> = RequiredHandlers<HTMLDivElement, K>;
|
|
12
|
+
export type { Indices, InterpolationWithTheme, PrimitiveWiden, RequiredDivHandlers, Widen };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infomaximum/ui-kit",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -34,26 +34,26 @@
|
|
|
34
34
|
"update-icons": "node scripts/updateIcons/updateIcons.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@dnd-kit/core": "6.
|
|
38
|
-
"@dnd-kit/sortable": "
|
|
37
|
+
"@dnd-kit/core": "6.3.1",
|
|
38
|
+
"@dnd-kit/sortable": "10.0.0",
|
|
39
39
|
"@dnd-kit/utilities": "^3.2.2",
|
|
40
40
|
"@emotion/react": "^11.0.0",
|
|
41
|
-
"@floating-ui/react": "^0.27.
|
|
42
|
-
"@infomaximum/icons": "^1.
|
|
43
|
-
"@tanstack/react-virtual": "^3.13.
|
|
41
|
+
"@floating-ui/react": "^0.27.19",
|
|
42
|
+
"@infomaximum/icons": "^1.4.0",
|
|
43
|
+
"@tanstack/react-virtual": "^3.13.24",
|
|
44
44
|
"@types/lodash-es": "^4.17.12",
|
|
45
45
|
"classnames": "^2.5.1",
|
|
46
|
-
"lodash-es": "^4.
|
|
46
|
+
"lodash-es": "^4.18.1",
|
|
47
47
|
"rc-picker": "^4.11.3",
|
|
48
48
|
"rc-resize-observer": "^1.4.3",
|
|
49
49
|
"rc-util": "^5.44.4",
|
|
50
50
|
"react": "^18.3.1",
|
|
51
51
|
"react-dom": "^18.3.1",
|
|
52
|
-
"react-intersection-observer": "^
|
|
52
|
+
"react-intersection-observer": "^10.0.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@dnd-kit/core": "^6",
|
|
56
|
-
"@dnd-kit/sortable": "^
|
|
56
|
+
"@dnd-kit/sortable": "^10",
|
|
57
57
|
"@dnd-kit/utilities": "^3",
|
|
58
58
|
"@emotion/react": "^11.0.0",
|
|
59
59
|
"dayjs": "^1.0.0",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"@vitest/coverage-v8": "3.0.4",
|
|
80
80
|
"dayjs": "^1.0.0",
|
|
81
81
|
"eslint": "^9.17.0",
|
|
82
|
+
"eslint-plugin-react": "^7.37.5",
|
|
82
83
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
83
84
|
"eslint-plugin-react-refresh": "^0.4.16",
|
|
84
85
|
"eslint-plugin-storybook": "^0.11.2",
|