Share Access
Invite people by email, change permissions, remove with undo, and manage a copyable review link.
pnpm dlx shadcn@latest add @haze/share-access---
import { UserPlus, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";
import Button from "./button.astro";
import Input from "./input.astro";
import Select from "./select.astro";
import CopyButton from "./copy-button.astro";
interface Props {
id: string;
title?: string;
link?: string;
people?: { name: string; email: string; role: "viewer" | "editor" | "owner" }[];
suggestions?: { name: string; email: string }[];
class?: string;
}
const { id, title = "Release notes", link = "https://example.com/reviews/release-notes", class: className, suggestions = [],
people = [{ name: "Mila Chen", email: "mila@example.com", role: "owner" }, { name: "Owen Park", email: "owen@example.com", role: "editor" }],
} = Astro.props;
const roles = [{ label: "Can view", value: "viewer" }, { label: "Can edit", value: "editor" }];
---
<section data-haze-share-access aria-labelledby={`${id}-title`} class={cn("group/share grid min-w-0 gap-4 rounded-xl border border-border bg-popover p-4.5 shadow-float", className)}>
<p id={`${id}-title`} class="text-[1.0625rem] leading-[1.4] font-medium tracking-[-0.01em]">Share “{title}”</p>
<form data-share-invite class="grid min-w-0 gap-2">
<label for={`${id}-email`} class="text-[0.8125rem]/5 font-medium">Invite by email</label>
<Input id={`${id}-email`} name="email" type="email" multiple required placeholder="name@example.com" autocomplete="off" list={`${id}-directory`} aria-describedby={`${id}-hint`} />
<datalist id={`${id}-directory`}>{suggestions.map(person => <option value={person.email}>{person.name}</option>)}</datalist>
<p id={`${id}-hint`} class="text-[0.8125rem]/5 text-muted-foreground">Separate multiple addresses with commas.</p>
<div class="flex min-w-0 items-end gap-2">
<div class="min-w-0 flex-1"><label for={`${id}-role`} class="sr-only">Invite permission</label><Select id={`${id}-role`} name="role" value="viewer" options={roles} /></div>
<Button type="submit" variant="secondary" size="md"><UserPlus aria-hidden="true" />Invite</Button>
</div>
</form>
<ul data-share-people aria-label="People with access" class="grid min-w-0 gap-3">
{people.map((person, index) => <li data-share-person data-email={person.email.toLowerCase()} class="flex min-w-0 flex-wrap items-center gap-2">
<Avatar name={person.name} size="sm" />
<div class="min-w-24 flex-1"><p class="text-[0.8125rem]/5 font-medium wrap-anywhere">{person.name}</p><p class="text-xs/5 wrap-anywhere text-muted-foreground">{person.email}</p></div>
{person.role === "owner" ? <span class="text-[0.8125rem]/5 text-muted-foreground">Owner</span> : <div class="flex items-center gap-1">
<div class="w-28"><label for={`${id}-person-${index}`} class="sr-only">Permission for {person.name}</label><Select id={`${id}-person-${index}`} value={person.role} options={roles} data-person-role /></div>
<Button data-person-remove size="icon" variant="ghost" aria-label={`Remove ${person.name}`} class="hidden size-8 group-data-[enhanced]/share:inline-flex"><X aria-hidden="true" /></Button>
</div>}
</li>)}
</ul>
<div data-share-undo hidden class="flex flex-wrap items-center justify-between gap-2 rounded-lg bg-muted px-3 py-2 text-[0.8125rem]/5 motion-safe:animate-rise [&[hidden]]:hidden">
<span>Access removed.</span><Button data-undo-remove variant="ghost" size="sm">Undo</Button>
</div>
<div class="grid gap-2 border-t border-border pt-3">
<label for={`${id}-access`} class="text-[0.8125rem]/5 font-medium">Link access</label>
<Select id={`${id}-access`} name="access" value="restricted" options={[{ value: "restricted", label: "Invited people only" }, { value: "anyone", label: "Anyone with the link can view" }]} data-share-link-access />
<p data-share-link-hint class="text-[0.8125rem]/5 text-muted-foreground">Only invited people can open this link.</p>
<CopyButton text={link} label="Copy review link" />
</div>
<p data-share-status role="status" class="text-[0.8125rem]/5 text-muted-foreground empty:hidden"></p>
<template data-share-template>
<li data-share-person class="flex min-w-0 flex-wrap items-center gap-2 motion-safe:animate-rise">
<span data-person-avatar role="img" class="relative inline-flex shrink-0 items-center justify-center rounded-full bg-muted font-medium text-foreground inset-ring inset-ring-frame select-none size-6 text-[0.6875rem]/4"></span>
<div class="min-w-24 flex-1"><p data-person-name class="text-[0.8125rem]/5 font-medium wrap-anywhere"></p><p data-person-email class="text-xs/5 wrap-anywhere text-muted-foreground"></p></div>
<div class="flex items-center gap-1"><label class="flex items-center gap-1 text-xs"><span class="sr-only" data-person-role-label></span><select data-person-role class="h-10 rounded-lg border border-frame-input bg-field px-2 text-xs hover:border-frame-strong transition-[border-color,box-shadow] duration-150 ease-snappy focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden"><option value="viewer">Can view</option><option value="editor">Can edit</option></select></label>
<Button data-person-remove size="icon" variant="ghost" class="size-8"><X aria-hidden="true" /></Button></div>
</li>
</template>
</section>
<script>
function enhance(root: HTMLElement) {
if (root.hasAttribute("data-enhanced")) return;
const form = root.querySelector<HTMLFormElement>("[data-share-invite]")!;
const list = root.querySelector<HTMLElement>("[data-share-people]")!;
const email = form.querySelector<HTMLInputElement>("input[type=email]")!;
const inviteRole = form.querySelector<HTMLSelectElement>("select")!;
const template = root.querySelector<HTMLTemplateElement>("[data-share-template]")!;
const status = root.querySelector<HTMLElement>("[data-share-status]")!;
const undo = root.querySelector<HTMLElement>("[data-share-undo]")!;
const removed: { row: HTMLElement; next: Element | null }[] = [];
const undoText = undo.querySelector("span")!;
const syncUndo = () => { undo.hidden = removed.length === 0; undoText.textContent = removed.length > 1 ? `${removed.length} people removed.` : "Access removed."; };
const notify = (kind: string, detail: unknown) => root.dispatchEvent(new CustomEvent("haze:share-change", { bubbles: true, detail: { kind, value: detail } }));
form.addEventListener("submit", event => {
event.preventDefault();
if (!form.reportValidity()) return;
const existing = new Set([...list.querySelectorAll<HTMLElement>("[data-email]")].map(row => row.dataset.email));
const invites = [...new Set(email.value.split(",").map(address => address.trim().toLowerCase()).filter(Boolean))].filter(address => !existing.has(address));
for (let i = removed.length - 1; i >= 0; i--) if (invites.includes(removed[i]!.row.dataset.email ?? "")) removed.splice(i, 1);
syncUndo();
invites.forEach(address => {
const row = template.content.firstElementChild!.cloneNode(true) as HTMLElement;
row.dataset.email = address;
const personName = address.split("@")[0];
const avatar = row.querySelector<HTMLElement>("[data-person-avatar]")!;
avatar.textContent = personName.split(/\s+/).map(part => part[0] ?? "").join("").slice(0, 2).toUpperCase();
avatar.setAttribute("aria-label", personName);
row.querySelector<HTMLElement>("[data-person-name]")!.textContent = personName;
row.querySelector<HTMLElement>("[data-person-email]")!.textContent = address;
row.querySelector<HTMLElement>("[data-person-role-label]")!.textContent = `Permission for ${address}`;
row.querySelector<HTMLSelectElement>("select")!.value = inviteRole.value;
row.querySelector("[data-person-remove]")!.setAttribute("aria-label", `Remove ${address}`);
list.append(row);
});
notify("invite", invites.map(address => ({ email: address, role: inviteRole.value })));
status.textContent = invites.length ? `${invites.length} ${invites.length === 1 ? "person" : "people"} added.` : "These people already have access.";
email.value = "";
email.focus();
});
list.addEventListener("change", event => {
const field = (event.target as Element).closest<HTMLSelectElement>("[data-person-role]");
if (!field) return;
const address = field.closest<HTMLElement>("[data-email]")?.dataset.email;
notify("role", { email: address, role: field.value });
status.textContent = `Permission updated for ${address}.`;
});
list.addEventListener("click", event => {
const button = (event.target as Element).closest("[data-person-remove]");
const row = button?.closest<HTMLElement>("[data-share-person]");
if (!row) return;
removed.push({ row, next: row.nextElementSibling });
row.remove();
syncUndo();
undo.querySelector<HTMLButtonElement>("button")!.focus();
notify("remove", row.dataset.email);
status.textContent = `Access removed for ${row.dataset.email}. Undo is available.`;
});
undo.querySelector("button")!.addEventListener("click", () => {
const last = removed.pop();
if (!last) return;
list.insertBefore(last.row, last.next?.parentElement === list ? last.next : null);
syncUndo();
(removed.length ? undo.querySelector<HTMLButtonElement>("button") : last.row.querySelector<HTMLButtonElement>("[data-person-remove]"))?.focus();
notify("restore", last.row.dataset.email);
status.textContent = `Access restored for ${last.row.dataset.email}.${removed.length ? " Undo is available for the others." : ""}`;
});
const access = root.querySelector<HTMLSelectElement>("[data-share-link-access]")!;
access.addEventListener("change", () => {
root.querySelector<HTMLElement>("[data-share-link-hint]")!.textContent = access.value === "anyone" ? "Anyone with this link can view this item." : "Only invited people can open this link.";
notify("link", access.value);
status.textContent = "Link access updated.";
});
root.setAttribute("data-enhanced", "");
}
const init = () => document.querySelectorAll<HTMLElement>("[data-haze-share-access]").forEach(enhance);
init();
if (!document.documentElement.hasAttribute("data-haze-share-access-listener")) {
document.documentElement.setAttribute("data-haze-share-access-listener", "");
document.addEventListener("astro:page-load", init);
}
</script>When to use
- One document needs a single place to inspect and manage its access.
- Email invitations and link permissions belong in the same panel.
When not to use
- Access depends on complex organization-wide policy. Build a dedicated settings view.
Installation
Add the Haze registry to components.json once, then install Share Access with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/share-accessnpx shadcn@latest add @haze/share-accessyarn dlx shadcn@latest add @haze/share-accessbunx --bun shadcn@latest add @haze/share-accessFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Input, directory and panel heading ID prefix. |
| title | string | – | Name of the shared resource. |
| link | string | – | Review link to copy. |
| people | { name: string; email: string; role: 'viewer' | 'editor' | 'owner' }[] | – | Initial access list. Owner controls are locked. |
| suggestions | { name: string; email: string }[] | – | Native email directory suggestions. |
| class | string | – | Additional classes on the component wrapper. |
Keyboard interactions
- TabArrow keys
- Reach invitations, permissions and link settings and use native select navigation.
- EnterSpace
- Invite validated addresses, remove someone or undo removal.
Accessibility
- The invitation field uses native multiple-email validation and optional directory suggestions. Per-person permission fields and removal buttons include the person's name.
- The UI emits haze:share-change for invitation, role, removal, restoration and link changes. Application code must authorize and persist those changes.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Share Access" with `npx shadcn@latest add @haze/share-access`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ShareAccess from "@/components/haze/ui/share-access.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/share-access.md
Customize with real content
Adapt the Haze share-access ui for our product. Replace the demo values of these props with our real content: id, title, link, people, suggestions, class. Keep the layout, the heading level rules and these accessibility details: The invitation field uses native multiple-email validation and optional directory suggestions. Per-person permission fields and removal buttons include the person's name. The UI emits haze:share-change for invitation, role, removal, restoration and link changes. Application code must authorize and persist those changes. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using share-access, check it fits: use it when one document needs a single place to inspect and manage its access.; email invitations and link permissions belong in the same panel.. Avoid it when access depends on complex organization-wide policy. build a dedicated settings view.. Alternatives: @haze/popover, @haze/dialog, @haze/copy-button.
Dependencies
- npm: @lucide/astro
- @haze/avatar
- @haze/button
- @haze/input
- @haze/select
- @haze/copy-button
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.