All files / src/apps/user/pages/agents/setup primitives.tsx

100% Statements 9/9
100% Branches 12/12
100% Functions 3/3
100% Lines 9/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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121                                  20x   2335x     20x     20x   20x         3745x                           20x                                             180x               180x                                                                                      
import React from "react";
import {
  SectionCard as DetailSectionCard,
  SectionCardProps,
} from "@/components/detail";
 
// Shared form primitives for the agent setup pages (mirrors the styling of
// the manual NewAgent form).
 
/**
 * The setup flow's panel: `components/detail`'s `SectionCard` fixed to the
 * `form` variant.
 *
 * Every step in the flow is a form, so binding the variant once here keeps
 * ten call sites from repeating it — and keeps a step from accidentally
 * rendering as a viewer panel in the middle of a form.
 */
export const SectionCard: React.FC<Omit<SectionCardProps, "variant">> = (
  props,
) => <DetailSectionCard {...props} variant="form" />;
 
export const inputBase =
  "w-full px-3 py-2 text-sm rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:focus:ring-gray-500 transition-colors";
 
export const errorBase =
  "w-full px-3 py-2 text-sm rounded-lg border border-red-300 dark:border-red-700 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-red-200 dark:focus:ring-red-900 transition-colors";
 
export const FieldLabel: React.FC<{
  label: string;
  description?: string;
  required?: boolean;
}> = ({ label, description, required }) => (
  <div className="mb-1.5">
    <div className="text-sm font-medium text-gray-700 dark:text-gray-300">
      {label}
      {required && <span className="ml-0.5 text-red-500">*</span>}
    </div>
    {description && (
      <p className="text-xs text-gray-400 dark:text-gray-500 mt-0.5">
        {description}
      </p>
    )}
  </div>
);
 
/** Generic include/exclude toggle row used across the review steps. */
export const ToggleRow: React.FC<{
  title: string;
  subtitle?: string;
  meta?: React.ReactNode;
  /** Leading glyph for a resource that carries its own appearance — drawn
   *  before the title, so a proposed resource previews here exactly as it
   *  will once created. Distinct from `accent`, which styles the row's
   *  *selected* state, not the resource. */
  icon?: React.ReactNode;
  selected: boolean;
  accent: "violet" | "emerald" | "amber";
  onToggle: () => void;
  children?: React.ReactNode;
}> = ({
  title,
  subtitle,
  meta,
  icon,
  selected,
  accent,
  onToggle,
  children,
}) => {
  const accents = {
    violet:
      "border-violet-400 dark:border-violet-500 bg-violet-50 dark:bg-violet-900/20",
    emerald:
      "border-emerald-400 dark:border-emerald-500 bg-emerald-50 dark:bg-emerald-900/20",
    amber:
      "border-amber-400 dark:border-amber-500 bg-amber-50 dark:bg-amber-900/20",
  };
  return (
    <div
      className={`rounded-lg border transition-all ${
        selected
          ? `${accents[accent]} shadow-sm`
          : "border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 opacity-70"
      }`}
    >
      <div className="flex items-start gap-3 px-4 py-3">
        <label className="mt-0.5 shrink-0 inline-flex items-center cursor-pointer">
          <input
            type="checkbox"
            checked={selected}
            onChange={onToggle}
            // Named after the row it governs: several of these stack up in a
            // review step, and "checkbox" alone tells a screen reader nothing.
            aria-label={`Include ${title}`}
            className="size-4 accent-gray-800 dark:accent-gray-200"
          />
        </label>
        {icon && <span className="mt-0.5 shrink-0">{icon}</span>}
        <div className="min-w-0 flex-1">
          <div className="flex items-center justify-between gap-2">
            <div className="text-sm font-medium text-gray-800 dark:text-gray-200">
              {title}
            </div>
            {meta && (
              <div className="flex items-center gap-1 shrink-0 text-xs text-gray-400 dark:text-gray-500">
                {meta}
              </div>
            )}
          </div>
          {subtitle && (
            <div className="text-xs text-gray-500 dark:text-gray-400 mt-0.5 line-clamp-2">
              {subtitle}
            </div>
          )}
          {children}
        </div>
      </div>
    </div>
  );
};