@lt-ui/uikit 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/floating/use-floating.d.ts +1 -1
- package/_internal/floating/use-floating.js +6 -2
- package/cjs/_internal/floating/use-floating.js +6 -2
- package/cjs/image/image-viewer.js +3 -13
- package/cjs/image/image.js +4 -27
- package/cjs/image/use-image-preview.js +32 -0
- package/cjs/image/use-image-viewer.js +21 -0
- package/cjs/modal/modal.js +4 -10
- package/cjs/modal/styles/_animations.css +2 -2
- package/cjs/modal/styles/modal.module.css +7 -2
- package/cjs/modal/use-modal.js +15 -1
- package/cjs/navigation/navigation-compact.js +2 -30
- package/cjs/navigation/navigation-row.js +5 -65
- package/cjs/navigation/navigation-views.js +3 -57
- package/cjs/navigation/styles/navigation.module.css +2 -0
- package/cjs/navigation/use-navigation-flyout.js +39 -0
- package/cjs/navigation/use-navigation-panel-stages.js +23 -0
- package/cjs/navigation/use-navigation-row.js +39 -0
- package/cjs/select/components/select-multiselect-panel.js +9 -67
- package/cjs/select/components/select-option-row.js +7 -53
- package/cjs/select/hooks/use-select-multiselect-panel-layout.js +53 -0
- package/cjs/select/hooks/use-select-option-row.js +23 -0
- package/cjs/select/views/select-view.js +2 -2
- package/cjs/snackbar/snack-view.js +9 -42
- package/cjs/snackbar/use-snack-view.js +16 -0
- package/cjs/tabs/tab-list.js +2 -20
- package/cjs/tabs/tab-panel.js +4 -39
- package/cjs/tabs/use-tab-list-navigation.js +27 -0
- package/cjs/tabs/use-tab-panel.js +12 -0
- package/cjs/time-picker/time-panel.js +2 -47
- package/cjs/time-picker/use-time-column-list.js +48 -0
- package/cjs/tooltip/tooltip.js +1 -1
- package/cjs/tree/tree-row.js +13 -73
- package/cjs/tree/use-tree-row.js +102 -0
- package/cjs/utils/class-names.js +3 -1
- package/image/image-viewer.js +3 -13
- package/image/image.js +5 -28
- package/image/use-image-preview.d.ts +10 -0
- package/image/use-image-preview.js +29 -0
- package/image/use-image-viewer.d.ts +8 -0
- package/image/use-image-viewer.js +18 -0
- package/input/fields/use-text-field.d.ts +2 -0
- package/masked-input/use-mask.d.ts +2 -0
- package/modal/modal.d.ts +1 -0
- package/modal/modal.js +4 -10
- package/modal/styles/_animations.css +2 -2
- package/modal/styles/modal.module.css +7 -2
- package/modal/types.d.ts +5 -0
- package/modal/use-modal.d.ts +3 -1
- package/modal/use-modal.js +17 -3
- package/navigation/navigation-compact.d.ts +1 -2
- package/navigation/navigation-compact.js +3 -31
- package/navigation/navigation-row.d.ts +1 -2
- package/navigation/navigation-row.js +6 -33
- package/navigation/navigation-views.js +3 -24
- package/navigation/styles/navigation.module.css +2 -0
- package/navigation/types.d.ts +1 -0
- package/navigation/use-navigation-flyout.d.ts +9 -0
- package/navigation/use-navigation-flyout.js +36 -0
- package/navigation/use-navigation-panel-stages.d.ts +5 -0
- package/navigation/use-navigation-panel-stages.js +20 -0
- package/navigation/use-navigation-row.d.ts +16 -0
- package/navigation/use-navigation-row.js +36 -0
- package/number-input/use-number-input.d.ts +2 -0
- package/package.json +1 -1
- package/popover/types.d.ts +2 -2
- package/select/components/select-multiselect-panel.d.ts +3 -1
- package/select/components/select-multiselect-panel.js +8 -66
- package/select/components/select-option-row.js +7 -20
- package/select/hooks/use-select-multiselect-panel-layout.d.ts +14 -0
- package/select/hooks/use-select-multiselect-panel-layout.js +49 -0
- package/select/hooks/use-select-option-row.d.ts +13 -0
- package/select/hooks/use-select-option-row.js +20 -0
- package/select/hooks/use-select-view-model.d.ts +1 -1
- package/select/select.d.ts +1 -1
- package/select/types.d.ts +3 -2
- package/select/views/select-view.js +2 -2
- package/snackbar/snack-view.js +7 -7
- package/snackbar/use-snack-view.d.ts +8 -0
- package/snackbar/use-snack-view.js +13 -0
- package/tabs/tab-list.js +4 -22
- package/tabs/tab-panel.js +4 -6
- package/tabs/use-tab-list-navigation.d.ts +2 -0
- package/tabs/use-tab-list-navigation.js +24 -0
- package/tabs/use-tab-panel.d.ts +6 -0
- package/tabs/use-tab-panel.js +9 -0
- package/time-picker/time-panel.js +2 -47
- package/time-picker/use-time-column-list.d.ts +7 -0
- package/time-picker/use-time-column-list.js +45 -0
- package/tooltip/tooltip.js +1 -1
- package/tree/tree-row.js +15 -75
- package/tree/use-tree-row.d.ts +331 -0
- package/tree/use-tree-row.js +99 -0
- package/utils/class-names.d.ts +1 -1
- package/utils/class-names.js +3 -1
|
@@ -7,61 +7,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.TimePanel = void 0;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const clsx_1 = __importDefault(require("clsx"));
|
|
10
|
-
const react_1 = require("react");
|
|
11
10
|
const compat_1 = require("../_internal/compat");
|
|
12
11
|
const hooks_1 = require("../hooks");
|
|
13
12
|
const use_locale_1 = require("../locale/use-locale");
|
|
14
13
|
const data_attributes_1 = require("../utils/data-attributes");
|
|
15
14
|
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
16
15
|
const use_time_panel_1 = require("./use-time-panel");
|
|
16
|
+
const use_time_column_list_1 = require("./use-time-column-list");
|
|
17
17
|
/** Одна колонка: список вариантов с блуждающим фокусом; стрелки двигают фокус и сразу выбирают значение */
|
|
18
18
|
function TimeColumnList({ column, label, onSelect }) {
|
|
19
|
-
const listRef = (0,
|
|
20
|
-
const selectedIndex = column.options.findIndex(option => option.selected);
|
|
21
|
-
const firstEnabled = column.options.findIndex(option => !option.disabled);
|
|
22
|
-
const rovingIndex = selectedIndex !== -1 ? selectedIndex : Math.max(firstEnabled, 0);
|
|
23
|
-
// Выбранный вариант держим в видимой части колонки, строки целиком: он становится третьим сверху,
|
|
24
|
-
// а колонка прокручивается кратно высоте строки (сверху и снизу нет «обрезанных» вариантов).
|
|
25
|
-
// Первый показ — сразу, без анимации. Дальше, если вариант уже виден целиком, колонка стоит на месте
|
|
26
|
-
// (клик по видимому значению ничего не двигает), иначе плавно подъезжает к нужной строке
|
|
27
|
-
const placed = (0, react_1.useRef)(false);
|
|
28
|
-
(0, react_1.useEffect)(() => {
|
|
29
|
-
const list = listRef.current;
|
|
30
|
-
// Без выбранного значения показываем первый доступный вариант (например, начало рабочих часов)
|
|
31
|
-
const target = list === null || list === void 0 ? void 0 : list.querySelectorAll('[role="option"]')[rovingIndex];
|
|
32
|
-
if (!list || !target)
|
|
33
|
-
return;
|
|
34
|
-
const gap = Number.parseFloat(getComputedStyle(list).rowGap) || 0;
|
|
35
|
-
const top = target.offsetTop - 2 * (target.offsetHeight + gap);
|
|
36
|
-
const first = !placed.current;
|
|
37
|
-
placed.current = true;
|
|
38
|
-
const visible = target.offsetTop >= list.scrollTop &&
|
|
39
|
-
target.offsetTop + target.offsetHeight <= list.scrollTop + list.clientHeight;
|
|
40
|
-
if (!first && visible)
|
|
41
|
-
return;
|
|
42
|
-
const calm = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
43
|
-
if (first || calm || typeof list.scrollTo !== 'function')
|
|
44
|
-
list.scrollTop = top;
|
|
45
|
-
else
|
|
46
|
-
list.scrollTo({ top, behavior: 'smooth' });
|
|
47
|
-
}, [rovingIndex]);
|
|
48
|
-
const onKeyDown = (event) => {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
const step = { ArrowDown: 1, ArrowUp: -1 }[event.key];
|
|
51
|
-
const edge = { Home: 0, End: column.options.length - 1 }[event.key];
|
|
52
|
-
if (step === undefined && edge === undefined)
|
|
53
|
-
return;
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
let index = step === undefined ? edge : rovingIndex + step;
|
|
56
|
-
const direction = step !== null && step !== void 0 ? step : (edge === 0 ? 1 : -1);
|
|
57
|
-
while (index >= 0 && index < column.options.length && column.options[index].disabled)
|
|
58
|
-
index += direction;
|
|
59
|
-
if (index < 0 || index >= column.options.length)
|
|
60
|
-
return;
|
|
61
|
-
onSelect(column.options[index].value);
|
|
62
|
-
const options = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="option"]');
|
|
63
|
-
(_b = options === null || options === void 0 ? void 0 : options[index]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
64
|
-
};
|
|
19
|
+
const { listRef, rovingIndex, onKeyDown } = (0, use_time_column_list_1.useTimeColumnList)(column, onSelect);
|
|
65
20
|
return ((0, jsx_runtime_1.jsx)("div", { ref: listRef, role: "listbox", "aria-label": label, className: styles_module_scss_1.default.column, onKeyDown: onKeyDown, children: column.options.map((option, index) => ((0, jsx_runtime_1.jsx)("button", { type: "button", role: "option", className: (0, clsx_1.default)(styles_module_scss_1.default.option, option.selected && styles_module_scss_1.default.selected), "aria-selected": option.selected, disabled: option.disabled, tabIndex: index === rovingIndex ? 0 : -1, onClick: () => onSelect(option.value), children: option.label }, option.value))) }));
|
|
66
21
|
}
|
|
67
22
|
/**
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useTimeColumnList = useTimeColumnList;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
function useTimeColumnList(column, onSelect) {
|
|
7
|
+
const listRef = (0, react_1.useRef)(null);
|
|
8
|
+
const selectedIndex = column.options.findIndex(option => option.selected);
|
|
9
|
+
const firstEnabled = column.options.findIndex(option => !option.disabled);
|
|
10
|
+
const rovingIndex = selectedIndex !== -1 ? selectedIndex : Math.max(firstEnabled, 0);
|
|
11
|
+
const placed = (0, react_1.useRef)(false);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
const list = listRef.current;
|
|
14
|
+
const target = list === null || list === void 0 ? void 0 : list.querySelectorAll('[role="option"]')[rovingIndex];
|
|
15
|
+
if (!list || !target)
|
|
16
|
+
return;
|
|
17
|
+
const gap = Number.parseFloat(getComputedStyle(list).rowGap) || 0;
|
|
18
|
+
const top = target.offsetTop - 2 * (target.offsetHeight + gap);
|
|
19
|
+
const first = !placed.current;
|
|
20
|
+
placed.current = true;
|
|
21
|
+
const visible = target.offsetTop >= list.scrollTop &&
|
|
22
|
+
target.offsetTop + target.offsetHeight <= list.scrollTop + list.clientHeight;
|
|
23
|
+
if (!first && visible)
|
|
24
|
+
return;
|
|
25
|
+
const calm = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
26
|
+
if (first || calm || typeof list.scrollTo !== 'function')
|
|
27
|
+
list.scrollTop = top;
|
|
28
|
+
else
|
|
29
|
+
list.scrollTo({ top, behavior: 'smooth' });
|
|
30
|
+
}, [rovingIndex]);
|
|
31
|
+
const onKeyDown = (event) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const step = { ArrowDown: 1, ArrowUp: -1 }[event.key];
|
|
34
|
+
const edge = { Home: 0, End: column.options.length - 1 }[event.key];
|
|
35
|
+
if (step === undefined && edge === undefined)
|
|
36
|
+
return;
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
let index = step === undefined ? edge : rovingIndex + step;
|
|
39
|
+
const direction = step !== null && step !== void 0 ? step : (edge === 0 ? 1 : -1);
|
|
40
|
+
while (index >= 0 && index < column.options.length && column.options[index].disabled)
|
|
41
|
+
index += direction;
|
|
42
|
+
if (index < 0 || index >= column.options.length)
|
|
43
|
+
return;
|
|
44
|
+
onSelect(column.options[index].value);
|
|
45
|
+
(_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('[role="option"]')[index]) === null || _b === void 0 ? void 0 : _b.focus();
|
|
46
|
+
};
|
|
47
|
+
return { listRef, rovingIndex, onKeyDown };
|
|
48
|
+
}
|
package/cjs/tooltip/tooltip.js
CHANGED
|
@@ -65,6 +65,6 @@ const Tooltip = ({ className, classNames: classNamesProp, title, placement = 'to
|
|
|
65
65
|
const { open, setOpen, tooltipId, anchorContent } = (0, use_tooltip_1.useTooltip)({ children });
|
|
66
66
|
const anchorRef = (0, react_1.useRef)(null);
|
|
67
67
|
const controlledShown = (0, use_tooltip_1.useDelayedOpen)(controlledOpen, openDelay);
|
|
68
|
-
return ((0, jsx_runtime_1.jsx)(popover_1.Popover, { "data-testid": (0, data_attributes_1.getRelatedTestId)((_a = props['data-testid']) !== null && _a !== void 0 ? _a : 'tooltip', 'popup'), anchor: (0, jsx_runtime_1.jsx)("span", { ...props, ...(0, data_attributes_1.getDataAttributes)(props, 'tooltip'), ref: anchorRef, className: (0, clsx_1.default)(styles_module_scss_1.default.wrapper, classNames.root, className), children: anchorContent }), open: controlledShown !== null && controlledShown !== void 0 ? controlledShown : open, onOpenChange: next => setOpen(next && overflowOnly ? isOverflowing(anchorRef.current) : next), trigger: controlledOpen === undefined ? ['hover', 'focus'] : 'manual', layer: "tooltip", placement: placement, openDelay: openDelay, closeDelay: 0, returnFocus: false, closeOnOutsideClick: false, container: container, id: tooltipId, role: "tooltip", className: (0, clsx_1.default)(styles_module_scss_1.default.tooltip, classNames.popup), theme: theme, children: typeof title === 'string' ? ((0, jsx_runtime_1.jsx)("span", { className: (0, clsx_1.default)(styles_module_scss_1.default.text, classNames.text), children: title })) : ((0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.node, children: title })) }));
|
|
68
|
+
return ((0, jsx_runtime_1.jsx)(popover_1.Popover, { "data-testid": (0, data_attributes_1.getRelatedTestId)((_a = props['data-testid']) !== null && _a !== void 0 ? _a : 'tooltip', 'popup'), anchor: (0, jsx_runtime_1.jsx)("span", { ...props, ...(0, data_attributes_1.getDataAttributes)(props, 'tooltip'), ref: anchorRef, className: (0, clsx_1.default)(styles_module_scss_1.default.wrapper, classNames.root, className), children: anchorContent }), open: controlledShown !== null && controlledShown !== void 0 ? controlledShown : open, onOpenChange: next => setOpen(next && overflowOnly ? isOverflowing(anchorRef.current) : next), trigger: controlledOpen === undefined ? ['hover', 'focus'] : 'manual', layer: "tooltip", placement: placement, openDelay: openDelay, closeDelay: 0, returnFocus: false, closeOnOutsideClick: false, container: container, id: tooltipId, role: "tooltip", className: (0, clsx_1.default)(styles_module_scss_1.default.tooltip, classNames.popup), theme: theme, children: typeof title === 'string' ? ((0, jsx_runtime_1.jsx)("span", { className: (0, clsx_1.default)(styles_module_scss_1.default.text, classNames.text, classNames.content), children: title })) : ((0, jsx_runtime_1.jsx)("span", { className: (0, clsx_1.default)(styles_module_scss_1.default.node, classNames.content), children: title })) }));
|
|
69
69
|
};
|
|
70
70
|
exports.Tooltip = Tooltip;
|
package/cjs/tree/tree-row.js
CHANGED
|
@@ -7,92 +7,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.TreeRowView = TreeRowView;
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const clsx_1 = __importDefault(require("clsx"));
|
|
10
|
-
const react_1 = require("react");
|
|
11
|
-
const use_list_navigation_1 = require("../hooks/use-list-navigation");
|
|
12
10
|
const utils_1 = require("../utils");
|
|
13
11
|
const class_names_context_1 = require("./class-names-context");
|
|
14
12
|
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
15
13
|
const tree_row_content_1 = require("./tree-row-content");
|
|
14
|
+
const use_tree_row_1 = require("./use-tree-row");
|
|
16
15
|
/** Строка дерева: линии уровней, индикатор ветки/листа, чекбокс, иконка, заголовок и контейнер справа */
|
|
17
16
|
function TreeRowView({ row, node, size, selectionMode, selected, checked, disabled, loading, matched, query, showLines, showLeafIndicator, label, selectedCount = 0, onActivate, onToggle, setExpanded, renderItem, extra, 'data-testid': testId, }) {
|
|
18
|
-
var _a;
|
|
19
|
-
const nav = (0, use_list_navigation_1.useListNavigationItem)({ id: row.id, disabled });
|
|
20
17
|
const classNames = (0, class_names_context_1.useTreeClassNames)();
|
|
21
|
-
const {
|
|
22
|
-
// Раскрытие отключается отдельно от строки: недоступная строка с рабочим индикатором и наоборот
|
|
23
|
-
const toggleLocked = (_a = node.toggleDisabled) !== null && _a !== void 0 ? _a : disabled;
|
|
24
|
-
// Клик по кнопке, ссылке или полю внутри строки (контейнер справа, свой заголовок) — отдельная зона: строку не выбирает
|
|
25
|
-
const handleClick = (0, react_1.useCallback)((event) => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const zone = (_b = (_a = event.target).closest) === null || _b === void 0 ? void 0 : _b.call(_a, 'button, a, input, textarea, select, [role="button"]');
|
|
28
|
-
if (zone && zone !== event.currentTarget && event.currentTarget.contains(zone))
|
|
29
|
-
return;
|
|
30
|
-
if (!disabled)
|
|
31
|
-
onActivate(row.id);
|
|
32
|
-
}, [disabled, onActivate, row.id]);
|
|
33
|
-
const handleToggle = (0, react_1.useCallback)((event) => {
|
|
34
|
-
event.stopPropagation();
|
|
35
|
-
if (!toggleLocked)
|
|
36
|
-
onToggle(row.id);
|
|
37
|
-
}, [toggleLocked, onToggle, row.id]);
|
|
38
|
-
const isCheckbox = selectionMode === 'checkbox';
|
|
39
|
-
const isSelectable = selectionMode === 'single' || selectionMode === 'multiple';
|
|
40
|
-
const aria = {
|
|
41
|
-
'aria-level': row.level,
|
|
42
|
-
'aria-setsize': row.setSize,
|
|
43
|
-
'aria-posinset': row.posInSet,
|
|
44
|
-
'aria-disabled': disabled || undefined,
|
|
45
|
-
'aria-busy': loading || undefined,
|
|
46
|
-
};
|
|
47
|
-
if (row.expandable)
|
|
48
|
-
aria['aria-expanded'] = row.expanded;
|
|
49
|
-
if (isSelectable)
|
|
50
|
-
aria['aria-selected'] = selected;
|
|
51
|
-
if (isCheckbox)
|
|
52
|
-
aria['aria-checked'] = checked;
|
|
53
|
-
const indicatorProps = {
|
|
18
|
+
const { navProps, rootRef, extraRest, extraClass, extraStyle, extraClick, isCheckbox, aria, contentProps, item, handleClick, } = (0, use_tree_row_1.useTreeRow)({
|
|
54
19
|
row,
|
|
55
|
-
node: node,
|
|
56
|
-
loading,
|
|
57
|
-
toggleLocked,
|
|
58
|
-
showLeafIndicator,
|
|
59
|
-
onToggle: handleToggle,
|
|
60
|
-
testId,
|
|
61
|
-
};
|
|
62
|
-
const contentProps = {
|
|
63
|
-
...indicatorProps,
|
|
64
|
-
isCheckbox,
|
|
65
|
-
checked,
|
|
66
|
-
disabled,
|
|
67
|
-
matched,
|
|
68
|
-
query,
|
|
69
|
-
label,
|
|
70
|
-
selectedCount,
|
|
71
|
-
};
|
|
72
|
-
const item = {
|
|
73
|
-
id: row.id,
|
|
74
20
|
node,
|
|
75
|
-
|
|
76
|
-
expanded: row.expanded,
|
|
77
|
-
expandable: row.expandable,
|
|
21
|
+
selectionMode,
|
|
78
22
|
selected,
|
|
79
23
|
checked,
|
|
80
24
|
disabled,
|
|
81
25
|
loading,
|
|
82
26
|
matched,
|
|
83
|
-
|
|
27
|
+
query,
|
|
28
|
+
showLeafIndicator,
|
|
84
29
|
label,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
'data-locked': toggleLocked || undefined,
|
|
94
|
-
tabIndex: -1,
|
|
95
|
-
}),
|
|
96
|
-
};
|
|
97
|
-
return ((0, jsx_runtime_1.jsxs)("div", { ...extraRest, ...nav.props, ...aria, ref: (0, utils_1.mergeRefs)([nav.props.ref, extraRef]), role: "treeitem", id: `${testId !== null && testId !== void 0 ? testId : 'tree'}-${row.id}`, className: (0, clsx_1.default)(styles_module_scss_1.default.row, styles_module_scss_1.default[`size-${size}`], classNames.row, extraClass), style: { ...extraStyle, ['--tree-level']: row.level }, "data-tree-id": row.id, "data-selected": selected || undefined, "data-checked": isCheckbox && checked ? String(checked) : undefined, "data-disabled": disabled || undefined, "data-hoverable": node.hoverable === false ? 'false' : undefined, "data-custom": renderItem ? '' : undefined, "data-matched": matched || undefined, "data-expandable": row.expandable || undefined, "data-plain": (!row.expandable && !showLeafIndicator && !node.icon) || undefined, "data-icon-leaf": (!row.expandable && !showLeafIndicator && node.icon) || undefined, "data-bold": node.bold || undefined, onClick: (0, utils_1.composeEventHandlers)(handleClick, extraClick), children: [row.guides.map((guide, index) => ((0, jsx_runtime_1.jsx)("span", { className: (0, clsx_1.default)(styles_module_scss_1.default.guide, classNames.guide), "data-guide": showLines ? guide : 'none', "aria-hidden": true }, index))), renderItem ? renderItem(item) : (0, jsx_runtime_1.jsx)(tree_row_content_1.TreeRowContent, { ...contentProps })] }));
|
|
30
|
+
selectedCount,
|
|
31
|
+
onActivate,
|
|
32
|
+
onToggle,
|
|
33
|
+
setExpanded,
|
|
34
|
+
extra,
|
|
35
|
+
testId,
|
|
36
|
+
});
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ...extraRest, ...navProps, ...aria, ref: rootRef, role: "treeitem", id: `${testId !== null && testId !== void 0 ? testId : 'tree'}-${row.id}`, className: (0, clsx_1.default)(styles_module_scss_1.default.row, styles_module_scss_1.default[`size-${size}`], classNames.row, extraClass), style: { ...extraStyle, ['--tree-level']: row.level }, "data-tree-id": row.id, "data-selected": selected || undefined, "data-checked": isCheckbox && checked ? String(checked) : undefined, "data-disabled": disabled || undefined, "data-hoverable": node.hoverable === false ? 'false' : undefined, "data-custom": renderItem ? '' : undefined, "data-matched": matched || undefined, "data-expandable": row.expandable || undefined, "data-plain": (!row.expandable && !showLeafIndicator && !node.icon) || undefined, "data-icon-leaf": (!row.expandable && !showLeafIndicator && node.icon) || undefined, "data-bold": node.bold || undefined, onClick: (0, utils_1.composeEventHandlers)(handleClick, extraClick), children: [row.guides.map((guide, index) => ((0, jsx_runtime_1.jsx)("span", { className: (0, clsx_1.default)(styles_module_scss_1.default.guide, classNames.guide), "data-guide": showLines ? guide : 'none', "aria-hidden": true }, index))), renderItem ? renderItem(item) : (0, jsx_runtime_1.jsx)(tree_row_content_1.TreeRowContent, { ...contentProps })] }));
|
|
98
38
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useTreeRow = useTreeRow;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const use_list_navigation_1 = require("../hooks/use-list-navigation");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const tree_row_content_1 = require("./tree-row-content");
|
|
10
|
+
/** Поведение строки дерева: клавиатурная навигация, зоны клика и API пользовательского рендера. */
|
|
11
|
+
function useTreeRow(params) {
|
|
12
|
+
var _a;
|
|
13
|
+
const { row, node, selectionMode, selected, checked, disabled, loading, matched, query, showLeafIndicator, label, selectedCount, onActivate, onToggle, setExpanded, extra, testId, } = params;
|
|
14
|
+
const nav = (0, use_list_navigation_1.useListNavigationItem)({ id: row.id, disabled });
|
|
15
|
+
const { ref: extraRef, className: extraClass, style: extraStyle, onClick: extraClick, ...extraRest } = extra !== null && extra !== void 0 ? extra : {};
|
|
16
|
+
const toggleLocked = (_a = node.toggleDisabled) !== null && _a !== void 0 ? _a : disabled;
|
|
17
|
+
const handleClick = (0, react_1.useCallback)((event) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const zone = (_b = (_a = event.target).closest) === null || _b === void 0 ? void 0 : _b.call(_a, 'button, a, input, textarea, select, [role="button"]');
|
|
20
|
+
if (zone && zone !== event.currentTarget && event.currentTarget.contains(zone))
|
|
21
|
+
return;
|
|
22
|
+
if (!disabled)
|
|
23
|
+
onActivate(row.id);
|
|
24
|
+
}, [disabled, onActivate, row.id]);
|
|
25
|
+
const handleToggle = (0, react_1.useCallback)((event) => {
|
|
26
|
+
event.stopPropagation();
|
|
27
|
+
if (!toggleLocked)
|
|
28
|
+
onToggle(row.id);
|
|
29
|
+
}, [toggleLocked, onToggle, row.id]);
|
|
30
|
+
const isCheckbox = selectionMode === 'checkbox';
|
|
31
|
+
const isSelectable = selectionMode === 'single' || selectionMode === 'multiple';
|
|
32
|
+
const aria = {
|
|
33
|
+
'aria-level': row.level,
|
|
34
|
+
'aria-setsize': row.setSize,
|
|
35
|
+
'aria-posinset': row.posInSet,
|
|
36
|
+
'aria-disabled': disabled || undefined,
|
|
37
|
+
'aria-busy': loading || undefined,
|
|
38
|
+
};
|
|
39
|
+
if (row.expandable)
|
|
40
|
+
aria['aria-expanded'] = row.expanded;
|
|
41
|
+
if (isSelectable)
|
|
42
|
+
aria['aria-selected'] = selected;
|
|
43
|
+
if (isCheckbox)
|
|
44
|
+
aria['aria-checked'] = checked;
|
|
45
|
+
const indicatorProps = {
|
|
46
|
+
row,
|
|
47
|
+
node: node,
|
|
48
|
+
loading,
|
|
49
|
+
toggleLocked,
|
|
50
|
+
showLeafIndicator,
|
|
51
|
+
onToggle: handleToggle,
|
|
52
|
+
testId,
|
|
53
|
+
};
|
|
54
|
+
const contentProps = {
|
|
55
|
+
...indicatorProps,
|
|
56
|
+
isCheckbox,
|
|
57
|
+
checked,
|
|
58
|
+
disabled,
|
|
59
|
+
matched,
|
|
60
|
+
query,
|
|
61
|
+
label,
|
|
62
|
+
selectedCount,
|
|
63
|
+
};
|
|
64
|
+
const item = {
|
|
65
|
+
id: row.id,
|
|
66
|
+
node,
|
|
67
|
+
level: row.level,
|
|
68
|
+
expanded: row.expanded,
|
|
69
|
+
expandable: row.expandable,
|
|
70
|
+
selected,
|
|
71
|
+
checked,
|
|
72
|
+
disabled,
|
|
73
|
+
loading,
|
|
74
|
+
matched,
|
|
75
|
+
toggleDisabled: toggleLocked,
|
|
76
|
+
label,
|
|
77
|
+
indicator: (0, jsx_runtime_1.jsx)(tree_row_content_1.TreeIndicator, { ...indicatorProps }),
|
|
78
|
+
toggle: () => !toggleLocked && onToggle(row.id),
|
|
79
|
+
setExpanded: value => !toggleLocked && setExpanded(row.id, value),
|
|
80
|
+
activate: () => !disabled && onActivate(row.id),
|
|
81
|
+
getToggleProps: () => ({
|
|
82
|
+
onClick: handleToggle,
|
|
83
|
+
'aria-expanded': row.expandable ? row.expanded : undefined,
|
|
84
|
+
'aria-disabled': toggleLocked || undefined,
|
|
85
|
+
'data-locked': toggleLocked || undefined,
|
|
86
|
+
tabIndex: -1,
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
navProps: nav.props,
|
|
91
|
+
rootRef: (0, utils_1.mergeRefs)([nav.props.ref, extraRef]),
|
|
92
|
+
extraRest,
|
|
93
|
+
extraClass,
|
|
94
|
+
extraStyle,
|
|
95
|
+
extraClick,
|
|
96
|
+
isCheckbox,
|
|
97
|
+
aria,
|
|
98
|
+
contentProps,
|
|
99
|
+
item,
|
|
100
|
+
handleClick,
|
|
101
|
+
};
|
|
102
|
+
}
|
package/cjs/utils/class-names.js
CHANGED
|
@@ -10,6 +10,8 @@ exports.getStaticClassName = exports.componentClassNames = void 0;
|
|
|
10
10
|
* - ключ — компонент в PascalCase, значение — части в camelCase; `root` — корневой элемент;
|
|
11
11
|
* - часть — это элемент DOM, на который класс попадает вместе со своим классом компонента (свой не заменяется);
|
|
12
12
|
* - состояния частей — атрибуты (`data-selected`, `data-open`, `aria-current`…), на них пишутся селекторы;
|
|
13
|
+
* - произвольный пользовательский JSX получает слот `content`; библиотека не навязывает ему раскладку и отступы,
|
|
14
|
+
* а пользователь оформляет его своим классом и компонентными токенами;
|
|
13
15
|
* - новый компонент: добавить строку сюда, описания — в docs, применить `useClassNames` (см. `use-class-names.ts`).
|
|
14
16
|
*/
|
|
15
17
|
/** Части рамки поля (`FieldFrame`): одинаковы у Input, Textarea, NumberInput, DatePicker, TimePicker */
|
|
@@ -90,7 +92,7 @@ exports.componentClassNames = {
|
|
|
90
92
|
Avatar: ['root', 'picture', 'icon', 'name', 'description'],
|
|
91
93
|
ProgressBar: ['root', 'track', 'fill', 'text'],
|
|
92
94
|
Skeleton: ['root', 'line', 'content'],
|
|
93
|
-
Tooltip: ['root', 'popup', 'text'],
|
|
95
|
+
Tooltip: ['root', 'popup', 'content', 'text'],
|
|
94
96
|
Popover: ['root', 'arrow', 'content'],
|
|
95
97
|
Hint: ['root', 'popover', 'content', 'header', 'paragraph', 'buttons'],
|
|
96
98
|
Stepper: ['root', 'step', 'control', 'marker', 'title', 'description'],
|
package/image/image-viewer.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo, useRef, useState } from 'react';
|
|
4
3
|
import ReactDOM from 'react-dom';
|
|
5
4
|
import { contextProvider } from '../_internal/compat';
|
|
6
5
|
import { FocusTrap } from '../_internal/focus-trap';
|
|
7
6
|
import { FocusOnContext } from '../_internal/hooks';
|
|
8
|
-
import { useLayer } from '../_internal/layer';
|
|
9
7
|
import { Button } from '../button';
|
|
10
8
|
import { CloseIcon } from '../icons';
|
|
11
9
|
import { Loader } from '../loader';
|
|
12
10
|
import { isInlineContainer, usePortalTarget } from '../portal';
|
|
13
11
|
import styles from './viewer.module.css';
|
|
12
|
+
import { useImageViewer } from './use-image-viewer';
|
|
14
13
|
const FocusOnProvider = contextProvider(FocusOnContext);
|
|
15
14
|
/**
|
|
16
15
|
* Полноэкранный просмотр: затемнение, фокус остаётся внутри, закрывается Escape, кликом вне картинки или крестиком.
|
|
@@ -19,22 +18,13 @@ const FocusOnProvider = contextProvider(FocusOnContext);
|
|
|
19
18
|
const DownloadIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", "aria-hidden": true, children: _jsx("path", { d: "M12 4v11m0 0-4-4m4 4 4-4M5 19.5h14", stroke: "currentColor", strokeWidth: "1.75", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
20
19
|
export function ImageViewer({ testId, src, alt, srcSet, sizes, closeLabel, loading, downloadLabel, downloadName, onClose, container, }) {
|
|
21
20
|
const target = usePortalTarget({ container });
|
|
22
|
-
const imageRef =
|
|
23
|
-
const closeRef = useRef(null);
|
|
24
|
-
const [zoomed, setZoomed] = useState(false);
|
|
25
|
-
const contentRefs = useMemo(() => [imageRef, closeRef], []);
|
|
26
|
-
useLayer({ open: true, type: 'image-viewer', contentRefs, onClose });
|
|
21
|
+
const { imageRef, closeRef, zoomed, toggleZoom, onImageKeyDown } = useImageViewer(onClose);
|
|
27
22
|
const viewer = (_jsx(FocusTrap, { returnFocus: true, children: _jsxs("div", { className: styles.viewer, role: "dialog", "data-testid": testId, "aria-modal": "true", "aria-label": alt, "data-lt-ui-theme": "dark", "data-lt-ui-portal": "", children: [_jsxs("div", { ref: closeRef, className: styles.close, children: [downloadLabel && !loading && (_jsx(Button, { iconOnly: true, compact: true, "aria-label": downloadLabel, variant: "link-minor", className: styles.tool, onClick: () => {
|
|
28
23
|
const link = globalThis.document.createElement('a');
|
|
29
24
|
link.href = src;
|
|
30
25
|
link.download = downloadName !== null && downloadName !== void 0 ? downloadName : '';
|
|
31
26
|
link.click();
|
|
32
|
-
}, children: _jsx(DownloadIcon, {}) })), _jsx(Button, { iconOnly: true, compact: true, "aria-label": closeLabel, variant: "link-minor", className: styles.tool, onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: zoomed ? styles.scrollZoomed : styles.scroll, children: _jsx(FocusOnProvider, { value: true, children: loading ? (_jsx(Loader, { size: "m" })) : (_jsx("img", { ref: imageRef, className: zoomed ? styles.zoomed : styles.fit, src: src, srcSet: srcSet, sizes: sizes, alt: alt, role: "button", tabIndex: 0, "aria-pressed": zoomed, onClick:
|
|
33
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
34
|
-
event.preventDefault();
|
|
35
|
-
setZoomed(value => !value);
|
|
36
|
-
}
|
|
37
|
-
} })) }) })] }) }));
|
|
27
|
+
}, children: _jsx(DownloadIcon, {}) })), _jsx(Button, { iconOnly: true, compact: true, "aria-label": closeLabel, variant: "link-minor", className: styles.tool, onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: zoomed ? styles.scrollZoomed : styles.scroll, children: _jsx(FocusOnProvider, { value: true, children: loading ? (_jsx(Loader, { size: "m" })) : (_jsx("img", { ref: imageRef, className: zoomed ? styles.zoomed : styles.fit, src: src, srcSet: srcSet, sizes: sizes, alt: alt, role: "button", tabIndex: 0, "aria-pressed": zoomed, onClick: toggleZoom, onKeyDown: onImageKeyDown })) }) })] }) }));
|
|
38
28
|
if (isInlineContainer(container))
|
|
39
29
|
return viewer;
|
|
40
30
|
return target ? ReactDOM.createPortal(viewer, target) : null;
|
package/image/image.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import { useMemo
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
5
|
import { withRef } from '../_internal/compat';
|
|
6
6
|
import { useLocale } from '../locale/use-locale';
|
|
7
7
|
import { mergeRefs, useClassNames } from '../utils';
|
|
@@ -9,6 +9,7 @@ import { getDataAttributes, getRelatedTestId, splitDataAttributes } from '../uti
|
|
|
9
9
|
import { ImageViewer } from './image-viewer';
|
|
10
10
|
import style from './style.module.css';
|
|
11
11
|
import { useImage } from './use-image';
|
|
12
|
+
import { useImagePreview } from './use-image-preview';
|
|
12
13
|
/**
|
|
13
14
|
* `<Image />` — изображение с состояниями загрузки и ошибки, скруглением и необязательным просмотром на весь экран.
|
|
14
15
|
* Принимает все атрибуты `<img>` (`srcSet`, `sizes`, `loading="lazy"`...).
|
|
@@ -18,7 +19,7 @@ import { useImage } from './use-image';
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
export const Image = withRef(function Image({ src, alt, rounding, width, height, objectFit, fallback, placeholder, preview, previewSrc, loadPreview, download, downloadLabel, previewOpen: previewOpenProp, onPreviewOpenChange, previewLabel, previewCloseLabel, container, className, classNames: classNamesProp, style: styleProp, onLoad, onError, srcSet, sizes, ...imgProps }, ref) {
|
|
21
|
-
var _a, _b;
|
|
22
|
+
var _a, _b, _c;
|
|
22
23
|
const { t } = useLocale();
|
|
23
24
|
const classNames = useClassNames('Image', classNamesProp);
|
|
24
25
|
const vm = useImage({
|
|
@@ -29,31 +30,7 @@ export const Image = withRef(function Image({ src, alt, rounding, width, height,
|
|
|
29
30
|
previewOpen: previewOpenProp,
|
|
30
31
|
onPreviewOpenChange,
|
|
31
32
|
});
|
|
32
|
-
const
|
|
33
|
-
const [resolving, setResolving] = useState(false);
|
|
34
|
-
const openPreview = async () => {
|
|
35
|
-
vm.openPreview();
|
|
36
|
-
if (!loadPreview || resolved)
|
|
37
|
-
return;
|
|
38
|
-
// Окно открывается сразу с индикатором, большая версия подставляется, когда загружена
|
|
39
|
-
setResolving(true);
|
|
40
|
-
try {
|
|
41
|
-
const url = await loadPreview();
|
|
42
|
-
await new Promise(resolve => {
|
|
43
|
-
const probe = new globalThis.Image();
|
|
44
|
-
probe.onload = () => resolve();
|
|
45
|
-
probe.onerror = () => resolve();
|
|
46
|
-
probe.src = url;
|
|
47
|
-
});
|
|
48
|
-
setResolved(url);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
// не получилось: останется то, что есть
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
setResolving(false);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
33
|
+
const previewState = useImagePreview({ loadPreview, openPreview: vm.openPreview });
|
|
57
34
|
const imgRef = useMemo(() => mergeRefs([vm.setImg, ref]), [vm.setImg, ref]);
|
|
58
35
|
const image = (_jsx("img", { ...splitDataAttributes(imgProps).nativeProps, ref: imgRef, className: clsx(style.img, classNames.img), style: { objectFit }, src: src, srcSet: srcSet, sizes: sizes, alt: alt, onLoad: vm.onLoad, onError: vm.onError }));
|
|
59
36
|
const content = (_jsxs(_Fragment, { children: [image, vm.status === 'loading' && placeholder && (_jsx("span", { className: clsx(style.overlay, classNames.overlay), children: placeholder })), vm.status === 'error' && fallback && (_jsx("span", { className: clsx(style.overlay, classNames.overlay), children: fallback }))] }));
|
|
@@ -63,5 +40,5 @@ export const Image = withRef(function Image({ src, alt, rounding, width, height,
|
|
|
63
40
|
...getDataAttributes(imgProps, 'image-wrapper'),
|
|
64
41
|
'data-status': vm.status,
|
|
65
42
|
};
|
|
66
|
-
return (_jsxs(_Fragment, { children: [vm.interactive ? (_jsx("button", { ...wrapperProps, type: "button", className: clsx(wrapperProps.className, style.interactive), "aria-label": `${previewLabel !== null && previewLabel !== void 0 ? previewLabel : t('image.preview')}: ${alt}`, "aria-haspopup": "dialog", onClick: openPreview, children: content })) : (_jsx("div", { ...wrapperProps, children: content })), vm.previewOpen && src && (_jsx(ImageViewer, { testId: getRelatedTestId((_a = imgProps['data-testid']) !== null && _a !== void 0 ? _a : 'image-wrapper', 'popup'), src: (_b = resolved !== null &&
|
|
43
|
+
return (_jsxs(_Fragment, { children: [vm.interactive ? (_jsx("button", { ...wrapperProps, type: "button", className: clsx(wrapperProps.className, style.interactive), "aria-label": `${previewLabel !== null && previewLabel !== void 0 ? previewLabel : t('image.preview')}: ${alt}`, "aria-haspopup": "dialog", onClick: previewState.openPreview, children: content })) : (_jsx("div", { ...wrapperProps, children: content })), vm.previewOpen && src && (_jsx(ImageViewer, { testId: getRelatedTestId((_a = imgProps['data-testid']) !== null && _a !== void 0 ? _a : 'image-wrapper', 'popup'), src: (_c = (_b = previewState.resolved) !== null && _b !== void 0 ? _b : previewSrc) !== null && _c !== void 0 ? _c : src, srcSet: previewState.resolved || previewSrc ? undefined : srcSet, sizes: sizes, alt: alt, closeLabel: previewCloseLabel !== null && previewCloseLabel !== void 0 ? previewCloseLabel : t('image.closePreview'), loading: previewState.resolving, downloadLabel: download ? (downloadLabel !== null && downloadLabel !== void 0 ? downloadLabel : t('image.download')) : undefined, downloadName: typeof download === 'string' ? download : undefined, onClose: vm.closePreview, container: container }))] }));
|
|
67
44
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Params = {
|
|
2
|
+
loadPreview?: () => Promise<string>;
|
|
3
|
+
openPreview: () => void;
|
|
4
|
+
};
|
|
5
|
+
export declare function useImagePreview({ loadPreview, openPreview }: Params): {
|
|
6
|
+
resolved: string | undefined;
|
|
7
|
+
resolving: boolean;
|
|
8
|
+
openPreview: () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
export function useImagePreview({ loadPreview, openPreview }) {
|
|
4
|
+
const [resolved, setResolved] = useState();
|
|
5
|
+
const [resolving, setResolving] = useState(false);
|
|
6
|
+
const open = useCallback(async () => {
|
|
7
|
+
openPreview();
|
|
8
|
+
if (!loadPreview || resolved)
|
|
9
|
+
return;
|
|
10
|
+
setResolving(true);
|
|
11
|
+
try {
|
|
12
|
+
const url = await loadPreview();
|
|
13
|
+
await new Promise(resolve => {
|
|
14
|
+
const probe = new globalThis.Image();
|
|
15
|
+
probe.onload = () => resolve();
|
|
16
|
+
probe.onerror = () => resolve();
|
|
17
|
+
probe.src = url;
|
|
18
|
+
});
|
|
19
|
+
setResolved(url);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Если большая версия недоступна, остаётся исходное изображение.
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
setResolving(false);
|
|
26
|
+
}
|
|
27
|
+
}, [loadPreview, openPreview, resolved]);
|
|
28
|
+
return { resolved, resolving, openPreview: open };
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
export declare function useImageViewer(onClose: () => void): {
|
|
3
|
+
imageRef: import("react").RefObject<HTMLImageElement | null>;
|
|
4
|
+
closeRef: import("react").RefObject<HTMLDivElement | null>;
|
|
5
|
+
zoomed: boolean;
|
|
6
|
+
toggleZoom: () => void;
|
|
7
|
+
onImageKeyDown: (event: KeyboardEvent<HTMLImageElement>) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useLayer } from '../_internal/layer';
|
|
4
|
+
export function useImageViewer(onClose) {
|
|
5
|
+
const imageRef = useRef(null);
|
|
6
|
+
const closeRef = useRef(null);
|
|
7
|
+
const [zoomed, setZoomed] = useState(false);
|
|
8
|
+
const contentRefs = useMemo(() => [imageRef, closeRef], []);
|
|
9
|
+
useLayer({ open: true, type: 'image-viewer', contentRefs, onClose });
|
|
10
|
+
const toggleZoom = () => setZoomed(value => !value);
|
|
11
|
+
const onImageKeyDown = (event) => {
|
|
12
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
13
|
+
return;
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
toggleZoom();
|
|
16
|
+
};
|
|
17
|
+
return { imageRef, closeRef, zoomed, toggleZoom, onImageKeyDown };
|
|
18
|
+
}
|
|
@@ -361,6 +361,7 @@ export declare function useTextField(props: InputProps, ref: Ref<HTMLInputElemen
|
|
|
361
361
|
placeholder?: string | undefined | undefined;
|
|
362
362
|
readOnly?: boolean | undefined | undefined;
|
|
363
363
|
required?: boolean | undefined | undefined;
|
|
364
|
+
webkitdirectory?: boolean | string | undefined | undefined;
|
|
364
365
|
type?: "text" | "search" | "password" | "email" | "tel" | "url";
|
|
365
366
|
} | {
|
|
366
367
|
id: string;
|
|
@@ -671,6 +672,7 @@ export declare function useTextField(props: InputProps, ref: Ref<HTMLInputElemen
|
|
|
671
672
|
placeholder?: string | undefined | undefined;
|
|
672
673
|
readOnly?: boolean | undefined | undefined;
|
|
673
674
|
required?: boolean | undefined | undefined;
|
|
675
|
+
webkitdirectory?: boolean | string | undefined | undefined;
|
|
674
676
|
type?: "text" | "search" | "password" | "email" | "tel" | "url";
|
|
675
677
|
};
|
|
676
678
|
};
|
|
@@ -319,6 +319,7 @@ export declare const useMask: (props: MaskedInputProps, inputRef: React.RefObjec
|
|
|
319
319
|
placeholder?: string | undefined | undefined;
|
|
320
320
|
readOnly?: boolean | undefined | undefined;
|
|
321
321
|
required?: boolean | undefined | undefined;
|
|
322
|
+
webkitdirectory?: boolean | string | undefined | undefined;
|
|
322
323
|
type?: "text" | "search" | "password" | "email" | "tel" | "url";
|
|
323
324
|
defaultValue?: string;
|
|
324
325
|
classNames?: import("..").ComponentClassNames<"Input">;
|
|
@@ -642,6 +643,7 @@ export declare const useMask: (props: MaskedInputProps, inputRef: React.RefObjec
|
|
|
642
643
|
placeholder?: string | undefined | undefined;
|
|
643
644
|
readOnly?: boolean | undefined | undefined;
|
|
644
645
|
required?: boolean | undefined | undefined;
|
|
646
|
+
webkitdirectory?: boolean | string | undefined | undefined;
|
|
645
647
|
type?: "text" | "search" | "password" | "email" | "tel" | "url";
|
|
646
648
|
defaultValue?: string;
|
|
647
649
|
classNames?: import("..").ComponentClassNames<"Input">;
|
package/modal/modal.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const Modal: import("react").ForwardRefExoticComponent<import("..
|
|
|
13
13
|
theme?: import("..").ThemeSetting;
|
|
14
14
|
modalID?: string;
|
|
15
15
|
show: boolean;
|
|
16
|
+
animated?: boolean;
|
|
16
17
|
size?: import("./types").ModalSize;
|
|
17
18
|
variant?: import("./types").ModalVariant;
|
|
18
19
|
toTop?: boolean;
|
package/modal/modal.js
CHANGED
|
@@ -28,22 +28,16 @@ export { getTimerCurtain } from './utils';
|
|
|
28
28
|
</Modal>;
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export const Modal = withRef(function Modal({ children, modalID, className = '', classNames: classNamesProp, onClose, size = 'm', variant = 'simple', show, toTop = false, sticky, closeButton = true, overlayClose = true, container, theme, ...dataProps }, ref) {
|
|
31
|
+
export const Modal = withRef(function Modal({ children, modalID, className = '', classNames: classNamesProp, onClose, size = 'm', variant = 'simple', show, animated = true, toTop = false, sticky, closeButton = true, overlayClose = true, container, theme, ...dataProps }, ref) {
|
|
32
32
|
const classNames = useClassNames('Modal', classNamesProp);
|
|
33
|
-
const { modalRef, overlayRef, nodeRef, timeout, style, scroll, changeContentOnScroll } = useModal({
|
|
34
|
-
show,
|
|
35
|
-
onClose,
|
|
36
|
-
overlayClose,
|
|
37
|
-
variant,
|
|
38
|
-
children,
|
|
39
|
-
});
|
|
33
|
+
const { modalRef, overlayRef, nodeRef, timeout, style, scroll, changeContentOnScroll, renderedChildren, onExited, } = useModal({ show, onClose, overlayClose, variant, children });
|
|
40
34
|
const themeAttribute = useThemeAttribute(theme, { portal: true });
|
|
41
35
|
const overLayClass = clsx(styles.overlay, styles[variant], classNames.overlay);
|
|
42
36
|
const modalClass = clsx(styles.modal, styles[variant], styles[size], sticky && styles.sticky, classNames.root, className);
|
|
43
37
|
const wrapperClass = clsx(styles.wrapper, styles[size], styles[variant], toTop && styles.toTop, classNames.wrapper);
|
|
44
38
|
const scrollContext = useMemo(() => ({ changeContentOnScroll, scrollTop: scroll.top, scrollBottom: scroll.bottom }), [changeContentOnScroll, scroll.top, scroll.bottom]);
|
|
45
39
|
const modalContext = useMemo(() => ({ variant, sticky, size, classNames }), [variant, sticky, size, classNames]);
|
|
46
|
-
return (_jsx(Portal, { container: container, children: _jsx(CSSTransition, { nodeRef: nodeRef, timeout: timeout, in: show,
|
|
40
|
+
return (_jsx(Portal, { container: container, children: _jsx(CSSTransition, { nodeRef: nodeRef, timeout: animated ? timeout : 0, in: show, enter: animated, exit: animated, onExited: onExited,
|
|
47
41
|
// Окно, смонтированное уже открытым (`{open && <Modal show />}`), тоже должно появляться с анимацией
|
|
48
42
|
appear: true, classNames: {
|
|
49
43
|
appear: styles.modalTransitionEnter,
|
|
@@ -52,5 +46,5 @@ export const Modal = withRef(function Modal({ children, modalID, className = '',
|
|
|
52
46
|
enterActive: styles.modalTransitionEnterActive,
|
|
53
47
|
exit: styles.modalTransitionExit,
|
|
54
48
|
exitActive: styles.modalTransitionExitActive,
|
|
55
|
-
}, unmountOnExit: true, children: _jsxs("div", { className: styles.animationWrapper, ref: nodeRef, children: [_jsx(RestoreFocus, {}), _jsx(FocusTrap, { children: _jsx("div", { ref: overlayRef, className: overLayClass, style: style, "data-lt-ui-theme": themeAttribute, ...getDataAttributes(dataProps, 'modal'), "data-lt-ui": "modal", children: _jsx("div", { className: wrapperClass, ref: ref, children: _jsxs("div", { className: modalClass, role: "dialog", "aria-modal": "true", "aria-labelledby": modalID && `${modalID}_label`, "aria-describedby": modalID && `${modalID}_desc`, ref: modalRef, children: [closeButton && _jsx(ModalCloseButton, { onClose: onClose, className: classNames.close }), _jsx(ScrollProvider, { value: scrollContext, children: _jsx(ModalProvider, { value: modalContext, children: _jsx(FocusOnProvider, { value: true, children: _jsx("div", { className: styles.contentWrapper, children:
|
|
49
|
+
}, unmountOnExit: true, children: _jsxs("div", { className: clsx(styles.animationWrapper, !animated && styles.motionDisabled), ref: nodeRef, children: [_jsx(RestoreFocus, {}), _jsx(FocusTrap, { children: _jsx("div", { ref: overlayRef, className: overLayClass, style: style, "data-lt-ui-theme": themeAttribute, ...getDataAttributes(dataProps, 'modal'), "data-lt-ui": "modal", children: _jsx("div", { className: wrapperClass, ref: ref, children: _jsxs("div", { className: modalClass, role: "dialog", "aria-modal": "true", "aria-labelledby": modalID && `${modalID}_label`, "aria-describedby": modalID && `${modalID}_desc`, ref: modalRef, children: [closeButton && _jsx(ModalCloseButton, { onClose: onClose, className: classNames.close }), _jsx(ScrollProvider, { value: scrollContext, children: _jsx(ModalProvider, { value: modalContext, children: _jsx(FocusOnProvider, { value: true, children: _jsx("div", { className: styles.contentWrapper, children: renderedChildren }) }) }) })] }) }) }) })] }) }) }));
|
|
56
50
|
});
|