57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import styles from "./profile-form.module.css";
|
|
|
|
/* Field helpers shared by the steps of the profile form. */
|
|
|
|
export function ErrorText({ id, children }: { id: string; children?: string | undefined }) {
|
|
return children ? (
|
|
<p className={styles.error} id={id}>
|
|
{children}
|
|
</p>
|
|
) : null;
|
|
}
|
|
|
|
export function Suggestion({
|
|
source,
|
|
}: {
|
|
source: { quote: string | null; origin: string } | null;
|
|
}) {
|
|
if (!source || source.origin === "manual") return null;
|
|
const origin = source.origin === "imported" ? "Импортировано" : "Предложено из документа";
|
|
return (
|
|
<details className={styles.suggestion}>
|
|
<summary>{origin}. Значение пока не подтверждено.</summary>
|
|
{source.quote ? <blockquote>{source.quote}</blockquote> : <p>Цитата не сохранена.</p>}
|
|
</details>
|
|
);
|
|
}
|
|
|
|
export type FieldProps = {
|
|
id: string;
|
|
label: string;
|
|
error?: string | undefined;
|
|
description?: ReactNode | undefined;
|
|
suggestion?: { quote: string | null; origin: string } | null | undefined;
|
|
children: ReactNode;
|
|
};
|
|
|
|
export function Field({ id, label, error, description, suggestion, children }: FieldProps) {
|
|
return (
|
|
<div className={styles.field}>
|
|
<label htmlFor={id}>{label}</label>
|
|
{description ? (
|
|
<p className={styles.hint} id={`${id}-hint`}>
|
|
{description}
|
|
</p>
|
|
) : null}
|
|
{children}
|
|
{suggestion ? (
|
|
<div id={`${id}-suggestion`}>
|
|
<Suggestion source={suggestion} />
|
|
</div>
|
|
) : null}
|
|
<ErrorText id={`${id}-error`}>{error}</ErrorText>
|
|
</div>
|
|
);
|
|
}
|