({
schema,
form,
path,
minLength,
renderers,
}: {
schema: z.ZodType;
form: UseFormReturn<any>;
path: Path<any>;
renderers: FormRenderer[];
minLength?: number;
})
| 477 | * Type: T[] |
| 478 | */ |
| 479 | const FormArray = ({ |
| 480 | schema, |
| 481 | form, |
| 482 | path, |
| 483 | minLength, |
| 484 | renderers, |
| 485 | }: { |
| 486 | schema: z.ZodType; |
| 487 | form: UseFormReturn<any>; |
| 488 | path: Path<any>; |
| 489 | renderers: FormRenderer[]; |
| 490 | minLength?: number; |
| 491 | }) => { |
| 492 | const { label, description } = FieldOptions.parse(schema.description || ""); |
| 493 | |
| 494 | const control = form.control; |
| 495 | // prepend, remove, swap, move, insert, replace |
| 496 | const { fields, append, remove } = useFieldArray({ |
| 497 | control, |
| 498 | name: path, |
| 499 | }); |
| 500 | |
| 501 | const isBelowMinLength = minLength != null && fields.length < minLength; |
| 502 | const canRemove = minLength == null || fields.length > minLength; |
| 503 | |
| 504 | return ( |
| 505 | <div className="flex flex-col gap-2 min-w-[220px]"> |
| 506 | <FormLabel>{label}</FormLabel> |
| 507 | <FormDescription>{description}</FormDescription> |
| 508 | {fields.map((field, index) => { |
| 509 | return ( |
| 510 | <div |
| 511 | className="flex flex-row pl-2 ml-2 border-l-2 border-disabled hover-actions-parent relative pr-5 pt-1 items-center w-fit" |
| 512 | key={field.id} |
| 513 | onKeyDown={Events.onEnter((e) => e.preventDefault())} |
| 514 | > |
| 515 | {renderZodSchema(schema, form, `${path}[${index}]`, renderers)} |
| 516 | {canRemove && ( |
| 517 | <Trash2Icon |
| 518 | className="w-4 h-4 ml-2 my-1 text-muted-foreground hover:text-destructive cursor-pointer absolute right-0 top-5" |
| 519 | onClick={() => { |
| 520 | remove(index); |
| 521 | }} |
| 522 | /> |
| 523 | )} |
| 524 | </div> |
| 525 | ); |
| 526 | })} |
| 527 | {isBelowMinLength && ( |
| 528 | <div className="text-destructive text-xs font-semibold"> |
| 529 | <div>At least {minLength} required.</div> |
| 530 | </div> |
| 531 | )} |
| 532 | <div> |
| 533 | <Button |
| 534 | size="xs" |
| 535 | data-testid="marimo-plugin-data-frames-add-array-item" |
| 536 | variant="text" |
nothing calls this directly
no test coverage detected
searching dependent graphs…