{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "share-dialog-people",
  "title": "Share Dialog People",
  "description": "Content panel of a people-sharing dialog with a share link, people with role menus, and an invite form.",
  "dependencies": [
    "@vllnt/ui@^0.3.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/share-dialog-people/share-dialog-people.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cva } from \"class-variance-authority\";\nimport { X } from \"lucide-react\";\n\nimport { cn } from \"@vllnt/ui\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@vllnt/ui\";\nimport { Button } from \"@vllnt/ui\";\nimport { Input } from \"@vllnt/ui\";\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectSeparator,\n  SelectTrigger,\n  SelectValue,\n} from \"@vllnt/ui\";\nimport { Separator } from \"@vllnt/ui\";\n\n/** Panel to display: the people with access, or the invite form. */\nexport type ShareDialogPeopleKind = \"invite\" | \"list\";\n\n/** Density of the panel: `desktop` is roomy, `phone` is compact. */\nexport type ShareDialogPeopleLayout = \"desktop\" | \"phone\";\n\n/** One person who has access. */\nexport type ShareDialogPeoplePerson = {\n  avatarSrc?: string;\n  email?: string;\n  id: string;\n  name: string;\n  /** The `value` of the person's current role in `roles`. */\n  role: string;\n};\n\n/** A role a person can hold. */\nexport type ShareDialogPeopleRole = {\n  label: string;\n  value: string;\n};\n\n/** Every visible and screen-reader string of the panel. */\nexport type ShareDialogPeopleLabels = {\n  back: string;\n  close: string;\n  copyLink: string;\n  done: string;\n  emailInput: string;\n  emailPlaceholder: string;\n  empty: string;\n  invite: string;\n  inviteRole: string;\n  linkInput: string;\n  note: string;\n  peopleList: string;\n  personRole: (name: string) => string;\n  remove: string;\n  send: string;\n};\n\n/** Props of {@link ShareDialogPeople}. */\nexport type ShareDialogPeopleProps = Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"aria-labelledby\" | \"role\" | \"title\"\n> & {\n  /** Panel to display. The host owns it and updates it from `onKindChange`. */\n  kind?: ShareDialogPeopleKind;\n  /** Overrides for the English default strings. */\n  labels?: Partial<ShareDialogPeopleLabels>;\n  layout?: ShareDialogPeopleLayout;\n  /** Share link for the link row. Without it, the row does not render. */\n  linkUrl?: string;\n  /** Renders the close button when set. */\n  onClose?: () => void;\n  onCopyLink?: () => void;\n  onDone?: () => void;\n  /** Called with the trimmed email and the chosen role on Send. */\n  onInvite?: (email: string, role: string) => void;\n  /** Called with `\"invite\"` by the Invite button and `\"list\"` by Back. */\n  onKindChange?: (kind: ShareDialogPeopleKind) => void;\n  /** Adds a Remove choice to every person's role menu when set. */\n  onRemove?: (id: string) => void;\n  onRoleChange?: (id: string, role: string) => void;\n  people: ShareDialogPeoplePerson[];\n  roles: ShareDialogPeopleRole[];\n  title?: string;\n};\n\nconst REMOVE_VALUE = \"__remove__\";\n\nconst DEFAULT_LABELS: ShareDialogPeopleLabels = {\n  back: \"Back\",\n  close: \"Close\",\n  copyLink: \"Copy link\",\n  done: \"Done\",\n  emailInput: \"Email address\",\n  emailPlaceholder: \"name@example.com\",\n  empty: \"No one has access yet.\",\n  invite: \"Invite\",\n  inviteRole: \"Role for the new person\",\n  linkInput: \"Share link\",\n  note: \"Invited people get an email with a link.\",\n  peopleList: \"People with access\",\n  personRole: (name) => `${name} role`,\n  remove: \"Remove\",\n  send: \"Send\",\n};\n\nconst panelVariants = cva(\n  \"flex w-full flex-col rounded-lg border bg-card text-card-foreground\",\n  {\n    defaultVariants: { layout: \"desktop\" },\n    variants: {\n      layout: {\n        desktop: \"max-w-lg gap-4 p-6\",\n        phone: \"max-w-sm gap-3 p-4\",\n      },\n    },\n  },\n);\n\nconst stackVariants = cva(\"flex flex-col\", {\n  defaultVariants: { layout: \"desktop\" },\n  variants: {\n    layout: {\n      desktop: \"gap-4\",\n      phone: \"gap-3\",\n    },\n  },\n});\n\nconst actionsVariants = cva(\"flex gap-2\", {\n  defaultVariants: { layout: \"desktop\" },\n  variants: {\n    layout: {\n      desktop: \"flex-row justify-end\",\n      phone: \"flex-col-reverse [&>button]:w-full\",\n    },\n  },\n});\n\nconst avatarVariants = cva(\"\", {\n  defaultVariants: { layout: \"desktop\" },\n  variants: {\n    layout: {\n      desktop: \"size-10\",\n      phone: \"size-8 text-xs\",\n    },\n  },\n});\n\nconst roleTriggerVariants = cva(\"shrink-0\", {\n  defaultVariants: { layout: \"desktop\" },\n  variants: {\n    layout: {\n      desktop: \"w-36\",\n      phone: \"h-9 w-28\",\n    },\n  },\n});\n\ntype Layout = { layout: ShareDialogPeopleLayout };\n\ntype Labelled = { labels: ShareDialogPeopleLabels };\n\nfunction getInitials(name: string): string {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part.slice(0, 1).toUpperCase())\n    .join(\"\");\n}\n\nfunction getRoleLabel(roles: ShareDialogPeopleRole[], value: string): string {\n  return roles.find((role) => role.value === value)?.label ?? value;\n}\n\nfunction RoleItems({\n  roles,\n}: {\n  roles: ShareDialogPeopleRole[];\n}): React.JSX.Element {\n  return (\n    <>\n      {roles.map((role) => (\n        <SelectItem key={role.value} value={role.value}>\n          {role.label}\n        </SelectItem>\n      ))}\n    </>\n  );\n}\n\nfunction PanelHeader({\n  labels,\n  onClose,\n  title,\n  titleId,\n}: Labelled & {\n  onClose?: () => void;\n  title: string;\n  titleId: string;\n}): React.JSX.Element {\n  const handleClose = (): void => {\n    onClose?.();\n  };\n\n  return (\n    <header className=\"flex items-center justify-between gap-3\">\n      <h2\n        className=\"text-lg font-semibold leading-none tracking-tight\"\n        id={titleId}\n      >\n        {title}\n      </h2>\n      {onClose ? (\n        <Button\n          className=\"-mr-2 shrink-0\"\n          onClick={handleClose}\n          size=\"icon\"\n          type=\"button\"\n          variant=\"ghost\"\n        >\n          <X aria-hidden=\"true\" />\n          <span className=\"sr-only\">{labels.close}</span>\n        </Button>\n      ) : null}\n    </header>\n  );\n}\n\nfunction LinkRow({\n  labels,\n  linkUrl,\n  onCopyLink,\n}: Labelled & {\n  linkUrl: string;\n  onCopyLink?: () => void;\n}): React.JSX.Element {\n  const handleCopy = (): void => {\n    onCopyLink?.();\n  };\n\n  return (\n    <div className=\"flex items-center gap-2\">\n      <Input\n        aria-label={labels.linkInput}\n        className=\"min-w-0 flex-1\"\n        readOnly\n        value={linkUrl}\n      />\n      <Button\n        className=\"shrink-0\"\n        onClick={handleCopy}\n        type=\"button\"\n        variant=\"outline\"\n      >\n        {labels.copyLink}\n      </Button>\n    </div>\n  );\n}\n\nfunction PersonEntry({\n  labels,\n  layout,\n  onRemove,\n  onRoleChange,\n  person,\n  roles,\n}: Labelled &\n  Layout & {\n    onRemove?: (id: string) => void;\n    onRoleChange?: (id: string, role: string) => void;\n    person: ShareDialogPeoplePerson;\n    roles: ShareDialogPeopleRole[];\n  }): React.JSX.Element {\n  const handleValueChange = (value: string): void => {\n    if (value === REMOVE_VALUE) {\n      onRemove?.(person.id);\n      return;\n    }\n    onRoleChange?.(person.id, value);\n  };\n\n  return (\n    <li className=\"flex items-center gap-3\">\n      <Avatar className={avatarVariants({ layout })}>\n        {person.avatarSrc ? (\n          <AvatarImage alt=\"\" src={person.avatarSrc} />\n        ) : null}\n        <AvatarFallback>{getInitials(person.name)}</AvatarFallback>\n      </Avatar>\n      <div className=\"min-w-0 flex-1\">\n        <p className=\"truncate text-sm font-medium\">{person.name}</p>\n        {person.email ? (\n          <p className=\"truncate text-xs text-muted-foreground\">\n            {person.email}\n          </p>\n        ) : null}\n      </div>\n      <Select onValueChange={handleValueChange} value={person.role}>\n        <SelectTrigger\n          aria-label={labels.personRole(person.name)}\n          className={roleTriggerVariants({ layout })}\n        >\n          <SelectValue>{getRoleLabel(roles, person.role)}</SelectValue>\n        </SelectTrigger>\n        <SelectContent>\n          <RoleItems roles={roles} />\n          {onRemove ? (\n            <>\n              <SelectSeparator className=\"my-1\" />\n              <SelectItem\n                className=\"text-destructive focus:text-destructive\"\n                value={REMOVE_VALUE}\n              >\n                {labels.remove}\n              </SelectItem>\n            </>\n          ) : null}\n        </SelectContent>\n      </Select>\n    </li>\n  );\n}\n\nfunction PeopleList({\n  labels,\n  layout,\n  onRemove,\n  onRoleChange,\n  people,\n  roles,\n}: Labelled &\n  Layout & {\n    onRemove?: (id: string) => void;\n    onRoleChange?: (id: string, role: string) => void;\n    people: ShareDialogPeoplePerson[];\n    roles: ShareDialogPeopleRole[];\n  }): React.JSX.Element {\n  if (people.length === 0) {\n    return <p className=\"text-sm text-muted-foreground\">{labels.empty}</p>;\n  }\n\n  return (\n    <ul aria-label={labels.peopleList} className=\"flex flex-col gap-3\">\n      {people.map((person) => (\n        <PersonEntry\n          key={person.id}\n          labels={labels}\n          layout={layout}\n          onRemove={onRemove}\n          onRoleChange={onRoleChange}\n          person={person}\n          roles={roles}\n        />\n      ))}\n    </ul>\n  );\n}\n\nfunction ListView({\n  labels,\n  layout,\n  linkUrl,\n  onCopyLink,\n  onDone,\n  onKindChange,\n  onRemove,\n  onRoleChange,\n  people,\n  roles,\n}: Labelled &\n  Layout & {\n    linkUrl?: string;\n    onCopyLink?: () => void;\n    onDone?: () => void;\n    onKindChange?: (kind: ShareDialogPeopleKind) => void;\n    onRemove?: (id: string) => void;\n    onRoleChange?: (id: string, role: string) => void;\n    people: ShareDialogPeoplePerson[];\n    roles: ShareDialogPeopleRole[];\n  }): React.JSX.Element {\n  const handleInvite = (): void => {\n    onKindChange?.(\"invite\");\n  };\n  const handleDone = (): void => {\n    onDone?.();\n  };\n\n  return (\n    <>\n      <div className={stackVariants({ layout })}>\n        {linkUrl ? (\n          <>\n            <LinkRow\n              labels={labels}\n              linkUrl={linkUrl}\n              onCopyLink={onCopyLink}\n            />\n            <Separator />\n          </>\n        ) : null}\n        <PeopleList\n          labels={labels}\n          layout={layout}\n          onRemove={onRemove}\n          onRoleChange={onRoleChange}\n          people={people}\n          roles={roles}\n        />\n      </div>\n      <div className={actionsVariants({ layout })}>\n        <Button onClick={handleInvite} type=\"button\" variant=\"outline\">\n          {labels.invite}\n        </Button>\n        <Button onClick={handleDone} type=\"button\">\n          {labels.done}\n        </Button>\n      </div>\n    </>\n  );\n}\n\nfunction InviteForm({\n  labels,\n  layout,\n  onInvite,\n  onKindChange,\n  roles,\n}: Labelled &\n  Layout & {\n    onInvite?: (email: string, role: string) => void;\n    onKindChange?: (kind: ShareDialogPeopleKind) => void;\n    roles: ShareDialogPeopleRole[];\n  }): React.JSX.Element {\n  const noteId = React.useId();\n  const [email, setEmail] = React.useState(\"\");\n  const [role, setRole] = React.useState(roles[0]?.value ?? \"\");\n\n  const handleEmailChange = (\n    event: React.ChangeEvent<HTMLInputElement>,\n  ): void => {\n    setEmail(event.target.value);\n  };\n  const handleSubmit = (event: React.SyntheticEvent<HTMLFormElement>): void => {\n    event.preventDefault();\n    onInvite?.(email.trim(), role);\n  };\n  const handleBack = (): void => {\n    onKindChange?.(\"list\");\n  };\n\n  return (\n    <form className={stackVariants({ layout })} onSubmit={handleSubmit}>\n      <div className=\"flex flex-col gap-2\">\n        <div className=\"flex items-center gap-2\">\n          <Input\n            aria-describedby={noteId}\n            aria-label={labels.emailInput}\n            autoComplete=\"email\"\n            className=\"min-w-0 flex-1\"\n            onChange={handleEmailChange}\n            placeholder={labels.emailPlaceholder}\n            required\n            type=\"email\"\n            value={email}\n          />\n          <Select onValueChange={setRole} value={role}>\n            <SelectTrigger\n              aria-label={labels.inviteRole}\n              className={roleTriggerVariants({ layout })}\n            >\n              <SelectValue>{getRoleLabel(roles, role)}</SelectValue>\n            </SelectTrigger>\n            <SelectContent>\n              <RoleItems roles={roles} />\n            </SelectContent>\n          </Select>\n        </div>\n        <p className=\"text-sm text-muted-foreground\" id={noteId}>\n          {labels.note}\n        </p>\n      </div>\n      <div className={actionsVariants({ layout })}>\n        <Button onClick={handleBack} type=\"button\" variant=\"outline\">\n          {labels.back}\n        </Button>\n        <Button type=\"submit\">{labels.send}</Button>\n      </div>\n    </form>\n  );\n}\n\n/**\n * Content panel of a people-sharing dialog: a share link, the people who have\n * access with a role menu each, and an invite form. The host wraps it in a\n * `Dialog` or `Sheet` and owns `kind`, the people and every side effect.\n */\nexport const ShareDialogPeople = ({\n  className,\n  kind = \"list\",\n  labels: labelOverrides,\n  layout = \"desktop\",\n  linkUrl,\n  onClose,\n  onCopyLink,\n  onDone,\n  onInvite,\n  onKindChange,\n  onRemove,\n  onRoleChange,\n  people,\n  ref: reference,\n  roles,\n  title = \"Share\",\n  ...props\n}: ShareDialogPeopleProps & {\n  ref?: React.Ref<HTMLElement>;\n}): React.JSX.Element => {\n  const titleId = React.useId();\n  const labels = { ...DEFAULT_LABELS, ...labelOverrides };\n\n  return (\n    <section\n      {...props}\n      aria-labelledby={titleId}\n      className={cn(panelVariants({ layout }), className)}\n      data-kind={kind}\n      data-layout={layout}\n      ref={reference}\n      role=\"group\"\n    >\n      <PanelHeader\n        labels={labels}\n        onClose={onClose}\n        title={title}\n        titleId={titleId}\n      />\n      {kind === \"invite\" ? (\n        <InviteForm\n          labels={labels}\n          layout={layout}\n          onInvite={onInvite}\n          onKindChange={onKindChange}\n          roles={roles}\n        />\n      ) : (\n        <ListView\n          labels={labels}\n          layout={layout}\n          linkUrl={linkUrl}\n          onCopyLink={onCopyLink}\n          onDone={onDone}\n          onKindChange={onKindChange}\n          onRemove={onRemove}\n          onRoleChange={onRoleChange}\n          people={people}\n          roles={roles}\n        />\n      )}\n    </section>\n  );\n};\n\nShareDialogPeople.displayName = \"ShareDialogPeople\";\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component",
  "version": "0.3.0",
  "stability": "stable",
  "platforms": [
    "web"
  ]
}
