@astral/ui 4.106.0 → 4.107.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/components/Autocomplete/Autocomplete.js +2 -3
- package/components/Onboarding/ui/StepStrategy/steps/HighlightStep/styles.d.ts +1 -1
- package/components/Select/Select.js +4 -3
- package/components/Select/useLogic/useLogic.d.ts +11 -2
- package/components/Select/useLogic/useLogic.js +4 -1
- package/components/TagsList/PopoverTags/PopoverTags.d.ts +7 -0
- package/components/TagsList/PopoverTags/PopoverTags.js +8 -0
- package/components/TagsList/PopoverTags/index.d.ts +2 -0
- package/components/TagsList/PopoverTags/index.js +2 -0
- package/components/TagsList/PopoverTags/styles.d.ts +8 -0
- package/components/TagsList/PopoverTags/styles.js +15 -0
- package/components/TagsList/PopoverTags/types.d.ts +24 -0
- package/components/TagsList/PopoverTags/types.js +1 -0
- package/components/TagsList/Tag/Tag.d.ts +9 -1
- package/components/TagsList/Tag/Tag.js +4 -3
- package/components/TagsList/TagsList.js +11 -5
- package/components/TagsList/constants.d.ts +35 -0
- package/components/TagsList/constants.js +35 -0
- package/components/TagsList/styles.d.ts +9 -1
- package/components/TagsList/styles.js +20 -1
- package/components/TagsList/types.d.ts +4 -0
- package/components/TagsList/useLogic/hooks/index.d.ts +1 -0
- package/components/TagsList/useLogic/hooks/index.js +1 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/index.d.ts +1 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/index.js +1 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/types.d.ts +20 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/types.js +1 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/useHoverDelay.d.ts +5 -0
- package/components/TagsList/useLogic/hooks/useHoverDelay/useHoverDelay.js +27 -0
- package/components/TagsList/useLogic/useLogic.d.ts +14 -2
- package/components/TagsList/useLogic/useLogic.js +84 -4
- package/components/TagsList/utils/calculatePopoverWidth/calculatePopoverWidth.d.ts +5 -0
- package/components/TagsList/utils/calculatePopoverWidth/calculatePopoverWidth.js +22 -0
- package/components/TagsList/utils/calculatePopoverWidth/index.d.ts +1 -0
- package/components/TagsList/utils/calculatePopoverWidth/index.js +1 -0
- package/components/TagsList/utils/index.d.ts +1 -0
- package/components/TagsList/utils/index.js +1 -0
- package/components/TreeLikeAsyncAutocomplete/Input/Input.js +3 -2
- package/components/TreeLikeAsyncAutocomplete/Input/useLogic/useLogic.d.ts +3 -2
- package/components/TreeLikeAsyncAutocomplete/Input/useLogic/useLogic.js +3 -1
- package/components/TreeLikeAutocomplete/Input/Input.js +2 -2
- package/components/TreeLikeAutocomplete/Input/useLogic/useLogic.d.ts +2 -1
- package/components/TreeLikeAutocomplete/Input/useLogic/useLogic.js +3 -1
- package/node/components/Autocomplete/Autocomplete.js +2 -3
- package/node/components/Onboarding/ui/StepStrategy/steps/HighlightStep/styles.d.ts +1 -1
- package/node/components/Select/Select.js +4 -3
- package/node/components/Select/useLogic/useLogic.d.ts +11 -2
- package/node/components/Select/useLogic/useLogic.js +4 -1
- package/node/components/TagsList/PopoverTags/PopoverTags.d.ts +7 -0
- package/node/components/TagsList/PopoverTags/PopoverTags.js +12 -0
- package/node/components/TagsList/PopoverTags/index.d.ts +2 -0
- package/node/components/TagsList/PopoverTags/index.js +18 -0
- package/node/components/TagsList/PopoverTags/styles.d.ts +8 -0
- package/node/components/TagsList/PopoverTags/styles.js +18 -0
- package/node/components/TagsList/PopoverTags/types.d.ts +24 -0
- package/node/components/TagsList/PopoverTags/types.js +2 -0
- package/node/components/TagsList/Tag/Tag.d.ts +9 -1
- package/node/components/TagsList/Tag/Tag.js +4 -4
- package/node/components/TagsList/TagsList.js +10 -4
- package/node/components/TagsList/constants.d.ts +35 -0
- package/node/components/TagsList/constants.js +36 -1
- package/node/components/TagsList/styles.d.ts +9 -1
- package/node/components/TagsList/styles.js +20 -1
- package/node/components/TagsList/types.d.ts +4 -0
- package/node/components/TagsList/useLogic/hooks/index.d.ts +1 -0
- package/node/components/TagsList/useLogic/hooks/index.js +17 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/index.d.ts +1 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/index.js +17 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/types.d.ts +20 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/types.js +2 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/useHoverDelay.d.ts +5 -0
- package/node/components/TagsList/useLogic/hooks/useHoverDelay/useHoverDelay.js +31 -0
- package/node/components/TagsList/useLogic/useLogic.d.ts +14 -2
- package/node/components/TagsList/useLogic/useLogic.js +81 -1
- package/node/components/TagsList/utils/calculatePopoverWidth/calculatePopoverWidth.d.ts +5 -0
- package/node/components/TagsList/utils/calculatePopoverWidth/calculatePopoverWidth.js +26 -0
- package/node/components/TagsList/utils/calculatePopoverWidth/index.d.ts +1 -0
- package/node/components/TagsList/utils/calculatePopoverWidth/index.js +17 -0
- package/node/components/TagsList/utils/index.d.ts +1 -0
- package/node/components/TagsList/utils/index.js +3 -1
- package/node/components/TreeLikeAsyncAutocomplete/Input/Input.js +3 -2
- package/node/components/TreeLikeAsyncAutocomplete/Input/useLogic/useLogic.d.ts +3 -2
- package/node/components/TreeLikeAsyncAutocomplete/Input/useLogic/useLogic.js +3 -1
- package/node/components/TreeLikeAutocomplete/Input/Input.js +2 -2
- package/node/components/TreeLikeAutocomplete/Input/useLogic/useLogic.d.ts +2 -1
- package/node/components/TreeLikeAutocomplete/Input/useLogic/useLogic.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useHoverDelay"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type UseHoverDelayResult = {
|
|
2
|
+
/**
|
|
3
|
+
* Запускает отсчёт задержки. Повторный вызов перезапускает отсчёт
|
|
4
|
+
*/
|
|
5
|
+
start: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Отменяет отсчёт, если он не завершился
|
|
8
|
+
*/
|
|
9
|
+
cancel: () => void;
|
|
10
|
+
};
|
|
11
|
+
export type UseHoverDelayParams = {
|
|
12
|
+
/**
|
|
13
|
+
* Функция, вызывающаяся при hover-эффекте после задержки
|
|
14
|
+
*/
|
|
15
|
+
onHover: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Задержка вызова функции в мс
|
|
18
|
+
*/
|
|
19
|
+
delay: number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useHoverDelay = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Откладывает вызов на время удержания указателя над элементом.
|
|
7
|
+
*/
|
|
8
|
+
const useHoverDelay = ({ delay, onHover, }) => {
|
|
9
|
+
const timeoutRef = (0, react_1.useRef)(undefined);
|
|
10
|
+
const savedOnHoverRef = (0, react_1.useRef)(onHover);
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
savedOnHoverRef.current = onHover;
|
|
13
|
+
});
|
|
14
|
+
const cancel = () => {
|
|
15
|
+
if (timeoutRef.current === undefined) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
clearTimeout(timeoutRef.current);
|
|
19
|
+
timeoutRef.current = undefined;
|
|
20
|
+
};
|
|
21
|
+
const start = () => {
|
|
22
|
+
cancel();
|
|
23
|
+
timeoutRef.current = setTimeout(() => {
|
|
24
|
+
timeoutRef.current = undefined;
|
|
25
|
+
savedOnHoverRef.current();
|
|
26
|
+
}, delay);
|
|
27
|
+
};
|
|
28
|
+
(0, react_1.useEffect)(() => cancel, []);
|
|
29
|
+
return { start, cancel };
|
|
30
|
+
};
|
|
31
|
+
exports.useHoverDelay = useHoverDelay;
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { type CSSProperties, type MouseEvent, type SyntheticEvent } from 'react';
|
|
2
2
|
import type { TagsListProps, TagValue } from '../types';
|
|
3
3
|
type UseLogicParams<TData extends TagValue> = TagsListProps<TData>;
|
|
4
|
-
export declare const useLogic: <TData extends TagValue>({ data, keyId, getOptionLabel, onChange, inputContainerRef, reservedWidth, }: UseLogicParams<TData>) => {
|
|
4
|
+
export declare const useLogic: <TData extends TagValue>({ data, keyId, isDisabled, getOptionLabel, onChange, onClick, inputContainerRef, fieldRef, reservedWidth, }: UseLogicParams<TData>) => {
|
|
5
5
|
visibleOptions: TData[];
|
|
6
6
|
hiddenCount: number;
|
|
7
7
|
showCounter: boolean;
|
|
8
8
|
tagsContainerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
9
|
+
counterRef: import("react").RefObject<HTMLDivElement | null>;
|
|
9
10
|
getTagProps: (option: TData) => {
|
|
10
11
|
label: string | number;
|
|
11
12
|
shrinks: boolean;
|
|
12
13
|
onDelete: () => void;
|
|
13
14
|
};
|
|
15
|
+
isPopoverOpen: boolean;
|
|
16
|
+
isPopoverEnabled: boolean;
|
|
17
|
+
setPopoverContentRef: (node: HTMLDivElement | null) => void;
|
|
18
|
+
popoverContentCssVars: CSSProperties;
|
|
19
|
+
stopPopoverEventPropagation: (event: SyntheticEvent) => void;
|
|
20
|
+
popoverAnchorEl: HTMLElement | null;
|
|
21
|
+
closePopover: () => void;
|
|
22
|
+
startPopoverDelay: () => void;
|
|
23
|
+
cancelPopoverDelay: () => void;
|
|
24
|
+
handleTagClick: (event: MouseEvent<HTMLDivElement>) => void;
|
|
25
|
+
handleCounterClick: (event: MouseEvent<HTMLDivElement>) => void;
|
|
14
26
|
};
|
|
15
27
|
export {};
|
|
@@ -3,14 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useTheme_1 = require("../../theme/hooks/useTheme");
|
|
6
|
+
const useClickAwayEffect_1 = require("../../useClickAwayEffect");
|
|
7
|
+
const useNewToggle_1 = require("../../useNewToggle");
|
|
8
|
+
const useViewportType_1 = require("../../useViewportType");
|
|
6
9
|
const constants_1 = require("../constants");
|
|
7
10
|
const utils_1 = require("../utils");
|
|
8
|
-
const
|
|
11
|
+
const useHoverDelay_1 = require("./hooks/useHoverDelay");
|
|
12
|
+
const useLogic = ({ data = [], keyId, isDisabled, getOptionLabel, onChange, onClick, inputContainerRef, fieldRef, reservedWidth = 0, }) => {
|
|
9
13
|
const [visibleOptions, setVisibleOptions] = (0, react_1.useState)([]);
|
|
10
14
|
const [hiddenCount, setHiddenCount] = (0, react_1.useState)(0);
|
|
15
|
+
const [isPopoverOpen, togglePopover] = (0, useNewToggle_1.useNewToggle)(false);
|
|
16
|
+
const [isPopoverContentMounted, togglePopoverContentMounted] = (0, useNewToggle_1.useNewToggle)(false);
|
|
17
|
+
/**
|
|
18
|
+
* Ширина окна и якорь позиционирования фиксируются на момент открытия
|
|
19
|
+
* и дальше не пересчитываются
|
|
20
|
+
*/
|
|
21
|
+
const [popoverWidth, setPopoverWidth] = (0, react_1.useState)(0);
|
|
22
|
+
const [popoverAnchorEl, setPopoverAnchorEl] = (0, react_1.useState)(null);
|
|
11
23
|
const tagsContainerRef = (0, react_1.useRef)(null);
|
|
12
24
|
const availableWidthRef = (0, react_1.useRef)(0);
|
|
25
|
+
const popoverContentRef = (0, react_1.useRef)(null);
|
|
26
|
+
const counterRef = (0, react_1.useRef)(null);
|
|
13
27
|
const theme = (0, useTheme_1.useTheme)();
|
|
28
|
+
const { isMobile } = (0, useViewportType_1.useViewportType)();
|
|
29
|
+
const openPopover = () => {
|
|
30
|
+
const field = fieldRef.current;
|
|
31
|
+
if (isPopoverOpen || !field) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setPopoverWidth((0, utils_1.calculatePopoverWidth)(field.getBoundingClientRect().width, data.map((item) => getOptionLabel(item).toString()), theme));
|
|
35
|
+
setPopoverAnchorEl(field);
|
|
36
|
+
togglePopover(true);
|
|
37
|
+
};
|
|
38
|
+
const closePopover = () => togglePopover(false);
|
|
14
39
|
/**
|
|
15
40
|
* Обновляет доступную ширину для расчета количества отображаемых тегов
|
|
16
41
|
*/
|
|
@@ -67,6 +92,7 @@ const useLogic = ({ data = [], keyId, getOptionLabel, onChange, inputContainerRe
|
|
|
67
92
|
if (!data.length) {
|
|
68
93
|
setVisibleOptions([]);
|
|
69
94
|
setHiddenCount(0);
|
|
95
|
+
closePopover();
|
|
70
96
|
return;
|
|
71
97
|
}
|
|
72
98
|
const resizeObserver = new ResizeObserver(() => {
|
|
@@ -105,12 +131,66 @@ const useLogic = ({ data = [], keyId, getOptionLabel, onChange, inputContainerRe
|
|
|
105
131
|
return { label, shrinks: false, onDelete };
|
|
106
132
|
};
|
|
107
133
|
const showCounter = hiddenCount > 0;
|
|
134
|
+
const { start: startPopoverDelay, cancel: cancelPopoverDelay } = (0, useHoverDelay_1.useHoverDelay)({ onHover: openPopover, delay: constants_1.POPOVER_HOVER_DELAY });
|
|
135
|
+
const setPopoverContentRef = (0, react_1.useCallback)((node) => {
|
|
136
|
+
popoverContentRef.current = node;
|
|
137
|
+
togglePopoverContentMounted(Boolean(node));
|
|
138
|
+
}, []);
|
|
139
|
+
const popoverExcludedNodes = (0, react_1.useMemo)(() => [counterRef], []);
|
|
140
|
+
(0, useClickAwayEffect_1.useClickAwayEffect)({
|
|
141
|
+
ref: popoverContentRef,
|
|
142
|
+
onClickAway: closePopover,
|
|
143
|
+
isActive: isPopoverOpen && isPopoverContentMounted,
|
|
144
|
+
excludeNodes: popoverExcludedNodes,
|
|
145
|
+
});
|
|
146
|
+
const isPopoverEnabled = !isMobile && !isDisabled;
|
|
147
|
+
const handleTagClick = (event) => {
|
|
148
|
+
event.stopPropagation();
|
|
149
|
+
onClick?.(event);
|
|
150
|
+
};
|
|
151
|
+
const handleCounterClick = (event) => {
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
cancelPopoverDelay();
|
|
154
|
+
// На мобильной ширине и в заблокированном поле у счётчика прежнее поведение — список опций
|
|
155
|
+
if (!isPopoverEnabled) {
|
|
156
|
+
onClick?.(event);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (isPopoverOpen) {
|
|
160
|
+
closePopover();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
openPopover();
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Окно живёт в портале, но синтетические события React всплывают по дереву
|
|
167
|
+
* компонентов и доходят до обработчиков поля: у MUI Select это `handleMouseDown`,
|
|
168
|
+
* который переводит фокус на поле и открывает список, у TreeLike* — `onClick` поля
|
|
169
|
+
*/
|
|
170
|
+
const stopPopoverEventPropagation = (event) => {
|
|
171
|
+
event.stopPropagation();
|
|
172
|
+
};
|
|
173
|
+
const popoverContentCssVars = {
|
|
174
|
+
'--tags-list-popover-width': `${popoverWidth}px`,
|
|
175
|
+
};
|
|
108
176
|
return {
|
|
109
177
|
visibleOptions,
|
|
110
178
|
hiddenCount,
|
|
111
179
|
showCounter,
|
|
112
180
|
tagsContainerRef,
|
|
181
|
+
counterRef,
|
|
113
182
|
getTagProps,
|
|
183
|
+
isPopoverOpen,
|
|
184
|
+
isPopoverEnabled,
|
|
185
|
+
setPopoverContentRef,
|
|
186
|
+
popoverContentCssVars,
|
|
187
|
+
stopPopoverEventPropagation,
|
|
188
|
+
popoverAnchorEl,
|
|
189
|
+
closePopover,
|
|
190
|
+
startPopoverDelay,
|
|
191
|
+
cancelPopoverDelay,
|
|
192
|
+
handleTagClick,
|
|
193
|
+
handleCounterClick,
|
|
114
194
|
};
|
|
115
195
|
};
|
|
116
196
|
exports.useLogic = useLogic;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculatePopoverWidth = void 0;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const getTagWidth_1 = require("../getTagWidth");
|
|
6
|
+
const getSpacingValue = (theme, spacing) => parseInt(theme.spacing(spacing), 10);
|
|
7
|
+
/**
|
|
8
|
+
* Минимальная ширина popover: вмещает в строку POPOVER_MIN_TAGS_IN_ROW самых
|
|
9
|
+
* широких тэгов вместе с отступом между ними и отступами контейнера
|
|
10
|
+
*/
|
|
11
|
+
const getMinWidth = (tagLabels, theme) => {
|
|
12
|
+
const widestTagWidths = tagLabels
|
|
13
|
+
.map((label) => (0, getTagWidth_1.getTagWidth)(label, theme))
|
|
14
|
+
.sort((current, next) => next - current)
|
|
15
|
+
.slice(0, constants_1.POPOVER_MIN_TAGS_IN_ROW);
|
|
16
|
+
const tagsWidth = widestTagWidths.reduce((width, tagWidth) => width + tagWidth, 0);
|
|
17
|
+
const gapsWidth = Math.max(widestTagWidths.length - 1, 0) *
|
|
18
|
+
getSpacingValue(theme, constants_1.POPOVER_TAGS_GAP_SPACING);
|
|
19
|
+
const paddingsWidth = getSpacingValue(theme, constants_1.POPOVER_TAGS_PADDING_SPACING) * 2;
|
|
20
|
+
return tagsWidth + gapsWidth + paddingsWidth;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Вычисляет ширину всплывающего окна
|
|
24
|
+
*/
|
|
25
|
+
const calculatePopoverWidth = (fieldWidth, tagLabels, theme) => Math.min(Math.max(fieldWidth, getMinWidth(tagLabels, theme)), constants_1.POPOVER_MAX_WIDTH);
|
|
26
|
+
exports.calculatePopoverWidth = calculatePopoverWidth;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './calculatePopoverWidth';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./calculatePopoverWidth"), exports);
|
|
@@ -3,3 +3,4 @@ export { getKey } from './getKey';
|
|
|
3
3
|
export { getTagWidth } from './getTagWidth';
|
|
4
4
|
export { getAvailableWidth } from './getAvailableWidth';
|
|
5
5
|
export { calculateVisibleTagsCount } from './calculateVisibleTagsCount';
|
|
6
|
+
export { calculatePopoverWidth } from './calculatePopoverWidth';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateVisibleTagsCount = exports.getAvailableWidth = exports.getTagWidth = exports.getKey = exports.getElementByText = void 0;
|
|
3
|
+
exports.calculatePopoverWidth = exports.calculateVisibleTagsCount = exports.getAvailableWidth = exports.getTagWidth = exports.getKey = exports.getElementByText = void 0;
|
|
4
4
|
var getElementByText_1 = require("./getElementByText");
|
|
5
5
|
Object.defineProperty(exports, "getElementByText", { enumerable: true, get: function () { return getElementByText_1.getElementByText; } });
|
|
6
6
|
var getKey_1 = require("./getKey");
|
|
@@ -11,3 +11,5 @@ var getAvailableWidth_1 = require("./getAvailableWidth");
|
|
|
11
11
|
Object.defineProperty(exports, "getAvailableWidth", { enumerable: true, get: function () { return getAvailableWidth_1.getAvailableWidth; } });
|
|
12
12
|
var calculateVisibleTagsCount_1 = require("./calculateVisibleTagsCount");
|
|
13
13
|
Object.defineProperty(exports, "calculateVisibleTagsCount", { enumerable: true, get: function () { return calculateVisibleTagsCount_1.calculateVisibleTagsCount; } });
|
|
14
|
+
var calculatePopoverWidth_1 = require("./calculatePopoverWidth");
|
|
15
|
+
Object.defineProperty(exports, "calculatePopoverWidth", { enumerable: true, get: function () { return calculatePopoverWidth_1.calculatePopoverWidth; } });
|
|
@@ -12,13 +12,14 @@ const styles_1 = require("./styles");
|
|
|
12
12
|
const useLogic_1 = require("./useLogic");
|
|
13
13
|
const ClearButton = ({ disabled, onClick }) => ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, onClick: onClick, title: constants_1.CLEAR_TEXT, "aria-label": constants_1.CLEAR_TEXT, children: (0, jsx_runtime_1.jsx)(CrossOutlineMd_1.CrossOutlineMd, {}) }));
|
|
14
14
|
exports.Input = (0, react_1.forwardRef)(({ disabled, onChange: propsOnChange, value, inputRef, hideHelperText = false, onClick, isLoading, ...restProps }, forwardedRef) => {
|
|
15
|
-
const { isVisibleClearButton, isVisibleTagsList, onChange, textFieldProps, onClearAll, } = (0, useLogic_1.useLogic)({
|
|
15
|
+
const { isVisibleClearButton, isVisibleTagsList, onChange, textFieldProps, onClearAll, fieldRef, } = (0, useLogic_1.useLogic)({
|
|
16
16
|
inputRef,
|
|
17
|
+
InputProps: restProps.InputProps,
|
|
17
18
|
value,
|
|
18
19
|
onChange: propsOnChange,
|
|
19
20
|
disabled,
|
|
20
21
|
onClick,
|
|
21
22
|
isLoading,
|
|
22
23
|
});
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTextField, { ...restProps, hideHelperText: hideHelperText, ref: forwardedRef, disabled: disabled, inputProps: { readOnly: true }, ...textFieldProps, startAdornment: isVisibleTagsList && ((0, jsx_runtime_1.jsx)(styles_1.StyledTagsList, { data: value, keyId: "id", isDisabled: disabled, getOptionLabel: (option) => option.label, onClick: onClick, onChange: onChange })), endAdornment: (0, jsx_runtime_1.jsxs)(styles_1.IconWrapper, { children: [isVisibleClearButton && ((0, jsx_runtime_1.jsx)(ClearButton, { disabled: disabled, onClick: onClearAll })), isLoading ? ((0, jsx_runtime_1.jsx)(Loader_1.Loader, { size: "small" })) : ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, children: (0, jsx_runtime_1.jsx)(DownOutlineMd_1.DownOutlineMd, {}) }))] }) }));
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTextField, { ...restProps, hideHelperText: hideHelperText, ref: forwardedRef, disabled: disabled, inputProps: { readOnly: true }, ...textFieldProps, InputProps: { ...restProps.InputProps, ref: fieldRef }, startAdornment: isVisibleTagsList && ((0, jsx_runtime_1.jsx)(styles_1.StyledTagsList, { data: value, keyId: "id", isDisabled: disabled, fieldRef: fieldRef, getOptionLabel: (option) => option.label, onClick: onClick, onChange: onChange })), endAdornment: (0, jsx_runtime_1.jsxs)(styles_1.IconWrapper, { children: [isVisibleClearButton && ((0, jsx_runtime_1.jsx)(ClearButton, { disabled: disabled, onClick: onClearAll })), isLoading ? ((0, jsx_runtime_1.jsx)(Loader_1.Loader, { size: "small" })) : ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, children: (0, jsx_runtime_1.jsx)(DownOutlineMd_1.DownOutlineMd, {}) }))] }) }));
|
|
24
25
|
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type MouseEvent, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type TreeLikeAsyncAutocompleteValue } from '../../types';
|
|
3
3
|
import type { InputProps } from '../types';
|
|
4
|
-
type UseLogicParams = Pick<InputProps, 'value' | 'disabled' | 'inputRef' | 'onChange' | 'isLoading' | 'onClick'>;
|
|
5
|
-
export declare const useLogic: ({ value, disabled, isLoading, inputRef: externalInputRef, onChange: propsOnChange, onClick: propsOnClick, }: UseLogicParams) => {
|
|
4
|
+
type UseLogicParams = Pick<InputProps, 'value' | 'disabled' | 'inputRef' | 'InputProps' | 'onChange' | 'isLoading' | 'onClick'>;
|
|
5
|
+
export declare const useLogic: ({ value, disabled, isLoading, inputRef: externalInputRef, InputProps: externalInputProps, onChange: propsOnChange, onClick: propsOnClick, }: UseLogicParams) => {
|
|
6
6
|
isVisibleClearButton: boolean;
|
|
7
7
|
onClearAll: (event: SyntheticEvent<HTMLButtonElement>) => void;
|
|
8
8
|
onChange: (newValue: TreeLikeAsyncAutocompleteValue | undefined) => void;
|
|
9
9
|
onClick: (event: MouseEvent<HTMLDivElement>) => void;
|
|
10
10
|
isVisibleTagsList: boolean;
|
|
11
|
+
fieldRef: import("react").RefObject<HTMLElement | null>;
|
|
11
12
|
textFieldProps: {
|
|
12
13
|
value: string;
|
|
13
14
|
$isHidden: boolean;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useForwardedRef_1 = require("../../../useForwardedRef");
|
|
6
|
-
const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, onChange: propsOnChange, onClick: propsOnClick, }) => {
|
|
6
|
+
const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, InputProps: externalInputProps, onChange: propsOnChange, onClick: propsOnClick, }) => {
|
|
7
7
|
const inputRef = (0, useForwardedRef_1.useForwardedRef)(externalInputRef);
|
|
8
|
+
const fieldRef = (0, useForwardedRef_1.useForwardedRef)(externalInputProps?.ref);
|
|
8
9
|
const prevValue = (0, react_1.useRef)(undefined);
|
|
9
10
|
(0, react_1.useEffect)(() => {
|
|
10
11
|
if (value && !prevValue.current) {
|
|
@@ -43,6 +44,7 @@ const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, onCh
|
|
|
43
44
|
onChange,
|
|
44
45
|
onClick,
|
|
45
46
|
isVisibleTagsList: hasValue,
|
|
47
|
+
fieldRef,
|
|
46
48
|
textFieldProps: {
|
|
47
49
|
value: preparedValue,
|
|
48
50
|
$isHidden: hasValue,
|
|
@@ -11,7 +11,7 @@ const styles_1 = require("./styles");
|
|
|
11
11
|
const useLogic_1 = require("./useLogic");
|
|
12
12
|
const ClearButton = ({ disabled, onClick }) => ((0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, title: constants_1.CLEAR_TEXT, "aria-label": constants_1.CLEAR_TEXT, onClick: onClick, children: (0, jsx_runtime_1.jsx)(CrossOutlineMd_1.CrossOutlineMd, {}) }));
|
|
13
13
|
exports.Input = (0, react_1.forwardRef)((props, forwardedRef) => {
|
|
14
|
-
const { textFieldProps, isVisibleTagsList, isVisibleClearButton, handleChange, handleClearAll, } = (0, useLogic_1.useLogic)(props);
|
|
14
|
+
const { textFieldProps, isVisibleTagsList, isVisibleClearButton, handleChange, handleClearAll, fieldRef, } = (0, useLogic_1.useLogic)(props);
|
|
15
15
|
const { value, valueToRender, disabled, isLoading, onChange, onClick, ...restProps } = props;
|
|
16
|
-
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTextField, { ...restProps, ref: forwardedRef, disabled: disabled, inputProps: { readOnly: true }, startAdornment: isVisibleTagsList && ((0, jsx_runtime_1.jsx)(styles_1.StyledTagsList, { data: valueToRender, keyId: "id", isDisabled: disabled, getOptionLabel: (option) => option.label, onClick: onClick, onChange: handleChange })), endAdornment: (0, jsx_runtime_1.jsxs)(styles_1.EndAdornmentWrapper, { children: [isLoading && (0, jsx_runtime_1.jsx)(styles_1.StyledLoader, {}), isVisibleClearButton && ((0, jsx_runtime_1.jsx)(ClearButton, { disabled: disabled, onClick: handleClearAll })), (0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, children: (0, jsx_runtime_1.jsx)(DownOutlineMd_1.DownOutlineMd, {}) })] }), onClick: onClick, ...textFieldProps }));
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.StyledTextField, { ...restProps, ref: forwardedRef, disabled: disabled, inputProps: { readOnly: true }, InputProps: { ...restProps.InputProps, ref: fieldRef }, startAdornment: isVisibleTagsList && ((0, jsx_runtime_1.jsx)(styles_1.StyledTagsList, { data: valueToRender, keyId: "id", isDisabled: disabled, fieldRef: fieldRef, getOptionLabel: (option) => option.label, onClick: onClick, onChange: handleChange })), endAdornment: (0, jsx_runtime_1.jsxs)(styles_1.EndAdornmentWrapper, { children: [isLoading && (0, jsx_runtime_1.jsx)(styles_1.StyledLoader, {}), isVisibleClearButton && ((0, jsx_runtime_1.jsx)(ClearButton, { disabled: disabled, onClick: handleClearAll })), (0, jsx_runtime_1.jsx)(IconButton_1.IconButton, { variant: "text", color: "grey", disabled: disabled, children: (0, jsx_runtime_1.jsx)(DownOutlineMd_1.DownOutlineMd, {}) })] }), onClick: onClick, ...textFieldProps }));
|
|
17
17
|
});
|
|
@@ -2,12 +2,13 @@ import { type SyntheticEvent } from 'react';
|
|
|
2
2
|
import { type TreeListData } from '../../../Tree';
|
|
3
3
|
import type { TreeLikeAutocompleteValue } from '../../types';
|
|
4
4
|
import { type InputProps } from '../types';
|
|
5
|
-
export declare const useLogic: ({ value, disabled, isLoading, inputRef: externalInputRef, onChange, }: InputProps) => {
|
|
5
|
+
export declare const useLogic: ({ value, disabled, isLoading, inputRef: externalInputRef, InputProps: externalInputProps, onChange, }: InputProps) => {
|
|
6
6
|
textFieldProps: {
|
|
7
7
|
$isHidden: boolean;
|
|
8
8
|
inputRef: import("react").RefObject<HTMLInputElement | null>;
|
|
9
9
|
value: string | TreeLikeAutocompleteValue;
|
|
10
10
|
};
|
|
11
|
+
fieldRef: import("react").RefObject<HTMLElement | null>;
|
|
11
12
|
isVisibleTagsList: boolean;
|
|
12
13
|
isVisibleClearButton: boolean;
|
|
13
14
|
handleChange: (newValue: TreeListData[] | undefined) => void;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useForwardedRef_1 = require("../../../useForwardedRef");
|
|
6
|
-
const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, onChange, }) => {
|
|
6
|
+
const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, InputProps: externalInputProps, onChange, }) => {
|
|
7
7
|
const inputRef = (0, useForwardedRef_1.useForwardedRef)(externalInputRef);
|
|
8
|
+
const fieldRef = (0, useForwardedRef_1.useForwardedRef)(externalInputProps?.ref);
|
|
8
9
|
const prevValue = (0, react_1.useRef)(undefined);
|
|
9
10
|
(0, react_1.useEffect)(() => {
|
|
10
11
|
if (value && !prevValue.current) {
|
|
@@ -41,6 +42,7 @@ const useLogic = ({ value, disabled, isLoading, inputRef: externalInputRef, onCh
|
|
|
41
42
|
inputRef,
|
|
42
43
|
value: preparedValue,
|
|
43
44
|
},
|
|
45
|
+
fieldRef,
|
|
44
46
|
isVisibleTagsList: hasValue,
|
|
45
47
|
isVisibleClearButton,
|
|
46
48
|
handleChange,
|