Relation picker
Links records of another table: search by name, id or hint; one or several.
import { RelationPicker } from "@forgeron/ui";import { RelationPicker } from "@forgeron/ui";
const companies = [
{ id: "c-104", label: "Fromagerie Roy", hint: "Lyon" },
{ id: "c-212", label: "Garnier Transports", hint: "Grenoble" },
{ id: "c-318", label: "Petit & Fils", hint: "Annecy" },
{ id: "c-402", label: "Martin Distribution", hint: "Chambéry" },
];
export default function Default() {
return (
<div style={{ width: 260 }}>
<RelationPicker label="Company" targets={companies} defaultValue={["c-212"]} />
</div>
);
}// Several records at once: the list stays open while they are ticked; search by name, id or hint.
import { RelationPicker } from "@forgeron/ui";
import { useState } from "react";
const contacts = [
{ id: "p-1", label: "Camille Roy", hint: "Fromagerie Roy" },
{ id: "p-2", label: "Hugo Bernard", hint: "Garnier" },
{ id: "p-3", label: "Léa Martin", hint: "Martin Distribution" },
{ id: "p-4", label: "Nadia Petit", hint: "Petit & Fils" },
{ id: "p-5", label: "Tom Garnier", hint: "Garnier" },
];
export default function Several() {
const [ids, setIds] = useState<string[]>(["p-1", "p-3"]);
return (
<div style={{ display: "flex", gap: 16, alignItems: "center", flexWrap: "wrap" }}>
<div style={{ width: 320 }}>
<RelationPicker
label="Contacts"
multiple
targets={contacts}
value={ids}
onChange={setIds}
/>
</div>
<RelationPicker
label="Contacts"
variant="chip"
multiple
targets={contacts}
value={ids}
onChange={setIds}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the control and the search. |
targets | { id, label, hint? }[] | — | The records to link. |
value / defaultValue | string[] | — | The linked ids. Controlled or not. |
onChange | (ids: string[]) => void | — | When a link changes. |
multiple | boolean | false | Several records; the list stays open while they are ticked. |
variant | "field" | "chip" | "field" | A form control, or a chip in a row. |
open / onOpenChange | boolean | — | Opens the list from outside: a grid cell, a shortcut. |
className | string | — | Extra classes. |