shadcn.io is not affiliated with official shadcn/ui
Share Link Dialog Block for React
A prototype file with a share dialog shown open: a switch for anyone with the link, a read-only link whose role and expiry show in its suffix, a Copy link button that really copies, and a viewer preview that turns the file behind the dialog read-only.
Installation
Overview
Let people see what a link lets others do before they send it, with this share link dialog for React with Base UI. It opens from a file in Mocklane, a prototyping tool: the page's header holds an outline Share Button, and the file itself, a top bar, a toolbar and three frames on a canvas, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The Dialog starts with a Switch for anyone with the link. While it is on, a read-only mono Input holds the link, an Access Native Select (Can view, Can comment, Can edit) writes the role into the link as ?role= and an expiry select (never, 7 or 30 days) adds &until= and the date. One sentence says in words what the link allows and when it stops. A second switch, Preview as a viewer, turns the file behind the dialog read-only: its toolbar dims and a chip says View only. Copy link is the only Shine Button and copies the link to your clipboard. For preview the dialog is drawn open in place when the page loads; the header button opens the real dialog, with the same state. For design files, documents, boards and any app that shares by link.
FAQ
Why is the dialog already open, and what do I keep?
So you can see it without a click. On load the dialog is a copy drawn in place over the file: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Share button opens the real Dialog, modal, with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same LinkFields component and share the block's state, so a switch flipped in the copy is flipped in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How does the link show what it allows?
The link is built from the choices, not typed once per state: the file's address, then ?role= and the access you picked, then &until= and the end day when it expires. The end day is the as-of day in the file (15 October 2026) plus 7 or 30 days, by UTC arithmetic, so it never moves with your clock. The sentence under the selects says the same thing in words: who can do what, and when the link stops working. Turn the switch off and the field says so, the selects wait and Copy link explains what is missing.
What does Preview as a viewer do?
It draws what a person with the link would find. With Can view or Can comment the toolbar behind the dialog dims and a chip names the limit; with Can edit nothing is locked and the sentence says so. It only changes the drawing and the status line, because this demo has no real file, and it stays on after you close the dialog so you can look at the result. Turn the link off and the preview waits, since nobody could open the file.
Does Copy link really copy?
Yes. The browser's clipboard is real, so pressing it puts the whole link, suffix included, on your clipboard, the button reads Copied for three seconds and the status line says what was copied. If the browser refuses (a page without permission), a short alert under the field says so and asks you to select the link and copy it by hand. The link itself is typed in the file and points nowhere: in your app create the link on your server and return it.
Is it accessible from the keyboard?
Yes. The real dialog is named by its title and described by its sentence, focus starts on the link switch, and Escape, Done and the close button return focus to the Share button. Every control is a real switch, select or input with a name, and what changes is spoken once in a polite status line (inside the dialog while it is open). The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange.
What stays local, and how do I wire it for real?
Everything but the clipboard. Nothing is shared: switching the link on, picking an access or an expiry and previewing only change this block's state and the drawing, and the link is a typed address. In your app call your API when a control changes (turn link sharing on or off, set the role, set an end date), return the link it makes, and check the role and the end date on the server every time the link is opened, never in the page.
Related
- Pro
Share Permissions Dialog
Share and inviteA team drive with its share dialog shown open: a name or email field with suggestions under it, a role select and a Remove for each person added, a fixed owner, two inherited rows with a lock, and a general access select, with the people count said whenever it changes.
- Pro
Invite Members Dialog
Share and inviteA household calendar's Members page with its invite dialog shown open: one email field that knows the household's domain, so an outside address joins as a guest, the people who already have access, and a Send invite button that adds a pending row.
- Pro
A stock spreadsheet with its copy-as dialog shown open: the same four selected rows as Markdown, CSV, JSON or plain text, a preview that shows exactly what lands on the clipboard, a header-row option and a button that writes it.
- Pro
Share Receipt Dialog
Share and inviteA payments app's Payment sent page with a dialog shown open that keeps the receipt three honest ways: a paper receipt drawn in mono type, Copy as text, Save .txt and Print, each doing what the browser really does.
- Pro
No Shared Items Empty State
Files and docsA document tool's share dialog shown open over a drawn page: three access cards beside a padlock that is shut, ajar or open, a people field with a pick list of five teammates, avatar chips, and a Share with 2 people button.
- Pro
Contact Card Dialog
Share and inviteA team directory with a contact card shown open that pages through six people: initials avatar, role, email, phone, desk and the time where they are, copy buttons, real mailto and tel links, and a Save contact button that downloads a vCard.