import { optionLabel } from "~/lib/issue-templates"; import type { IssueFormField } from "~/lib/issue-templates"; import { Select as KumoSelect } from "@cloudflare/kumo/components/select"; import { Markdown } from "~/ui/Markdown"; import { inputClass } from "~/ui/Field"; import { cn } from "~/utils/cn"; type Answers = Record; type Props = { fields: IssueFormField[]; answers: Answers; onChange: (answers: Answers) => void; markdown: string[] }; function Label({ htmlFor, text, required }: { htmlFor: string; text: string; required: boolean }) { return ( ); } /** Renders a `.gitfor/ISSUE_TEMPLATE` issue form; `markdown` holds server-rendered HTML for markdown blocks. */ export function IssueForm({ fields, answers, onChange, markdown }: Props) { const set = (key: string, value: string | string[]) => onChange({ ...answers, [key]: value }); let markdownIndex = 0; return (
{fields.map((field, index) => { if (field.type === "markdown") { const html = markdown[markdownIndex++] ?? ""; return ; } const key = field.id ?? `field-${index}`; const id = `issue-form-${key}`; const description = field.attributes.description && (

{field.attributes.description}

); if (field.type === "checkboxes") { const checked = new Set(Array.isArray(answers[key]) ? answers[key] : []); return (
{field.attributes.label} {description} {field.attributes.options.map((option) => { const label = optionLabel(option); return ( ); })}
); } const required = field.validations?.required ?? false; if (field.type === "dropdown") { const value = answers[key]; const labelText = required ? `${field.attributes.label} *` : field.attributes.label; const options = field.attributes.options.map(optionLabel); return (
{field.attributes.multiple ? ( multiple label={labelText} hideLabel={false} required={required} value={Array.isArray(value) ? value : []} onValueChange={(next) => set(key, next)} placeholder="Select…" className="w-full" > {options.map((option) => ( {option} ))} ) : ( label={labelText} hideLabel={false} required={required} value={String(value ?? "")} onValueChange={(next) => set(key, next ?? "")} className="w-full" items={[ { value: "", label: "Select…" }, ...options.map((option) => ({ value: option, label: option })), ]} > Select… {options.map((option) => ( {option} ))} )} {description}
); } const value = String(answers[key] ?? field.attributes.value ?? ""); return (