Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

2.7 KB
Raw Blame
import { type RefObject } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@editor/ui";
import { Icon } from "@editor/ui/Icon";
import type {
  FlowComingSoonSource,
  FlowSource,
} from "@processor/api/processorFlow";
import {
  EDITOR_TYPE,
  ICON_SIZE,
} from "@processor/components/processor-flow/flowTypes";
import { SourceIcon } from "@processor/components/processor-flow/FlowIcons";

interface FlowSourcesProps {
  sources: FlowSource[];
  comingSoonSources: FlowComingSoonSource[];
  /** One ref slot per live source, in order, for geometry measurement. */
  srcRefs: RefObject<(HTMLElement | null)[]>;
  onOpen: () => void;
}

/** Left column: live source cards (measured) + coming-soon connect cards. */
export function FlowSources({
  sources,
  comingSoonSources,
  srcRefs,
  onOpen,
}: FlowSourcesProps) {
  const { t } = useTranslation();
  return (
    <section
      className="portal-pf__col portal-pf__col--sources"
      aria-label={t("portal.processorFlow.sources.heading")}
    >
      <span className="portal-pf__col-head">
        {t("portal.processorFlow.sources.heading")}
      </span>
      {sources.map((source, i) => (
        <Button
          key={source.id}
          variant="quiet"
          justify="start"
          fullWidth
          px="sm"
          py="sm"
          className="portal-pf__node portal-pf__node--source"
          onClick={onOpen}
          ref={(el: HTMLButtonElement | null) => {
            srcRefs.current[i] = el;
          }}
          leftSection={
            <span className="portal-pf__node-icon" aria-hidden>
              <SourceIcon type={source.type} />
            </span>
          }
        >
          <span className="portal-pf__node-text">
            <strong>
              {source.type === EDITOR_TYPE
                ? t("portal.processorFlow.sources.editor")
                : source.name}
            </strong>
            <span>
              {t("portal.processorFlow.sources.perDay", { n: source.docs24h })}
            </span>
          </span>
        </Button>
      ))}
      {comingSoonSources.map((cs) => (
        <Button
          key={cs.key}
          variant="quiet"
          justify="start"
          fullWidth
          px="sm"
          py="sm"
          className="portal-pf__node portal-pf__node--soon"
          onClick={onOpen}
          leftSection={
            <span className="portal-pf__node-icon" aria-hidden>
              <Icon name="plus" size={ICON_SIZE} />
            </span>
          }
        >
          <span className="portal-pf__node-text">
            <strong>{t(cs.labelKey)}</strong>
            <span>{t("portal.processorFlow.sources.comingSoonTag")}</span>
          </span>
        </Button>
      ))}
    </section>
  );
}