@mrktg-common/internal-ui 1.12.0 → 1.14.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/Combobox.js +21 -18
- package/dist/SelectMenu.js +28 -21
- package/dist/Toast.d.ts +9 -1
- package/dist/Toast.js +58 -15
- package/dist/activeOption.d.ts +5 -6
- package/dist/activeOption.js +10 -4
- package/dist/components.css +5 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/tokens/tokens.json +1 -1
package/dist/Combobox.js
CHANGED
|
@@ -7,7 +7,7 @@ import { FixedPortal } from './portal.js';
|
|
|
7
7
|
import { Spinner } from './Spinner.js';
|
|
8
8
|
import { cx } from './cx.js';
|
|
9
9
|
import { devError } from './devWarn.js';
|
|
10
|
-
import { openingActive, stepActive } from './activeOption.js';
|
|
10
|
+
import { isKeysActive, openingActive, stepActive } from './activeOption.js';
|
|
11
11
|
const GAP = 4;
|
|
12
12
|
const EDGE = 12;
|
|
13
13
|
const defaultEmptyText = (query) => `No options match “${query}”`;
|
|
@@ -19,8 +19,10 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
19
19
|
const [open, setOpen] = useState(false);
|
|
20
20
|
// Кнопка открывает весь список, ввод — отфильтрованный
|
|
21
21
|
const [filtering, setFiltering] = useState(false);
|
|
22
|
-
|
|
23
|
-
const [
|
|
22
|
+
// Куда поставила клавиатура и что под мышью; Enter берёт пункт под мышью, иначе пункт клавиатуры
|
|
23
|
+
const [keysIndex, setKeysIndex] = useState(null);
|
|
24
|
+
const [pointerIndex, setPointerIndex] = useState(null);
|
|
25
|
+
const active = pointerIndex ?? keysIndex;
|
|
24
26
|
const [listStyle, setListStyle] = useState({ visibility: 'hidden' });
|
|
25
27
|
const rootRef = useRef(null);
|
|
26
28
|
const inputRef = useRef(null);
|
|
@@ -83,7 +85,8 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
83
85
|
if (!visible)
|
|
84
86
|
return;
|
|
85
87
|
// В jsdom прокрутки нет: тесты потребителей не должны падать на ней
|
|
86
|
-
|
|
88
|
+
if (active !== null)
|
|
89
|
+
document.getElementById(optionId(active))?.scrollIntoView?.({ block: 'nearest' });
|
|
87
90
|
});
|
|
88
91
|
const show = ({ filter, byKeys }) => {
|
|
89
92
|
if (failed)
|
|
@@ -93,10 +96,10 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
93
96
|
setFiltering(filter);
|
|
94
97
|
const current = all.findIndex((option) => option.value === value);
|
|
95
98
|
if (filter)
|
|
96
|
-
|
|
99
|
+
setKeysIndex(0);
|
|
97
100
|
else
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
setKeysIndex(byKeys ? openingActive(current) : null);
|
|
102
|
+
setPointerIndex(null);
|
|
100
103
|
setOpen(true);
|
|
101
104
|
};
|
|
102
105
|
const commit = (next) => {
|
|
@@ -120,12 +123,12 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
120
123
|
if (shown.length === 0)
|
|
121
124
|
return;
|
|
122
125
|
const checked = shown.findIndex((option) => option.value === value);
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
setKeysIndex(stepActive({ active, checked, step: event.key === 'ArrowDown' ? 1 : -1, count: shown.length }));
|
|
127
|
+
setPointerIndex(null);
|
|
125
128
|
}
|
|
126
129
|
else if (event.key === 'Enter') {
|
|
127
|
-
//
|
|
128
|
-
const option = visible && !loading &&
|
|
130
|
+
// Без активного пункта (открыт шевроном, мышь ушла) Enter оставляет текст как есть
|
|
131
|
+
const option = visible && !loading && active !== null ? shown[active] : undefined;
|
|
129
132
|
if (visible)
|
|
130
133
|
event.preventDefault();
|
|
131
134
|
if (option === undefined) {
|
|
@@ -145,7 +148,7 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
145
148
|
setOpen(false);
|
|
146
149
|
}
|
|
147
150
|
};
|
|
148
|
-
const activeOption = visible && !loading &&
|
|
151
|
+
const activeOption = visible && !loading && active !== null && shown[active] !== undefined ? optionId(active) : undefined;
|
|
149
152
|
return (_jsxs("div", { className: cx('combo', className), ref: rootRef, children: [_jsx("input", { ref: inputRef, id: id, type: "text", className: controlClass({ size, invalid, mono }), role: "combobox", "aria-autocomplete": "list", "aria-expanded": visible, "aria-controls": visible ? listId : undefined, "aria-activedescendant": activeOption, "aria-invalid": invalid || undefined, autoComplete: "off", value: value, placeholder: placeholder, disabled: disabled, onChange: (event) => {
|
|
150
153
|
committed.current = null;
|
|
151
154
|
onChange(event.target.value);
|
|
@@ -161,17 +164,17 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
161
164
|
setOpen(false);
|
|
162
165
|
else
|
|
163
166
|
show({ filter: false, byKeys: false });
|
|
164
|
-
}, children: _jsx(ChevronDown, { className: "ic", "aria-hidden": true }) })), visible && (_jsx(FixedPortal, { children: _jsx("div", { ref: listRef, className: "pop pop-scroll", style: listStyle, role: "listbox", id: listId, "aria-labelledby": id,
|
|
167
|
+
}, children: _jsx(ChevronDown, { className: "ic", "aria-hidden": true }) })), visible && (_jsx(FixedPortal, { children: _jsx("div", { ref: listRef, className: "pop pop-scroll", style: listStyle, role: "listbox", id: listId, "aria-labelledby": id,
|
|
168
|
+
// Уход мыши снимает её пункт: полоса возвращается на пункт клавиатуры, если он есть
|
|
169
|
+
onMouseLeave: () => setPointerIndex(null), children: loading ? (_jsx("div", { className: "menu-empty", role: "status", children: _jsxs("span", { className: "row", style: { justifyContent: 'center' }, children: [_jsx(Spinner, { size: "sm" }), "Loading\u2026"] }) })) : shown.length === 0 ? (_jsxs("div", { className: "menu-empty", children: [_jsx("span", { className: "strong", children: emptyText(query) }), _jsx("span", { className: "hint", children: "You can keep it as typed." })] })) : (shownGroups.map((group, groupIndex) => {
|
|
165
170
|
const rows = group.options.map((option) => {
|
|
166
171
|
const index = shown.indexOf(option);
|
|
167
172
|
const isCurrent = option.value === value;
|
|
168
|
-
return (_jsxs("div", { id: optionId(index), role: "option", "aria-selected": isCurrent, className: cx('menu-item',
|
|
173
|
+
return (_jsxs("div", { id: optionId(index), role: "option", "aria-selected": isCurrent, className: cx('menu-item', mono && 'mono', isKeysActive(index, keysIndex, pointerIndex) && 'is-active'), onMouseDown: (event) => event.preventDefault(),
|
|
169
174
|
// Только настоящее движение мыши: список, открытый или прокрученный под курсором, пункт не меняет
|
|
170
175
|
onMouseMove: () => {
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
setActive(index);
|
|
174
|
-
setActiveSource('pointer');
|
|
176
|
+
if (pointerIndex !== index)
|
|
177
|
+
setPointerIndex(index);
|
|
175
178
|
}, onClick: () => pick(option), children: [_jsx("span", { className: "trunc", children: filtering ? _jsx(Highlight, { text: option.value, query: query }) : option.value }), option.trailing !== undefined && _jsx("span", { className: "trail", children: option.trailing }), isCurrent && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, option.value));
|
|
176
179
|
});
|
|
177
180
|
if (group.label === null)
|
package/dist/SelectMenu.js
CHANGED
|
@@ -6,7 +6,7 @@ import { cx } from './cx.js';
|
|
|
6
6
|
import { buttonClass } from './buttonClass.js';
|
|
7
7
|
import { controlClass } from './Field.js';
|
|
8
8
|
import { FixedPortal } from './portal.js';
|
|
9
|
-
import { openingActive, stepActive } from './activeOption.js';
|
|
9
|
+
import { isKeysActive, openingActive, stepActive } from './activeOption.js';
|
|
10
10
|
const GAP = 4;
|
|
11
11
|
const EDGE = 12;
|
|
12
12
|
/**
|
|
@@ -24,8 +24,10 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
24
24
|
.filter((group) => group.items.length > 0),
|
|
25
25
|
];
|
|
26
26
|
const items = shownGroups.flatMap((group) => group.items);
|
|
27
|
-
|
|
28
|
-
const [
|
|
27
|
+
// Куда поставила клавиатура и что под мышью; Enter берёт пункт под мышью, иначе пункт клавиатуры
|
|
28
|
+
const [keysIndex, setKeysIndex] = useState(null);
|
|
29
|
+
const [pointerIndex, setPointerIndex] = useState(null);
|
|
30
|
+
const active = pointerIndex ?? keysIndex;
|
|
29
31
|
const rootRef = useRef(null);
|
|
30
32
|
const buttonRef = useRef(null);
|
|
31
33
|
const menuRef = useRef(null);
|
|
@@ -84,14 +86,15 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
84
86
|
if (!open)
|
|
85
87
|
return;
|
|
86
88
|
// В jsdom прокрутки нет: тесты потребителей не должны падать на ней
|
|
87
|
-
|
|
89
|
+
if (active !== null)
|
|
90
|
+
menuRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView?.({ block: 'nearest' });
|
|
88
91
|
}, [open, active]);
|
|
89
92
|
const openMenu = ({ byKeys }) => {
|
|
90
93
|
setMenuStyle({ visibility: 'hidden' });
|
|
91
94
|
setQuery('');
|
|
92
95
|
const checked = items.findIndex((item) => item.value === value);
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
setKeysIndex(byKeys ? openingActive(checked) : null);
|
|
97
|
+
setPointerIndex(null);
|
|
95
98
|
setOpen(true);
|
|
96
99
|
};
|
|
97
100
|
const close = () => {
|
|
@@ -120,13 +123,13 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
120
123
|
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
121
124
|
event.preventDefault();
|
|
122
125
|
const checked = items.findIndex((item) => item.value === value);
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
setKeysIndex(stepActive({ active, checked, step: event.key === 'ArrowDown' ? 1 : -1, count: items.length }));
|
|
127
|
+
setPointerIndex(null);
|
|
125
128
|
}
|
|
126
129
|
else if (event.key === 'Enter') {
|
|
127
130
|
event.preventDefault();
|
|
128
|
-
//
|
|
129
|
-
const item =
|
|
131
|
+
// Без активного пункта (открыт кликом, мышь ушла) Enter закрывает без изменений
|
|
132
|
+
const item = active === null ? undefined : items[active];
|
|
130
133
|
if (item === undefined)
|
|
131
134
|
close();
|
|
132
135
|
else
|
|
@@ -137,36 +140,40 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
137
140
|
}
|
|
138
141
|
else if (search === undefined && event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
139
142
|
const letter = event.key.toLowerCase();
|
|
140
|
-
const from =
|
|
143
|
+
const from = active ?? items.findIndex((item) => item.value === value);
|
|
141
144
|
const order = [...items.slice(from + 1), ...items.slice(0, from + 1)];
|
|
142
145
|
const match = order.find((item) => item.label.toLowerCase().startsWith(letter));
|
|
143
146
|
if (match !== undefined) {
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
setKeysIndex(items.indexOf(match));
|
|
148
|
+
setPointerIndex(null);
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
};
|
|
149
152
|
const optionId = (index) => `${listId}-option-${index}`;
|
|
150
153
|
// Только когда активный пункт есть: у списка, открытого кликом, его нет
|
|
151
|
-
const activeOption = open &&
|
|
154
|
+
const activeOption = open && active !== null && items[active] !== undefined ? optionId(active) : undefined;
|
|
155
|
+
// Без поиска триггер — select-only combobox: на кнопке aria-activedescendant дикторы не озвучивают.
|
|
156
|
+
// С поиском combobox — поле поиска, триггер остаётся кнопкой
|
|
157
|
+
const triggerCombobox = search === undefined;
|
|
152
158
|
const triggerClass = filter === undefined
|
|
153
159
|
? controlClass({ size, invalid }, 'select-btn')
|
|
154
160
|
: buttonClass({ variant: 'secondary', size, active: filter.active });
|
|
155
|
-
return (_jsxs("div", { className: cx('anchor', className), style: filter === undefined ? { display: 'flex' } : undefined, ref: rootRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { ref: buttonRef, id: id, type: "button", className: triggerClass, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listId : undefined, "aria-activedescendant":
|
|
161
|
+
return (_jsxs("div", { className: cx('anchor', className), style: filter === undefined ? { display: 'flex' } : undefined, ref: rootRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { ref: buttonRef, id: id, type: "button", className: triggerClass, role: triggerCombobox ? 'combobox' : undefined, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": triggerCombobox && open ? listId : undefined, "aria-activedescendant": triggerCombobox ? activeOption : undefined, "aria-invalid": invalid || undefined, disabled: disabled, onClick: () => (open ? setOpen(false) : openMenu({ byKeys: false })), ...aria, children: [filter !== undefined ? filter.label : selected === undefined ? _jsx("span", { className: "muted trunc", children: placeholder ?? value }) : _jsx(ItemContent, { item: selected }), _jsx(ChevronDown, { className: cx('ic', 'chev', filter !== undefined && 'ic-sm'), "aria-hidden": true })] }), open && (_jsx(FixedPortal, { children: _jsxs("div", { ref: menuRef, className: "pop pop-scroll", style: menuStyle, role: "listbox", id: listId, "aria-labelledby": id,
|
|
162
|
+
// Уход мыши снимает её пункт: полоса возвращается на пункт клавиатуры, если он есть
|
|
163
|
+
onMouseLeave: () => setPointerIndex(null), children: [search !== undefined && (_jsx("div", { className: "menu-search", children: _jsxs("label", { className: "with-icon", children: [_jsx(SearchIcon, { className: "ic", "aria-hidden": true }), _jsx("span", { className: "sr-only", children: search.label }), _jsx("input", { ref: searchRef, className: "control control-sm", value: query, placeholder: search.placeholder, role: "combobox", "aria-autocomplete": "list", "aria-expanded": "true", "aria-controls": listId, "aria-activedescendant": activeOption, onChange: (event) => {
|
|
156
164
|
setQuery(event.target.value);
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
setKeysIndex(0);
|
|
166
|
+
setPointerIndex(null);
|
|
159
167
|
} })] }) })), items.length === 0 && (_jsxs("div", { className: "menu-empty", children: [_jsxs("span", { className: "strong", children: ["Nothing matches \u201C", query.trim(), "\u201D"] }), _jsx("span", { className: "hint", children: "Try a shorter name." })] })), shownGroups.map((group, groupIndex) => (_jsxs("div", { role: "group", "aria-label": group.label ?? undefined, children: [group.label !== null && _jsx("div", { className: "menu-label", children: group.label }), group.note !== undefined && (_jsxs("div", { className: "menu-note", children: [_jsx(TriangleAlert, { className: "ic ic-sm", "aria-hidden": true }), _jsx("span", { children: group.note })] })), group.items.map((item) => {
|
|
160
168
|
const index = items.indexOf(item);
|
|
161
169
|
const isSelected = item.value === value;
|
|
162
|
-
return (_jsxs("button", { type: "button", role: "option", id: optionId(index), "data-index": index, tabIndex: -1, "aria-selected": isSelected, "aria-disabled": item.disabled || undefined, className: cx('menu-item', index
|
|
170
|
+
return (_jsxs("button", { type: "button", role: "option", id: optionId(index), "data-index": index, tabIndex: -1, "aria-selected": isSelected, "aria-disabled": item.disabled || undefined, className: cx('menu-item', isKeysActive(index, keysIndex, pointerIndex) && 'is-active'),
|
|
163
171
|
// Только настоящее движение мыши: список, открытый или прокрученный под курсором, пункт не меняет.
|
|
164
172
|
// Выключенный пункт под мышью не меняется
|
|
165
173
|
onMouseMove: () => {
|
|
166
|
-
if (item.disabled ||
|
|
174
|
+
if (item.disabled || pointerIndex === index)
|
|
167
175
|
return;
|
|
168
|
-
|
|
169
|
-
setActiveSource('pointer');
|
|
176
|
+
setPointerIndex(index);
|
|
170
177
|
}, onClick: () => choose(item), children: [_jsx(ItemContent, { item: item }), item.trailing !== undefined && _jsx("span", { className: "trail", children: item.trailing }), isSelected && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, item.value));
|
|
171
178
|
})] }, group.label ?? `group-${groupIndex}`)))] }) }))] }));
|
|
172
179
|
}
|
package/dist/Toast.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export type TToastAction = {
|
|
|
5
5
|
label: string;
|
|
6
6
|
onClick: () => void;
|
|
7
7
|
icon?: LucideIcon;
|
|
8
|
+
/** Действие идёт: спиннер вместо иконки, нажатия не проходят, таймер тоста стоит. */
|
|
9
|
+
busy?: boolean;
|
|
10
|
+
/** Нажатие не закрывает тост: результат придёт позже, через update. */
|
|
11
|
+
keepOpen?: boolean;
|
|
8
12
|
};
|
|
9
13
|
export type TToast = {
|
|
10
14
|
/** neutral — сохранено, удалено, скопировано; success — только «vN is live» (на Production или Test). */
|
|
@@ -20,9 +24,13 @@ export type TToast = {
|
|
|
20
24
|
/** Сколько висит, мс; null — пока не закроют. По умолчанию 6 с, с Undo 10 с, ошибки висят. */
|
|
21
25
|
duration?: number | null;
|
|
22
26
|
};
|
|
27
|
+
/** Поле со значением undefined убирается: `{ action: undefined }` снимает кнопку. */
|
|
28
|
+
export type TToastPatch = Partial<Pick<TToast, 'tone' | 'icon' | 'title' | 'description' | 'action' | 'duration'>>;
|
|
23
29
|
export type TToastApi = {
|
|
24
30
|
show: (toast: TToast) => number;
|
|
25
31
|
dismiss: (id: number) => void;
|
|
32
|
+
/** Меняет показанный тост на месте и запускает его таймер заново; закрытый тост не возвращает. */
|
|
33
|
+
update: (id: number, patch: TToastPatch) => void;
|
|
26
34
|
};
|
|
27
35
|
export declare const TOAST_MS = 6000;
|
|
28
36
|
export declare const TOAST_UNDO_MS = 10000;
|
|
@@ -36,7 +44,7 @@ export declare function useToast(): TToastApi;
|
|
|
36
44
|
export declare function useToastInsetEnd(width: number | null): void;
|
|
37
45
|
/**
|
|
38
46
|
* Что только что произошло: справа снизу, до трёх штук, новый внизу. Таймеры стоят, пока указатель
|
|
39
|
-
* над стопкой или фокус внутри
|
|
47
|
+
* над стопкой или фокус внутри неё, и пока идёт действие тоста. Закрыть можно всегда.
|
|
40
48
|
*/
|
|
41
49
|
export declare function ToastProvider({ children }: {
|
|
42
50
|
children: ReactNode;
|
package/dist/Toast.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { Check, CircleCheck, CircleX, Info, TriangleAlert, Undo2, X } from 'lucide-react';
|
|
5
|
+
import { Button } from './Button.js';
|
|
5
6
|
import { cx } from './cx.js';
|
|
6
7
|
import { FixedPortal } from './portal.js';
|
|
7
8
|
export const TOAST_MS = 6000;
|
|
@@ -39,7 +40,7 @@ export function useToastInsetEnd(width) {
|
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Что только что произошло: справа снизу, до трёх штук, новый внизу. Таймеры стоят, пока указатель
|
|
42
|
-
* над стопкой или фокус внутри
|
|
43
|
+
* над стопкой или фокус внутри неё, и пока идёт действие тоста. Закрыть можно всегда.
|
|
43
44
|
*/
|
|
44
45
|
export function ToastProvider({ children }) {
|
|
45
46
|
const [toasts, setToasts] = useState([]);
|
|
@@ -48,34 +49,66 @@ export function ToastProvider({ children }) {
|
|
|
48
49
|
const dismiss = useCallback((id) => setToasts((current) => current.filter((toast) => toast.id !== id)), []);
|
|
49
50
|
const show = useCallback((toast) => {
|
|
50
51
|
const id = nextId.current++;
|
|
51
|
-
setToasts((current) => [...current, { ...toast, id }].slice(-MAX_TOASTS));
|
|
52
|
+
setToasts((current) => [...current, { ...toast, id, node: 0, revision: 0 }].slice(-MAX_TOASTS));
|
|
52
53
|
return id;
|
|
53
54
|
}, []);
|
|
54
|
-
const
|
|
55
|
+
const update = useCallback((id, patch) => {
|
|
56
|
+
setToasts((current) => {
|
|
57
|
+
const shown = current.find((toast) => toast.id === id);
|
|
58
|
+
if (shown === undefined)
|
|
59
|
+
return current;
|
|
60
|
+
const next = { ...shown, ...patch, revision: shown.revision + 1 };
|
|
61
|
+
// role="alert" читается, только если стоит на узле в момент появления: ошибка приходит новым тостом
|
|
62
|
+
if (next.tone === 'danger' && shown.tone !== 'danger') {
|
|
63
|
+
return [...current.filter((toast) => toast !== shown), { ...next, node: shown.node + 1 }];
|
|
64
|
+
}
|
|
65
|
+
return current.map((toast) => (toast === shown ? next : toast));
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
const api = useMemo(() => ({ show, dismiss, update }), [show, dismiss, update]);
|
|
55
69
|
return (_jsx(ToastContext.Provider, { value: api, children: _jsxs(ToastInsetContext.Provider, { value: setInsetEnd, children: [children, _jsx(ToastStack, { toasts: toasts, insetEnd: insetEnd, onDismiss: dismiss })] }) }));
|
|
56
70
|
}
|
|
57
71
|
function ToastStack({ toasts, insetEnd, onDismiss }) {
|
|
58
72
|
const [hovered, setHovered] = useState(false);
|
|
59
73
|
const [focused, setFocused] = useState(false);
|
|
60
74
|
const paused = hovered || focused;
|
|
75
|
+
const stack = useRef(null);
|
|
76
|
+
// Тост ушёл вместе с кнопкой, на которой был фокус: blur не приходит, а таймеры остальных стоять не должны
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (stack.current?.contains(document.activeElement) !== true)
|
|
79
|
+
setFocused(false);
|
|
80
|
+
}, [toasts]);
|
|
61
81
|
if (toasts.length === 0)
|
|
62
82
|
return null;
|
|
63
83
|
const style = { '--toast-inset-end': `${insetEnd}px` };
|
|
64
|
-
return (_jsx(FixedPortal, { children: _jsx("div", { className: "toasts is-fixed", style: style, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onFocus: () => setFocused(true), onBlur: (event) => {
|
|
84
|
+
return (_jsx(FixedPortal, { children: _jsx("div", { ref: stack, className: "toasts is-fixed", style: style, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), onFocus: () => setFocused(true), onBlur: (event) => {
|
|
65
85
|
if (!event.currentTarget.contains(event.relatedTarget))
|
|
66
86
|
setFocused(false);
|
|
67
|
-
}, children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, paused: paused, onDismiss: () => onDismiss(toast.id) }, toast.id))) }) }));
|
|
87
|
+
}, children: toasts.map((toast) => (_jsx(ToastItem, { toast: toast, paused: paused, onDismiss: () => onDismiss(toast.id) }, `${toast.id}:${toast.node}`))) }) }));
|
|
68
88
|
}
|
|
69
89
|
function ToastItem({ toast, paused, onDismiss }) {
|
|
70
90
|
const duration = toastDuration(toast);
|
|
91
|
+
const tone = toast.tone ?? 'neutral';
|
|
92
|
+
const Icon = toast.icon ?? TONE_ICON[tone];
|
|
93
|
+
const action = toast.undo === undefined ? toast.action : { label: 'Undo', onClick: toast.undo, icon: Undo2 };
|
|
94
|
+
const ActionIcon = action?.icon;
|
|
95
|
+
const busy = action?.busy === true;
|
|
96
|
+
const hasAction = action !== undefined;
|
|
97
|
+
const stopped = paused || busy;
|
|
71
98
|
// Остаток времени копится между паузами: наведение не сбрасывает таймер на полный срок
|
|
72
99
|
const remaining = useRef(duration);
|
|
100
|
+
const revision = useRef(toast.revision);
|
|
73
101
|
const dismissRef = useRef(onDismiss);
|
|
74
102
|
useEffect(() => {
|
|
75
103
|
dismissRef.current = onDismiss;
|
|
76
104
|
});
|
|
77
105
|
useEffect(() => {
|
|
78
|
-
|
|
106
|
+
// После update срок идёт заново, по правилам нового содержимого
|
|
107
|
+
if (revision.current !== toast.revision) {
|
|
108
|
+
revision.current = toast.revision;
|
|
109
|
+
remaining.current = duration;
|
|
110
|
+
}
|
|
111
|
+
if (stopped || remaining.current === null)
|
|
79
112
|
return;
|
|
80
113
|
const startedAt = Date.now();
|
|
81
114
|
const timer = window.setTimeout(() => dismissRef.current(), remaining.current);
|
|
@@ -84,13 +117,23 @@ function ToastItem({ toast, paused, onDismiss }) {
|
|
|
84
117
|
if (remaining.current !== null)
|
|
85
118
|
remaining.current = Math.max(0, remaining.current - (Date.now() - startedAt));
|
|
86
119
|
};
|
|
87
|
-
}, [
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
}, [stopped, toast.revision, duration]);
|
|
121
|
+
// update убрал кнопку, на которой был фокус: он не должен уйти из тоста на страницу
|
|
122
|
+
const dismissButton = useRef(null);
|
|
123
|
+
const actionFocused = useRef(false);
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
if (hasAction || !actionFocused.current)
|
|
126
|
+
return;
|
|
127
|
+
actionFocused.current = false;
|
|
128
|
+
dismissButton.current?.focus();
|
|
129
|
+
}, [hasAction]);
|
|
130
|
+
return (_jsxs("div", { className: "toast", role: tone === 'danger' ? 'alert' : 'status', "aria-atomic": "true", children: [_jsx(Icon, { className: cx('ic', `t-${tone}`), "aria-hidden": true }), _jsxs("div", { className: "toast-body", children: [_jsx("span", { className: "toast-title", children: toast.title }), toast.description !== undefined && _jsx("span", { className: "toast-desc", children: toast.description }), action !== undefined && (_jsx("div", { className: "toast-act", children: _jsxs(Button, { size: "sm", busy: busy, onFocus: () => {
|
|
131
|
+
actionFocused.current = true;
|
|
132
|
+
}, onBlur: () => {
|
|
133
|
+
actionFocused.current = false;
|
|
134
|
+
}, onClick: () => {
|
|
135
|
+
if (action.keepOpen !== true)
|
|
136
|
+
onDismiss();
|
|
94
137
|
action.onClick();
|
|
95
|
-
}, children: [ActionIcon && _jsx(ActionIcon, { className: "ic ic-sm", "aria-hidden": true }), action.label] }) }))] }), _jsx("button", { type: "button", className: "btn btn-ghost btn-sm btn-icon", "aria-label": "Dismiss", onClick: onDismiss, children: _jsx(X, { className: "ic", "aria-hidden": true }) })] }));
|
|
138
|
+
}, children: [ActionIcon && !busy && _jsx(ActionIcon, { className: "ic ic-sm", "aria-hidden": true }), action.label] }) }))] }), _jsx("button", { ref: dismissButton, type: "button", className: "btn btn-ghost btn-sm btn-icon", "aria-label": "Dismiss", onClick: onDismiss, children: _jsx(X, { className: "ic", "aria-hidden": true }) })] }));
|
|
96
139
|
}
|
package/dist/activeOption.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
/** Откуда активный пункт: с клавиатуры — полоса is-active, от мыши — только :hover, нет — список открыт кликом */
|
|
2
|
-
export type TActiveSource = 'keys' | 'pointer' | 'none';
|
|
3
1
|
interface IStepActiveArgs {
|
|
4
|
-
active: number;
|
|
5
|
-
source: TActiveSource;
|
|
2
|
+
active: number | null;
|
|
6
3
|
checked: number;
|
|
7
4
|
step: 1 | -1;
|
|
8
5
|
count: number;
|
|
9
6
|
}
|
|
10
|
-
/** Пункт после ↓ / ↑: от активного, а если его нет — от отмеченного галочкой; без
|
|
11
|
-
export declare function stepActive({ active,
|
|
7
|
+
/** Пункт после ↓ / ↑: от активного, а если его нет — от отмеченного галочкой; без обоих ↓ берёт первый, ↑ последний */
|
|
8
|
+
export declare function stepActive({ active, checked, step, count }: IStepActiveArgs): number;
|
|
12
9
|
/** Пункт при открытии стрелкой: текущее значение, иначе первый */
|
|
13
10
|
export declare function openingActive(checked: number): number;
|
|
11
|
+
/** Пункт, у которого полоса: тот, что выбрала клавиатура, пока под мышью ничего нет */
|
|
12
|
+
export declare function isKeysActive(index: number, keysIndex: number | null, pointerIndex: number | null): boolean;
|
|
14
13
|
export {};
|
package/dist/activeOption.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// Активный пункт Select menu и Combobox: тот, что возьмёт Enter (карточки, раздел «Active option»)
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Активный пункт Select menu и Combobox: тот, что возьмёт Enter (карточки, раздел «Active option»).
|
|
2
|
+
// Два источника: куда поставила клавиатура (keys) и что под мышью (pointer). Активный — pointer ?? keys,
|
|
3
|
+
// полоса is-active — только у пункта клавиатуры, пока мышь ничего не отметила.
|
|
4
|
+
/** Пункт после ↓ / ↑: от активного, а если его нет — от отмеченного галочкой; без обоих ↓ берёт первый, ↑ последний */
|
|
5
|
+
export function stepActive({ active, checked, step, count }) {
|
|
4
6
|
if (count === 0)
|
|
5
7
|
return 0;
|
|
6
|
-
const from =
|
|
8
|
+
const from = active ?? checked;
|
|
7
9
|
if (from < 0 || from >= count)
|
|
8
10
|
return step === 1 ? 0 : count - 1;
|
|
9
11
|
return (from + step + count) % count;
|
|
@@ -12,3 +14,7 @@ export function stepActive({ active, source, checked, step, count }) {
|
|
|
12
14
|
export function openingActive(checked) {
|
|
13
15
|
return Math.max(0, checked);
|
|
14
16
|
}
|
|
17
|
+
/** Пункт, у которого полоса: тот, что выбрала клавиатура, пока под мышью ничего нет */
|
|
18
|
+
export function isKeysActive(index, keysIndex, pointerIndex) {
|
|
19
|
+
return pointerIndex === null && keysIndex === index;
|
|
20
|
+
}
|
package/dist/components.css
CHANGED
|
@@ -228,8 +228,9 @@
|
|
|
228
228
|
.menu-item.is-active { background: var(--bg-subtle); box-shadow: inset 3px 0 0 var(--accent); }
|
|
229
229
|
.menu-item.is-danger, .menu-item.is-danger > .ic { color: var(--danger-text); }
|
|
230
230
|
.menu-item:disabled, .menu-item[aria-disabled='true'] { color: var(--text-muted); opacity: 0.55; cursor: not-allowed; background: none; }
|
|
231
|
-
/* The keyboard mark on an off item keeps its 3:1: the
|
|
231
|
+
/* The keyboard mark on an off item keeps its 3:1: while the keyboard is on it, the content is dimmed, the ring or the bar is not. */
|
|
232
232
|
.menu-item[aria-disabled='true']:focus-visible, .menu-item.is-focus[aria-disabled='true'], .menu-item.is-active[aria-disabled='true'] { opacity: 1; }
|
|
233
|
+
.menu-item[aria-disabled='true']:focus-visible > *, .menu-item.is-focus[aria-disabled='true'] > *, .menu-item.is-active[aria-disabled='true'] > * { opacity: 0.55; }
|
|
233
234
|
/* Selected option: check on the right, as on the agreed Publish window. */
|
|
234
235
|
.menu-item > .check { margin-left: auto; color: var(--accent-text); }
|
|
235
236
|
.menu-item[aria-selected='true'] { font-weight: 500; }
|
|
@@ -250,6 +251,9 @@
|
|
|
250
251
|
.combo > .control-sm + .combo-btn { right: 1px; width: 24px; height: 24px; }
|
|
251
252
|
.combo > .pop { left: 0; right: 0; min-width: 0; }
|
|
252
253
|
.menu-item mark { background: none; color: inherit; font-weight: 600; }
|
|
254
|
+
/* Codes and keys: the options of a mono field are mono too (.mono alone loses to the item's own font). */
|
|
255
|
+
.menu-item.mono { font-family: var(--font-mono); }
|
|
256
|
+
.menu-item.mono .trail { font-family: var(--font-ui); }
|
|
253
257
|
.menu-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-1) var(--space-1); border-top: 1px solid var(--border); margin-top: var(--space-1); }
|
|
254
258
|
|
|
255
259
|
/* ---------- Badge ---------- */
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export type { IAlertProps, TAlertTone } from './Alert.tsx';
|
|
|
42
42
|
export { Banner } from './Banner.tsx';
|
|
43
43
|
export type { IBannerProps, TBannerTone } from './Banner.tsx';
|
|
44
44
|
export { ToastProvider, useToast, useToastInsetEnd, toastDuration, TOAST_MS, TOAST_UNDO_MS, MAX_TOASTS } from './Toast.tsx';
|
|
45
|
-
export type { TToast, TToastApi, TToastTone, TToastAction } from './Toast.tsx';
|
|
45
|
+
export type { TToast, TToastApi, TToastTone, TToastAction, TToastPatch } from './Toast.tsx';
|
|
46
46
|
export { Tooltip, TOOLTIP_DELAY_MS } from './Tooltip.tsx';
|
|
47
47
|
export type { ITooltipProps } from './Tooltip.tsx';
|
|
48
48
|
export { Skeleton } from './Skeleton.tsx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrktg-common/internal-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Общий интерфейс внутренних инструментов маркетинга (Landings Admin, LP Constructor): токены, классы компонентов и тонкие React-обёртки над ними.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|