diff --git a/packages/island/src/atoms/avatar/Avatar.tsx b/packages/island/src/atoms/avatar/Avatar.tsx
index 01f1b85..92082c2 100644
--- a/packages/island/src/atoms/avatar/Avatar.tsx
+++ b/packages/island/src/atoms/avatar/Avatar.tsx
@@ -16,6 +16,7 @@ export function Avatar({
src,
size = 'md',
verified = false,
+ muted = false,
verifiedLabel,
label,
className,
@@ -36,7 +37,7 @@ export function Avatar({
aria-hidden={label ? undefined : true}
justifyItems="justify-items-center"
alignItems="items-center"
- className={avatarVariants({ size })}
+ className={avatarVariants({ size, muted })}
>
, 'children'> & {
size?: AvatarSize;
/** The creator's verification mark at the bottom inline end. */
verified?: boolean;
+ /** Greyed: an account that can't be used now (a suspended creator's own channel). */
+ muted?: boolean;
/** The mark's accessible name, such as «تأییدشده». */
verifiedLabel?: string;
/**
diff --git a/packages/island/src/atoms/avatar/variants.ts b/packages/island/src/atoms/avatar/variants.ts
index df74a67..b962df8 100644
--- a/packages/island/src/atoms/avatar/variants.ts
+++ b/packages/island/src/atoms/avatar/variants.ts
@@ -17,7 +17,12 @@ export const avatarVariants = cva(
/** The profile photo field. */
'2xl': 'size-24',
},
+ /** An account that can't be used, such as a suspended creator's own avatar: no brand colour. */
+ muted: {
+ true: 'bg-surface-sunken text-text-secondary grayscale',
+ false: '',
+ },
},
- defaultVariants: { size: 'md' },
+ defaultVariants: { size: 'md', muted: false },
},
);
diff --git a/packages/island/src/atoms/button/Button.tsx b/packages/island/src/atoms/button/Button.tsx
index c57bc5b..f70c674 100644
--- a/packages/island/src/atoms/button/Button.tsx
+++ b/packages/island/src/atoms/button/Button.tsx
@@ -22,6 +22,8 @@ export function Button({
label,
frozen = false,
frozenReason,
+ frozenAlign,
+ pressableWhenFrozen = false,
isLoading = false,
className,
children,
@@ -68,6 +70,7 @@ export function Button({
{...buttonProps}
reason={frozenReason}
block={block}
+ align={frozenAlign}
className={classes}
aria-label={ariaLabel}
>
@@ -80,10 +83,11 @@ export function Button({
// blocked, swallows the click: preventDefault also stops a submit button's form, including Enter
// in a field. A server render can't carry a handler, so a blocked button without onClick renders
// `type="button"` instead, which can't submit its form at all.
+ const swallowsClick = isLoading || (frozen && !pressableWhenFrozen);
const handleClick =
onClick &&
((event: MouseEvent) => {
- if (isBlocked) {
+ if (swallowsClick) {
event.preventDefault();
return;
}
diff --git a/packages/island/src/atoms/button/components/FrozenButton.tsx b/packages/island/src/atoms/button/components/FrozenButton.tsx
index 00978d3..7dd9da2 100644
--- a/packages/island/src/atoms/button/components/FrozenButton.tsx
+++ b/packages/island/src/atoms/button/components/FrozenButton.tsx
@@ -15,6 +15,7 @@ import { frozenTipVariants } from '../variants';
export function FrozenButton({
reason,
block,
+ align,
children,
...props
}: FrozenButtonProps) {
@@ -45,7 +46,7 @@ export function FrozenButton({
role="tooltip"
variant="caption"
color="inverse"
- className={frozenTipVariants({ open: isOpen })}
+ className={frozenTipVariants({ open: isOpen, align })}
>
{reason}
diff --git a/packages/island/src/atoms/button/types.ts b/packages/island/src/atoms/button/types.ts
index dd3141a..0dbe867 100644
--- a/packages/island/src/atoms/button/types.ts
+++ b/packages/island/src/atoms/button/types.ts
@@ -3,7 +3,9 @@ import type NextLink from 'next/link';
import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { IconName } from '../icon';
-import type { buttonVariants } from './variants';
+import type { buttonVariants, frozenTipVariants } from './variants';
+
+type FrozenTipAlign = VariantProps['align'];
type ButtonOwnProps = Pick<
VariantProps,
@@ -18,6 +20,16 @@ type ButtonOwnProps = Pick<
frozen?: boolean;
/** Why the button is frozen, shown on tap, hover and focus. */
frozenReason?: ReactNode;
+ /**
+ * Frozen without a reason, yet a press still calls `onClick`, which explains or checks instead:
+ * a publish menu that opens why it can't publish, an empty post's check.
+ */
+ pressableWhenFrozen?: boolean;
+ /**
+ * Where the reason sits above the button: centred (default), or `end`, its end on the button's,
+ * for a button at the screen's end edge, so a long reason stays on screen.
+ */
+ frozenAlign?: FrozenTipAlign;
/** An action is in flight: keeps the label, shows a spinner, and blocks repeat taps. */
isLoading?: boolean;
children?: ReactNode;
@@ -57,5 +69,6 @@ export type FrozenButtonProps = Omit<
> & {
reason: ReactNode;
block?: boolean | null;
+ align?: FrozenTipAlign;
children: ReactNode;
};
diff --git a/packages/island/src/atoms/button/variants.ts b/packages/island/src/atoms/button/variants.ts
index 1731980..171c759 100644
--- a/packages/island/src/atoms/button/variants.ts
+++ b/packages/island/src/atoms/button/variants.ts
@@ -48,14 +48,19 @@ export const buttonVariants = cva(
},
);
-/** The tooltip that explains a frozen button, above it and centred on it. */
+/** The tooltip that explains a frozen button, above it. */
export const frozenTipVariants = cva(
- // Physical left: centring is the same in RTL and LTR.
- 'pointer-events-none absolute bottom-[calc(100%+0.5rem)] left-1/2 z-menu hidden w-max max-w-[16.25rem] -translate-x-1/2 rounded-sm bg-surface-inverse px-3 py-1.5 text-center whitespace-normal shadow-2 group-focus-within:block group-hover:block',
+ 'pointer-events-none absolute bottom-[calc(100%+0.5rem)] z-menu hidden w-max max-w-[16.25rem] rounded-sm bg-surface-inverse px-3 py-1.5 text-center whitespace-normal shadow-2 group-focus-within:block group-hover:block',
{
variants: {
open: { true: 'block', false: '' },
+ align: {
+ // Physical left: centring is the same in RTL and LTR.
+ center: 'left-1/2 -translate-x-1/2',
+ // Its end on the button's end, so it grows toward the screen from a button at the edge.
+ end: 'end-0',
+ },
},
- defaultVariants: { open: false },
+ defaultVariants: { open: false, align: 'center' },
},
);
diff --git a/packages/island/src/index.ts b/packages/island/src/index.ts
index 11f458d..0e460f3 100644
--- a/packages/island/src/index.ts
+++ b/packages/island/src/index.ts
@@ -107,6 +107,8 @@ export { Banner, bannerVariants } from './molecules/banner';
export type { BannerProps, BannerTone } from './molecules/banner';
export { Card, cardVariants } from './molecules/card';
export type { CardOwnProps, CardProps } from './molecules/card';
+export { ActionMenu } from './molecules/action-menu';
+export type { ActionMenuItem, ActionMenuProps } from './molecules/action-menu';
export { ChipGroup } from './molecules/chip-group';
export type { ChipGroupOption, ChipGroupProps } from './molecules/chip-group';
export { ChoiceCard, choiceCardVariants } from './molecules/choice-card';
@@ -122,7 +124,7 @@ export type { LockedTeaserProps } from './molecules/locked-teaser';
export { MediaCarousel } from './molecules/media-carousel';
export type { MediaCarouselProps, MediaItem } from './molecules/media-carousel';
export { Modal } from './molecules/modal';
-export type { ModalProps } from './molecules/modal';
+export type { ModalProps, ModalSize } from './molecules/modal';
export {
NetworkStatus,
networkStatusVariants,
@@ -139,6 +141,17 @@ export type {
ResendCodeProps,
ResendStatus,
} from './molecules/resend-code';
+export {
+ SegmentedChoice,
+ segmentedChoiceOptionVariants,
+ segmentedChoiceVariants,
+} from './molecules/segmented-choice';
+export type {
+ SegmentedChoiceOption,
+ SegmentedChoiceProps,
+ SegmentedChoiceSize,
+ SegmentedChoiceTrack,
+} from './molecules/segmented-choice';
export { Sheet } from './molecules/sheet';
export type { SheetPlacement, SheetProps } from './molecules/sheet';
export { StateMessage, stateMessageVariants } from './molecules/state-message';
@@ -148,6 +161,8 @@ export type {
} from './molecules/state-message';
export { StepProgress } from './molecules/step-progress';
export type { StepProgressProps } from './molecules/step-progress';
+export { TabLinks } from './molecules/tab-links';
+export type { TabLinkItem, TabLinksProps } from './molecules/tab-links';
export {
TextInput,
textInputBoxVariants,
diff --git a/packages/island/src/molecules/action-menu/ActionMenu.tsx b/packages/island/src/molecules/action-menu/ActionMenu.tsx
new file mode 100644
index 0000000..5a9e032
--- /dev/null
+++ b/packages/island/src/molecules/action-menu/ActionMenu.tsx
@@ -0,0 +1,97 @@
+'use client';
+
+import { useEffect, useEffectEvent, useRef } from 'react';
+import type { KeyboardEvent } from 'react';
+
+import { Element } from '../../primitives/element';
+import { cn } from '../../tools/cn';
+import { ActionMenuItem } from './components/ActionMenuItem';
+import type { ActionMenuProps } from './types';
+import { actionMenuVariants } from './variants';
+
+/**
+ * A short list of destinations or actions anchored to its trigger, such as «انتشار» → «پست جدید»
+ * / «پیشبینی جدید», or a post's share → «کپی لینک». Put it in a positioned container that holds
+ * only the trigger and the menu, and give the trigger `aria-haspopup="menu"`. It takes focus when
+ * it opens; ↑ ↓ move, and the trigger keeps its own press. Escape or a choice closes it and puts
+ * focus back on that container's `[aria-haspopup]` trigger; a press outside, or Tab out of the
+ * menu and its trigger, closes it and leaves focus where the press or Tab put it.
+ */
+export function ActionMenu({
+ open,
+ onClose,
+ items,
+ label,
+ placement = 'below',
+ className,
+}: ActionMenuProps) {
+ const ref = useRef(null);
+ const close = useEffectEvent(onClose);
+
+ useEffect(() => {
+ if (!open) return undefined;
+ // The trigger's container: the menu and its trigger, nothing else.
+ const area = ref.current?.parentElement ?? ref.current;
+ if (!area) return undefined;
+ ref.current?.querySelector('[role="menuitem"]')?.focus();
+ const handlePointerDown = (event: PointerEvent) => {
+ if (!area.contains(event.target as Node)) close();
+ };
+ // Tab out of it closes it; focus has already moved on, so it stays there. A null target
+ // (another window, a press on nothing focusable) keeps it open.
+ const handleFocusOut = (event: FocusEvent) => {
+ const next = event.relatedTarget;
+ if (next instanceof Node && !area.contains(next)) close();
+ };
+ document.addEventListener('pointerdown', handlePointerDown);
+ area.addEventListener('focusout', handleFocusOut);
+ return () => {
+ document.removeEventListener('pointerdown', handlePointerDown);
+ area.removeEventListener('focusout', handleFocusOut);
+ };
+ }, [open]);
+
+ if (!open) return null;
+
+ // Read on the event, before the menu unmounts; focusing the trigger keeps the keyboard in place.
+ const closeToTrigger = () => {
+ const trigger =
+ ref.current?.parentElement?.querySelector('[aria-haspopup]');
+ onClose();
+ trigger?.focus();
+ };
+
+ const onKeyDown = (event: KeyboardEvent) => {
+ const options = Array.from(
+ ref.current?.querySelectorAll('[role="menuitem"]') ?? [],
+ );
+ const at = options.indexOf(document.activeElement as HTMLElement);
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ closeToTrigger();
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
+ event.preventDefault();
+ const step = event.key === 'ArrowDown' ? 1 : -1;
+ options[(at + step + options.length) % options.length]?.focus();
+ }
+ };
+
+ return (
+
+ {items.map((item) => (
+
+ ))}
+
+ );
+}
diff --git a/packages/island/src/molecules/action-menu/components/ActionMenuItem.tsx b/packages/island/src/molecules/action-menu/components/ActionMenuItem.tsx
new file mode 100644
index 0000000..cbac0c8
--- /dev/null
+++ b/packages/island/src/molecules/action-menu/components/ActionMenuItem.tsx
@@ -0,0 +1,70 @@
+import NextLink from 'next/link';
+
+import { FlexBox } from '../../../atoms/flex-box';
+import { Icon } from '../../../atoms/icon';
+import { Typography } from '../../../atoms/typography';
+import { Element } from '../../../primitives/element';
+import { cn } from '../../../tools/cn';
+import type { ActionMenuItemProps } from '../types';
+
+/** A link row and a button row look the same. */
+const ROW_CLASS =
+ 'min-h-touch-target rounded-md px-3 text-text-primary no-underline outline-none hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:focus-ring';
+
+/**
+ * One destination or action: its icon in the brand colour and its name, a 44px row. A link
+ * navigates; a button closes the menu, then runs its `onSelect`.
+ */
+export function ActionMenuItem({
+ href,
+ label,
+ icon,
+ onSelect,
+ onClose,
+}: ActionMenuItemProps) {
+ const content = (
+ <>
+
+
+ {label}
+
+ >
+ );
+
+ return (
+
+ {href != null ? (
+
+ {content}
+
+ ) : (
+ {
+ onClose();
+ onSelect?.();
+ }}
+ alignItems="items-center"
+ gap="gap-3"
+ className={cn(ROW_CLASS, 'w-full cursor-pointer text-start')}
+ >
+ {content}
+
+ )}
+
+ );
+}
diff --git a/packages/island/src/molecules/action-menu/index.ts b/packages/island/src/molecules/action-menu/index.ts
new file mode 100644
index 0000000..3c8c951
--- /dev/null
+++ b/packages/island/src/molecules/action-menu/index.ts
@@ -0,0 +1,2 @@
+export { ActionMenu } from './ActionMenu';
+export type { ActionMenuItem, ActionMenuProps } from './types';
diff --git a/packages/island/src/molecules/action-menu/types.ts b/packages/island/src/molecules/action-menu/types.ts
new file mode 100644
index 0000000..741c5a4
--- /dev/null
+++ b/packages/island/src/molecules/action-menu/types.ts
@@ -0,0 +1,31 @@
+import type { IconName } from '../../atoms/icon';
+
+/** A destination (`href`, a link) or an action (`onSelect`, a button), never both. */
+export type ActionMenuItem = {
+ label: string;
+ icon: IconName;
+} & (
+ | { href: string; onSelect?: never }
+ | {
+ /** Runs after the menu has closed, such as «کپی لینک». */
+ onSelect: () => void;
+ href?: never;
+ }
+);
+
+export type ActionMenuProps = {
+ open: boolean;
+ /** Escape, a press or Tab outside the menu and its trigger, or a choice close it. */
+ onClose: () => void;
+ items: readonly ActionMenuItem[];
+ /** The menu's accessible name, such as «انتشار». */
+ label: string;
+ /** above: over a bottom-nav button. below: under a header button. */
+ placement?: 'above' | 'below';
+ className?: string;
+};
+
+export type ActionMenuItemProps = ActionMenuItem & {
+ /** The menu's close, which also returns focus to the trigger. */
+ onClose: () => void;
+};
diff --git a/packages/island/src/molecules/action-menu/variants.ts b/packages/island/src/molecules/action-menu/variants.ts
new file mode 100644
index 0000000..8eee572
--- /dev/null
+++ b/packages/island/src/molecules/action-menu/variants.ts
@@ -0,0 +1,15 @@
+import { cva } from 'class-variance-authority';
+
+/** A card that hangs off its trigger: centred over it, or under it at the inline end. */
+export const actionMenuVariants = cva(
+ 'absolute z-menu m-0 min-w-55 rounded-lg border border-border-subtle bg-surface-raised p-1 shadow-2',
+ {
+ variants: {
+ placement: {
+ above: 'bottom-full left-1/2 mb-3 -translate-x-1/2',
+ below: 'end-0 top-full mt-2',
+ },
+ },
+ defaultVariants: { placement: 'below' },
+ },
+);
diff --git a/packages/island/src/molecules/locked-teaser/LockedTeaser.tsx b/packages/island/src/molecules/locked-teaser/LockedTeaser.tsx
index 7c84a03..d9296b2 100644
--- a/packages/island/src/molecules/locked-teaser/LockedTeaser.tsx
+++ b/packages/island/src/molecules/locked-teaser/LockedTeaser.tsx
@@ -4,17 +4,19 @@ import { Button } from '../../atoms/button';
import { FlexBox } from '../../atoms/flex-box';
import { GridBox } from '../../atoms/grid-box';
import { Icon } from '../../atoms/icon';
+import { Skeleton } from '../../atoms/skeleton';
import { Tag } from '../../atoms/tag';
import { Typography } from '../../atoms/typography';
import { Element } from '../../primitives/element';
-import { ACTION_CLASS } from './constants';
+import { ACTION_CLASS, PENDING_ACTION_CLASS } from './constants';
import type { LockedTeaserProps } from './types';
/**
* The one locked premium body, on the channel, the post page and the feed alike: two lines of
* preview fading into a saffron lock, a lock placeholder for the images, a prediction's frame,
* then one message and one CTA on `premium-subtle`. Images are never shown or blurred, not even
- * from a blurHash: a blurred chart still leaks the direction.
+ * from a blurHash: a blurred chart still leaks the direction. While the viewer is unknown
+ * (`pending`), the gate keeps the message's place and draws the CTA as a skeleton.
*/
export function LockedTeaser({
preview,
@@ -26,6 +28,9 @@ export function LockedTeaser({
actionLabel,
actionHref,
onAction,
+ actionFrozenReason,
+ actionIndicator,
+ pending = false,
className,
}: LockedTeaserProps) {
return (
@@ -76,8 +81,41 @@ export function LockedTeaser({
gap="gap-3"
className="rounded-md bg-premium-subtle p-4 text-center"
>
- {message}
- {actionHref ? (
+ {pending ? (
+ <>
+ {/* The message's own height, so the gate doesn't move when the viewer is known. */}
+
+ {message}
+
+
+
+
+
+ >
+ ) : actionIndicator ? (
+
+ ) : actionFrozenReason ? (
+
+ ) : actionHref ? (
diff --git a/packages/island/src/molecules/locked-teaser/constants.ts b/packages/island/src/molecules/locked-teaser/constants.ts
index c1f59d1..fa71f4a 100644
--- a/packages/island/src/molecules/locked-teaser/constants.ts
+++ b/packages/island/src/molecules/locked-teaser/constants.ts
@@ -1,2 +1,5 @@
/** Puts the CTA above a card's stretched link (PostCard's), so it keeps its own tap. */
export const ACTION_CLASS = 'relative z-1';
+
+/** The CTA's skeleton: a Button md's height and about its width. */
+export const PENDING_ACTION_CLASS = 'h-control-md w-34';
diff --git a/packages/island/src/molecules/locked-teaser/index.ts b/packages/island/src/molecules/locked-teaser/index.ts
index 5a98d4d..c9b7b8b 100644
--- a/packages/island/src/molecules/locked-teaser/index.ts
+++ b/packages/island/src/molecules/locked-teaser/index.ts
@@ -1,2 +1,2 @@
export { LockedTeaser } from './LockedTeaser';
-export type { LockedTeaserProps } from './types';
+export type { LockedTeaserIndicator, LockedTeaserProps } from './types';
diff --git a/packages/island/src/molecules/locked-teaser/types.ts b/packages/island/src/molecules/locked-teaser/types.ts
index 1d451e7..109f5bd 100644
--- a/packages/island/src/molecules/locked-teaser/types.ts
+++ b/packages/island/src/molecules/locked-teaser/types.ts
@@ -1,5 +1,14 @@
import type { ReactNode } from 'react';
+import type { IconName } from '../../atoms/icon';
+
+/** A frozen status in the CTA's place, such as «پرداخت در حال بررسی», and why it can't be pressed. */
+export type LockedTeaserIndicator = {
+ label: ReactNode;
+ reason: ReactNode;
+ icon?: IconName;
+};
+
export type LockedTeaserProps = {
/** `captionPreview` from the API. Clamped to 2 lines, a hard limit so no analysis leaks. */
preview?: ReactNode;
@@ -22,5 +31,14 @@ export type LockedTeaserProps = {
actionHref?: string;
/** Instead of `actionHref`, such as opening the auth sheet. Client callers only. */
onAction?: () => void;
+ /** The CTA shows but does nothing, and says why: the creator previewing their own post. */
+ actionFrozenReason?: ReactNode;
+ /** Replaces the CTA with a frozen status, such as a payment waiting for the bank. */
+ actionIndicator?: LockedTeaserIndicator;
+ /**
+ * The viewer isn't known yet (the server render and the first browser render): the message keeps
+ * its place unseen and the CTA is a skeleton, so a guest never sees a member's CTA or the reverse.
+ */
+ pending?: boolean;
className?: string;
};
diff --git a/packages/island/src/molecules/modal/Modal.tsx b/packages/island/src/molecules/modal/Modal.tsx
index 2aa3d39..db6c83b 100644
--- a/packages/island/src/molecules/modal/Modal.tsx
+++ b/packages/island/src/molecules/modal/Modal.tsx
@@ -7,11 +7,15 @@ import { Dialog } from '../../atoms/dialog';
import { Element } from '../../primitives/element';
import { cn } from '../../tools/cn';
import type { ModalProps } from './types';
+import { modalPanelVariants } from './variants';
/**
* A centred dialog for short, blocking decisions on desktop, at most 420px wide. On mobile the
* same content is always a bottom Sheet, never a Modal. The panel takes focus when it opens, and
* focus returns to the trigger when it closes.
+ *
+ * `size="wide"` is the desktop form dialog (C4 ۷.۳, «پست جدید»): 640px, a header row with the
+ * title and `headerAction`, then the caller's body and footer bar, edge to edge.
*/
export function Modal({
open,
@@ -19,6 +23,8 @@ export function Modal({
children,
actions,
icon,
+ size = 'default',
+ headerAction,
onClose,
onExited,
closeLabel,
@@ -38,44 +44,68 @@ export function Modal({
labelledBy={titleId}
className="items-center justify-center p-4"
>
-
- {closeLabel && dismissible && (
-
- )}
- {icon && {icon}}
-
- {title}
-
- {children != null && (
- // Plain text reads as body-md; paragraphs keep space-3 between them.
-
- {children}
-
- )}
- {actions && (
-
- {actions}
+
+
+ {title}
+
+ {headerAction}
- )}
-
+ {children}
+
+ ) : (
+
+ {closeLabel && dismissible && (
+
+ )}
+ {icon && {icon}}
+
+ {title}
+
+ {children != null && (
+ // Plain text reads as body-md; paragraphs keep space-3 between them.
+
+ {children}
+
+ )}
+ {actions && (
+
+ {actions}
+
+ )}
+
+ )}
);
}
diff --git a/packages/island/src/molecules/modal/index.ts b/packages/island/src/molecules/modal/index.ts
index 880f4a9..b695b16 100644
--- a/packages/island/src/molecules/modal/index.ts
+++ b/packages/island/src/molecules/modal/index.ts
@@ -1,2 +1,2 @@
export { Modal } from './Modal';
-export type { ModalProps } from './types';
+export type { ModalProps, ModalSize } from './types';
diff --git a/packages/island/src/molecules/modal/types.ts b/packages/island/src/molecules/modal/types.ts
index dcb991b..0f31a4f 100644
--- a/packages/island/src/molecules/modal/types.ts
+++ b/packages/island/src/molecules/modal/types.ts
@@ -1,19 +1,38 @@
import type { ReactNode } from 'react';
+/** default: a short decision at 420px. wide: a desktop form at the 640px column (C4 ۷.۳). */
+export type ModalSize = 'default' | 'wide';
+
export type ModalProps = {
open: boolean;
title: ReactNode;
- /** The body. */
+ /**
+ * The body. default: in body-md under the title. wide: edge to edge with no padding; lay out
+ * the scrolling body and the footer bar yourself (a `min-h-0` flex column, so the body scrolls).
+ */
children?: ReactNode;
- /** Buttons, stacked full-width: primary (or danger-solid) first, the cancel under it. */
+ /**
+ * Buttons, stacked full-width: primary (or danger-solid) first, the cancel under it. Not in
+ * wide, whose form draws its own footer bar.
+ */
actions?: ReactNode;
- /** Art above the title, such as a StateArt. */
+ /** Art above the title, such as a StateArt. Not in wide. */
icon?: ReactNode;
+ /**
+ * wide: a header row with the title at its start and `headerAction` at its end, over a hairline,
+ * and only `children` under it; `icon`, `actions` and the ✕ are not used.
+ */
+ size?: ModalSize;
+ /** wide only: the header row's end, such as a ghost «انصراف». */
+ headerAction?: ReactNode;
/** Escape and the scrim call it, unless `dismissible` is false. */
onClose?: () => void;
/** The modal has closed and focus is back on the page. */
onExited?: () => void;
- /** The ✕'s accessible name, such as «بستن». Shows the ✕; omit it when there is a cancel button. */
+ /**
+ * The ✕'s accessible name, such as «بستن». Shows the ✕; omit it when there is a cancel button.
+ * Not in wide: its cancel is `headerAction`.
+ */
closeLabel?: string;
/** false: no ✕, and Escape and the scrim do nothing, such as «در حال تأیید پرداخت...». */
dismissible?: boolean;
diff --git a/packages/island/src/molecules/modal/variants.ts b/packages/island/src/molecules/modal/variants.ts
new file mode 100644
index 0000000..d4708a3
--- /dev/null
+++ b/packages/island/src/molecules/modal/variants.ts
@@ -0,0 +1,16 @@
+import { cva } from 'class-variance-authority';
+
+/** The panel in the centred layer: it scales in, and scrolls inside when it outgrows the screen. */
+export const modalPanelVariants = cva(
+ 'relative max-h-full w-full rounded-xl bg-surface shadow-3 outline-none transition-[opacity,scale] duration-200 ease-standard starting:scale-95 starting:opacity-0 group-data-closing/dialog:scale-95 group-data-closing/dialog:opacity-0',
+ {
+ variants: {
+ size: {
+ default: 'max-w-105 overflow-auto px-5 pt-6 pb-5',
+ /** C4 ۷.۳: no padding, so the header row and the caller's footer bar reach the edges. */
+ wide: 'max-w-content overflow-hidden',
+ },
+ },
+ defaultVariants: { size: 'default' },
+ },
+);
diff --git a/packages/island/src/molecules/segmented-choice/SegmentedChoice.tsx b/packages/island/src/molecules/segmented-choice/SegmentedChoice.tsx
new file mode 100644
index 0000000..f20459f
--- /dev/null
+++ b/packages/island/src/molecules/segmented-choice/SegmentedChoice.tsx
@@ -0,0 +1,74 @@
+import { useId } from 'react';
+
+import { FlexBox } from '../../atoms/flex-box';
+import { Icon } from '../../atoms/icon';
+import { Typography } from '../../atoms/typography';
+import { Element } from '../../primitives/element';
+import { cn } from '../../tools/cn';
+import type { SegmentedChoiceProps } from './types';
+import {
+ segmentedChoiceOptionVariants,
+ segmentedChoiceVariants,
+} from './variants';
+
+/**
+ * A one-of choice as chips on a pill track, such as a post's «رایگان» / «پریمیوم» (C4 ۷.۳, C5 ۱.۱,
+ * ۱.۵, ۱.۶, ۱.۷, ۷.۱). A named radiogroup fieldset of real radios, so Tab reaches the chosen one,
+ * the arrow keys pick, and disabling the fieldset disables them all. A chosen option fills brand
+ * with no check.
+ */
+export function SegmentedChoice({
+ options,
+ value,
+ onChange,
+ label,
+ size = 'md',
+ track = 'sunken',
+ disabled = false,
+ frozen = false,
+ className,
+}: SegmentedChoiceProps) {
+ const name = useId();
+
+ return (
+
+ {options.map((option) => (
+
+ onChange(option.value) : undefined}
+ readOnly={!onChange}
+ className="pointer-events-none absolute m-0 size-px opacity-0"
+ />
+ {option.icon && }
+
+ {option.label}
+
+
+ ))}
+
+ );
+}
diff --git a/packages/island/src/molecules/segmented-choice/index.ts b/packages/island/src/molecules/segmented-choice/index.ts
new file mode 100644
index 0000000..87636ac
--- /dev/null
+++ b/packages/island/src/molecules/segmented-choice/index.ts
@@ -0,0 +1,11 @@
+export { SegmentedChoice } from './SegmentedChoice';
+export type {
+ SegmentedChoiceOption,
+ SegmentedChoiceProps,
+ SegmentedChoiceSize,
+ SegmentedChoiceTrack,
+} from './types';
+export {
+ segmentedChoiceOptionVariants,
+ segmentedChoiceVariants,
+} from './variants';
diff --git a/packages/island/src/molecules/segmented-choice/types.ts b/packages/island/src/molecules/segmented-choice/types.ts
new file mode 100644
index 0000000..53c0032
--- /dev/null
+++ b/packages/island/src/molecules/segmented-choice/types.ts
@@ -0,0 +1,46 @@
+import type { VariantProps } from 'class-variance-authority';
+import type { ReactNode } from 'react';
+
+import type { IconName } from '../../atoms/icon';
+import type {
+ segmentedChoiceOptionVariants,
+ segmentedChoiceVariants,
+} from './variants';
+
+export type SegmentedChoiceSize = NonNullable<
+ VariantProps['size']
+>;
+
+export type SegmentedChoiceTrack = NonNullable<
+ VariantProps['track']
+>;
+
+export type SegmentedChoiceOption = {
+ value: T;
+ label: ReactNode;
+ /** Leads the label, chosen or not, such as the lock on «پریمیوم». No check mark otherwise. */
+ icon?: IconName;
+};
+
+export type SegmentedChoiceProps = {
+ /** Two or three short options, such as «رایگان» / «پریمیوم». */
+ options: readonly SegmentedChoiceOption[];
+ /** The chosen option's value. */
+ value: T;
+ /** Called with the option picked by a press, or by the arrow keys; never for the chosen one. */
+ onChange?: (value: T) => void;
+ /** The group's accessible name, such as «سطح دسترسی پست». */
+ label: string;
+ /** `md` (44px) in forms such as the composer, `sm` (36px) inside a card. */
+ size?: SegmentedChoiceSize;
+ /** `sunken` on a card or a form; `surface` on a tinted ground, such as the preview banner (C5 ۶.۲). */
+ track?: SegmentedChoiceTrack;
+ /** Out of reach for now, such as while the post publishes (C4 ۱.۶): each option dims. */
+ disabled?: boolean;
+ /**
+ * Locked for good, such as a post's access past its edit window (C5 ۱.۶): the whole pill dims as
+ * one and takes no focus, so put the reason in text beside it.
+ */
+ frozen?: boolean;
+ className?: string;
+};
diff --git a/packages/island/src/molecules/segmented-choice/variants.ts b/packages/island/src/molecules/segmented-choice/variants.ts
new file mode 100644
index 0000000..968e8da
--- /dev/null
+++ b/packages/island/src/molecules/segmented-choice/variants.ts
@@ -0,0 +1,38 @@
+import { cva } from 'class-variance-authority';
+
+/** The track the options sit in (C5 ۱.۱); frozen, it dims as one (C5 ۱.۶). */
+export const segmentedChoiceVariants = cva(
+ 'w-fit min-w-0 rounded-full border border-border-subtle p-1',
+ {
+ variants: {
+ /** sunken on a card or a form; surface on a tinted ground, such as a banner (C5 ۶.۲). */
+ track: { sunken: 'bg-surface-sunken', surface: 'bg-surface' },
+ frozen: { true: 'frozen', false: '' },
+ },
+ defaultVariants: { track: 'sunken', frozen: false },
+ },
+);
+
+/**
+ * One option, a chip with the real radio hidden inside: filled brand when chosen, bare on the
+ * track when not. The label is the hit area and shows the radio's keyboard focus.
+ */
+export const segmentedChoiceOptionVariants = cva(
+ 'relative rounded-full border whitespace-nowrap transition-colors duration-120 ease-standard has-[input:enabled]:cursor-pointer has-[input:focus-visible]:focus-ring',
+ {
+ variants: {
+ selected: {
+ true: 'border-action-primary bg-action-primary text-text-on-action',
+ false:
+ 'border-transparent bg-transparent text-text-primary has-[input:enabled]:hover:border-action-primary',
+ },
+ size: {
+ sm: 'min-h-control-sm px-3.5',
+ md: 'min-h-control-md px-4',
+ },
+ /** Disabled but not frozen: each option dims, as a disabled chip does (C4 ۱.۶). */
+ disabled: { true: 'frozen', false: '' },
+ },
+ defaultVariants: { selected: false, size: 'md', disabled: false },
+ },
+);
diff --git a/packages/island/src/molecules/tab-links/TabLinks.tsx b/packages/island/src/molecules/tab-links/TabLinks.tsx
new file mode 100644
index 0000000..a007e26
--- /dev/null
+++ b/packages/island/src/molecules/tab-links/TabLinks.tsx
@@ -0,0 +1,48 @@
+import NextLink from 'next/link';
+
+import { FlexBox } from '../../atoms/flex-box';
+import { Typography } from '../../atoms/typography';
+import { cn } from '../../tools/cn';
+import type { TabLinksProps } from './types';
+import { tabLinksVariants, tabLinkVariants } from './variants';
+
+/**
+ * A row of section tabs where each section is its own route, such as the investor داشبورد's
+ * «اشتراکها» · «تراکنشها» · «دنبالشدهها» (U2; U8 ۴.۱, ۶.۱; U8 ۵.۲: the 48px row, not a pill
+ * row). Mobile sets `band` under the top bar; desktop sits it in the column. Plain links in a named
+ * nav, so Tab walks them and Enter follows one; no state, so it renders on the server, and its
+ * place stays put while a tab's content loads.
+ */
+export function TabLinks({
+ items,
+ label,
+ fill = false,
+ band,
+ className,
+}: TabLinksProps) {
+ return (
+
+ {items.map((item) => (
+
+
+ {item.label}
+
+
+ ))}
+
+ );
+}
diff --git a/packages/island/src/molecules/tab-links/index.ts b/packages/island/src/molecules/tab-links/index.ts
new file mode 100644
index 0000000..7047027
--- /dev/null
+++ b/packages/island/src/molecules/tab-links/index.ts
@@ -0,0 +1,2 @@
+export { TabLinks } from './TabLinks';
+export type { TabLinkItem, TabLinksProps } from './types';
diff --git a/packages/island/src/molecules/tab-links/types.ts b/packages/island/src/molecules/tab-links/types.ts
new file mode 100644
index 0000000..5cbb217
--- /dev/null
+++ b/packages/island/src/molecules/tab-links/types.ts
@@ -0,0 +1,25 @@
+import type { VariantProps } from 'class-variance-authority';
+
+import type { tabLinksVariants } from './variants';
+
+export type TabLinkItem = {
+ /** The section's own route; each tab is a page, not a panel. */
+ href: string;
+ /** Its name, such as «دنبالشدهها». */
+ label: string;
+ /** The section on screen: brand colour, underline and `aria-current="page"`. */
+ isActive: boolean;
+};
+
+export type TabLinksProps = VariantProps & {
+ /** In reading order, such as «اشتراکها» · «تراکنشها» · «دنبالشدهها». */
+ items: readonly TabLinkItem[];
+ /** The nav's accessible name, such as «بخشهای داشبورد». */
+ label: string;
+ /**
+ * The tabs share the full width, as the داشبورد rows do (U8 ۴.۱, ۶.۱); unset, each hugs its
+ * label, as a short filter row does.
+ */
+ fill?: boolean;
+ className?: string;
+};
diff --git a/packages/island/src/molecules/tab-links/variants.ts b/packages/island/src/molecules/tab-links/variants.ts
new file mode 100644
index 0000000..ecc168e
--- /dev/null
+++ b/packages/island/src/molecules/tab-links/variants.ts
@@ -0,0 +1,31 @@
+import { cva } from 'class-variance-authority';
+
+/** The row on its hairline; as a `band`, the surface strip under the mobile top bar (U8 ۴.۱). */
+export const tabLinksVariants = cva('min-w-0 border-b border-border-subtle', {
+ variants: {
+ band: { true: 'bg-surface px-2', false: '' },
+ },
+ defaultVariants: { band: false },
+});
+
+/**
+ * One 48px tab, its 2px underline over the row's hairline. The current one takes the brand colour
+ * and the underline; the others are secondary and darken under the pointer.
+ */
+export const tabLinkVariants = cva(
+ '-mb-px h-12 cursor-pointer border-b-2 px-4 text-[0.9375rem] leading-6 font-semibold whitespace-nowrap no-underline transition-colors duration-120 ease-standard focus-visible:focus-ring',
+ {
+ variants: {
+ active: {
+ true: 'border-action-primary text-action-primary-text',
+ false: 'border-transparent text-text-secondary hover:text-text-primary',
+ },
+ /**
+ * Equal shares of the width, the label centred. Centred, the padding only sets a floor, so a
+ * smaller one keeps three labels on a 320px screen without changing the look at 390.
+ */
+ fill: { true: 'flex-1 px-2', false: '' },
+ },
+ defaultVariants: { active: false, fill: false },
+ },
+);
diff --git a/packages/island/src/molecules/text-input/TextInput.tsx b/packages/island/src/molecules/text-input/TextInput.tsx
index 192af99..f9df951 100644
--- a/packages/island/src/molecules/text-input/TextInput.tsx
+++ b/packages/island/src/molecules/text-input/TextInput.tsx
@@ -20,8 +20,9 @@ import {
textInputControlVariants,
} from './variants';
+/** In UTF-16 units, as the native `maxLength` counts, so the counter reaches the limit with it. */
function lengthOf(value: unknown): number {
- return value == null ? 0 : Array.from(String(value)).length;
+ return value == null ? 0 : String(value).length;
}
/**
diff --git a/packages/island/src/organisms/lightbox/Lightbox.tsx b/packages/island/src/organisms/lightbox/Lightbox.tsx
index dba666a..42000dc 100644
--- a/packages/island/src/organisms/lightbox/Lightbox.tsx
+++ b/packages/island/src/organisms/lightbox/Lightbox.tsx
@@ -2,7 +2,7 @@
import { iso, number, percent } from '@lumina/tools/format';
import { useRef, useState } from 'react';
-import type { KeyboardEvent, PointerEvent } from 'react';
+import type { CSSProperties, KeyboardEvent, PointerEvent } from 'react';
import { FlexBox } from '../../atoms/flex-box';
import { GridBox } from '../../atoms/grid-box';
@@ -11,8 +11,14 @@ import { Dialog } from '../../atoms/dialog';
import { Element } from '../../primitives/element';
import { cn } from '../../tools/cn';
import { LightboxButton } from './components/LightboxButton';
-import { SWIPE_THRESHOLD_PX, ZOOM_STEPS } from './constants';
-import type { LightboxProps } from './types';
+import {
+ SWIPE_CLOSE_GROUND,
+ SWIPE_CLOSE_PX,
+ SWIPE_THRESHOLD_PX,
+ ZOOM_STEPS,
+} from './constants';
+import type { LightboxPoint, LightboxProps } from './types';
+import { nearestZoomStep, pointOf, spread } from './utils';
import { lightboxReadoutVariants, lightboxStageVariants } from './variants';
/**
@@ -21,6 +27,10 @@ import { lightboxReadoutVariants, lightboxStageVariants } from './variants';
* next image). It is a top-layer dialog opened after any sheet, and it doesn't lift the toasts, so
* it stays above the snackbar. The root takes focus; Escape closes it.
*
+ * Touch gestures (R1, C4 ۴.۳, C4b ۳.۱): a finger or pen dragged down carries the image with it and
+ * fades the ground, and closes the viewer past `SWIPE_CLOSE_PX`; a shorter drag springs back. With
+ * `zoomable`, a pinch zooms in or back out, landing on the nearest of the buttons' steps.
+ *
* Never open it on a locked premium post: locked images are never rendered at all.
*/
export function Lightbox({
@@ -39,14 +49,20 @@ export function Lightbox({
// The zoom belongs to one image, so every other image starts at 100%.
const [zoom, setZoom] = useState({ at: index, step: 0 });
const [wasOpen, setWasOpen] = useState(open);
- const swipeFrom = useRef(null);
+ // How far a finger drags the image down; null when nothing holds it, so it springs back.
+ const [drop, setDrop] = useState(null);
+ const pointers = useRef(new Map());
+ const swipeFrom = useRef(null);
+ const pinchFrom = useRef(null);
+ const pinchRatio = useRef(1);
- // Each opening starts at `index`, unzoomed.
+ // Each opening starts at `index`, unzoomed and in place.
if (open !== wasOpen) {
setWasOpen(open);
if (open) {
setOwnIndex(index);
setZoom({ at: index, step: 0 });
+ setDrop(null);
}
}
@@ -62,6 +78,15 @@ export function Lightbox({
const isBack = closeIcon === 'back';
const place = number(current + 1);
const count = number(total);
+ const ground =
+ 100 -
+ (Math.min(drop ?? 0, SWIPE_CLOSE_PX) / SWIPE_CLOSE_PX) *
+ (100 - SWIPE_CLOSE_GROUND);
+ // Read by the ground's colour and the image's offset.
+ const dragStyle = {
+ '--lightbox-ground': `${ground}%`,
+ '--lightbox-drop': `${drop ?? 0}px`,
+ } as CSSProperties;
const goTo = (target: number) => {
if (target < 0 || target >= total || target === current) return;
@@ -87,23 +112,85 @@ export function Lightbox({
// A second finger makes it a pinch, never a swipe.
const handlePointerDown = (event: PointerEvent) => {
- swipeFrom.current = event.isPrimary ? event.clientX : null;
+ const active = pointers.current;
+ // A primary pointer starts a new gesture, so nothing is left over from the last one.
+ if (event.isPrimary) active.clear();
+ active.set(event.pointerId, pointOf(event));
+ // A drag that leaves the stage still counts; zoomed, the browser owns the drag.
+ if (!isZoomed) event.currentTarget.setPointerCapture(event.pointerId);
+ if (active.size === 1) {
+ swipeFrom.current = pointOf(event);
+ } else if (active.size === 2) {
+ const [a, b] = [...active.values()];
+ pinchFrom.current = spread(a, b);
+ pinchRatio.current = 1;
+ swipeFrom.current = null;
+ setDrop(null);
+ }
+ };
+
+ const handlePointerMove = (event: PointerEvent) => {
+ const active = pointers.current;
+ if (!active.has(event.pointerId)) return;
+ active.set(event.pointerId, pointOf(event));
+ if (pinchFrom.current !== null) {
+ const [a, b] = [...active.values()];
+ if (a && b) pinchRatio.current = spread(a, b) / pinchFrom.current;
+ return;
+ }
+ const from = swipeFrom.current;
+ // Paused while zoomed; a mouse never carries the image.
+ if (from === null || isZoomed || event.pointerType === 'mouse') return;
+ const dx = event.clientX - from.x;
+ const dy = event.clientY - from.y;
+ // Only a drag that runs mostly down carries the image.
+ setDrop(dy > Math.abs(dx) ? dy : 0);
+ };
+
+ // A pinch ends when its first finger lifts, or when the browser takes it over, at the last spread.
+ const endPinch = () => {
+ const ratio = pinchRatio.current;
+ pinchFrom.current = null;
+ if (zoomable) zoomTo(nearestZoomStep(scale * ratio));
};
const handlePointerUp = (event: PointerEvent) => {
+ pointers.current.delete(event.pointerId);
+ if (pinchFrom.current !== null) {
+ endPinch();
+ return;
+ }
const from = swipeFrom.current;
swipeFrom.current = null;
- // Paused while zoomed, by the buttons or by pinching the page.
- const isPinched = (window.visualViewport?.scale ?? 1) > 1;
- if (from === null || isZoomed || isPinched) return;
- const distance = event.clientX - from;
+ // Paused while zoomed, by the buttons or a pinch.
+ if (from === null || isZoomed) {
+ setDrop(null);
+ return;
+ }
+ const dx = event.clientX - from.x;
+ const dy = event.clientY - from.y;
+ // A mouse never closes it; the image stays where the finger left it while the viewer fades.
+ if (
+ event.pointerType !== 'mouse' &&
+ dy > SWIPE_CLOSE_PX &&
+ dy > Math.abs(dx)
+ ) {
+ onClose();
+ return;
+ }
+ setDrop(null);
+ // A drag that runs mostly down or up never pages.
+ if (Math.abs(dx) <= Math.abs(dy)) return;
// RTL: a swipe to the right brings the next image.
- if (distance > SWIPE_THRESHOLD_PX) goTo(current + 1);
- else if (distance < -SWIPE_THRESHOLD_PX) goTo(current - 1);
+ if (dx > SWIPE_THRESHOLD_PX) goTo(current + 1);
+ else if (dx < -SWIPE_THRESHOLD_PX) goTo(current - 1);
};
const handlePointerCancel = () => {
+ pointers.current.clear();
swipeFrom.current = null;
+ setDrop(null);
+ if (pinchFrom.current !== null) endPinch();
};
return (
@@ -120,8 +207,9 @@ export function Lightbox({
tabIndex={-1}
direction="flex-col"
onKeyDown={handleKeyDown}
+ style={dragStyle}
className={cn(
- 'size-full bg-lightbox text-text-inverse outline-none transition-opacity duration-200 ease-standard starting:opacity-0 group-data-closing/dialog:opacity-0',
+ 'size-full bg-lightbox/(--lightbox-ground) text-text-inverse outline-none transition-[opacity,background-color] duration-200 ease-standard starting:opacity-0 group-data-closing/dialog:opacity-0',
className,
)}
>
@@ -194,11 +282,14 @@ export function Lightbox({
-
{image && (
)}
-
+
{/* Outside the scroll box, so they stay put while a zoomed image scrolls. */}
{total > 1 && (
<>
diff --git a/packages/island/src/organisms/lightbox/constants.ts b/packages/island/src/organisms/lightbox/constants.ts
index 132b4e1..1f7d4f2 100644
--- a/packages/island/src/organisms/lightbox/constants.ts
+++ b/packages/island/src/organisms/lightbox/constants.ts
@@ -1,5 +1,11 @@
-/** The zoom buttons step through these scales: ۱۰۰٪ → ۱۵۰٪ → ۲۰۰٪ → ۳۰۰٪. */
+/** The zoom buttons and a pinch step through these scales: ۱۰۰٪ → ۱۵۰٪ → ۲۰۰٪ → ۳۰۰٪. */
export const ZOOM_STEPS = [1, 1.5, 2, 3] as const;
/** How far (px) a pointer travels sideways before it counts as a swipe to the next image. */
export const SWIPE_THRESHOLD_PX = 48;
+
+/** How far (px) a finger or pen drags down before letting go closes the viewer (C4 ۴.۳). */
+export const SWIPE_CLOSE_PX = 96;
+
+/** The black ground's opacity (%) once a drag down reaches `SWIPE_CLOSE_PX`; it fades from 100. */
+export const SWIPE_CLOSE_GROUND = 70;
diff --git a/packages/island/src/organisms/lightbox/types.ts b/packages/island/src/organisms/lightbox/types.ts
index f52d30f..2a88dfc 100644
--- a/packages/island/src/organisms/lightbox/types.ts
+++ b/packages/island/src/organisms/lightbox/types.ts
@@ -40,11 +40,14 @@ export type LightboxProps = {
/** Makes `index` controlled: called with the image to show. */
onIndexChange?: (index: number) => void;
open: boolean;
- /** Escape, ✕ and back call it. */
+ /** Escape, ✕, back and a swipe down (touch or pen) call it. */
onClose: () => void;
- /** back: a back arrow instead of ✕, for the post-image viewer (C4 §7). */
+ /** back: a back arrow instead of ✕, for the post-image viewer (C4 ۴.۳, C4b ۳.۱). */
closeIcon?: 'close' | 'back';
- /** Zoom buttons from ۱۰۰٪ to ۳۰۰٪, for admin ID review and payout receipts. */
+ /**
+ * Zoom buttons from ۱۰۰٪ to ۳۰۰٪, and a pinch that snaps to the same steps, for the post-image
+ * viewer, admin ID review and payout receipts. Without it a pinch zooms the page itself.
+ */
zoomable?: boolean;
/** Adds a download button for the image on screen. */
onDownload?: (index: number) => void;
@@ -52,6 +55,12 @@ export type LightboxProps = {
className?: string;
};
+/** A pointer's place on screen, in client pixels. */
+export type LightboxPoint = {
+ x: number;
+ y: number;
+};
+
export type LightboxButtonProps = {
icon: IconName;
label: string;
diff --git a/packages/island/src/organisms/lightbox/utils.ts b/packages/island/src/organisms/lightbox/utils.ts
new file mode 100644
index 0000000..29061f5
--- /dev/null
+++ b/packages/island/src/organisms/lightbox/utils.ts
@@ -0,0 +1,24 @@
+import type { PointerEvent } from 'react';
+
+import { ZOOM_STEPS } from './constants';
+import type { LightboxPoint } from './types';
+
+export function pointOf(event: PointerEvent): LightboxPoint {
+ return { x: event.clientX, y: event.clientY };
+}
+
+/** The distance between two fingers; never 0, so a pinch ratio stays finite. */
+export function spread(a: LightboxPoint, b: LightboxPoint): number {
+ return Math.max(Math.hypot(a.x - b.x, a.y - b.y), 1);
+}
+
+/** The `ZOOM_STEPS` index closest to `scale`, where a pinch lands when it lets go. */
+export function nearestZoomStep(scale: number): number {
+ let nearest = 0;
+ ZOOM_STEPS.forEach((step, index) => {
+ if (Math.abs(step - scale) < Math.abs(ZOOM_STEPS[nearest] - scale)) {
+ nearest = index;
+ }
+ });
+ return nearest;
+}
diff --git a/packages/island/src/organisms/lightbox/variants.ts b/packages/island/src/organisms/lightbox/variants.ts
index 9668e03..00271ae 100644
--- a/packages/island/src/organisms/lightbox/variants.ts
+++ b/packages/island/src/organisms/lightbox/variants.ts
@@ -8,19 +8,28 @@ export const lightboxButtonVariants = cva(
'size-touch-target flex-none rounded-full bg-inverse-control text-text-inverse transition-colors duration-120 ease-standard focus-visible:focus-ring-lightbox aria-disabled:opacity-35 actionable:cursor-pointer actionable:hover:bg-inverse-control-hover',
);
-/** The image's scroll box: centred and swipeable, or scrolling the zoomed image. */
+/**
+ * The image's scroll box: centred and swipeable, or scrolling the zoomed image. Unzoomed, every
+ * one-finger drag reaches the viewer (sideways to page, down to close), even on a page pinched in;
+ * the browser keeps a pinch and a two-finger pan only when the viewer can't zoom, as the page's
+ * own zoom. It renders as a FlexBox, which places the image from the zoomed state.
+ */
export const lightboxStageVariants = cva(
- 'absolute inset-0 flex overscroll-contain',
+ 'absolute inset-0 overscroll-contain',
{
variants: {
zoomed: {
- /** Vertical pans and pinch stay with the browser; sideways drags are swipes. */
- false:
- 'touch-pan-y touch-pinch-zoom items-center justify-center overflow-hidden',
- true: 'touch-auto items-start justify-start overflow-auto',
+ false: 'overflow-hidden',
+ /** The browser pans the zoomed image; a pinch still reaches the viewer to zoom back out. */
+ true: 'touch-pan-x touch-pan-y overflow-auto',
},
+ zoomable: { true: '', false: '' },
},
- defaultVariants: { zoomed: false },
+ compoundVariants: [
+ { zoomed: false, zoomable: true, className: 'touch-none' },
+ { zoomed: false, zoomable: false, className: 'touch-pinch-zoom' },
+ ],
+ defaultVariants: { zoomed: false, zoomable: false },
},
);
diff --git a/packages/island/src/organisms/post-card/PostCard.tsx b/packages/island/src/organisms/post-card/PostCard.tsx
index 03f51dd..db3df91 100644
--- a/packages/island/src/organisms/post-card/PostCard.tsx
+++ b/packages/island/src/organisms/post-card/PostCard.tsx
@@ -1,6 +1,8 @@
import { FlexBox } from '../../atoms/flex-box';
import { Card } from '../../molecules/card';
import { cn } from '../../tools/cn';
+import { PostAccess } from './components/PostAccess';
+import { PostAccessNote } from './components/PostAccessNote';
import { PostActions } from './components/PostActions';
import { PostContent } from './components/PostContent';
import { PostHead } from './components/PostHead';
@@ -13,9 +15,9 @@ import type { PostCardProps } from './types';
* views of text, image and prediction posts. A locked post keeps the header and swaps the body
* for the shared LockedTeaser, so locking never changes the feed's rhythm.
*
- * Server-renderable: only a multi-image carousel and a frozen edit's tooltip are client parts.
- * The handlers (`owner`, `onShare`, `onImageClick`, `onCta`) need a client caller; a server render
- * passes `href`, `channelHref` and `ctaHref` links instead.
+ * Server-renderable: only a multi-image carousel, a frozen edit's tooltip and the desktop share
+ * menu are client parts. The handlers (`owner`, `onShare`, `onCopyLink`, `onImageClick`, `onCta`)
+ * need a client caller; a server render passes `href`, `channelHref` and `ctaHref` links instead.
*/
export function PostCard(props: PostCardProps) {
const {
@@ -25,12 +27,15 @@ export function PostCard(props: PostCardProps) {
publishedAt,
now,
timeLabel,
+ ownerTag,
premium = props.locked ?? false,
edited = false,
variant = 'compact',
predictionLabels,
owner,
onShare,
+ onCopyLink,
+ accessNote,
labels,
className,
} = props;
@@ -48,6 +53,7 @@ export function PostCard(props: PostCardProps) {
publishedAt={publishedAt}
now={now}
timeLabel={timeLabel}
+ ownerTag={ownerTag}
premium={premium}
edited={edited}
labels={labels}
@@ -60,6 +66,8 @@ export function PostCard(props: PostCardProps) {
viewer={props.viewer}
onCta={props.onCta}
ctaHref={props.ctaHref}
+ ctaFrozenReason={props.ctaFrozenReason}
+ ctaIndicator={props.ctaIndicator}
publishedAt={publishedAt}
now={now}
premium={premium}
@@ -82,9 +90,20 @@ export function PostCard(props: PostCardProps) {
labels={labels}
/>
)}
+ {owner?.accessFrozen && props.prediction == null && (
+
+ )}
+ {!props.locked && accessNote != null && (
+ {accessNote}
+ )}
+
+
+
+
+ {reason}
+
+
+
+ );
+}
diff --git a/packages/island/src/organisms/post-card/components/PostAccessNote.tsx b/packages/island/src/organisms/post-card/components/PostAccessNote.tsx
new file mode 100644
index 0000000..4c34bcd
--- /dev/null
+++ b/packages/island/src/organisms/post-card/components/PostAccessNote.tsx
@@ -0,0 +1,22 @@
+import { FlexBox } from '../../../atoms/flex-box';
+import { Icon } from '../../../atoms/icon';
+import { Typography } from '../../../atoms/typography';
+import type { PostAccessNoteProps } from '../types';
+
+/**
+ * How the viewer has an open premium post (Post--unlocked), «دسترسی از طریق اشتراک سالانه»: a
+ * check and the note in secondary caption, under a hairline at the end of the body.
+ */
+export function PostAccessNote({ children }: PostAccessNoteProps) {
+ return (
+
+
+
+ {children}
+
+
+ );
+}
diff --git a/packages/island/src/organisms/post-card/components/PostActions.tsx b/packages/island/src/organisms/post-card/components/PostActions.tsx
index 7e3cb5c..ce7b578 100644
--- a/packages/island/src/organisms/post-card/components/PostActions.tsx
+++ b/packages/island/src/organisms/post-card/components/PostActions.tsx
@@ -3,26 +3,33 @@ import { FlexBox } from '../../../atoms/flex-box';
import { cn } from '../../../tools/cn';
import { ABOVE_LINK_CLASS } from '../constants';
import type { PostActionsProps } from '../types';
+import { PostShareMenu } from './PostShareMenu';
/**
* Ghost icon buttons at the inline end. Everyone else: share. The creator: preview (premium),
* share, edit (frozen after 15 minutes) and delete; a prediction post keeps only preview and
- * share, because predictions can't be edited or deleted.
+ * share, because predictions can't be edited or deleted. With a copy handler, share opens the
+ * desktop menu (C4b ۳.۴, ۶.۱); while it is open the footer rises over the cards after it, which
+ * would otherwise paint over the menu hanging below.
*/
export function PostActions({
owner,
onShare,
+ onCopyLink,
premium,
isPrediction,
labels,
}: PostActionsProps) {
const share = owner?.onShare ?? onShare;
+ const copy = owner?.onCopyLink ?? onCopyLink;
+ const { copyLink } = labels;
+ const hasMenu = copy != null && copyLink != null;
const preview = premium ? owner?.onPreview : undefined;
const mutable = owner != null && !isPrediction;
const canEdit = mutable && (owner.onEdit != null || owner.editFrozen);
const canDelete = mutable && owner.onDelete != null;
- if (!share && !preview && !canEdit && !canDelete) return null;
+ if (!share && !hasMenu && !preview && !canEdit && !canDelete) return null;
return (
{preview && (
@@ -43,13 +50,21 @@ export function PostActions({
onClick={preview}
/>
)}
- {share && (
-
+ ) : (
+ share && (
+
+ )
)}
{canEdit && (
+ {ownerTag && (
+
+ {ownerTag}
+
+ )}
{premium && (
{labels.premium}
diff --git a/packages/island/src/organisms/post-card/components/PostLocked.tsx b/packages/island/src/organisms/post-card/components/PostLocked.tsx
index 8454600..5cee741 100644
--- a/packages/island/src/organisms/post-card/components/PostLocked.tsx
+++ b/packages/island/src/organisms/post-card/components/PostLocked.tsx
@@ -14,6 +14,8 @@ export function PostLocked({
viewer = 'member',
onCta,
ctaHref,
+ ctaFrozenReason,
+ ctaIndicator,
publishedAt,
now,
premium,
@@ -32,6 +34,9 @@ export function PostLocked({
actionLabel={guest ? labels.locked.login : labels.locked.subscribe}
actionHref={ctaHref}
onAction={onCta}
+ actionFrozenReason={ctaFrozenReason}
+ actionIndicator={ctaIndicator}
+ pending={viewer === 'pending'}
>
{prediction && predictionLabels && (
+