Sharing

Invite people and set who can view or edit.

Share “Checkout retries”

People with access

  • AL

    Ada Lovelace (you)

    [email protected]

    Full accessOwner
  • BO
  • Payments team

    6 members · Inherited from Engineering

    Can commentChange it on Engineering
  • Scout

    Agent · acts with this access

General access

Only the people above can open it.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/share

Usage

import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { Share, type ShareCandidate, type ShareEntry } from "./ui/uicontext/components/kit/Share.ts"
const Message = UiSchema.TaggedEnum({	RequestedShareAdd: { id: Schema.String, role: Schema.String },	RequestedShareInvite: { request: Schema.String, emails: Schema.Array(Schema.String), role: Schema.String },	RequestedShareRole: { id: Schema.String, role: Schema.String },	RequestedShareRemove: { id: Schema.String },})// every change is a request; the app answers through `outcomes` and sends the new entries backexport const PageSharing = (	h: Html.H<typeof Message.Type>,	page: { readonly title: string; readonly entries: ReadonlyArray<ShareEntry>; readonly members: ReadonlyArray<ShareCandidate>; readonly outcomes: ReadonlyArray<Outcome> },) =>	Share(h, {		props: {			objectName: page.title,			roles: [				{ value: "view", label: "Can view" },				{ value: "edit", label: "Can edit" },			],			entries: page.entries,			candidates: page.members,			inviteEmails: true,			can: ["manage"],			outcomes: page.outcomes,		},		onEmit: {			RequestedAdd: ({ id, role }) => Message.RequestedShareAdd({ id, role }),			RequestedInvite: ({ request, emails, role }) => Message.RequestedShareInvite({ request, emails, role }),			RequestedRole: ({ id, role }) => Message.RequestedShareRole({ id, role }),			RequestedRemove: ({ id }) => Message.RequestedShareRemove({ id }),			RequestedGeneral: () => undefined,			RequestedInviteLink: () => undefined,			RequestedClose: () => undefined,		},	})

Examples

In a dialog

layout: "dialog" with open; Escape, a press outside and Done all ask to close with RequestedClose.

Read-only

Without manage in can, roles show as badges and readOnlyReason says who can change them.

Who can see this page

Only people with full access can change sharing. Ask Ada Lovelace.

People with access

  • AL

    Ada Lovelace

    [email protected]

    Full accessOwner
  • BO
    Can edit
  • Payments team

    6 members · Inherited from Engineering

    Can commentChange it on Engineering
  • Scout (you)

    Agent · acts with this access

    Can view

General access

Everyone at Northwind Freight

Anyone in the workspace can find and open it. · Can comment

API reference

ShareComponent

Props

Share props
NameTypeDefaultDescription
agentIdstring—This share control's id for agents, unique on the page: "share-page-q3"
objectNamerequiredstring—What is shared: "Q3 plan"
titlestringShare "<objectName>""Share", "Share this agent"; Share "<objectName>" by default
rolesrequiredRoleOption[]—The roles that can be given, from least to most access: "Can view", "Can edit"
maxRolestring—The most the person may grant, by value; roles above it are disabled
entriesrequiredShareEntry[]—The people, groups and domains that have access now, each with a role
candidatesShareCandidate[]—Who can be added; empty or left out hides the add row unless inviteEmails is on
inviteEmailsboolean—People outside candidates can be invited by typing or pasting their email addresses
defaultRolestring—The role a new entry gets unless the person picks another
general{ value, options, role }—Who else can open it, from narrowest to widest
canrequiredCan(["manage"])—What the person may do: "manage" changes sharing; without it everything is read-only with readOnlyReason
readOnlyReasonstring—Why sharing can't be changed here, shown when can leaves out "manage"
keepOne{ role, message }—At least one entry must keep this role: { role: "owner", message: "A workspace needs at least one owner." }
notestring—A line about what sharing means here: "People who run the agent get its access, not their own."
applyingstring—A change is still being applied: "Applying to 12 subfolders…"
outcomesOutcome[]—The app's answers to requests, one per request. The request id is the entry's (or candidate's) id for RequestedAdd, RequestedRole and RequestedRemove, "general" for RequestedGeneral and "invite-link" for RequestedInviteLink. A pending entry is busy, a pending "invite-link" says the link is being made, and the newest refusal shows its reason.
linkstring—A link to the object, to copy
invite{ label, url, note }—An invitation link: anyone who opens it can join. "Create invite link" asks the app (RequestedInviteLink); once the app has made one it passes url and the person copies it.
layout"dialog" | "inline"—A native modal dialog (with open) or inline on the page
openboolean—Whether the dialog is showing, with the dialog layout; closing it comes back as RequestedClose

Events

Share events
EventPayloadDescription
RequestedAdd{ id: string; role: string }Give this person or group access with this role
RequestedRole{ id: string; role: string }Change the role of someone who already has access
RequestedRemove{ id: string }Take away this person's or group's access
RequestedGeneral{ value: string; role?: string }Change who else can open it, to this general access option; role when its role changes
RequestedInvite{ request: string; emails: string[]; role: string }Invite people by email at this role; answer through outcomes with the same request
RequestedInviteLink{}Make an invitation link; send it back as invite.url
RequestedClose{}The person closed the dialog

Agent actions

What agents can do with Share
ActionDescription
AddedEntryasks firstShare with a candidate (id from page_query) at a role. Target: { id, role: null }.
ChangedRoleasks firstChange an entry's role. Target: { id, role } as in the snapshot.
ConfirmedRemoveasks firstRemove an entry's access. Target: { id, role } as in the snapshot.
InvitedByEmailasks firstInvite people by email address at a role. Target: { emails }.
ClickedInviteLinkasks firstMake an invitation link that lets anyone who has it join. The person copies it; you don't see it.
ConfirmedGeneralSet general access (a value from generalOptions). Widening is consequential: target { general }.

RoleBadgeView function

Options

RoleBadge options
NameTypeDescription
labelrequiredstringThe role's name: "Owner"

Accessibility

  • Opens as a modal dialog or sits inline, titled either way. Adding someone is a form with labelled selects for the person and the role.
  • Each person has a role select and a Remove button named for them; roles above your own access are disabled, and locked entries say why.
  • Removing someone and widening general access ask first, inline. Copying a link, a pending change and a refusal are announced.
  • Agents read who has which role; adding, changing, removing and widening access are consequential and name the entry they change.

Source