All files / react-app/src/components/Form/content ContentWrappers.tsx

88.88% Statements 8/9
28.57% Branches 2/7
50% Functions 3/6
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89          71x                                                   71x 328x         71x 656x         71x                             71x               71x                                            
import { Alert, RequiredIndicator, SectionCard } from "@/components";
import clsx from "clsx";
import { Info } from "lucide-react";
import { ReactElement, ReactNode } from "react";
 
export const FormSectionCard = ({
  children,
  title,
  id,
  required,
}: {
  children: ReactNode;
  title: string;
  id: string;
  description?: string;
  required?: boolean;
}) => {
  return (
    <SectionCard
      id={id}
      title={
        <>
          {title} {required && <RequiredIndicator />}
        </>
      }
    >
      {children}
    </SectionCard>
  );
};
 
export const RequiredFieldDescription = () => (
  <>
    <RequiredIndicator /> <em className="text-neutral-500">Indicates a required field.</em>
  </>
);
 
export const ProgressLossReminder = ({ className = "" }: { className?: string }) => (
  <p className={clsx("font-bold", className)}>
    If you leave this page, you will lose your progress on this form.
  </p>
);
 
export const ActionFormDescription = ({
  children,
  boldReminder,
}: {
  children: ReactNode;
  boldReminder?: boolean;
}) => {
  return (
    <div className="mt-4">
      {children}
      {boldReminder && <ProgressLossReminder />}
    </div>
  );
};
 
export const ActionFormHeading = ({ title }: { title: string }) => {
  return (
    <h1 data-testid="AFH" className="text-2xl font-semibold mt-4 mb-2">
      {title}
    </h1>
  );
};
 
export const PreSubmitNotice = ({
  message,
  hasProgressLossReminder = true,
}: {
  message: string | ReactElement;
  hasProgressLossReminder?: boolean;
}) => (
  <Alert variant={"infoBlock"} className="space-x-2 mb-8">
    <Info />
    {/* Wraps strings, but allows for ReactElements to declare their own wrapper */}
    {typeof message === "string" ? (
      <p>
        {message}
        {hasProgressLossReminder && <ProgressLossReminder />}
      </p>
    ) : (
      <>
        {message} {hasProgressLossReminder && <ProgressLossReminder />}
      </>
    )}
  </Alert>
);