"use client" /** * EmailChipField — an address field (To, Cc, Bcc, From, Reply to) that holds people as badges. * * Two kinds of chip: `chips` are people the page already chose (the audience), removable but * not typed; `values` are addresses the sender typed or picked from `suggestions`. Enter, * comma, semicolon or leaving the field commits typed text; an address that does not look * like one stays visible as a destructive chip so it is fixed, not silently dropped. */ import * as React from "react" import { cn } from "../../lib/utils" import { Badge } from "../ui/badge" import { Popover, PopoverAnchor, PopoverContent } from "../ui/popover" import type { EmailContact } from "./email-composer-types" export interface EmailChip { id: string label: string /** Hover text, usually the email address. */ title?: string invalid?: boolean } export interface EmailChipFieldProps { /** Accessible name of the input: "Add To". */ label: string chips?: EmailChip[] onRemoveChip?: (id: string) => void values: string[] onChange: (values: string[]) => void suggestions?: EmailContact[] placeholder?: string /** Optional cap on chips shown while idle. By default as many as fit. */ maxVisible?: number /** Holds one address at a time: picking replaces. */ single?: boolean id?: string className?: string } const looksLikeEmail = (text: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(text) function Chip({ label, title, invalid, onRemove, }: { label: string title?: string invalid?: boolean onRemove?: () => void }) { return ( {invalid ?