feat(island): post card access and share, action menu, tab links, segmented choice
Island pieces for the channel, post page, composer and dashboard. - New molecules: ActionMenu (links or actions in a popover), TabLinks (route tabs), SegmentedChoice. - PostCard: owner footer, share menu on desktop, access note for an open premium post, frozen CTA reason on a locked one. - LockedTeaser keeps the gate's place while the viewer is unknown; Modal gains sizes; Lightbox and skeleton presets for feeds and headers. - Button: `pressableWhenFrozen`, a frozen look whose press still calls onClick (explain or check instead of a tooltip). - TextInput counts UTF-16 units, as the native maxLength does, so the counter reaches the limit with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
636430640d
commit
88384fa72d
|
|
@ -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 })}
|
||||
>
|
||||
<Typography
|
||||
tag="span"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ export type AvatarProps = Omit<ComponentPropsWithRef<'span'>, '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;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<HTMLButtonElement>) => {
|
||||
if (isBlocked) {
|
||||
if (swallowsClick) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -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<typeof frozenTipVariants>['align'];
|
||||
|
||||
type ButtonOwnProps = Pick<
|
||||
VariantProps<typeof buttonVariants>,
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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' },
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<HTMLUListElement>(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<HTMLElement>('[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<HTMLElement>('[aria-haspopup]');
|
||||
onClose();
|
||||
trigger?.focus();
|
||||
};
|
||||
|
||||
const onKeyDown = (event: KeyboardEvent<HTMLUListElement>) => {
|
||||
const options = Array.from(
|
||||
ref.current?.querySelectorAll<HTMLElement>('[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 (
|
||||
<Element
|
||||
ref={ref}
|
||||
tag="ul"
|
||||
role="menu"
|
||||
aria-label={label}
|
||||
onKeyDown={onKeyDown}
|
||||
className={cn(actionMenuVariants({ placement }), className)}
|
||||
>
|
||||
{items.map((item) => (
|
||||
<ActionMenuItem
|
||||
key={item.href ?? item.label}
|
||||
{...item}
|
||||
onClose={closeToTrigger}
|
||||
/>
|
||||
))}
|
||||
</Element>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 = (
|
||||
<>
|
||||
<Icon
|
||||
name={icon}
|
||||
size={20}
|
||||
className="flex-none text-action-primary-text"
|
||||
/>
|
||||
<Typography tag="span" color="inherit" className="font-semibold">
|
||||
{label}
|
||||
</Typography>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<Element tag="li" role="none">
|
||||
{href != null ? (
|
||||
<FlexBox
|
||||
tag={NextLink}
|
||||
href={href}
|
||||
role="menuitem"
|
||||
onClick={onClose}
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className={ROW_CLASS}
|
||||
>
|
||||
{content}
|
||||
</FlexBox>
|
||||
) : (
|
||||
<FlexBox
|
||||
tag="button"
|
||||
type="button"
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
onClose();
|
||||
onSelect?.();
|
||||
}}
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className={cn(ROW_CLASS, 'w-full cursor-pointer text-start')}
|
||||
>
|
||||
{content}
|
||||
</FlexBox>
|
||||
)}
|
||||
</Element>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { ActionMenu } from './ActionMenu';
|
||||
export type { ActionMenuItem, ActionMenuProps } from './types';
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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' },
|
||||
},
|
||||
);
|
||||
|
|
@ -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"
|
||||
>
|
||||
<Typography>{message}</Typography>
|
||||
{actionHref ? (
|
||||
{pending ? (
|
||||
<>
|
||||
{/* The message's own height, so the gate doesn't move when the viewer is known. */}
|
||||
<Element className="relative self-stretch" aria-hidden>
|
||||
<Typography className="invisible">{message}</Typography>
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
justifyContent="justify-center"
|
||||
className="absolute inset-0"
|
||||
>
|
||||
<Skeleton width="70%" />
|
||||
</FlexBox>
|
||||
</Element>
|
||||
<Skeleton shape="pill" className={PENDING_ACTION_CLASS} />
|
||||
</>
|
||||
) : actionIndicator ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={actionIndicator.icon}
|
||||
frozen
|
||||
frozenReason={actionIndicator.reason}
|
||||
className={ACTION_CLASS}
|
||||
>
|
||||
{actionIndicator.label}
|
||||
</Button>
|
||||
) : actionFrozenReason ? (
|
||||
<Button
|
||||
variant="primary"
|
||||
frozen
|
||||
frozenReason={actionFrozenReason}
|
||||
className={ACTION_CLASS}
|
||||
>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
) : actionHref ? (
|
||||
<Button variant="primary" href={actionHref} className={ACTION_CLASS}>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
export { LockedTeaser } from './LockedTeaser';
|
||||
export type { LockedTeaserProps } from './types';
|
||||
export type { LockedTeaserIndicator, LockedTeaserProps } from './types';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
>
|
||||
<Element
|
||||
data-dialog-panel=""
|
||||
tabIndex={-1}
|
||||
className={cn(
|
||||
'relative max-h-full w-full max-w-105 overflow-auto rounded-xl bg-surface px-5 pt-6 pb-5 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',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{closeLabel && dismissible && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="close"
|
||||
label={closeLabel}
|
||||
onClick={onClose}
|
||||
className="absolute end-2 top-2"
|
||||
/>
|
||||
)}
|
||||
{icon && <Element className="mb-3">{icon}</Element>}
|
||||
<Typography
|
||||
tag="h2"
|
||||
id={titleId}
|
||||
variant="heading-sm"
|
||||
className="mb-2 pe-10"
|
||||
{size === 'wide' ? (
|
||||
<FlexBox
|
||||
data-dialog-panel=""
|
||||
tabIndex={-1}
|
||||
direction="flex-col"
|
||||
className={cn(modalPanelVariants({ size }), className)}
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
{children != null && (
|
||||
// Plain text reads as body-md; paragraphs keep space-3 between them.
|
||||
<Typography tag="div" variant="body-md" className="[&>p]:mb-3">
|
||||
{children}
|
||||
</Typography>
|
||||
)}
|
||||
{actions && (
|
||||
<FlexBox direction="flex-col" gap="gap-2" className="mt-6">
|
||||
{actions}
|
||||
<FlexBox
|
||||
tag="header"
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
className="flex-none border-b border-border-subtle py-2.5 ps-6 pe-4"
|
||||
>
|
||||
<Typography
|
||||
tag="h2"
|
||||
id={titleId}
|
||||
variant="heading-sm"
|
||||
className="min-w-0 flex-1"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
{headerAction}
|
||||
</FlexBox>
|
||||
)}
|
||||
</Element>
|
||||
{children}
|
||||
</FlexBox>
|
||||
) : (
|
||||
<Element
|
||||
data-dialog-panel=""
|
||||
tabIndex={-1}
|
||||
className={cn(modalPanelVariants({ size }), className)}
|
||||
>
|
||||
{closeLabel && dismissible && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="close"
|
||||
label={closeLabel}
|
||||
onClick={onClose}
|
||||
className="absolute end-2 top-2"
|
||||
/>
|
||||
)}
|
||||
{icon && <Element className="mb-3">{icon}</Element>}
|
||||
<Typography
|
||||
tag="h2"
|
||||
id={titleId}
|
||||
variant="heading-sm"
|
||||
className="mb-2 pe-10"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
{children != null && (
|
||||
// Plain text reads as body-md; paragraphs keep space-3 between them.
|
||||
<Typography tag="div" variant="body-md" className="[&>p]:mb-3">
|
||||
{children}
|
||||
</Typography>
|
||||
)}
|
||||
{actions && (
|
||||
<FlexBox direction="flex-col" gap="gap-2" className="mt-6">
|
||||
{actions}
|
||||
</FlexBox>
|
||||
)}
|
||||
</Element>
|
||||
)}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
export { Modal } from './Modal';
|
||||
export type { ModalProps } from './types';
|
||||
export type { ModalProps, ModalSize } from './types';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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' },
|
||||
},
|
||||
);
|
||||
|
|
@ -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<T extends string>({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
size = 'md',
|
||||
track = 'sunken',
|
||||
disabled = false,
|
||||
frozen = false,
|
||||
className,
|
||||
}: SegmentedChoiceProps<T>) {
|
||||
const name = useId();
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
tag="fieldset"
|
||||
role="radiogroup"
|
||||
aria-label={label}
|
||||
disabled={disabled || frozen}
|
||||
gap="gap-1"
|
||||
className={cn(segmentedChoiceVariants({ track, frozen }), className)}
|
||||
>
|
||||
{options.map((option) => (
|
||||
<FlexBox
|
||||
key={option.value}
|
||||
tag="label"
|
||||
alignItems="items-center"
|
||||
className={cn(
|
||||
segmentedChoiceOptionVariants({
|
||||
selected: option.value === value,
|
||||
size,
|
||||
disabled: disabled && !frozen,
|
||||
}),
|
||||
'gap-1.5',
|
||||
)}
|
||||
>
|
||||
<Element
|
||||
tag="input"
|
||||
type="radio"
|
||||
name={name}
|
||||
value={option.value}
|
||||
checked={option.value === value}
|
||||
onChange={onChange ? () => onChange(option.value) : undefined}
|
||||
readOnly={!onChange}
|
||||
className="pointer-events-none absolute m-0 size-px opacity-0"
|
||||
/>
|
||||
{option.icon && <Icon name={option.icon} size={16} />}
|
||||
<Typography tag="span" variant="label" color="inherit">
|
||||
{option.label}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
))}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
export { SegmentedChoice } from './SegmentedChoice';
|
||||
export type {
|
||||
SegmentedChoiceOption,
|
||||
SegmentedChoiceProps,
|
||||
SegmentedChoiceSize,
|
||||
SegmentedChoiceTrack,
|
||||
} from './types';
|
||||
export {
|
||||
segmentedChoiceOptionVariants,
|
||||
segmentedChoiceVariants,
|
||||
} from './variants';
|
||||
|
|
@ -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<typeof segmentedChoiceOptionVariants>['size']
|
||||
>;
|
||||
|
||||
export type SegmentedChoiceTrack = NonNullable<
|
||||
VariantProps<typeof segmentedChoiceVariants>['track']
|
||||
>;
|
||||
|
||||
export type SegmentedChoiceOption<T extends string> = {
|
||||
value: T;
|
||||
label: ReactNode;
|
||||
/** Leads the label, chosen or not, such as the lock on «پریمیوم». No check mark otherwise. */
|
||||
icon?: IconName;
|
||||
};
|
||||
|
||||
export type SegmentedChoiceProps<T extends string> = {
|
||||
/** Two or three short options, such as «رایگان» / «پریمیوم». */
|
||||
options: readonly SegmentedChoiceOption<T>[];
|
||||
/** 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;
|
||||
};
|
||||
|
|
@ -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 },
|
||||
},
|
||||
);
|
||||
|
|
@ -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 (
|
||||
<FlexBox
|
||||
tag="nav"
|
||||
aria-label={label}
|
||||
gap="gap-1"
|
||||
className={cn(tabLinksVariants({ band }), className)}
|
||||
>
|
||||
{items.map((item) => (
|
||||
<FlexBox
|
||||
key={item.href}
|
||||
tag={NextLink}
|
||||
href={item.href}
|
||||
aria-current={item.isActive ? 'page' : undefined}
|
||||
display="inline-flex"
|
||||
alignItems="items-center"
|
||||
justifyContent={fill ? 'justify-center' : undefined}
|
||||
className={tabLinkVariants({ active: item.isActive, fill })}
|
||||
>
|
||||
<Typography tag="span" variant="inherit" color="inherit">
|
||||
{item.label}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
))}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
export { TabLinks } from './TabLinks';
|
||||
export type { TabLinkItem, TabLinksProps } from './types';
|
||||
|
|
@ -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<typeof tabLinksVariants> & {
|
||||
/** 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;
|
||||
};
|
||||
|
|
@ -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 },
|
||||
},
|
||||
);
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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<number | null>(null);
|
||||
// How far a finger drags the image down; null when nothing holds it, so it springs back.
|
||||
const [drop, setDrop] = useState<number | null>(null);
|
||||
const pointers = useRef(new Map<number, LightboxPoint>());
|
||||
const swipeFrom = useRef<LightboxPoint | null>(null);
|
||||
const pinchFrom = useRef<number | null>(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<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
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({
|
|||
</FlexBox>
|
||||
</GridBox>
|
||||
<Element className="relative min-h-0 flex-1">
|
||||
<Element
|
||||
<FlexBox
|
||||
alignItems={isZoomed ? 'items-start' : 'items-center'}
|
||||
justifyContent={isZoomed ? 'justify-start' : 'justify-center'}
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={handlePointerUp}
|
||||
onPointerCancel={handlePointerCancel}
|
||||
className={lightboxStageVariants({ zoomed: isZoomed })}
|
||||
className={lightboxStageVariants({ zoomed: isZoomed, zoomable })}
|
||||
>
|
||||
{image && (
|
||||
<Element
|
||||
|
|
@ -209,12 +300,14 @@ export function Lightbox({
|
|||
decoding="async"
|
||||
style={isZoomed ? { width: `${scale * 100}%` } : undefined}
|
||||
className={cn(
|
||||
'object-contain select-none',
|
||||
'translate-y-(--lightbox-drop) object-contain select-none motion-reduce:translate-none',
|
||||
isZoomed ? 'max-w-none flex-none' : 'max-h-full max-w-full',
|
||||
drop === null &&
|
||||
'transition-[translate] duration-200 ease-standard',
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</Element>
|
||||
</FlexBox>
|
||||
{/* Outside the scroll box, so they stay put while a zoomed image scrolls. */}
|
||||
{total > 1 && (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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 },
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 && (
|
||||
<PostAccess
|
||||
premium={premium}
|
||||
reason={owner.editFrozenReason ?? labels.owner.editFrozen}
|
||||
labels={labels}
|
||||
/>
|
||||
)}
|
||||
{!props.locked && accessNote != null && (
|
||||
<PostAccessNote>{accessNote}</PostAccessNote>
|
||||
)}
|
||||
<PostActions
|
||||
owner={owner}
|
||||
onShare={onShare}
|
||||
onCopyLink={onCopyLink}
|
||||
premium={premium}
|
||||
isPrediction={props.prediction != null}
|
||||
labels={labels}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { Icon } from '../../../atoms/icon';
|
||||
import { Typography } from '../../../atoms/typography';
|
||||
import { SegmentedChoice } from '../../../molecules/segmented-choice';
|
||||
import { cn } from '../../../tools/cn';
|
||||
import { ABOVE_LINK_CLASS } from '../constants';
|
||||
import type { PostAccessProps } from '../types';
|
||||
|
||||
/**
|
||||
* The creator's access level after the edit window (C5 ۱.۶): it locks with the content, so it
|
||||
* shows frozen rather than hidden, «رایگان» / «پریمیوم» on a pill that dims as one, with the reason
|
||||
* under it in text (a frozen choice takes no focus, so it can't carry a tooltip).
|
||||
*/
|
||||
export function PostAccess({ premium, reason, labels }: PostAccessProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
alignItems="items-start"
|
||||
className={cn(ABOVE_LINK_CLASS, 'gap-1.5')}
|
||||
>
|
||||
<SegmentedChoice
|
||||
label={labels.owner.access ?? ''}
|
||||
value={premium ? 'premium' : 'free'}
|
||||
options={[
|
||||
{ value: 'free', label: labels.owner.free },
|
||||
{ value: 'premium', label: labels.premium, icon: 'lock' },
|
||||
]}
|
||||
size="sm"
|
||||
frozen
|
||||
/>
|
||||
<FlexBox alignItems="items-start" className="gap-1.5 text-text-secondary">
|
||||
<Icon name="lock" size={16} className="mt-0.75 flex-none" />
|
||||
<Typography variant="caption" color="secondary">
|
||||
{reason}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<FlexBox
|
||||
alignItems="items-center"
|
||||
className="gap-1.5 border-t border-border-subtle pt-3 text-text-secondary"
|
||||
>
|
||||
<Icon name="check" size={16} className="flex-none" />
|
||||
<Typography variant="caption" color="secondary">
|
||||
{children}
|
||||
</Typography>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<FlexBox
|
||||
|
|
@ -32,7 +39,7 @@ export function PostActions({
|
|||
gap="gap-1"
|
||||
className={cn(
|
||||
ABOVE_LINK_CLASS,
|
||||
'-mx-2 -mb-2 border-t border-border-subtle pt-2',
|
||||
'-mx-2 -mb-2 border-t border-border-subtle pt-2 has-[[role=menu]]:z-menu',
|
||||
)}
|
||||
>
|
||||
{preview && (
|
||||
|
|
@ -43,13 +50,21 @@ export function PostActions({
|
|||
onClick={preview}
|
||||
/>
|
||||
)}
|
||||
{share && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="share"
|
||||
{copy && copyLink != null ? (
|
||||
<PostShareMenu
|
||||
onCopyLink={copy}
|
||||
label={labels.share}
|
||||
onClick={share}
|
||||
copyLinkLabel={copyLink}
|
||||
/>
|
||||
) : (
|
||||
share && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="share"
|
||||
label={labels.share}
|
||||
onClick={share}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
{canEdit && (
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export function PostHead({
|
|||
publishedAt,
|
||||
now,
|
||||
timeLabel,
|
||||
ownerTag,
|
||||
premium,
|
||||
edited,
|
||||
labels,
|
||||
|
|
@ -114,6 +115,11 @@ export function PostHead({
|
|||
)}
|
||||
</FlexBox>
|
||||
</FlexBox>
|
||||
{ownerTag && (
|
||||
<Tag variant="neutral" icon={null} className="flex-none">
|
||||
{ownerTag}
|
||||
</Tag>
|
||||
)}
|
||||
{premium && (
|
||||
<Tag variant="premium" className="flex-none">
|
||||
{labels.premium}
|
||||
|
|
|
|||
|
|
@ -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 && (
|
||||
<PredictionCard
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { Button } from '../../../atoms/button';
|
||||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { ActionMenu } from '../../../molecules/action-menu';
|
||||
import type { PostShareMenuProps } from '../types';
|
||||
|
||||
/**
|
||||
* Desktop share (C4b ۳.۴, ۶.۱): there is no OS share sheet, so the share button opens a menu
|
||||
* under it at its inline end with one item, «کپی لینک». The copy closes the menu; the caller
|
||||
* confirms it with a toast. The wrapper holds only the trigger and the menu, the area the menu
|
||||
* treats as inside.
|
||||
*/
|
||||
export function PostShareMenu({
|
||||
onCopyLink,
|
||||
label,
|
||||
copyLinkLabel,
|
||||
}: PostShareMenuProps) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<FlexBox display="inline-flex" className="relative">
|
||||
<Button
|
||||
variant="ghost"
|
||||
icon="share"
|
||||
label={label}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={isOpen}
|
||||
onClick={() => setIsOpen((open) => !open)}
|
||||
/>
|
||||
<ActionMenu
|
||||
open={isOpen}
|
||||
onClose={() => setIsOpen(false)}
|
||||
label={label}
|
||||
placement="below"
|
||||
items={[{ icon: 'link', label: copyLinkLabel, onSelect: onCopyLink }]}
|
||||
/>
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import type { DateInput } from '@lumina/tools/format';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import type { LockedTeaserIndicator } from '../../molecules/locked-teaser';
|
||||
import type { MediaItem } from '../../molecules/media-carousel';
|
||||
import type { PredictionCardLabels, PredictionData } from '../prediction-card';
|
||||
|
||||
|
|
@ -11,8 +12,11 @@ export type PostAuthor = {
|
|||
verified?: boolean;
|
||||
};
|
||||
|
||||
/** Who is looking at a locked post; it picks the gate's one message and CTA. */
|
||||
export type PostViewer = 'guest' | 'member';
|
||||
/**
|
||||
* Who is looking at a locked post; it picks the gate's one message and CTA. `pending`: not known
|
||||
* yet (the server render and the first browser render), so the CTA is a skeleton.
|
||||
*/
|
||||
export type PostViewer = 'pending' | 'guest' | 'member';
|
||||
|
||||
/**
|
||||
* The creator's own post. Every handler needs a client caller; a button whose handler is absent
|
||||
|
|
@ -20,6 +24,8 @@ export type PostViewer = 'guest' | 'member';
|
|||
*/
|
||||
export type PostCardOwner = {
|
||||
onShare?: () => void;
|
||||
/** Desktop (C4b ۶.۱): share opens a menu with «کپی لینک» instead of calling `onShare`. */
|
||||
onCopyLink?: () => void;
|
||||
/** Never shown on a prediction post: predictions are immutable. */
|
||||
onEdit?: () => void;
|
||||
/** Never shown on a prediction post. */
|
||||
|
|
@ -32,6 +38,11 @@ export type PostCardOwner = {
|
|||
editFrozen?: boolean;
|
||||
/** Replaces `labels.owner.editFrozen` as the frozen edit's reason. */
|
||||
editFrozenReason?: ReactNode;
|
||||
/**
|
||||
* C5 ۱.۶, after the edit window: the access level shows under the body, locked with the content,
|
||||
* as disabled «رایگان» / «پریمیوم» chips over the frozen reason. Never on a prediction post.
|
||||
*/
|
||||
accessFrozen?: boolean;
|
||||
};
|
||||
|
||||
/** Every text, from the translations. */
|
||||
|
|
@ -58,6 +69,8 @@ export type PostCardLabels = {
|
|||
imageCount: (count: string) => ReactNode;
|
||||
/** «اشتراکگذاری». */
|
||||
share: string;
|
||||
/** «کپی لینک», the desktop share menu's one item. Required with `onCopyLink`. */
|
||||
copyLink?: string;
|
||||
/** The creator's own footer. */
|
||||
owner: {
|
||||
/** «مشاهده به عنوان کاربر». */
|
||||
|
|
@ -68,6 +81,10 @@ export type PostCardLabels = {
|
|||
editFrozen: ReactNode;
|
||||
/** «حذف پست». */
|
||||
delete: string;
|
||||
/** The frozen access level's name, «سطح دسترسی پست». Required with `accessFrozen`. */
|
||||
access?: string;
|
||||
/** Its free chip, «رایگان»; the premium chip reads `premium`. Required with `accessFrozen`. */
|
||||
free?: ReactNode;
|
||||
};
|
||||
/** A locked premium post's gate. */
|
||||
locked: {
|
||||
|
|
@ -99,6 +116,8 @@ type PostCardBaseProps = {
|
|||
now?: DateInput;
|
||||
/** Replaces the relative time («۵ دقیقه پیش»). */
|
||||
timeLabel?: ReactNode;
|
||||
/** The creator's own post on its page: a neutral tag in the header, «پست شما». */
|
||||
ownerTag?: ReactNode;
|
||||
/** پریمیوم in the header. Defaults to `locked`: a locked post is always premium. */
|
||||
premium?: boolean;
|
||||
edited?: boolean;
|
||||
|
|
@ -113,6 +132,16 @@ type PostCardBaseProps = {
|
|||
owner?: PostCardOwner;
|
||||
/** Everyone else: a share-only footer. Client callers only. */
|
||||
onShare?: () => void;
|
||||
/**
|
||||
* Desktop, everyone else (C4b ۳.۴): share opens a menu with «کپی لینک» under it instead of
|
||||
* calling `onShare`. Confirm the copy with a toast. Client callers only.
|
||||
*/
|
||||
onCopyLink?: () => void;
|
||||
/**
|
||||
* An open post: how the viewer has it, «دسترسی از طریق اشتراک سالانه» (Post--unlocked), with a
|
||||
* check under a hairline at the end of the body. A locked post ignores it.
|
||||
*/
|
||||
accessNote?: ReactNode;
|
||||
labels: PostCardLabels;
|
||||
className?: string;
|
||||
};
|
||||
|
|
@ -132,6 +161,8 @@ type PostCardOpenProps = {
|
|||
viewer?: never;
|
||||
onCta?: never;
|
||||
ctaHref?: never;
|
||||
ctaFrozenReason?: never;
|
||||
ctaIndicator?: never;
|
||||
};
|
||||
|
||||
type PostCardLockedProps = {
|
||||
|
|
@ -146,20 +177,24 @@ type PostCardLockedProps = {
|
|||
mediaCount?: number;
|
||||
/** A locked prediction post: pass what the API sends, even `{}`; only its frame shows. */
|
||||
prediction?: Partial<PredictionData>;
|
||||
/** guest → «ورود/ثبتنام», member (the default) → «اشتراک در کانال». */
|
||||
/** guest → «ورود/ثبتنام», member (the default) → «اشتراک در کانال», pending → a skeleton. */
|
||||
viewer?: PostViewer;
|
||||
/** The CTA as a button, such as opening the auth sheet. Client callers only. */
|
||||
onCta?: () => void;
|
||||
/** The CTA as a link (auth with a return path, or the channel's tiers). */
|
||||
ctaHref?: string;
|
||||
/** The CTA shows but does nothing, with this reason: the creator's preview of their post. */
|
||||
ctaFrozenReason?: ReactNode;
|
||||
/** A frozen status in the CTA's place: «پرداخت در حال بررسی» while a payment waits. */
|
||||
ctaIndicator?: LockedTeaserIndicator;
|
||||
text?: never;
|
||||
images?: never;
|
||||
onImageClick?: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* Serializable except the handlers (`owner`, `onShare`, `onImageClick`, `onCta`): a server
|
||||
* component can render a post with links only, and a client caller adds the handlers.
|
||||
* Serializable except the handlers (`owner`, `onShare`, `onCopyLink`, `onImageClick`, `onCta`): a
|
||||
* server component can render a post with links only, and a client caller adds the handlers.
|
||||
*/
|
||||
export type PostCardProps = PostCardBaseProps &
|
||||
(PostCardOpenProps | PostCardLockedProps);
|
||||
|
|
@ -172,6 +207,7 @@ export type PostHeadProps = Pick<
|
|||
| 'publishedAt'
|
||||
| 'now'
|
||||
| 'timeLabel'
|
||||
| 'ownerTag'
|
||||
| 'labels'
|
||||
> & {
|
||||
premium: boolean;
|
||||
|
|
@ -199,6 +235,8 @@ export type PostLockedProps = Pick<
|
|||
| 'viewer'
|
||||
| 'onCta'
|
||||
| 'ctaHref'
|
||||
| 'ctaFrozenReason'
|
||||
| 'ctaIndicator'
|
||||
> &
|
||||
Pick<
|
||||
PostCardBaseProps,
|
||||
|
|
@ -209,9 +247,27 @@ export type PostLockedProps = Pick<
|
|||
|
||||
export type PostActionsProps = Pick<
|
||||
PostCardBaseProps,
|
||||
'owner' | 'onShare' | 'labels'
|
||||
'owner' | 'onShare' | 'onCopyLink' | 'labels'
|
||||
> & {
|
||||
premium: boolean;
|
||||
/** Predictions are immutable: no edit or delete. */
|
||||
isPrediction: boolean;
|
||||
};
|
||||
|
||||
export type PostShareMenuProps = {
|
||||
onCopyLink: () => void;
|
||||
/** The share button's and the menu's accessible name, «اشتراکگذاری». */
|
||||
label: string;
|
||||
/** «کپی لینک». */
|
||||
copyLinkLabel: string;
|
||||
};
|
||||
|
||||
export type PostAccessProps = Pick<PostCardBaseProps, 'labels'> & {
|
||||
premium: boolean;
|
||||
/** The frozen reason under the chips. */
|
||||
reason: ReactNode;
|
||||
};
|
||||
|
||||
export type PostAccessNoteProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ export function SkeletonPreset({
|
|||
count,
|
||||
columns = DEFAULT_TABLE_COLUMNS,
|
||||
avatar = true,
|
||||
cards,
|
||||
framed,
|
||||
delayed,
|
||||
label,
|
||||
className,
|
||||
|
|
@ -42,9 +44,11 @@ export function SkeletonPreset({
|
|||
{preset === 'prediction' &&
|
||||
indexes.map((index) => <PredictionSkeleton key={index} />)}
|
||||
{preset === 'stats' && <StatsSkeleton />}
|
||||
{preset === 'header' && <HeaderSkeleton />}
|
||||
{preset === 'header' && <HeaderSkeleton framed={framed} />}
|
||||
{preset === 'figure' && <FigureSkeleton />}
|
||||
{preset === 'list' && <ListSkeleton rows={n} avatar={avatar} />}
|
||||
{preset === 'list' && (
|
||||
<ListSkeleton rows={n} avatar={avatar} cards={cards} />
|
||||
)}
|
||||
{preset === 'table' && <TableSkeleton rows={n} columns={columns} />}
|
||||
{preset === 'form' && <FormSkeleton fields={n} />}
|
||||
{preset === 'state' && <StateSkeleton />}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { Skeleton } from '../../../atoms/skeleton';
|
||||
import type { HeaderSkeletonProps } from '../types';
|
||||
|
||||
/**
|
||||
* The channel header: 72px avatar, name and link, two bio lines, three market chips, the action
|
||||
* row. It sits on the page edge like the real header, so it is a band, not a card.
|
||||
* row. It sits on the page edge like the real header, so it is a band, not a card; `framed`, it
|
||||
* fills the desktop header's panel instead.
|
||||
*/
|
||||
export function HeaderSkeleton() {
|
||||
export function HeaderSkeleton({ framed }: HeaderSkeletonProps) {
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap="gap-4"
|
||||
aria-hidden
|
||||
className="border-b border-border-subtle bg-surface px-4 py-5"
|
||||
className={
|
||||
framed
|
||||
? undefined
|
||||
: 'border-b border-border-subtle bg-surface px-4 py-5'
|
||||
}
|
||||
>
|
||||
<FlexBox alignItems="items-center" gap="gap-3">
|
||||
<Skeleton shape="circle" className="size-18" />
|
||||
|
|
|
|||
|
|
@ -1,20 +1,51 @@
|
|||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { Skeleton } from '../../../atoms/skeleton';
|
||||
import { Card } from '../../../molecules/card';
|
||||
import { Element } from '../../../primitives/element';
|
||||
import { cn } from '../../../tools/cn';
|
||||
import type { ListSkeletonProps } from '../types';
|
||||
|
||||
/** 72px rows in one card, with alternating line lengths so the rows don't read as a pattern. */
|
||||
export function ListSkeleton({ rows, avatar }: ListSkeletonProps) {
|
||||
/**
|
||||
* 72px rows in one card, with alternating line lengths so the rows don't read as a pattern. With
|
||||
* `cards`, each row is its own card, as the following list's are (U8 ۴.۱, ۶.۱): the avatar, the
|
||||
* @username line and the 44px «دنبال نکردن», so the list lands at the same height.
|
||||
*/
|
||||
export function ListSkeleton({ rows, avatar, cards }: ListSkeletonProps) {
|
||||
// Static placeholders that never reorder, so the index is a stable key.
|
||||
const indexes = Array.from({ length: rows }, (_, row) => row);
|
||||
|
||||
if (cards) {
|
||||
return (
|
||||
<FlexBox
|
||||
direction="flex-col"
|
||||
gap={cards === 'lg' ? 'gap-4' : 'gap-3'}
|
||||
aria-hidden
|
||||
>
|
||||
{indexes.map((row) => (
|
||||
<Card key={row} padding={cards}>
|
||||
<FlexBox alignItems="items-center" gap="gap-3">
|
||||
{avatar && <Skeleton shape="circle" className="size-10" />}
|
||||
<Element className="min-w-0 flex-1">
|
||||
<Skeleton
|
||||
className={cn('h-4', row % 2 ? 'w-[52%]' : 'w-[64%]')}
|
||||
/>
|
||||
</Element>
|
||||
<Skeleton shape="pill" className="h-control-md w-30" />
|
||||
</FlexBox>
|
||||
</Card>
|
||||
))}
|
||||
</FlexBox>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card
|
||||
padding="none"
|
||||
aria-hidden
|
||||
className="divide-y divide-border-subtle overflow-hidden"
|
||||
>
|
||||
{Array.from({ length: rows }, (_, row) => (
|
||||
{indexes.map((row) => (
|
||||
<FlexBox
|
||||
// Static placeholders that never reorder, so the index is a stable key.
|
||||
key={row}
|
||||
alignItems="items-center"
|
||||
gap="gap-3"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ export type SkeletonPresetName =
|
|||
| 'post-media'
|
||||
/** PredictionCard: symbol and chips, three hero tiles, the range bar, four level cells. */
|
||||
| 'prediction'
|
||||
/** 72px rows: subscriptions, transactions, following, notifications, the ledger. */
|
||||
/**
|
||||
* 72px rows in one card: subscriptions, transactions, notifications, the ledger. With `cards`,
|
||||
* one card per row, as the following list draws them.
|
||||
*/
|
||||
| 'list'
|
||||
/** Admin tables, with a sunken header row. */
|
||||
| 'table'
|
||||
|
|
@ -36,6 +39,17 @@ export type SkeletonPresetProps = {
|
|||
columns?: number;
|
||||
/** `list` only: `false` drops the leading avatar circle. */
|
||||
avatar?: boolean;
|
||||
/**
|
||||
* `list` only: each row its own card, padded `md` (mobile) or `lg` (desktop) and 12px or 16px
|
||||
* apart, holding the avatar, one line and a 44px pill, as the following list draws its rows (U8
|
||||
* ۴.۱, ۶.۱). Unset, the rows share one card with dividers.
|
||||
*/
|
||||
cards?: ListSkeletonCards;
|
||||
/**
|
||||
* `header` only: the caller frames it, as the desktop header's panel does, so it drops its own
|
||||
* page band (edge, border and ground).
|
||||
*/
|
||||
framed?: boolean;
|
||||
/** Fades in after 300ms, so fast routes never flash grey. Set it in loading.tsx only. */
|
||||
delayed?: boolean;
|
||||
/** Hidden status text, such as «در حال بارگذاری…». */
|
||||
|
|
@ -47,14 +61,23 @@ export type SkeletonCardProps = {
|
|||
children: ReactNode;
|
||||
};
|
||||
|
||||
export type HeaderSkeletonProps = {
|
||||
/** Inside the caller's panel: no band of its own. */
|
||||
framed?: boolean;
|
||||
};
|
||||
|
||||
export type PostSkeletonProps = {
|
||||
/** Adds the 180px media block. */
|
||||
media?: boolean;
|
||||
};
|
||||
|
||||
/** The card padding of a `list` drawn one card per row. */
|
||||
export type ListSkeletonCards = 'md' | 'lg';
|
||||
|
||||
export type ListSkeletonProps = {
|
||||
rows: number;
|
||||
avatar: boolean;
|
||||
cards?: ListSkeletonCards;
|
||||
};
|
||||
|
||||
export type FormSkeletonProps = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue