@mrktg-common/internal-ui 1.16.0 → 1.17.1
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 +5 -6
- package/dist/Modal.d.ts +3 -1
- package/dist/Modal.js +8 -2
- package/dist/SelectMenu.js +13 -6
- package/dist/Tooltip.js +3 -3
- package/dist/activeOption.d.ts +2 -0
- package/dist/activeOption.js +13 -0
- package/dist/components.css +5 -0
- package/dist/portal.d.ts +7 -1
- package/dist/portal.js +6 -0
- package/package.json +1 -1
- package/tokens/tokens.json +1 -1
package/dist/Combobox.js
CHANGED
|
@@ -3,11 +3,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { Fragment, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
4
|
import { Check, ChevronDown } from 'lucide-react';
|
|
5
5
|
import { controlClass } from './Field.js';
|
|
6
|
-
import { FixedPortal } from './portal.js';
|
|
6
|
+
import { FixedPortal, HIDDEN_OVERLAY } 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 { isKeysActive, openingActive, stepActive } from './activeOption.js';
|
|
10
|
+
import { isKeysActive, openingActive, revealInList, stepActive } from './activeOption.js';
|
|
11
11
|
const GAP = 4;
|
|
12
12
|
const EDGE = 12;
|
|
13
13
|
const defaultEmptyText = (query) => `No options match “${query}”`;
|
|
@@ -23,7 +23,7 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
23
23
|
const [keysIndex, setKeysIndex] = useState(null);
|
|
24
24
|
const [pointerIndex, setPointerIndex] = useState(null);
|
|
25
25
|
const active = pointerIndex ?? keysIndex;
|
|
26
|
-
const [listStyle, setListStyle] = useState(
|
|
26
|
+
const [listStyle, setListStyle] = useState(HIDDEN_OVERLAY);
|
|
27
27
|
const rootRef = useRef(null);
|
|
28
28
|
const inputRef = useRef(null);
|
|
29
29
|
const listRef = useRef(null);
|
|
@@ -84,15 +84,14 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
|
|
|
84
84
|
useLayoutEffect(() => {
|
|
85
85
|
if (!visible)
|
|
86
86
|
return;
|
|
87
|
-
// В jsdom прокрутки нет: тесты потребителей не должны падать на ней
|
|
88
87
|
if (active !== null)
|
|
89
|
-
document.getElementById(optionId(active))
|
|
88
|
+
revealInList(listRef.current, document.getElementById(optionId(active)));
|
|
90
89
|
});
|
|
91
90
|
const show = ({ filter, byKeys }) => {
|
|
92
91
|
if (failed)
|
|
93
92
|
return;
|
|
94
93
|
if (!open)
|
|
95
|
-
setListStyle(
|
|
94
|
+
setListStyle(HIDDEN_OVERLAY);
|
|
96
95
|
setFiltering(filter);
|
|
97
96
|
const current = all.findIndex((option) => option.value === value);
|
|
98
97
|
if (filter)
|
package/dist/Modal.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type TModalSize = 'sm' | 'md' | 'lg';
|
|
|
3
3
|
export interface IModalProps {
|
|
4
4
|
open: boolean;
|
|
5
5
|
title: string;
|
|
6
|
+
/** Короткий статус рядом с заголовком: Badge или Env («Connected before», «Draft»). В имя окна не входит; действия — в футер. */
|
|
7
|
+
titleAside?: ReactNode;
|
|
6
8
|
subtitle?: ReactNode;
|
|
7
9
|
size?: TModalSize;
|
|
8
10
|
/** Ширина не из набора размеров (окно события расписания, 600). */
|
|
@@ -23,4 +25,4 @@ export interface IModalProps {
|
|
|
23
25
|
* Окно для коротких решений и маленьких форм. Фокус не выходит из окна; Esc и клик по фону закрывают,
|
|
24
26
|
* если onClose задан. Cancel в футере — secondary, главная кнопка называет действие.
|
|
25
27
|
*/
|
|
26
|
-
export declare function Modal({ open, title, subtitle, size, width, onClose, footer, footerStart, flush, bodyStyle, initialFocus, children }: IModalProps): import("react").JSX.Element | null;
|
|
28
|
+
export declare function Modal({ open, title, titleAside, subtitle, size, width, onClose, footer, footerStart, flush, bodyStyle, initialFocus, children }: IModalProps): import("react").JSX.Element | null;
|
package/dist/Modal.js
CHANGED
|
@@ -4,15 +4,21 @@ import { useEffect, useId, useRef } from 'react';
|
|
|
4
4
|
import { X } from 'lucide-react';
|
|
5
5
|
import { cx } from './cx.js';
|
|
6
6
|
import { FixedPortal } from './portal.js';
|
|
7
|
+
import { devError } from './devWarn.js';
|
|
7
8
|
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
8
9
|
/**
|
|
9
10
|
* Окно для коротких решений и маленьких форм. Фокус не выходит из окна; Esc и клик по фону закрывают,
|
|
10
11
|
* если onClose задан. Cancel в футере — secondary, главная кнопка называет действие.
|
|
11
12
|
*/
|
|
12
|
-
export function Modal({ open, title, subtitle, size = 'md', width, onClose, footer, footerStart, flush = false, bodyStyle, initialFocus, children }) {
|
|
13
|
+
export function Modal({ open, title, titleAside, subtitle, size = 'md', width, onClose, footer, footerStart, flush = false, bodyStyle, initialFocus, children }) {
|
|
13
14
|
const modalRef = useRef(null);
|
|
14
15
|
const titleId = useId();
|
|
15
16
|
const previous = useRef(null);
|
|
17
|
+
const asideRef = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (asideRef.current?.querySelector('button, a[href]'))
|
|
20
|
+
devError('Modal: titleAside is a status, not an action; put buttons and links in the footer.');
|
|
21
|
+
});
|
|
16
22
|
useEffect(() => {
|
|
17
23
|
if (!open)
|
|
18
24
|
return;
|
|
@@ -62,5 +68,5 @@ export function Modal({ open, title, subtitle, size = 'md', width, onClose, foot
|
|
|
62
68
|
if (event.target === event.currentTarget)
|
|
63
69
|
onClose?.();
|
|
64
70
|
};
|
|
65
|
-
return (_jsx(FixedPortal, { children: _jsx("div", { className: "overlay is-fixed", onMouseDown: closeOnOverlay, children: _jsxs("div", { ref: modalRef, className: cx('modal', `modal-${size}`), style: width === undefined ? undefined : { maxWidth: width }, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, tabIndex: -1, onKeyDown: trapFocus, children: [_jsxs("div", { className: "modal-head", children: [_jsxs("div", { className: "modal-heading", children: [_jsx("h2", { className: "modal-title", id: titleId, children: title }), subtitle !== undefined && _jsx("span", { className: "modal-sub", children: subtitle })] }), onClose !== null && (_jsx("button", { type: "button", className: "btn btn-ghost btn-sm btn-icon", "aria-label": "Close", onClick: onClose, children: _jsx(X, { className: "ic", "aria-hidden": true }) }))] }), _jsx("div", { className: cx('modal-body', flush && 'flush'), style: bodyStyle, children: children }), footer !== undefined && (_jsxs("div", { className: "modal-foot", children: [typeof footerStart === 'string' ? _jsx("span", { className: "start", children: footerStart }) : footerStart !== undefined && _jsx("div", { className: "start", children: footerStart }), footer] }))] }) }) }));
|
|
71
|
+
return (_jsx(FixedPortal, { children: _jsx("div", { className: "overlay is-fixed", onMouseDown: closeOnOverlay, children: _jsxs("div", { ref: modalRef, className: cx('modal', `modal-${size}`), style: width === undefined ? undefined : { maxWidth: width }, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, tabIndex: -1, onKeyDown: trapFocus, children: [_jsxs("div", { className: "modal-head", children: [_jsxs("div", { className: "modal-heading", children: [titleAside === undefined ? (_jsx("h2", { className: "modal-title", id: titleId, children: title })) : (_jsxs("div", { className: "modal-title-row", children: [_jsx("h2", { className: "modal-title", id: titleId, children: title }), _jsx("div", { ref: asideRef, className: "modal-title-aside", children: titleAside })] })), subtitle !== undefined && _jsx("span", { className: "modal-sub", children: subtitle })] }), onClose !== null && (_jsx("button", { type: "button", className: "btn btn-ghost btn-sm btn-icon", "aria-label": "Close", onClick: onClose, children: _jsx(X, { className: "ic", "aria-hidden": true }) }))] }), _jsx("div", { className: cx('modal-body', flush && 'flush'), style: bodyStyle, children: children }), footer !== undefined && (_jsxs("div", { className: "modal-foot", children: [typeof footerStart === 'string' ? _jsx("span", { className: "start", children: footerStart }) : footerStart !== undefined && _jsx("div", { className: "start", children: footerStart }), footer] }))] }) }) }));
|
|
66
72
|
}
|
package/dist/SelectMenu.js
CHANGED
|
@@ -5,8 +5,8 @@ import { Check, ChevronDown, Search as SearchIcon, TriangleAlert } from 'lucide-
|
|
|
5
5
|
import { cx } from './cx.js';
|
|
6
6
|
import { buttonClass } from './buttonClass.js';
|
|
7
7
|
import { controlClass } from './Field.js';
|
|
8
|
-
import { FixedPortal } from './portal.js';
|
|
9
|
-
import { isKeysActive, openingActive, stepActive } from './activeOption.js';
|
|
8
|
+
import { FixedPortal, HIDDEN_OVERLAY } from './portal.js';
|
|
9
|
+
import { isKeysActive, openingActive, revealInList, stepActive } from './activeOption.js';
|
|
10
10
|
const GAP = 4;
|
|
11
11
|
const EDGE = 12;
|
|
12
12
|
/**
|
|
@@ -32,7 +32,7 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
32
32
|
const buttonRef = useRef(null);
|
|
33
33
|
const menuRef = useRef(null);
|
|
34
34
|
const searchRef = useRef(null);
|
|
35
|
-
const [menuStyle, setMenuStyle] = useState(
|
|
35
|
+
const [menuStyle, setMenuStyle] = useState(HIDDEN_OVERLAY);
|
|
36
36
|
const listId = useId();
|
|
37
37
|
const selected = pinned?.value === value ? pinned : groups.flatMap((group) => group.items).find((item) => item.value === value);
|
|
38
38
|
useEffect(() => {
|
|
@@ -85,12 +85,11 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
85
85
|
useEffect(() => {
|
|
86
86
|
if (!open)
|
|
87
87
|
return;
|
|
88
|
-
// В jsdom прокрутки нет: тесты потребителей не должны падать на ней
|
|
89
88
|
if (active !== null)
|
|
90
|
-
menuRef.current?.querySelector(`[data-index="${active}"]`)
|
|
89
|
+
revealInList(menuRef.current, menuRef.current?.querySelector(`[data-index="${active}"]`) ?? null);
|
|
91
90
|
}, [open, active]);
|
|
92
91
|
const openMenu = ({ byKeys }) => {
|
|
93
|
-
setMenuStyle(
|
|
92
|
+
setMenuStyle(HIDDEN_OVERLAY);
|
|
94
93
|
setQuery('');
|
|
95
94
|
const checked = items.findIndex((item) => item.value === value);
|
|
96
95
|
setKeysIndex(byKeys ? openingActive(checked) : null);
|
|
@@ -126,6 +125,14 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
|
|
|
126
125
|
setKeysIndex(stepActive({ active, checked, step: event.key === 'ArrowDown' ? 1 : -1, count: items.length }));
|
|
127
126
|
setPointerIndex(null);
|
|
128
127
|
}
|
|
128
|
+
else if ((event.key === 'Home' || event.key === 'End') && event.target !== searchRef.current) {
|
|
129
|
+
// Иначе End прокручивает модалку под открытым списком; в поле поиска Home и End двигают курсор
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
if (items.length === 0)
|
|
132
|
+
return;
|
|
133
|
+
setKeysIndex(event.key === 'Home' ? 0 : items.length - 1);
|
|
134
|
+
setPointerIndex(null);
|
|
135
|
+
}
|
|
129
136
|
else if (event.key === 'Enter') {
|
|
130
137
|
event.preventDefault();
|
|
131
138
|
// Без активного пункта (открыт кликом, мышь ушла) Enter закрывает без изменений
|
package/dist/Tooltip.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { cloneElement, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
-
import { FixedPortal } from './portal.js';
|
|
4
|
+
import { FixedPortal, HIDDEN_OVERLAY } from './portal.js';
|
|
5
5
|
export const TOOLTIP_DELAY_MS = 400;
|
|
6
6
|
const GAP = 6;
|
|
7
7
|
const EDGE = 8;
|
|
@@ -12,13 +12,13 @@ const EDGE = 8;
|
|
|
12
12
|
export function Tooltip({ content, children, instant = false }) {
|
|
13
13
|
const id = useId();
|
|
14
14
|
const [anchor, setAnchor] = useState(null);
|
|
15
|
-
const [style, setStyle] = useState(
|
|
15
|
+
const [style, setStyle] = useState(HIDDEN_OVERLAY);
|
|
16
16
|
const timer = useRef(undefined);
|
|
17
17
|
const tipRef = useRef(null);
|
|
18
18
|
const hide = () => {
|
|
19
19
|
window.clearTimeout(timer.current);
|
|
20
20
|
setAnchor(null);
|
|
21
|
-
setStyle(
|
|
21
|
+
setStyle(HIDDEN_OVERLAY);
|
|
22
22
|
};
|
|
23
23
|
const show = (element, delay) => {
|
|
24
24
|
window.clearTimeout(timer.current);
|
package/dist/activeOption.d.ts
CHANGED
|
@@ -10,4 +10,6 @@ export declare function stepActive({ active, checked, step, count }: IStepActive
|
|
|
10
10
|
export declare function openingActive(checked: number): number;
|
|
11
11
|
/** Пункт, у которого полоса: тот, что выбрала клавиатура, пока под мышью ничего нет */
|
|
12
12
|
export declare function isKeysActive(index: number, keysIndex: number | null, pointerIndex: number | null): boolean;
|
|
13
|
+
/** Прокрутка списка к пункту: двигает только сам список, а не модалку и страницу, как scrollIntoView */
|
|
14
|
+
export declare function revealInList(list: HTMLElement | null, option: Element | null): void;
|
|
13
15
|
export {};
|
package/dist/activeOption.js
CHANGED
|
@@ -18,3 +18,16 @@ export function openingActive(checked) {
|
|
|
18
18
|
export function isKeysActive(index, keysIndex, pointerIndex) {
|
|
19
19
|
return pointerIndex === null && keysIndex === index;
|
|
20
20
|
}
|
|
21
|
+
/** Прокрутка списка к пункту: двигает только сам список, а не модалку и страницу, как scrollIntoView */
|
|
22
|
+
export function revealInList(list, option) {
|
|
23
|
+
if (list === null || option === null)
|
|
24
|
+
return;
|
|
25
|
+
const view = list.getBoundingClientRect();
|
|
26
|
+
const item = option.getBoundingClientRect();
|
|
27
|
+
const top = view.top + list.clientTop;
|
|
28
|
+
const bottom = top + list.clientHeight;
|
|
29
|
+
if (item.top < top)
|
|
30
|
+
list.scrollTop -= top - item.top;
|
|
31
|
+
else if (item.bottom > bottom)
|
|
32
|
+
list.scrollTop += item.bottom - bottom;
|
|
33
|
+
}
|
package/dist/components.css
CHANGED
|
@@ -429,6 +429,11 @@
|
|
|
429
429
|
.modal-heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
430
430
|
.modal-title { margin: 0; font-size: var(--text-lg); font-weight: 600; }
|
|
431
431
|
.modal-sub { font-size: var(--text-sm); color: var(--text-muted); }
|
|
432
|
+
/* 1.17: a short status next to the title (Badge, Env tag). Centred on the title line, 8 px after it; when the title and
|
|
433
|
+
the aside don't fit on one line, the aside moves under the title. Outside the h2: not part of the window's name. */
|
|
434
|
+
.modal-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); min-width: 0; }
|
|
435
|
+
.modal-title-row > .modal-title { min-width: 0; overflow-wrap: anywhere; }
|
|
436
|
+
.modal-title-aside { display: inline-flex; align-items: center; gap: var(--space-1); flex-shrink: 0; }
|
|
432
437
|
.modal-body { flex: 1; display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); overflow-y: auto; }
|
|
433
438
|
.modal-body.flush { padding: 0; gap: 0; }
|
|
434
439
|
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
|
package/dist/portal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Оверлеи и стопка тостов живут в портале в body. Базовые правила системы (box-sizing, ссылки, шрифт)
|
|
4
4
|
* заданы внутри .app, поэтому портал оборачивается в .app без собственного бокса.
|
|
@@ -6,3 +6,9 @@ import type { ReactNode } from 'react';
|
|
|
6
6
|
export declare function FixedPortal({ children }: {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
}): import("react").ReactPortal | null;
|
|
9
|
+
/**
|
|
10
|
+
* Оверлей до первого замера: уже fixed, поэтому не попадает в прокрутку страницы. Классы .pop и .tip
|
|
11
|
+
* дают position: absolute, и в body без него невидимый список ниже экрана добавлял странице полосу
|
|
12
|
+
* прокрутки: центрированная модалка сдвигалась, а прокрутка к активному пункту листала страницу.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HIDDEN_OVERLAY: CSSProperties;
|
package/dist/portal.js
CHANGED
|
@@ -10,3 +10,9 @@ export function FixedPortal({ children }) {
|
|
|
10
10
|
return null;
|
|
11
11
|
return createPortal(_jsx("div", { className: "app", style: { display: 'contents' }, children: children }), document.body);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Оверлей до первого замера: уже fixed, поэтому не попадает в прокрутку страницы. Классы .pop и .tip
|
|
15
|
+
* дают position: absolute, и в body без него невидимый список ниже экрана добавлял странице полосу
|
|
16
|
+
* прокрутки: центрированная модалка сдвигалась, а прокрутка к активному пункту листала страницу.
|
|
17
|
+
*/
|
|
18
|
+
export const HIDDEN_OVERLAY = { position: 'fixed', top: 0, left: 0, visibility: 'hidden' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrktg-common/internal-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Общий интерфейс внутренних инструментов маркетинга (Landings Admin, LP Constructor): токены, классы компонентов и тонкие React-обёртки над ними.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|