Blocks / Share dialog

Share dialog

People and teams with their role, general access, and the link's expiry, password and download.

import { ShareDialog, SharePanel, DEFAULT_SHARE } from "@forgeron/ui";
/01 → Panel
Role for the people added

People with access

  • Camille RoySales
    Owner
  • Nadia PetitFinance
    Role of Nadia Petit

General access

General access
Anyone signed in to Atelier Moreau can find and open it
Role of everyone with access
1 person added, Editor by default
import { SharePanel } from "@forgeron/ui";

const directory = [
  { id: "hb", name: "Hugo Bernard", hint: "Engineering" },
  { id: "np", name: "Nadia Petit", hint: "Finance" },
  { id: "tg", name: "Tom Garnier", hint: "Support" },
  { id: "team-ops", name: "Operations team", hint: "2 people" },
];

export default function Panel() {
  return (
    <div style={{ width: "100%", maxWidth: 480 }}>
      <SharePanel
        directory={directory}
        organization="Atelier Moreau"
        inherited={[{ person: { id: "cr", name: "Camille Roy", hint: "Sales" }, role: "Owner" }]}
        defaultValue={{
          people: [{ id: "np", role: "commenter" }],
          general: "organization",
          generalRole: "viewer",
          link: { expires: "never", password: false, download: true },
        }}
      />
    </div>
  );
}
/02 → Dialog
1 people · link
// The modal: add people with the arrows and Enter, open the file to anyone with the link and set
// the link's expiry, password and download. Done hands back the settings.
import { Button, DEFAULT_SHARE, ShareDialog, type ShareSettings } from "@forgeron/ui";
import { useState } from "react";

const directory = [
  { id: "hb", name: "Hugo Bernard", hint: "Engineering" },
  { id: "lm", name: "Léa Martin", hint: "Engineering, Operations" },
  { id: "np", name: "Nadia Petit", hint: "Finance" },
  { id: "tg", name: "Tom Garnier", hint: "Support" },
  { id: "team-sales", name: "Sales team", hint: "1 person" },
];

export default function DialogExample() {
  const [open, setOpen] = useState(false);
  const [settings, setSettings] = useState<ShareSettings>({
    ...DEFAULT_SHARE,
    general: "link",
    people: [{ id: "lm", role: "editor" }],
  });
  const [copied, setCopied] = useState(false);
  return (
    <div style={{ display: "grid", gap: 8, justifyItems: "start" }}>
      <Button variant="primary" onClick={() => setOpen(true)}>
        Share
      </Button>
      <span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
        {settings.people.length} people · {settings.general}
        {copied ? " · link copied" : ""}
      </span>
      {open ? (
        <ShareDialog
          itemName="Proposal Lyon Logistique.docx"
          directory={directory}
          organization="Atelier Moreau"
          inherited={[{ person: { id: "cr", name: "Camille Roy", hint: "Sales" }, role: "Owner" }]}
          linkUrl="https://drive.example.com/s/p7Kq2"
          onCopyLink={() => setCopied(true)}
          value={settings}
          onChange={setSettings}
          onClose={() => setOpen(false)}
        />
      ) : null}
    </div>
  );
}
API → Props
PropTypeDefaultDescription
directory{ id, name, hint? }[]—Who can be added: a combobox with arrows and Enter.
value / defaultValue / onChange{ people, general, generalRole, link: { expires, password, download } }DEFAULT_SHAREThe settings; general is restricted, organization or link.
roles / defaultRole{ value, label }[]; stringviewer, commenter, editor; the lastThe roles, least first.
inherited{ person, role, from? }[]—Fixed rows: the owner, the access from a parent folder.
organization / allowLinkstring; boolean—Offers “Anyone at …”; and “Anyone with the link” (true by default).
linkUrl / onCopyLink / expiryOptions / onPasswordChangestring; () => void; option[]; (password) => void—The link's settings, shown when anyone with the link can open it.
itemName / onClose / onDone / descriptionstring; () => void; (settings) => void; ReactNode—ShareDialog only: the modal around SharePanel, Copy link and Done.
classNamestring—Extra classes.