Files
liqa/client/src/ui/Modal/Modal.tsx
T
ars9 daecf3d539
CI / changes (pull_request) Successful in 7s
CI / version (pull_request) Skipped
CI / server (pull_request) Skipped
CI / client (pull_request) Successful in 1m13s
CI / image (pull_request) Skipped
feat(client): add code reference modal to step and snippet editors
- a (?) button next to the Code label on the step and snippet
  create/edit pages opens a reference of the script runtime: globals,
  every context member with examples, and pitfalls such as awaiting
  getStepOutput and assert
- the reference lives in components/modals/code-help.md and is
  rendered as markdown
- Modal takes size="lg" for document-like content; the dialog is
  capped to the viewport and its body scrolls, focusable when lg so
  the keyboard can scroll it
- docs/scenario.md notes that getStepOutput is async and points to
  the in-app reference to keep in sync
2026-10-01 14:45:03 +03:00

47 lines
1.4 KiB
TypeScript

import { useEffect } from 'react';
import styles from './Modal.module.css';
export interface ModalProps {
open: boolean;
title: string;
children?: React.ReactNode;
onClose: () => void;
footer?: React.ReactNode;
/** `lg` widens the dialog for long, document-like content. */
size?: 'md' | 'lg';
}
export function Modal({ open, title, children, onClose, footer, size = 'md' }: ModalProps) {
useEffect(() => {
if (!open) return;
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') onClose();
};
window.addEventListener('keydown', onKeyDown);
return () => window.removeEventListener('keydown', onKeyDown);
}, [open, onClose]);
if (!open) return null;
return (
<div className={styles.overlay} role="presentation" onClick={onClose}>
<div
className={size === 'lg' ? `${styles.dialog} ${styles.lg}` : styles.dialog}
role="dialog"
aria-modal="true"
aria-label={title}
onClick={(event) => event.stopPropagation()}
>
<div className={styles.header}>
<h3 className={styles.title}>{title}</h3>
</div>
{/* Long (lg) content scrolls; make it focusable so the keyboard can scroll it. */}
<div className={styles.body} tabIndex={size === 'lg' ? 0 : undefined}>
{children}
</div>
{footer && <div className={styles.footer}>{footer}</div>}
</div>
</div>
);
}