Files
community-rule/app/components/modals/Share/Share.view.tsx
T
adilallo 3a264ac2df Open the Share access menu above the dialog so both options can be picked.
The listbox was clipped inside the sheet, sat at 24px, and ignored arrow keys, so Anyone with the link could not be chosen by mouse or touch.
2026-11-21 11:41:05 -07:00

348 lines
10 KiB
TypeScript

"use client";
import Image from "next/image";
import { memo } from "react";
import {
getAssetPath,
shareIconPath,
type ShareIconName,
} from "../../../../lib/assetUtils";
import Avatar from "../../asset/Avatar";
import Button from "../../buttons/Button";
import Checkbox from "../../controls/Checkbox";
import SelectInput from "../../controls/SelectInput";
import TextInput from "../../controls/TextInput";
import Alert from "../Alert";
import { CreateModalFrameView } from "../Create/CreateModalFrame.view";
import ModalHeader from "../ModalHeader";
import ContentLockup from "../../type/ContentLockup";
import type { SharePerson } from "../../../../lib/ruleShareTypes";
import type { ShareViewProps } from "./Share.types";
function ShareGlyph(props: { name: ShareIconName; size?: number }) {
const size = props.size ?? 24;
return (
<Image
src={getAssetPath(shareIconPath(props.name))}
alt=""
width={size}
height={size}
className="shrink-0"
unoptimized
aria-hidden
/>
);
}
function PersonRow(props: {
initials: string;
title: string;
subtitle?: string;
roleLabel: string;
}) {
return (
<div className="flex w-full items-center gap-3 overflow-hidden">
<Avatar
alt=""
initials={props.initials}
size="xlarge"
shape="circle"
variant="filled"
/>
<div className="flex min-w-0 flex-1 flex-col gap-0.5 overflow-hidden">
<p className="truncate text-small-label text-[var(--color-content-default-primary)]">
{props.title}
</p>
{props.subtitle ? (
<p className="truncate text-x-small-paragraph text-[var(--color-content-default-tertiary)]">
{props.subtitle}
</p>
) : null}
</div>
<p className="shrink-0 text-x-small-paragraph text-[var(--color-content-default-tertiary)]">
{props.roleLabel}
</p>
</div>
);
}
function ReaderRow({ reader, roleLabel }: { reader: SharePerson; roleLabel: string }) {
return (
<PersonRow
initials={reader.initials}
title={reader.email}
roleLabel={roleLabel}
/>
);
}
export const ShareView = memo(function ShareView({
isOpen,
onClose,
className,
backdropVariant,
dialogRef,
overlayRef,
titleId,
copy,
communityName,
inviteValue,
onInviteValueChange,
onInvite,
inviteBusy,
inviteError,
ownerEmail,
ownerInitials,
shownReaders,
overflowLabel,
selectValue,
onSelectValue,
showLinkField,
shareUrlDisplay,
onTurnOffLink,
showConfirm,
communityAgreed,
onCommunityAgreedChange,
onTurnOnLink,
turnOnDisabled,
turnOnBusy,
showError,
showSaveError,
copyEnabled,
linkCopied,
onCopyLink,
}: ShareViewProps) {
const linkOn = selectValue === "shared_by_link";
return (
<CreateModalFrameView
isOpen={isOpen}
onOverlayClick={onClose}
backdropVariant={backdropVariant}
presentation="sheet"
className={className}
ariaLabel={copy.title}
ariaLabelledBy={titleId}
overlayRef={overlayRef}
dialogRef={dialogRef}
>
<ModalHeader
onClose={onClose}
showMoreOptionsButton={false}
closeButtonAriaLabel={copy.closeDialogAriaLabel}
/>
<div className="shrink-0 bg-[var(--color-surface-default-primary)] px-6">
<ContentLockup
title={copy.title}
description={communityName}
variant="modal"
alignment="left"
titleId={titleId}
/>
</div>
<div className="flex min-h-0 flex-1 flex-col gap-5 overflow-x-clip overflow-y-auto px-6 pb-6 pt-6">
<div className="flex w-full items-center gap-2">
<div className="min-w-0 flex-1">
<TextInput
type="email"
inputSize="medium"
formHeader={false}
showHelpIcon={false}
label={copy.addPeoplePlaceholder}
placeholder={copy.addPeoplePlaceholder}
value={inviteValue}
error={Boolean(inviteError)}
disabled={inviteBusy}
autoComplete="email"
onChange={(e) => onInviteValueChange(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
onInvite();
}
}}
/>
</div>
<Button
type="button"
buttonType="outline"
palette="default"
size="small"
disabled={inviteBusy || inviteValue.trim().length === 0}
onClick={onInvite}
>
{copy.invite}
</Button>
</div>
{inviteError ? (
<p className="-mt-3 text-x-small-paragraph text-[var(--color-content-default-negative-primary)]">
{inviteError}
</p>
) : null}
<div className="flex w-full flex-col items-start gap-3 overflow-hidden">
<p className="w-full text-small-label text-[var(--color-content-default-secondary)]">
{copy.peopleWithAccess}
</p>
<PersonRow
initials={ownerInitials}
title={copy.you}
subtitle={ownerEmail}
roleLabel={copy.holdsThePen}
/>
{shownReaders.map((reader) => (
<ReaderRow
key={reader.email}
reader={reader}
roleLabel={copy.canRead}
/>
))}
{overflowLabel ? (
<p className="w-full text-x-small-paragraph text-[var(--color-content-default-tertiary)]">
{overflowLabel}
</p>
) : null}
</div>
<div className="flex w-full flex-col items-start gap-2 overflow-visible">
<p className="w-full text-small-label text-[var(--color-content-default-secondary)]">
{copy.whoCanRead}
</p>
<div className="flex w-full items-center gap-3">
<ShareGlyph name={linkOn ? "language" : "lock"} />
<div className="min-w-0 flex-1">
<SelectInput
showLabel={false}
iconHelp={false}
value={selectValue}
onChange={(data) => onSelectValue(data.target.value)}
options={[
{ value: "private", label: copy.inviteOnly },
{ value: "shared_by_link", label: copy.anyoneWithLink },
]}
/>
</div>
</div>
{!showConfirm && !showError ? (
<p className="w-full text-small-paragraph text-[var(--color-content-default-tertiary)]">
{linkOn ? copy.anyoneWithLinkHint : copy.inviteOnlyHint}
</p>
) : null}
{showSaveError ? (
<Alert
type="banner"
status="danger"
size="s"
title={copy.saveErrorTitle}
description={copy.saveErrorDescription}
hasLeadingIcon
hasBodyText
hasTrailingIcon={false}
className="w-full"
/>
) : null}
</div>
{showLinkField ? (
<div className="flex w-full flex-col items-start gap-3">
<TextInput
formHeader={false}
showHelpIcon={false}
label={copy.anyoneWithLink}
value={shareUrlDisplay}
disabled
textHint={copy.linkHint}
/>
<Button
type="button"
buttonType="ghost"
palette="default"
size="small"
onClick={onTurnOffLink}
>
{copy.turnOffLink}
</Button>
</div>
) : null}
{showConfirm || showError ? (
<div className="flex w-full flex-col items-start gap-4 overflow-hidden rounded-[8px] bg-[var(--color-surface-default-secondary)] p-4">
{showError ? (
<Alert
type="banner"
status="danger"
size="s"
title={copy.errorTitle}
description={copy.errorDescription}
hasLeadingIcon
hasBodyText
hasTrailingIcon={false}
className="w-full"
/>
) : null}
<p className="w-full text-small-paragraph text-[var(--color-content-default-primary)]">
{copy.confirmBody}
</p>
<Checkbox
checked={communityAgreed}
label={copy.communityAgreed}
onChange={(data) => onCommunityAgreedChange(data.checked)}
/>
<Button
type="button"
buttonType="filled"
palette="default"
size="small"
disabled={turnOnDisabled || turnOnBusy}
onClick={onTurnOnLink}
>
{copy.turnOnLink}
</Button>
</div>
) : null}
{linkCopied ? (
<Alert
type="toast"
status="positive"
size="s"
title={copy.copiedLive}
hasLeadingIcon
hasBodyText={false}
hasTrailingIcon={false}
className="w-full"
/>
) : null}
</div>
<div className="flex shrink-0 items-center justify-between border-t border-solid border-[var(--color-border-default-secondary)] bg-[var(--color-surface-default-primary)] px-6 py-4">
<Button
type="button"
buttonType="outline"
palette="default"
size="small"
disabled={!copyEnabled}
aria-pressed={linkCopied || undefined}
onClick={onCopyLink}
>
<ShareGlyph name={linkCopied ? "check" : "link"} size={14} />
{linkCopied ? copy.copied : copy.copyLink}
</Button>
<Button
type="button"
buttonType="filled"
palette="default"
size="small"
onClick={onClose}
>
{copy.done}
</Button>
</div>
</CreateModalFrameView>
);
});
ShareView.displayName = "ShareView";