@mrktg-common/internal-ui 0.0.0-stage → 1.2.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/README.md +114 -2
- package/dist/Alert.d.ts +18 -0
- package/dist/Alert.js +12 -0
- package/dist/Badge.d.ts +28 -0
- package/dist/Badge.js +23 -0
- package/dist/Banner.d.ts +16 -0
- package/dist/Banner.js +6 -0
- package/dist/BrandName.d.ts +9 -0
- package/dist/BrandName.js +10 -0
- package/dist/Breadcrumbs.d.ts +20 -0
- package/dist/Breadcrumbs.js +9 -0
- package/dist/Button.d.ts +25 -0
- package/dist/Button.js +25 -0
- package/dist/Card.d.ts +22 -0
- package/dist/Card.js +10 -0
- package/dist/CenteredCard.d.ts +12 -0
- package/dist/CenteredCard.js +6 -0
- package/dist/ChangeBlock.d.ts +16 -0
- package/dist/ChangeBlock.js +8 -0
- package/dist/CopyField.d.ts +16 -0
- package/dist/CopyField.js +20 -0
- package/dist/Dropzone.d.ts +31 -0
- package/dist/Dropzone.js +66 -0
- package/dist/EmptyState.d.ts +13 -0
- package/dist/EmptyState.js +5 -0
- package/dist/EnvTag.d.ts +18 -0
- package/dist/EnvTag.js +11 -0
- package/dist/Field.d.ts +52 -0
- package/dist/Field.js +47 -0
- package/dist/FileRow.d.ts +29 -0
- package/dist/FileRow.js +9 -0
- package/dist/Header.d.ts +46 -0
- package/dist/Header.js +11 -0
- package/dist/Menu.d.ts +36 -0
- package/dist/Menu.js +47 -0
- package/dist/Modal.d.ts +26 -0
- package/dist/Modal.js +66 -0
- package/dist/MultiSelectMenu.d.ts +32 -0
- package/dist/MultiSelectMenu.js +17 -0
- package/dist/Popover.d.ts +26 -0
- package/dist/Popover.js +42 -0
- package/dist/Progress.d.ts +26 -0
- package/dist/Progress.js +39 -0
- package/dist/ResultReport.d.ts +30 -0
- package/dist/ResultReport.js +13 -0
- package/dist/Search.d.ts +12 -0
- package/dist/Search.js +32 -0
- package/dist/Segmented.d.ts +27 -0
- package/dist/Segmented.js +17 -0
- package/dist/SelectMenu.d.ts +52 -0
- package/dist/SelectMenu.js +154 -0
- package/dist/Skeleton.d.ts +12 -0
- package/dist/Skeleton.js +6 -0
- package/dist/Spinner.d.ts +12 -0
- package/dist/Spinner.js +10 -0
- package/dist/Steps.d.ts +21 -0
- package/dist/Steps.js +11 -0
- package/dist/Switch.d.ts +11 -0
- package/dist/Switch.js +14 -0
- package/dist/Table.d.ts +59 -0
- package/dist/Table.js +39 -0
- package/dist/Tabs.d.ts +20 -0
- package/dist/Tabs.js +25 -0
- package/dist/Toast.d.ts +38 -0
- package/dist/Toast.js +79 -0
- package/dist/Tooltip.d.ts +18 -0
- package/dist/Tooltip.js +58 -0
- package/dist/UserMenu.d.ts +27 -0
- package/dist/UserMenu.js +28 -0
- package/dist/components.css +527 -0
- package/dist/cx.d.ts +2 -0
- package/dist/cx.js +4 -0
- package/dist/files.d.ts +4 -0
- package/dist/files.js +28 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +39 -0
- package/dist/portal.d.ts +8 -0
- package/dist/portal.js +12 -0
- package/dist/theme.d.ts +25 -0
- package/dist/theme.js +68 -0
- package/dist/themeScript.d.ts +9 -0
- package/dist/themeScript.js +13 -0
- package/dist/tokens.css +118 -0
- package/package.json +67 -4
- package/tokens/tokens.json +589 -0
package/dist/EnvTag.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TriangleAlert } from 'lucide-react';
|
|
3
|
+
import { cx } from './cx.js';
|
|
4
|
+
/** Где живёт админка: контур и окружение. Жёлтый значит «не продакшен» и всегда со словом. */
|
|
5
|
+
export function EnvPill({ contour, environment, dev, host, showHost = false, className }) {
|
|
6
|
+
return (_jsxs("span", { className: cx('env', dev ? 'env-dev' : 'env-prod', className), title: host === undefined ? `${contour} contour, ${environment}` : host, children: [_jsx("span", { className: "env-contour", children: contour }), showHost && host !== undefined && _jsx("span", { className: "env-host", children: host }), _jsxs("span", { className: "env-tag", children: [dev && _jsx(TriangleAlert, { className: "ic ic-xs", "aria-hidden": true }), environment] })] }));
|
|
7
|
+
}
|
|
8
|
+
/** Короткий чип окружения перед опубликованным лендингом: PROD нейтральный, TEST жёлтый. */
|
|
9
|
+
export function EnvChip({ environment, className }) {
|
|
10
|
+
return _jsx("span", { className: cx('env-chip', environment === 'prod' ? 'tag-prod' : 'tag-test', className), children: environment === 'prod' ? 'Prod' : 'Test' });
|
|
11
|
+
}
|
package/dist/Field.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
export type TControlSize = 'sm' | 'md';
|
|
3
|
+
export interface IControlStyle {
|
|
4
|
+
size?: TControlSize;
|
|
5
|
+
invalid?: boolean;
|
|
6
|
+
mono?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Классы поля ввода для своих контролов продукта. */
|
|
9
|
+
export declare function controlClass({ size, invalid, mono }?: IControlStyle, className?: string): string;
|
|
10
|
+
export interface IFieldProps {
|
|
11
|
+
label?: ReactNode;
|
|
12
|
+
/** id контрола; без него Field придумает свой и отдаст в children. */
|
|
13
|
+
htmlFor?: string;
|
|
14
|
+
hint?: ReactNode;
|
|
15
|
+
/** Ошибка под полем с circle-x; заменяет подсказку. */
|
|
16
|
+
error?: ReactNode;
|
|
17
|
+
/** Проверка пройдена: нейтральная строка с галочкой. */
|
|
18
|
+
ok?: ReactNode;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
/** Справа от подписи: счётчик символов и т. п. */
|
|
22
|
+
aside?: ReactNode;
|
|
23
|
+
className?: string;
|
|
24
|
+
children: ReactNode | ((ids: {
|
|
25
|
+
id: string;
|
|
26
|
+
describedBy: string | undefined;
|
|
27
|
+
}) => ReactNode);
|
|
28
|
+
}
|
|
29
|
+
/** Подпись, контрол и одна строка под ним: подсказка, ошибка или пройденная проверка. */
|
|
30
|
+
export declare function Field({ label, htmlFor, hint, error, ok, required, optional, aside, className, children }: IFieldProps): import("react").JSX.Element;
|
|
31
|
+
export type TInputProps = Omit<ComponentProps<'input'>, 'size'> & IControlStyle;
|
|
32
|
+
export declare function Input({ size, invalid, mono, className, type, ...rest }: TInputProps): import("react").JSX.Element;
|
|
33
|
+
export type TTextareaProps = ComponentProps<'textarea'> & IControlStyle;
|
|
34
|
+
export declare function Textarea({ size, invalid, mono, className, ...rest }: TTextareaProps): import("react").JSX.Element;
|
|
35
|
+
export interface ITextFieldProps extends Omit<TInputProps, 'id'> {
|
|
36
|
+
label: ReactNode;
|
|
37
|
+
id?: string;
|
|
38
|
+
hint?: ReactNode;
|
|
39
|
+
error?: ReactNode;
|
|
40
|
+
ok?: ReactNode;
|
|
41
|
+
optional?: boolean;
|
|
42
|
+
aside?: ReactNode;
|
|
43
|
+
fieldClassName?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Поле целиком: подпись, input и строка под ним, связанные id и aria-describedby. */
|
|
46
|
+
export declare function TextField({ label, id, hint, error, ok, optional, aside, required, fieldClassName, ...input }: ITextFieldProps): import("react").JSX.Element;
|
|
47
|
+
export interface ICheckboxProps extends Omit<ComponentProps<'input'>, 'type'> {
|
|
48
|
+
label?: ReactNode;
|
|
49
|
+
hint?: ReactNode;
|
|
50
|
+
}
|
|
51
|
+
/** Галочка, применяемая вместе с формой; вся строка — область нажатия. Для мгновенной настройки — Switch. */
|
|
52
|
+
export declare function Checkbox({ label, hint, className, onChange, onClick, ...rest }: ICheckboxProps): import("react").JSX.Element;
|
package/dist/Field.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { CircleCheck, CircleX } from 'lucide-react';
|
|
5
|
+
import { cx } from './cx.js';
|
|
6
|
+
/** Классы поля ввода для своих контролов продукта. */
|
|
7
|
+
export function controlClass({ size = 'md', invalid, mono } = {}, className) {
|
|
8
|
+
return cx('control', size === 'sm' && 'control-sm', mono && 'mono', invalid && 'invalid', className);
|
|
9
|
+
}
|
|
10
|
+
/** Подпись, контрол и одна строка под ним: подсказка, ошибка или пройденная проверка. */
|
|
11
|
+
export function Field({ label, htmlFor, hint, error, ok, required, optional, aside, className, children }) {
|
|
12
|
+
const autoId = useId();
|
|
13
|
+
const id = htmlFor ?? autoId;
|
|
14
|
+
const noteId = `${id}-note`;
|
|
15
|
+
const hasNote = Boolean(error ?? ok ?? hint);
|
|
16
|
+
const describedBy = hasNote ? noteId : undefined;
|
|
17
|
+
const labelNode = label !== undefined && (_jsxs("label", { className: "label", htmlFor: id, children: [label, required && _jsx("span", { className: "required", "aria-hidden": true, children: "*" }), optional && _jsx("span", { className: "opt", children: " optional" })] }));
|
|
18
|
+
return (_jsxs("div", { className: cx('field', className), children: [aside === undefined ? labelNode : (_jsxs("div", { className: "label-row", children: [labelNode, aside] })), typeof children === 'function' ? children({ id, describedBy }) : children, error ? (_jsxs("span", { className: "err", id: noteId, children: [_jsx(CircleX, { className: "ic ic-sm", "aria-hidden": true }), error] })) : ok ? (_jsxs("span", { className: "ok", id: noteId, children: [_jsx(CircleCheck, { className: "ic ic-sm", "aria-hidden": true }), ok] })) : hint ? (_jsx("span", { className: "hint", id: noteId, children: hint })) : null] }));
|
|
19
|
+
}
|
|
20
|
+
export function Input({ size, invalid, mono, className, type = 'text', ...rest }) {
|
|
21
|
+
return _jsx("input", { type: type, className: controlClass({ size, invalid, mono }, className), "aria-invalid": invalid || undefined, ...rest });
|
|
22
|
+
}
|
|
23
|
+
export function Textarea({ size, invalid, mono, className, ...rest }) {
|
|
24
|
+
return _jsx("textarea", { className: controlClass({ size, invalid, mono }, cx('textarea', className)), "aria-invalid": invalid || undefined, ...rest });
|
|
25
|
+
}
|
|
26
|
+
/** Поле целиком: подпись, input и строка под ним, связанные id и aria-describedby. */
|
|
27
|
+
export function TextField({ label, id, hint, error, ok, optional, aside, required, fieldClassName, ...input }) {
|
|
28
|
+
return (_jsx(Field, { label: label, htmlFor: id, hint: hint, error: error, ok: ok, required: required, optional: optional, aside: aside, className: fieldClassName, children: ({ id: controlId, describedBy }) => (_jsx(Input, { id: controlId, required: required, invalid: Boolean(error) || input.invalid, "aria-describedby": describedBy, ...input })) }));
|
|
29
|
+
}
|
|
30
|
+
/** Галочка, применяемая вместе с формой; вся строка — область нажатия. Для мгновенной настройки — Switch. */
|
|
31
|
+
export function Checkbox({ label, hint, className, onChange, onClick, ...rest }) {
|
|
32
|
+
const hintId = useId();
|
|
33
|
+
const off = rest['aria-disabled'] === true || rest['aria-disabled'] === 'true';
|
|
34
|
+
const box = (_jsx("input", { type: "checkbox", className: cx('checkbox', label === undefined && className), "aria-describedby": hint ? hintId : undefined, onChange: (event) => {
|
|
35
|
+
if (off)
|
|
36
|
+
return;
|
|
37
|
+
onChange?.(event);
|
|
38
|
+
}, onClick: (event) => {
|
|
39
|
+
if (off)
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
else
|
|
42
|
+
onClick?.(event);
|
|
43
|
+
}, ...rest }));
|
|
44
|
+
if (label === undefined)
|
|
45
|
+
return box;
|
|
46
|
+
return (_jsxs("label", { className: cx('check-row', className), style: off ? { opacity: 0.55, cursor: 'not-allowed' } : undefined, children: [box, _jsxs("span", { children: [label, hint && _jsx("span", { className: "hint", id: hintId, style: { display: 'block' }, children: hint })] })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type LucideIcon } from 'lucide-react';
|
|
3
|
+
export type TFileUpload = {
|
|
4
|
+
/** Сколько отправлено; без него полоса неопределённая. */
|
|
5
|
+
value?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
/** Под полосой: «12.6 of 38.2 MB» и «33%». */
|
|
8
|
+
label?: ReactNode;
|
|
9
|
+
percent?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export interface IFileRowProps {
|
|
12
|
+
name: string;
|
|
13
|
+
/** Размер или что найдено: «38.2 MB», «5 rows · column “link” found». */
|
|
14
|
+
meta?: ReactNode;
|
|
15
|
+
/** package для архивов, file для таблиц и картинок. */
|
|
16
|
+
kind?: 'archive' | 'file';
|
|
17
|
+
icon?: LucideIcon;
|
|
18
|
+
/** Идёт загрузка: полоса внутри строки вместо meta. */
|
|
19
|
+
upload?: TFileUpload;
|
|
20
|
+
/** Не загрузилось: строка красная, сообщение под именем. */
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
/** Кнопки справа: Replace, Change, Cancel, Retry. */
|
|
23
|
+
actions?: ReactNode;
|
|
24
|
+
/** Крестик «Remove file» последним в действиях. */
|
|
25
|
+
onRemove?: () => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Один выбранный файл: иконка, имя (полное — в title), размер или найденное, действия. */
|
|
29
|
+
export declare function FileRow({ name, meta, kind, icon, upload, error, actions, onRemove, className }: IFileRowProps): import("react").JSX.Element;
|
package/dist/FileRow.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleX, File, Package, X } from 'lucide-react';
|
|
3
|
+
import { cx } from './cx.js';
|
|
4
|
+
import { Progress, ProgressLabel } from './Progress.js';
|
|
5
|
+
/** Один выбранный файл: иконка, имя (полное — в title), размер или найденное, действия. */
|
|
6
|
+
export function FileRow({ name, meta, kind = 'file', icon, upload, error, actions, onRemove, className }) {
|
|
7
|
+
const Icon = icon ?? (kind === 'archive' ? Package : File);
|
|
8
|
+
return (_jsxs("div", { className: cx('file', error !== undefined && 'is-error', className), children: [_jsx("span", { className: "file-ic", children: _jsx(Icon, { className: "ic", "aria-hidden": true }) }), _jsxs("div", { className: "file-body", children: [_jsx("span", { className: "file-name", title: name, children: name }), error !== undefined ? (_jsxs("span", { className: "err", children: [_jsx(CircleX, { className: "ic ic-sm", "aria-hidden": true }), error] })) : upload !== undefined ? (_jsxs(_Fragment, { children: [_jsx(Progress, { value: upload.value, max: upload.max, label: "Uploading" }), upload.label !== undefined && _jsx(ProgressLabel, { start: upload.label, end: upload.percent })] })) : (meta !== undefined && _jsx("span", { className: "file-meta", children: meta }))] }), (actions !== undefined || onRemove !== undefined) && (_jsxs("div", { className: "file-actions", children: [actions, onRemove !== undefined && (_jsx("button", { type: "button", className: "btn btn-ghost btn-sm btn-icon", "aria-label": "Remove file", title: "Remove file", onClick: onRemove, children: _jsx(X, { className: "ic", "aria-hidden": true }) }))] }))] }));
|
|
9
|
+
}
|
package/dist/Header.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MouseEvent, ReactNode } from 'react';
|
|
2
|
+
import type { LucideIcon } from 'lucide-react';
|
|
3
|
+
export type TLinkProps = {
|
|
4
|
+
href: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
'aria-label'?: string;
|
|
7
|
+
'aria-current'?: 'page';
|
|
8
|
+
title?: string;
|
|
9
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/** Ссылка роутера продукта (react-router, next/link); по умолчанию обычный <a>. */
|
|
13
|
+
export type TLinkComponent = (props: TLinkProps) => ReactNode;
|
|
14
|
+
export declare const PlainLink: TLinkComponent;
|
|
15
|
+
export interface IHeaderProps {
|
|
16
|
+
productName: string;
|
|
17
|
+
/** Иконка плитки: globe у админки, blocks у конструктора. */
|
|
18
|
+
productIcon: LucideIcon;
|
|
19
|
+
homeHref: string;
|
|
20
|
+
link?: TLinkComponent;
|
|
21
|
+
/** Только плитка без названия (редактор): название уходит в aria-label ссылки. */
|
|
22
|
+
compact?: boolean;
|
|
23
|
+
/** Подпись ссылки-плитки в компактном режиме: «LP Constructor, projects». */
|
|
24
|
+
homeLabel?: string;
|
|
25
|
+
/** Жёлтая полоса сверху; только вместе с плашкой Dev — цвет не единственный сигнал. */
|
|
26
|
+
dev?: boolean;
|
|
27
|
+
/** Слот продукта после логотипа: плашка окружения, навигация, путь к проекту. */
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
/** Справа: кнопка пользователя с меню. */
|
|
30
|
+
end?: ReactNode;
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Шапка 56 px: плитка и название продукта, слот продукта, справа пользователь. */
|
|
34
|
+
export declare function Header({ productName, productIcon: Icon, homeHref, link: Link, compact, homeLabel, dev, children, end, className }: IHeaderProps): import("react").JSX.Element;
|
|
35
|
+
export type TNavItem = {
|
|
36
|
+
href: string;
|
|
37
|
+
label: string;
|
|
38
|
+
current: boolean;
|
|
39
|
+
icon?: LucideIcon;
|
|
40
|
+
};
|
|
41
|
+
/** Разделы продукта в шапке; текущий — aria-current="page". */
|
|
42
|
+
export declare function HeaderNav({ items, link: Link, 'aria-label': label }: {
|
|
43
|
+
items: TNavItem[];
|
|
44
|
+
link?: TLinkComponent;
|
|
45
|
+
'aria-label'?: string;
|
|
46
|
+
}): import("react").JSX.Element;
|
package/dist/Header.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from './cx.js';
|
|
3
|
+
export const PlainLink = ({ href, children, ...rest }) => (_jsx("a", { href: href, ...rest, children: children }));
|
|
4
|
+
/** Шапка 56 px: плитка и название продукта, слот продукта, справа пользователь. */
|
|
5
|
+
export function Header({ productName, productIcon: Icon, homeHref, link: Link = PlainLink, compact = false, homeLabel, dev = false, children, end, className }) {
|
|
6
|
+
return (_jsxs("header", { className: cx('hdr', dev && 'hdr-dev', className), children: [_jsxs("div", { className: "hdr-left", children: [_jsxs(Link, { href: homeHref, className: "logo", "aria-label": compact ? (homeLabel ?? productName) : undefined, children: [_jsx("span", { className: "logo-mark", children: _jsx(Icon, { className: "ic ic-sm", "aria-hidden": true }) }), !compact && productName] }), children] }), end !== undefined && _jsx("div", { className: "hdr-right", children: end })] }));
|
|
7
|
+
}
|
|
8
|
+
/** Разделы продукта в шапке; текущий — aria-current="page". */
|
|
9
|
+
export function HeaderNav({ items, link: Link = PlainLink, 'aria-label': label = 'Sections' }) {
|
|
10
|
+
return (_jsx("nav", { className: "nav", "aria-label": label, children: items.map(({ href, label: text, current, icon: Icon }) => (_jsxs(Link, { href: href, "aria-current": current ? 'page' : undefined, children: [Icon && _jsx(Icon, { className: "ic ic-sm", "aria-hidden": true }), text] }, href))) }));
|
|
11
|
+
}
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type KeyboardEvent, type ReactNode } from 'react';
|
|
2
|
+
import type { LucideIcon } from 'lucide-react';
|
|
3
|
+
export interface IMenuProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
trigger: ReactNode;
|
|
7
|
+
align?: 'start' | 'end';
|
|
8
|
+
width?: number;
|
|
9
|
+
'aria-label'?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** Перемещение по пунктам меню стрелками, Home и End. */
|
|
14
|
+
export declare function moveMenuFocus(event: KeyboardEvent<HTMLElement>): void;
|
|
15
|
+
/** Меню действий под кнопкой. Выбор пункта закрывает меню, выбор варианта (menuitemradio) — нет. */
|
|
16
|
+
export declare function Menu({ open, onClose, trigger, align, width, className, 'aria-label': label, children }: IMenuProps): import("react").JSX.Element;
|
|
17
|
+
export interface IMenuItemProps {
|
|
18
|
+
icon?: LucideIcon;
|
|
19
|
+
onSelect?: () => void;
|
|
20
|
+
/** Пункт-ссылка: рендерится как <a>. */
|
|
21
|
+
href?: string;
|
|
22
|
+
danger?: boolean;
|
|
23
|
+
/** Выключен с причиной: строка menu-hint под пунктом и aria-describedby. Пункт не прячется. */
|
|
24
|
+
disabledReason?: string;
|
|
25
|
+
/** Выключен, причина очевидна или в title: без строки под пунктом. */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/** Справа серым: сочетание клавиш или значение. */
|
|
28
|
+
trailing?: ReactNode;
|
|
29
|
+
title?: string;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
export declare function MenuItem({ icon: Icon, onSelect, href, danger, disabledReason, disabled, trailing, title, children }: IMenuItemProps): import("react").JSX.Element;
|
|
33
|
+
export declare function MenuSeparator(): import("react").JSX.Element;
|
|
34
|
+
export declare function MenuLabel({ children }: {
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
}): import("react").JSX.Element;
|
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useId } from 'react';
|
|
4
|
+
import { cx } from './cx.js';
|
|
5
|
+
import { MENU_ITEMS, Popover } from './Popover.js';
|
|
6
|
+
const MenuCloseContext = createContext(() => { });
|
|
7
|
+
/** Перемещение по пунктам меню стрелками, Home и End. */
|
|
8
|
+
export function moveMenuFocus(event) {
|
|
9
|
+
const items = Array.from(event.currentTarget.querySelectorAll(MENU_ITEMS));
|
|
10
|
+
if (items.length === 0)
|
|
11
|
+
return;
|
|
12
|
+
const current = items.findIndex((item) => item === document.activeElement);
|
|
13
|
+
const targets = {
|
|
14
|
+
ArrowDown: (current + 1) % items.length,
|
|
15
|
+
ArrowUp: (Math.max(current, 0) - 1 + items.length) % items.length,
|
|
16
|
+
Home: 0,
|
|
17
|
+
End: items.length - 1,
|
|
18
|
+
};
|
|
19
|
+
const next = targets[event.key];
|
|
20
|
+
if (next === undefined)
|
|
21
|
+
return;
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
items[next]?.focus();
|
|
24
|
+
}
|
|
25
|
+
/** Меню действий под кнопкой. Выбор пункта закрывает меню, выбор варианта (menuitemradio) — нет. */
|
|
26
|
+
export function Menu({ open, onClose, trigger, align, width, className, 'aria-label': label, children }) {
|
|
27
|
+
return (_jsx(Popover, { open: open, onClose: onClose, trigger: trigger, align: align, width: width, role: "menu", "aria-label": label, className: className, onKeyDown: moveMenuFocus, children: _jsx(MenuCloseContext.Provider, { value: onClose, children: children }) }));
|
|
28
|
+
}
|
|
29
|
+
export function MenuItem({ icon: Icon, onSelect, href, danger = false, disabledReason, disabled = false, trailing, title, children }) {
|
|
30
|
+
const close = useContext(MenuCloseContext);
|
|
31
|
+
const hintId = useId();
|
|
32
|
+
const off = disabled || disabledReason !== undefined;
|
|
33
|
+
const className = cx('menu-item', danger && 'is-danger');
|
|
34
|
+
const content = (_jsxs(_Fragment, { children: [Icon && _jsx(Icon, { className: "ic", "aria-hidden": true }), _jsx("span", { className: "trunc", style: { flex: 1 }, children: children }), trailing !== undefined && _jsx("span", { className: "trail", children: trailing })] }));
|
|
35
|
+
return (_jsxs(_Fragment, { children: [href !== undefined && !off ? (_jsx("a", { className: className, role: "menuitem", href: href, title: title, onClick: close, children: content })) : (_jsx("button", { type: "button", role: "menuitem", className: className, "aria-disabled": off || undefined, "aria-describedby": disabledReason === undefined ? undefined : hintId, title: title, onClick: () => {
|
|
36
|
+
if (off)
|
|
37
|
+
return;
|
|
38
|
+
close();
|
|
39
|
+
onSelect?.();
|
|
40
|
+
}, children: content })), disabledReason !== undefined && _jsx("div", { className: "menu-hint", id: hintId, children: disabledReason })] }));
|
|
41
|
+
}
|
|
42
|
+
export function MenuSeparator() {
|
|
43
|
+
return _jsx("div", { className: "menu-sep", role: "separator" });
|
|
44
|
+
}
|
|
45
|
+
export function MenuLabel({ children }) {
|
|
46
|
+
return _jsx("div", { className: "menu-label", children: children });
|
|
47
|
+
}
|
package/dist/Modal.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export type TModalSize = 'sm' | 'md' | 'lg';
|
|
3
|
+
export interface IModalProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: ReactNode;
|
|
7
|
+
size?: TModalSize;
|
|
8
|
+
/** Ширина не из набора размеров (окно события расписания, 600). */
|
|
9
|
+
width?: number;
|
|
10
|
+
/** null — закрыть нельзя: нет крестика, Esc и клик по фону не работают (идёт публикация). */
|
|
11
|
+
onClose: (() => void) | null;
|
|
12
|
+
footer?: ReactNode;
|
|
13
|
+
/** Слева в футере: пояснение или третье действие. */
|
|
14
|
+
footerStart?: ReactNode;
|
|
15
|
+
/** Тело без отступов: таблица во всю ширину окна. */
|
|
16
|
+
flush?: boolean;
|
|
17
|
+
bodyStyle?: CSSProperties;
|
|
18
|
+
/** Куда поставить фокус при открытии; по умолчанию — первое поле или кнопка тела, затем футера. */
|
|
19
|
+
initialFocus?: () => HTMLElement | null;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Окно для коротких решений и маленьких форм. Фокус не выходит из окна; Esc и клик по фону закрывают,
|
|
24
|
+
* если onClose задан. Cancel в футере — secondary, главная кнопка называет действие.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Modal({ open, title, subtitle, size, width, onClose, footer, footerStart, flush, bodyStyle, initialFocus, children }: IModalProps): import("react").JSX.Element | null;
|
package/dist/Modal.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef } from 'react';
|
|
4
|
+
import { X } from 'lucide-react';
|
|
5
|
+
import { cx } from './cx.js';
|
|
6
|
+
import { FixedPortal } from './portal.js';
|
|
7
|
+
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
8
|
+
/**
|
|
9
|
+
* Окно для коротких решений и маленьких форм. Фокус не выходит из окна; Esc и клик по фону закрывают,
|
|
10
|
+
* если onClose задан. Cancel в футере — secondary, главная кнопка называет действие.
|
|
11
|
+
*/
|
|
12
|
+
export function Modal({ open, title, subtitle, size = 'md', width, onClose, footer, footerStart, flush = false, bodyStyle, initialFocus, children }) {
|
|
13
|
+
const modalRef = useRef(null);
|
|
14
|
+
const titleId = useId();
|
|
15
|
+
const previous = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!open)
|
|
18
|
+
return;
|
|
19
|
+
previous.current = document.activeElement;
|
|
20
|
+
const modal = modalRef.current;
|
|
21
|
+
const target = initialFocus?.() ?? modal?.querySelector(`.modal-body ${FOCUSABLE}, .modal-foot .btn-primary, .modal-foot ${FOCUSABLE}`) ?? modal;
|
|
22
|
+
target?.focus();
|
|
23
|
+
return () => {
|
|
24
|
+
if (previous.current instanceof HTMLElement)
|
|
25
|
+
previous.current.focus();
|
|
26
|
+
};
|
|
27
|
+
// initialFocus читаем только при открытии
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, [open]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!open || onClose === null)
|
|
32
|
+
return;
|
|
33
|
+
const onKey = (event) => {
|
|
34
|
+
if (event.key === 'Escape' && !event.defaultPrevented)
|
|
35
|
+
onClose();
|
|
36
|
+
};
|
|
37
|
+
document.addEventListener('keydown', onKey);
|
|
38
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
39
|
+
}, [open, onClose]);
|
|
40
|
+
if (!open)
|
|
41
|
+
return null;
|
|
42
|
+
const trapFocus = (event) => {
|
|
43
|
+
if (event.key !== 'Tab')
|
|
44
|
+
return;
|
|
45
|
+
const focusable = Array.from(event.currentTarget.querySelectorAll(FOCUSABLE));
|
|
46
|
+
const first = focusable[0];
|
|
47
|
+
const last = focusable[focusable.length - 1];
|
|
48
|
+
if (first === undefined || last === undefined) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
last.focus();
|
|
55
|
+
}
|
|
56
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
first.focus();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const closeOnOverlay = (event) => {
|
|
62
|
+
if (event.target === event.currentTarget)
|
|
63
|
+
onClose?.();
|
|
64
|
+
};
|
|
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] }))] }) }) }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type TMultiSelectOption<T extends string> = {
|
|
3
|
+
value: T;
|
|
4
|
+
label: string;
|
|
5
|
+
/** Слева от подписи: фавиконка бренда. */
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
/** Сколько объектов под вариантом при остальных фильтрах; строкой — «≥ 5». */
|
|
8
|
+
count?: number | string;
|
|
9
|
+
/** Строка под вариантом: что он значит. */
|
|
10
|
+
hint?: string;
|
|
11
|
+
};
|
|
12
|
+
export type TMultiSelectGroup<T extends string> = {
|
|
13
|
+
/** Заголовок группы, не кликается. */
|
|
14
|
+
label: string | null;
|
|
15
|
+
/** Оговорка про всю группу одной строкой под её вариантами. */
|
|
16
|
+
note?: ReactNode;
|
|
17
|
+
options: TMultiSelectOption<T>[];
|
|
18
|
+
};
|
|
19
|
+
export interface IMultiSelectMenuProps<T extends string> {
|
|
20
|
+
/** Подпись кнопки: «Brand», «Status». */
|
|
21
|
+
label: string;
|
|
22
|
+
groups: TMultiSelectGroup<T>[];
|
|
23
|
+
value: T[];
|
|
24
|
+
onChange: (value: T[]) => void;
|
|
25
|
+
size?: 'sm' | 'md';
|
|
26
|
+
width?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Фильтр по нескольким значениям. Применяется сразу, как отмечаешь, без Apply; внизу Clear.
|
|
30
|
+
* На кнопке одно значение называется словом («Status: Error»), несколько — числом.
|
|
31
|
+
*/
|
|
32
|
+
export declare function MultiSelectMenu<T extends string>({ label, groups, value, onChange, size, width }: IMultiSelectMenuProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment, useState } from 'react';
|
|
4
|
+
import { ChevronDown } from 'lucide-react';
|
|
5
|
+
import { buttonClass } from './Button.js';
|
|
6
|
+
import { Popover } from './Popover.js';
|
|
7
|
+
/**
|
|
8
|
+
* Фильтр по нескольким значениям. Применяется сразу, как отмечаешь, без Apply; внизу Clear.
|
|
9
|
+
* На кнопке одно значение называется словом («Status: Error»), несколько — числом.
|
|
10
|
+
*/
|
|
11
|
+
export function MultiSelectMenu({ label, groups, value, onChange, size = 'md', width = 280 }) {
|
|
12
|
+
const [open, setOpen] = useState(false);
|
|
13
|
+
const all = groups.flatMap((group) => group.options);
|
|
14
|
+
const single = value.length === 1 ? all.find((option) => option.value === value[0]) : undefined;
|
|
15
|
+
const toggle = (option) => onChange(value.includes(option) ? value.filter((item) => item !== option) : [...value, option]);
|
|
16
|
+
return (_jsxs(Popover, { open: open, onClose: () => setOpen(false), width: width, role: "listbox", "aria-label": label, "aria-multiselectable": true, scroll: true, trigger: _jsxs("button", { type: "button", className: buttonClass({ variant: 'secondary', size, active: value.length > 0 }), "aria-haspopup": "listbox", "aria-expanded": open, onClick: () => setOpen((current) => !current), children: [single === undefined ? label : `${label}: ${single.label}`, value.length > 1 && _jsx("span", { className: "count-pill", children: value.length }), _jsx(ChevronDown, { className: "ic ic-sm", "aria-hidden": true })] }), children: [groups.map((group, index) => (_jsxs(Fragment, { children: [index > 0 && _jsx("div", { className: "menu-sep" }), group.label !== null && _jsx("div", { className: "menu-label", children: group.label }), group.options.map((option) => (_jsxs(Fragment, { children: [_jsxs("label", { className: "menu-item", role: "option", "aria-selected": value.includes(option.value), children: [_jsx("input", { className: "checkbox", type: "checkbox", checked: value.includes(option.value), onChange: () => toggle(option.value) }), option.icon === undefined ? option.label : (_jsxs("span", { className: "brand", children: [option.icon, _jsx("span", { className: "name", children: option.label })] })), option.count !== undefined && _jsx("span", { className: "count", children: option.count })] }), option.hint !== undefined && _jsx("div", { className: "menu-hint", children: option.hint })] }, option.value))), group.note !== undefined && _jsx("div", { className: "menu-hint", children: group.note })] }, group.label ?? `group-${index}`))), _jsxs("div", { className: "menu-foot", style: { position: 'sticky', bottom: 'calc(-1 * var(--space-1))', background: 'var(--surface)', paddingBottom: 'var(--space-1)' }, children: [_jsx("button", { type: "button", className: "btn btn-ghost btn-sm", disabled: value.length === 0, onClick: () => onChange([]), children: "Clear" }), _jsx("span", { className: "hint", children: "Applies as you tick" })] })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
|
2
|
+
export declare const MENU_ITEMS = "[role=\"menuitem\"]:not([aria-disabled=\"true\"]), [role=\"menuitemradio\"]:not([aria-disabled=\"true\"]), [role=\"menuitemcheckbox\"]:not([aria-disabled=\"true\"])";
|
|
3
|
+
export interface IPopoverProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
/** Кнопка, которая открывает панель: после Esc фокус возвращается на неё. */
|
|
7
|
+
trigger: ReactNode;
|
|
8
|
+
/** start — под кнопкой слева (pop), end — справа (pop-right). */
|
|
9
|
+
align?: 'start' | 'end';
|
|
10
|
+
width?: number;
|
|
11
|
+
role?: 'menu' | 'dialog' | 'listbox';
|
|
12
|
+
'aria-label'?: string;
|
|
13
|
+
'aria-multiselectable'?: boolean;
|
|
14
|
+
/** Длинный список: прокрутка в 320 px. */
|
|
15
|
+
scroll?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
anchorClassName?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Панель под кнопкой. Закрывается Esc и кликом мимо; при открытии фокус на первом пункте,
|
|
24
|
+
* после Esc — снова на кнопке.
|
|
25
|
+
*/
|
|
26
|
+
export declare function Popover({ open, onClose, trigger, align, width, role, scroll, className, anchorClassName, style, onKeyDown, children, ...aria }: IPopoverProps): import("react").JSX.Element;
|
package/dist/Popover.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { cx } from './cx.js';
|
|
5
|
+
export const MENU_ITEMS = '[role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"]), [role="menuitemcheckbox"]:not([aria-disabled="true"])';
|
|
6
|
+
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
7
|
+
/**
|
|
8
|
+
* Панель под кнопкой. Закрывается Esc и кликом мимо; при открытии фокус на первом пункте,
|
|
9
|
+
* после Esc — снова на кнопке.
|
|
10
|
+
*/
|
|
11
|
+
export function Popover({ open, onClose, trigger, align = 'start', width, role = 'dialog', scroll = false, className, anchorClassName, style, onKeyDown, children, ...aria }) {
|
|
12
|
+
const rootRef = useRef(null);
|
|
13
|
+
const panelRef = useRef(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!open)
|
|
16
|
+
return;
|
|
17
|
+
const closeOutside = (event) => {
|
|
18
|
+
if (event.target instanceof Node && !rootRef.current?.contains(event.target))
|
|
19
|
+
onClose();
|
|
20
|
+
};
|
|
21
|
+
document.addEventListener('mousedown', closeOutside);
|
|
22
|
+
return () => document.removeEventListener('mousedown', closeOutside);
|
|
23
|
+
}, [open, onClose]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!open)
|
|
26
|
+
return;
|
|
27
|
+
panelRef.current?.querySelector(role === 'menu' ? MENU_ITEMS : FOCUSABLE)?.focus();
|
|
28
|
+
}, [open, role]);
|
|
29
|
+
const handleKeyDown = (event) => {
|
|
30
|
+
if (event.key === 'Escape') {
|
|
31
|
+
// Иначе Esc закроет и модалку, в которой стоит панель
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
onClose();
|
|
34
|
+
rootRef.current?.querySelector(FOCUSABLE)?.focus();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (event.key === 'Tab')
|
|
38
|
+
onClose();
|
|
39
|
+
onKeyDown?.(event);
|
|
40
|
+
};
|
|
41
|
+
return (_jsxs("div", { className: cx('anchor', anchorClassName), ref: rootRef, children: [trigger, open && (_jsx("div", { ref: panelRef, className: cx('pop', align === 'end' && 'pop-right', scroll && 'pop-scroll', className), style: width === undefined ? style : { width, ...style }, role: role, onKeyDown: handleKeyDown, ...aria, children: children }))] }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface IProgressProps {
|
|
3
|
+
/** Сделано; без value полоса неопределённая (progress-ind). */
|
|
4
|
+
value?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
/** Что идёт, для скринридера: «Uploading». */
|
|
7
|
+
label: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Тонкая полоса: длина известна (value из max) или ждём сервер. */
|
|
11
|
+
export declare function Progress({ value, max, label, className }: IProgressProps): import("react").JSX.Element;
|
|
12
|
+
/** Подпись под полосой: байты слева, процент справа. */
|
|
13
|
+
export declare function ProgressLabel({ start, end }: {
|
|
14
|
+
start: ReactNode;
|
|
15
|
+
end?: ReactNode;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export interface ICountdownProps {
|
|
18
|
+
/** Сколько секунд до закрытия. */
|
|
19
|
+
seconds: number;
|
|
20
|
+
/** Отсчёт закончился: закрыть результат. */
|
|
21
|
+
onDone: () => void;
|
|
22
|
+
/** Нажали Keep open: отсчёт остановлен, onDone не придёт. */
|
|
23
|
+
onKeepOpen?: () => void;
|
|
24
|
+
}
|
|
25
|
+
/** Отсчёт перед тем, как результат закроется сам. Нейтральный: это таймер, не статус. */
|
|
26
|
+
export declare function Countdown({ seconds, onDone, onKeepOpen }: ICountdownProps): import("react").JSX.Element | null;
|
package/dist/Progress.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cx } from './cx.js';
|
|
5
|
+
/** Тонкая полоса: длина известна (value из max) или ждём сервер. */
|
|
6
|
+
export function Progress({ value, max = 100, label, className }) {
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
return (_jsx("div", { className: cx('progress', 'progress-ind', className), role: "progressbar", "aria-label": label, children: _jsx("span", {}) }));
|
|
9
|
+
}
|
|
10
|
+
const percent = max > 0 ? Math.min(100, Math.max(0, (value / max) * 100)) : 0;
|
|
11
|
+
return (_jsx("div", { className: cx('progress', className), role: "progressbar", "aria-valuenow": value, "aria-valuemin": 0, "aria-valuemax": max, "aria-label": label, children: _jsx("span", { style: { width: `${percent}%` } }) }));
|
|
12
|
+
}
|
|
13
|
+
/** Подпись под полосой: байты слева, процент справа. */
|
|
14
|
+
export function ProgressLabel({ start, end }) {
|
|
15
|
+
return (_jsxs("div", { className: "progress-label", children: [_jsx("span", { children: start }), end !== undefined && _jsx("span", { className: "num", children: end })] }));
|
|
16
|
+
}
|
|
17
|
+
/** Отсчёт перед тем, как результат закроется сам. Нейтральный: это таймер, не статус. */
|
|
18
|
+
export function Countdown({ seconds, onDone, onKeepOpen }) {
|
|
19
|
+
const [kept, setKept] = useState(false);
|
|
20
|
+
const doneRef = useRef(onDone);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
doneRef.current = onDone;
|
|
23
|
+
});
|
|
24
|
+
// Таймер, а не animationend: закрытие не зависит от того, дошла ли анимация (свёрнутая вкладка, reduced motion)
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (kept)
|
|
27
|
+
return;
|
|
28
|
+
const timer = window.setTimeout(() => doneRef.current(), seconds * 1000);
|
|
29
|
+
return () => window.clearTimeout(timer);
|
|
30
|
+
}, [kept, seconds]);
|
|
31
|
+
if (kept)
|
|
32
|
+
return null;
|
|
33
|
+
const style = { '--countdown': `${seconds}s` };
|
|
34
|
+
return (_jsxs("div", { className: "col", style: { gap: 6 }, children: [_jsx("div", { className: "progress progress-countdown", style: style, "aria-hidden": true, children: _jsx("span", {}) }), _jsxs("span", { className: "hint", children: ["Closes in a few seconds \u00B7", ' ', _jsx("a", { href: "#keep-open", onClick: (event) => {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
setKept(true);
|
|
37
|
+
onKeepOpen?.();
|
|
38
|
+
}, children: "Keep open" })] })] }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type LucideIcon } from 'lucide-react';
|
|
3
|
+
export type TReportTone = 'ok' | 'info' | 'warn' | 'err';
|
|
4
|
+
export type TReportPath = {
|
|
5
|
+
/** Где: «index.html ·», серым. */
|
|
6
|
+
location?: string;
|
|
7
|
+
/** Что не так, отмечено. */
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
10
|
+
export interface IReportRowProps {
|
|
11
|
+
/** ok нейтральный: зелёный только для «живёт на продакшене». */
|
|
12
|
+
tone: TReportTone;
|
|
13
|
+
paths?: TReportPath[];
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/** Одна находка: жирная первая фраза — что найдено, дальше — пояснение. */
|
|
17
|
+
export declare function ReportRow({ tone, paths, children }: IReportRowProps): import("react").JSX.Element;
|
|
18
|
+
export interface IResultReportProps {
|
|
19
|
+
/** Шапка: что проверяли и сводка справа («1 warning»). В окне сводку можно дать строкой над отчётом. */
|
|
20
|
+
head?: {
|
|
21
|
+
icon?: LucideIcon;
|
|
22
|
+
title: ReactNode;
|
|
23
|
+
summary?: ReactNode;
|
|
24
|
+
};
|
|
25
|
+
/** Строки ReportRow, худшие первыми. */
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
'aria-label'?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Что нашла проверка или импорт: архив перед публикацией, таблица переводов, список отелей. */
|
|
30
|
+
export declare function ResultReport({ head, children, 'aria-label': label }: IResultReportProps): import("react").JSX.Element;
|