All files / src/components/page/SubPage SubPage.tsx

80% Statements 4/5
45.45% Branches 5/11
50% Functions 1/2
80% Lines 4/5

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                              1x 2x 2x   2x                                                                                                  
import { MyLink } from "chainr-frontend-shared";
import { usePageMeta } from "@/contexts/PageContext";
import { Pencil } from "lucide-react";
import React from "react";
import { useLocation } from "react-router-dom";
 
export interface SubPageInterface {
  title: React.ReactNode;
  title_icon?: React.ReactNode;
  links?: React.ReactNode[];
  description?: string;
  children?: React.ReactNode;
  editable?: boolean;
}
 
const SubPage: React.FC<SubPageInterface> = (props) => {
  usePageMeta(props.title, true);
  const location = useLocation();
 
  return (
    <div className="pt-8 pb-4 px-6 md:px-8">
      {!props.title_icon && (
        <h1 className="text-xl font-bold drop-shadow-lg">{props.title}</h1>
      )}
      {props.title_icon && (
        <div className="flex flex-row gap-4 items-center">
          {props.title_icon}
          <h1 className="text-xl font-bold drop-shadow-lg">{props.title}</h1>
          {props.editable && (
            <MyLink
              to={`${location.pathname}/edit`}
              name={
                <>
                  <Pencil className="pr-2" /> Edit
                </>
              }
              classes="bg-slate-700 ml-auto"
            />
          )}
        </div>
      )}
      <br />
      <hr />
      <br />
      {props.links && props.links.length > 0 && (
        <>
          <div className="flex justify-start items-start gap-x-4">
            {/* Keyed here rather than at the call site: `links` is an array
                of elements, so React wants a key on each, and every page that
                passed one got a console warning nobody read. The order is
                fixed (it is a toolbar, not a data list), so the index is a
                stable key. */}
            {props.links.map((link, i) => (
              <React.Fragment key={i}>{link}</React.Fragment>
            ))}
          </div>
          <br />
          <hr />
          <br />
        </>
      )}
      {props.description && <p>{props.description}</p>}
      {props.children}
    </div>
  );
};
 
export default SubPage;