Files
wiki-montazh/apps/web/src/components/ui.tsx
T
deonisiiandClaude Opus 5.5 59be0307cc Этап 3: экраны чтения по макету
- API: GET /api/tree, GET /api/articles/:slug, раздача /uploads
- экраны: Главная, Раздел, Статья, Шпаргалка, Избранное (телефон и компьютер)
- блоки статьи, чек-листы с сохранением в localStorage (ключ slug + версия)
- просмотр фото: щипок, двойной тап, свайп, клавиатура
- липкая шапка с прогрессом, оглавление в bottom sheet, избранное, недавние
- три темы (тёмная / светлая / солнце), выбор запоминается
- печать и PDF: окно настроек, печатная версия статьи и шпаргалки с QR
- дизайн-токены в tokens.css, шрифт Onest в сборке
- scripts/check-layout.mjs: проверка отсутствия горизонтальной прокрутки
- исправлены два невидимых символа, на которые ругался линтер

Lighthouse mobile: Performance 95-96, Accessibility 100.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 12:33:37 +03:00

105 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Мелкие общие элементы интерфейса.
import type { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import type { PlaqueColor } from '@kb/shared';
import { useTheme } from '../lib/theme';
/** Цветная плашка с кодом раздела: «ВВ», «ВОК». size: sm (в сетке), lg (в шапке раздела). */
export function Plaque({ code, color, size = 'sm' }: { code: string; color: PlaqueColor; size?: 'sm' | 'lg' }) {
return <span className={`plaque plaque--${color} plaque--${size}`}>{code}</span>;
}
/** Код раздела в рамке: в списках избранного, в меню. */
export function CodeTag({ code, small }: { code: string; small?: boolean }) {
return <span className={small ? 'codetag codetag--sm' : 'codetag'}>{code}</span>;
}
/** Кнопка «Тема» в шапке экрана: переключает по кругу. */
export function ThemeButton() {
const { label, cycle } = useTheme();
return (
<button type="button" className="theme-btn" onClick={cycle} aria-label={`Тема: ${label}. Переключить`}>
<span className="theme-btn-dot" aria-hidden="true" />
{label}
</button>
);
}
/** Ссылка «‹ Назад». */
export function BackLink({ to, children }: { to: string; children: ReactNode }) {
return (
<Link to={to} className="back">
<span className="back-chev" aria-hidden="true">
‹
</span>
{children}
</Link>
);
}
export function Caps({ children, right }: { children: ReactNode; right?: ReactNode }) {
return (
<div className="caps-row">
<h2 className="caps">{children}</h2>
{right ? <span className="caps-right">{right}</span> : null}
</div>
);
}
/** Состояния «загрузка / ошибка / пусто» в стиле макета (в самом макете их нет). */
export function Notice({ title, children, tone }: { title: string; children?: ReactNode; tone?: 'error' }) {
return (
<div className={tone === 'error' ? 'notice notice--error' : 'notice'} role={tone === 'error' ? 'alert' : 'status'}>
<div className="notice-title">{title}</div>
{children ? <div className="notice-text">{children}</div> : null}
</div>
);
}
export function Skeleton({ lines = 3 }: { lines?: number }) {
return (
<div className="skeleton" aria-busy="true" aria-label="Загрузка">
{Array.from({ length: lines }, (_, i) => (
<span key={i} className="skeleton-line" />
))}
</div>
);
}
/** Выдвижная панель снизу (на телефоне) или окно по центру (на компьютере). */
export function Sheet({
title,
subtitle,
onClose,
children,
dialog,
}: {
title: string;
subtitle?: string;
onClose: () => void;
children: ReactNode;
/** true: на широком экране показывать окном по центру */
dialog?: boolean;
}) {
return (
<div className={dialog ? 'sheet-wrap sheet-wrap--dialog' : 'sheet-wrap'}>
<button type="button" className="scrim" aria-label="Закрыть" onClick={onClose} />
<div className="sheet" role="dialog" aria-modal="true" aria-label={title}>
<div className="sheet-grip" aria-hidden="true">
<span />
</div>
<div className="sheet-head">
<div className="sheet-titles">
<div className="sheet-title">{title}</div>
{subtitle ? <div className="sheet-sub">{subtitle}</div> : null}
</div>
<button type="button" className="sheet-close" onClick={onClose} aria-label="Закрыть">
✕
</button>
</div>
{children}
</div>
</div>
);
}