Blocks / Recipient input

Recipient input

To, Cc and Bcc: address tags with suggestions, groups that expand, validity, pasted lists.

import { RecipientInput, RecipientFields, parseRecipientText, isEmailAddress, addRecipients } from "@forgeron/ui";
/01 → Default
To
  • Léa Martin
  • oops@, not a valid address
import { RecipientFields, type ConversationContact } from "@forgeron/ui";

const contacts: ConversationContact[] = [
  { id: "1", name: "Léa Martin", email: "lea@acme.io" },
  { id: "2", name: "Karim Aziz", email: "karim@acme.io" },
  { id: "3", name: "Jo Bernard", email: "jo@partner.fr" },
  { id: "g", name: "Finance team", members: ["karim@acme.io", "jo@partner.fr", "compta@acme.io"] },
];

export default function Default() {
  return (
    <div style={{ width: "100%", maxWidth: 640 }}>
      <RecipientFields
        contacts={contacts}
        defaultValue={{ to: ["lea@acme.io", "oops@"], cc: [], bcc: [] }}
      />
    </div>
  );
}
/02 → Single
To

0 / 5

import { RecipientInput } from "@forgeron/ui";
import { useState } from "react";

export default function Single() {
  const [to, setTo] = useState<string[]>([]);
  return (
    <div style={{ width: "100%", maxWidth: 520 }}>
      <RecipientInput
        label="To"
        value={to}
        onChange={setTo}
        placeholder="Paste a list of addresses"
        max={5}
      />
      <p style={{ font: "12px var(--font-mono)", color: "var(--ink-muted)" }}>{to.length} / 5</p>
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—To, Cc, Bcc.
value / defaultValue / onChangestring[]—The addresses.
contacts{ id, name, email?, members?, avatar? }[]—Suggestions. A contact with members is a group: choosing it adds each address.
validate(address) => booleanisEmailAddressA tag that fails is marked and said.
max / disabled / onAdd / placeholdernumber; boolean; (added) => void; string—Limits and hooks.
RecipientFields{ to, cc, bcc }—The three fields as one value; Cc and Bcc open from buttons.
classNamestring—Extra classes.