feat(island,tools): share popover, 360 sheet popover, form section and avatar field options, switch frozen track, prediction card link, select, list row, tab links and info tip options, body-compact and stat type tokens, button document reload, list formatting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-10-09 19:34:24 +04:00
parent 85cedf9f98
commit 907bc23e25
56 changed files with 436 additions and 137 deletions

View File

@ -25,6 +25,7 @@ export function Button({
frozenAlign, frozenAlign,
pressableWhenFrozen = false, pressableWhenFrozen = false,
isLoading = false, isLoading = false,
reloadDocument = false,
className, className,
children, children,
...props ...props
@ -48,6 +49,21 @@ export function Button({
// also drop it from the tab order and lose focus. A button stays focused and announces busy. // also drop it from the tab order and lose focus. A button stays focused and announces busy.
if (props.href !== undefined && !isBlocked) { if (props.href !== undefined && !isBlocked) {
const linkProps = props as ButtonLinkElementProps; const linkProps = props as ButtonLinkElementProps;
if (reloadDocument) {
// A full load needs the native anchor: NextLink would navigate inside the app.
return (
<FlexBox
tag="a"
href={linkProps.href}
{...buttonLayout(block)}
className={classes}
aria-label={ariaLabel}
title={title}
>
{content}
</FlexBox>
);
}
return ( return (
<FlexBox <FlexBox
tag={NextLink} tag={NextLink}

View File

@ -32,6 +32,11 @@ type ButtonOwnProps = Pick<
frozenAlign?: FrozenTipAlign; frozenAlign?: FrozenTipAlign;
/** An action is in flight: keeps the label, shows a spinner, and blocks repeat taps. */ /** An action is in flight: keeps the label, shows a spinner, and blocks repeat taps. */
isLoading?: boolean; isLoading?: boolean;
/**
* With `href`: a plain `<a>` (href and name only) that loads the page afresh instead of the
* app's client navigation, for when no router can be trusted, such as after the app crashed.
*/
reloadDocument?: boolean;
children?: ReactNode; children?: ReactNode;
}; };

View File

@ -15,7 +15,7 @@ export const chipVariants = cva(
}, },
size: { size: {
sm: 'min-h-control-sm px-3.5 text-body-sm leading-6', sm: 'min-h-control-sm px-3.5 text-body-sm leading-6',
md: 'min-h-control-md text-[0.9375rem] leading-6', md: 'min-h-control-md text-body-compact leading-6',
}, },
}, },
defaultVariants: { selected: false, size: 'md' }, defaultVariants: { selected: false, size: 'md' },

View File

@ -54,7 +54,12 @@ export function Select({
{...props} {...props}
> >
{options.map((option) => ( {options.map((option) => (
<Element tag="option" key={option.value} value={option.value}> <Element
tag="option"
key={option.value}
value={option.value}
disabled={option.disabled}
>
{option.label} {option.label}
</Element> </Element>
))} ))}

View File

@ -2,7 +2,12 @@ import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { IconName } from '../icon'; import type { IconName } from '../icon';
export type SelectOption = { value: string; label: ReactNode }; export type SelectOption = {
value: string;
label: ReactNode;
/** Listed but can't be picked, such as a day before today in a date picker. */
disabled?: boolean;
};
export type SelectProps = Omit<ComponentPropsWithRef<'select'>, 'children'> & { export type SelectProps = Omit<ComponentPropsWithRef<'select'>, 'children'> & {
/** The visible label above the control, such as «روز». */ /** The visible label above the control, such as «روز». */

View File

@ -11,8 +11,9 @@ import { switchKnobVariants, switchTrackVariants } from './variants';
/** /**
* An on/off control that applies to a form, such as offering a period or running a promotion. It * An on/off control that applies to a form, such as offering a period or running a promotion. It
* is a `role="switch"` button in a 44px hit area; with `children` the label is part of it. A locked * is a `role="switch"` button in a 44px hit area; with `children` the label (DS body-md 600) is
* switch stays focusable and says why elsewhere; a disabled one is never used. * part of it. A locked switch stays focusable and says why elsewhere; only its track dims, as the
* DS frozen switch does, so the label stays readable. A disabled one is never used.
*/ */
export function Switch({ export function Switch({
checked, checked,
@ -46,9 +47,7 @@ export function Switch({
}} }}
className={cn( className={cn(
'inline-flex min-h-touch-target min-w-touch-target items-center justify-center gap-3 rounded-md outline-none focus-visible:focus-ring', 'inline-flex min-h-touch-target min-w-touch-target items-center justify-center gap-3 rounded-md outline-none focus-visible:focus-ring',
locked locked ? 'cursor-not-allowed' : 'cursor-pointer',
? 'cursor-not-allowed opacity-(--opacity-dimmed)'
: 'cursor-pointer',
hasText && 'justify-between text-start', hasText && 'justify-between text-start',
className, className,
)} )}
@ -64,7 +63,7 @@ export function Switch({
<Typography <Typography
tag="span" tag="span"
id={labelId} id={labelId}
variant="body-sm" variant="body-md"
className="font-semibold" className="font-semibold"
> >
{children} {children}
@ -85,7 +84,7 @@ export function Switch({
<Element <Element
tag="span" tag="span"
aria-hidden aria-hidden
className={switchTrackVariants({ checked })} className={switchTrackVariants({ checked, locked })}
> >
<Element tag="span" className={switchKnobVariants({ checked })} /> <Element tag="span" className={switchKnobVariants({ checked })} />
</Element> </Element>

View File

@ -16,6 +16,9 @@ export type SwitchProps = Omit<
* Read out as the switch's description. * Read out as the switch's description.
*/ */
description?: ReactNode; description?: ReactNode;
/** Can't change now, such as a period during the 7-day lock: 50%, `aria-disabled`, still focusable. */ /**
* Can't change now, such as a period during the 7-day lock: the track at 40%, `aria-disabled`,
* still focusable.
*/
locked?: boolean; locked?: boolean;
}; };

View File

@ -9,8 +9,10 @@ export const switchTrackVariants = cva(
true: 'border-action-primary bg-action-primary', true: 'border-action-primary bg-action-primary',
false: 'border-border-default bg-surface-sunken', false: 'border-border-default bg-surface-sunken',
}, },
/** Can't change now: the track alone at the DS frozen 40%. */
locked: { true: 'opacity-(--opacity-frozen)', false: '' },
}, },
defaultVariants: { checked: false }, defaultVariants: { checked: false, locked: false },
}, },
); );

View File

@ -123,6 +123,7 @@ export { AvatarField } from './molecules/avatar-field';
export type { export type {
AvatarFieldLabels, AvatarFieldLabels,
AvatarFieldProps, AvatarFieldProps,
AvatarFieldRemoveStyle,
AvatarFieldStatus, AvatarFieldStatus,
} from './molecules/avatar-field'; } from './molecules/avatar-field';
export { Banner, bannerVariants } from './molecules/banner'; export { Banner, bannerVariants } from './molecules/banner';
@ -162,7 +163,7 @@ export type {
export { FormSection } from './molecules/form-section'; export { FormSection } from './molecules/form-section';
export type { FormSectionProps } from './molecules/form-section'; export type { FormSectionProps } from './molecules/form-section';
export { InfoTip, infoTipVariants } from './molecules/info-tip'; export { InfoTip, infoTipVariants } from './molecules/info-tip';
export type { InfoTipProps } from './molecules/info-tip'; export type { InfoTipPlacement, InfoTipProps } from './molecules/info-tip';
export { KeyValue, keyValueVariants } from './molecules/key-value'; export { KeyValue, keyValueVariants } from './molecules/key-value';
export type { KeyValueProps, KeyValueTone } from './molecules/key-value'; export type { KeyValueProps, KeyValueTone } from './molecules/key-value';
export { export {
@ -265,7 +266,11 @@ export type {
SegmentedChoiceTrack, SegmentedChoiceTrack,
} from './molecules/segmented-choice'; } from './molecules/segmented-choice';
export { Sheet } from './molecules/sheet'; export { Sheet } from './molecules/sheet';
export type { SheetPlacement, SheetProps } from './molecules/sheet'; export type {
SheetPlacement,
SheetPopoverWidth,
SheetProps,
} from './molecules/sheet';
export { StateMessage, stateMessageVariants } from './molecules/state-message'; export { StateMessage, stateMessageVariants } from './molecules/state-message';
export type { export type {
StateMessageProps, StateMessageProps,

View File

@ -29,6 +29,8 @@ export function AvatarField({
onRemove, onRemove,
onRetry, onRetry,
disabled = false, disabled = false,
size = '2xl',
removeStyle = 'link',
labels, labels,
className, className,
}: AvatarFieldProps) { }: AvatarFieldProps) {
@ -51,7 +53,7 @@ export function AvatarField({
<Avatar <Avatar
name={name} name={name}
src={src} src={src}
size="2xl" size={size}
label={src ? labels.preview : undefined} label={src ? labels.preview : undefined}
className={cn( className={cn(
'rounded-full transition-opacity duration-120 ease-standard', 'rounded-full transition-opacity duration-120 ease-standard',
@ -80,11 +82,23 @@ export function AvatarField({
{labels.uploading(progress)} {labels.uploading(progress)}
</Typography> </Typography>
)} )}
{src && onRemove && status === 'idle' && ( {src &&
<LinkButton standalone disabled={disabled} onClick={onRemove}> onRemove &&
{labels.remove} status === 'idle' &&
</LinkButton> (removeStyle === 'ghost' ? (
)} <Button
variant="ghost"
size="sm"
disabled={disabled}
onClick={onRemove}
>
{labels.remove}
</Button>
) : (
<LinkButton standalone disabled={disabled} onClick={onRemove}>
{labels.remove}
</LinkButton>
))}
</FlexBox> </FlexBox>
</FlexBox> </FlexBox>
{hasError && ( {hasError && (

View File

@ -1,6 +1,7 @@
export { AvatarField } from './AvatarField'; export { AvatarField } from './AvatarField';
export type { export type {
AvatarFieldLabels, AvatarFieldLabels,
AvatarFieldRemoveStyle,
AvatarFieldProps, AvatarFieldProps,
AvatarFieldStatus, AvatarFieldStatus,
} from './types'; } from './types';

View File

@ -1,5 +1,10 @@
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import type { AvatarSize } from '../../atoms/avatar';
/** link: «حذف تصویر» as a standalone text link. ghost: a small ghost button (DS J12-2). */
export type AvatarFieldRemoveStyle = 'link' | 'ghost';
/** idle: nothing in flight. uploading: the picked photo is on its way. failed: it didn't arrive. */ /** idle: nothing in flight. uploading: the picked photo is on its way. failed: it didn't arrive. */
export type AvatarFieldStatus = 'idle' | 'uploading' | 'failed'; export type AvatarFieldStatus = 'idle' | 'uploading' | 'failed';
@ -38,6 +43,10 @@ export type AvatarFieldProps = {
/** Sends the same file again after a failed upload. */ /** Sends the same file again after a failed upload. */
onRetry?: () => void; onRetry?: () => void;
disabled?: boolean; disabled?: boolean;
/** The photo's size: 96px (`2xl`, the default), or the DS lg 52px of the account page (J12-2). */
size?: AvatarSize;
/** How «حذف تصویر» looks: a text link (the default) or a small ghost button (J12-2). */
removeStyle?: AvatarFieldRemoveStyle;
labels: AvatarFieldLabels; labels: AvatarFieldLabels;
className?: string; className?: string;
}; };

View File

@ -1,14 +1,24 @@
import type { ReactNode } from 'react';
import { Button } from '../../atoms/button'; import { Button } from '../../atoms/button';
import { FlexBox } from '../../atoms/flex-box'; import { FlexBox } from '../../atoms/flex-box';
import { Typography } from '../../atoms/typography'; import { Typography } from '../../atoms/typography';
import { Element } from '../../primitives/element';
import { cn } from '../../tools/cn'; import { cn } from '../../tools/cn';
import type { DetailRowProps } from './types'; import type { DetailRowProps } from './types';
import { detailRowVariants, detailValueVariants } from './variants'; import { detailRowVariants, detailValueVariants } from './variants';
/** A string or a number, or a list of only those (`{date} {t('to')} {date}`). */
function isPlainText(node: ReactNode): boolean {
return (
typeof node === 'string' ||
typeof node === 'number' ||
(Array.isArray(node) && node.every(isPlainText))
);
}
/** /**
* One line of a `<dl>` (DS KV), such as a receipt or a payment's detail: the key at the start in * One line of a `<dl>` (DS KV), such as a receipt or a payment's detail: the key at the start in
* 13px secondary, its value at the end on one baseline. Put rows in a KeyValue for the DS group with * 13px secondary, its value at the end on one baseline, text through Typography. Put rows in a KeyValue for the DS group with
* hairlines, or in any `dl`. * hairlines, or in any `dl`.
*/ */
export function DetailRow({ export function DetailRow({
@ -22,6 +32,9 @@ export function DetailRow({
onCopy, onCopy,
className, className,
}: DetailRowProps) { }: DetailRowProps) {
// Plain text goes through Typography here; parts (an Amount, a badge) bring their own.
const isText = isPlainText(children);
return ( return (
<FlexBox <FlexBox
alignItems="items-baseline" alignItems="items-baseline"
@ -45,9 +58,13 @@ export function DetailRow({
className={cn(detailValueVariants({ strong, tone }), 'gap-1.5')} className={cn(detailValueVariants({ strong, tone }), 'gap-1.5')}
> >
{ltr ? ( {ltr ? (
<Element tag="bdi" dir="ltr"> <Typography tag="bdi" dir="ltr" variant="inherit" color="inherit">
{children} {children}
</Element> </Typography>
) : isText ? (
<Typography tag="span" variant="inherit" color="inherit">
{children}
</Typography>
) : ( ) : (
children children
)} )}

View File

@ -19,7 +19,7 @@ export const detailRowVariants = cva('min-w-0', {
* (badge, value, copy) sit in one end-aligned row that wraps. * (badge, value, copy) sit in one end-aligned row that wraps.
*/ */
export const detailValueVariants = cva( export const detailValueVariants = cva(
'm-0 min-w-0 text-end text-[0.9375rem] leading-[1.625rem]', 'm-0 min-w-0 text-end text-body-compact leading-[1.625rem]',
{ {
variants: { variants: {
strong: { true: 'font-semibold', false: 'font-normal' }, strong: { true: 'font-semibold', false: 'font-normal' },

View File

@ -173,7 +173,7 @@ export function FileField({
<Typography <Typography
tag="span" tag="span"
variant="inherit" variant="inherit"
className="text-[0.9375rem] leading-6 font-semibold" className="text-body-compact leading-6 font-semibold"
> >
{labels.pick} {labels.pick}
</Typography> </Typography>

View File

@ -1,21 +1,30 @@
import { useId } from 'react'; import { useId } from 'react';
import { FlexBox } from '../../atoms/flex-box'; import { FlexBox } from '../../atoms/flex-box';
import { Icon } from '../../atoms/icon';
import { Typography } from '../../atoms/typography'; import { Typography } from '../../atoms/typography';
import type { FormSectionProps } from './types'; import type { FormSectionProps } from './types';
/** /**
* One titled part of a long form, such as a photo, a set of chips or a list of links: the heading * One titled part of a long form, such as a photo, a set of chips or a list of links: the heading
* with its optional marker, a hint, then the controls. The section is named by its heading. * with its optional icon and marker, a hint, then the controls. The section is named by its
* heading.
*/ */
export function FormSection({ export function FormSection({
title, title,
tag = 'h2',
titleIcon,
note, note,
hint, hint,
className, className,
children, children,
}: FormSectionProps) { }: FormSectionProps) {
const titleId = useId(); const titleId = useId();
const marker = note != null && (
<Typography tag="span" variant="caption" color="secondary" className="ms-1">
{note}
</Typography>
);
return ( return (
<FlexBox <FlexBox
@ -26,19 +35,29 @@ export function FormSection({
className={className} className={className}
> >
<FlexBox direction="flex-col" className="gap-0.5"> <FlexBox direction="flex-col" className="gap-0.5">
<Typography tag="h2" variant="heading-sm" id={titleId}> {titleIcon ? (
{title} <FlexBox
{note != null && ( tag={tag}
<Typography id={titleId}
tag="span" alignItems="items-center"
variant="caption" className="gap-1.5"
color="secondary" >
className="ms-1" <Typography tag="span" variant="heading-sm">
> {title}
{note}
</Typography> </Typography>
)} <Icon
</Typography> name={titleIcon}
size={16}
className="flex-none text-text-secondary"
/>
{marker}
</FlexBox>
) : (
<Typography tag={tag} variant="heading-sm" id={titleId}>
{title}
{marker}
</Typography>
)}
{hint != null && ( {hint != null && (
<Typography tag="p" variant="caption" color="secondary"> <Typography tag="p" variant="caption" color="secondary">
{hint} {hint}

View File

@ -1,8 +1,14 @@
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import type { IconName } from '../../atoms/icon';
export type FormSectionProps = { export type FormSectionProps = {
/** The section's name, a level-2 heading. */ /** The section's name, a heading at `tag`'s level. */
title: ReactNode; title: ReactNode;
/** The heading's level: h2 (default), or h3 for a section inside a titled block. */
tag?: 'h2' | 'h3';
/** A 16px secondary icon after the title, such as `lock` on a private section (J02-4). */
titleIcon?: IconName;
/** A quiet marker after the title, such as «(اختیاری)». */ /** A quiet marker after the title, such as «(اختیاری)». */
note?: ReactNode; note?: ReactNode;
/** One sentence under the title: what to put here. */ /** One sentence under the title: what to put here. */

View File

@ -12,9 +12,14 @@ import { infoTipVariants } from './variants';
/** /**
* An ⓘ that explains the figure beside it. Hover and keyboard focus show the text; a tap toggles * An ⓘ that explains the figure beside it. Hover and keyboard focus show the text; a tap toggles
* it, and a tap anywhere else or Escape closes it, because touch has no hover. The button is 44px; * it, and a tap anywhere else or Escape closes it, because touch has no hover. The button is 44px;
* the icon 16. * the icon 16. The text opens under the ⓘ, or above it with `placement="above"`.
*/ */
export function InfoTip({ label, children, className }: InfoTipProps) { export function InfoTip({
label,
children,
placement = 'below',
className,
}: InfoTipProps) {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const tipId = useId(); const tipId = useId();
const rootRef = useRef<HTMLSpanElement>(null); const rootRef = useRef<HTMLSpanElement>(null);
@ -62,7 +67,7 @@ export function InfoTip({ label, children, className }: InfoTipProps) {
role="tooltip" role="tooltip"
variant="caption" variant="caption"
color="inverse" color="inverse"
className={infoTipVariants({ open: isOpen })} className={infoTipVariants({ open: isOpen, placement })}
> >
{children} {children}
</Typography> </Typography>

View File

@ -1,3 +1,3 @@
export { InfoTip } from './InfoTip'; export { InfoTip } from './InfoTip';
export type { InfoTipProps } from './types'; export type { InfoTipPlacement, InfoTipProps } from './types';
export { infoTipVariants } from './variants'; export { infoTipVariants } from './variants';

View File

@ -5,5 +5,9 @@ export type InfoTipProps = {
label: string; label: string;
/** What the figure means, one or two sentences. */ /** What the figure means, one or two sentences. */
children: ReactNode; children: ReactNode;
/** Where the text opens: under the ⓘ (the default), or above it. */
placement?: InfoTipPlacement;
className?: string; className?: string;
}; };
export type InfoTipPlacement = 'below' | 'above';

View File

@ -1,12 +1,17 @@
import { cva } from 'class-variance-authority'; import { cva } from 'class-variance-authority';
/** Under the ⓘ, its start on the icon's, on the inverse surface. */ /** By the ⓘ, its start on the icon's, on the inverse surface: under it, or above it. */
export const infoTipVariants = cva( export const infoTipVariants = cva(
'pointer-events-none absolute start-0 top-[calc(100%+0.25rem)] z-menu hidden w-max max-w-[16.25rem] rounded-sm bg-surface-inverse px-3 py-1.5 text-start whitespace-normal shadow-2 group-hover:block group-has-[:focus-visible]:block', 'pointer-events-none absolute start-0 z-menu hidden w-max max-w-[16.25rem] rounded-sm bg-surface-inverse px-3 py-1.5 text-start whitespace-normal shadow-2 group-hover:block group-has-[:focus-visible]:block',
{ {
variants: { variants: {
open: { true: 'block', false: '' }, open: { true: 'block', false: '' },
/** above: where the tip under the icon would cover the figure it explains (J10-6e). */
placement: {
below: 'top-[calc(100%+0.25rem)]',
above: 'bottom-[calc(100%+0.25rem)]',
},
}, },
defaultVariants: { open: false }, defaultVariants: { open: false, placement: 'below' },
}, },
); );

View File

@ -32,6 +32,7 @@ export function ListRow(props: ListRowProps) {
unreadLabel, unreadLabel,
dimmed = false, dimmed = false,
disabled = false, disabled = false,
selected = false,
className, className,
} = props; } = props;
const hasSecondLine = subtitle != null || meta != null || children != null; const hasSecondLine = subtitle != null || meta != null || children != null;
@ -41,6 +42,7 @@ export function ListRow(props: ListRowProps) {
unread, unread,
dimmed, dimmed,
disabled, disabled,
selected,
interactive: props.href !== undefined || props.onClick !== undefined, interactive: props.href !== undefined || props.onClick !== undefined,
}), }),
className, className,
@ -48,6 +50,7 @@ export function ListRow(props: ListRowProps) {
const layout = { const layout = {
alignItems: hasSecondLine ? 'items-start' : 'items-center', alignItems: hasSecondLine ? 'items-start' : 'items-center',
gap: 'gap-3', gap: 'gap-3',
'aria-current': selected || undefined,
} as const; } as const;
const content = ( const content = (
@ -82,7 +85,7 @@ export function ListRow(props: ListRowProps) {
tag="span" tag="span"
variant="inherit" variant="inherit"
color="inherit" color="inherit"
className="text-[0.9375rem] leading-6 font-semibold" className="text-body-compact leading-6 font-semibold"
> >
{title} {title}
</Typography> </Typography>

View File

@ -53,6 +53,11 @@ type ListRowBaseProps = {
dimmed?: boolean; dimmed?: boolean;
/** Can't be opened now: 40%, no pointer, `aria-disabled`; a link row renders no link. */ /** Can't be opened now: 40%, no pointer, `aria-disabled`; a link row renders no link. */
disabled?: boolean; disabled?: boolean;
/**
* The current one, such as the row whose details are open in a side panel: the sunken ground
* and `aria-current`.
*/
selected?: boolean;
className?: string; className?: string;
}; };

View File

@ -28,8 +28,8 @@ export const listHeaderVariants = cva(
/** /**
* One 64px row: lead, text, end column, chevron. Top-aligned when it has a second line, centred * One 64px row: lead, text, end column, chevron. Top-aligned when it has a second line, centred
* when only a title. An unread row is tinted with a dot at its start; a dimmed one fades every child * when only a title. An unread row is tinted with a dot at its start; a selected one keeps the
* but those marked `data-keep`. As a link or a button the whole row is the hit area, and its focus * sunken ground; a dimmed one fades every child but those marked `data-keep`. As a link or a button the whole row is the hit area, and its focus
* ring sits inside, so the list's rounded clip never cuts it. * ring sits inside, so the list's rounded clip never cuts it.
*/ */
export const listRowVariants = cva( export const listRowVariants = cva(
@ -46,6 +46,8 @@ export const listRowVariants = cva(
false: '', false: '',
}, },
disabled: { true: 'frozen', false: '' }, disabled: { true: 'frozen', false: '' },
/** The row whose details are open beside the list: the DS hover ground, hovered or not. */
selected: { true: 'bg-surface-sunken', false: '' },
}, },
compoundVariants: [ compoundVariants: [
{ {
@ -53,12 +55,18 @@ export const listRowVariants = cva(
interactive: true, interactive: true,
className: 'actionable:hover:bg-action-primary-muted', className: 'actionable:hover:bg-action-primary-muted',
}, },
{
selected: true,
interactive: true,
className: 'actionable:hover:bg-surface-sunken',
},
], ],
defaultVariants: { defaultVariants: {
unread: false, unread: false,
interactive: false, interactive: false,
dimmed: false, dimmed: false,
disabled: false, disabled: false,
selected: false,
}, },
}, },
); );

View File

@ -8,7 +8,7 @@ export const pageHeaderTitleVariants = cva('m-0 min-w-0', {
variants: { variants: {
size: { size: {
md: 'text-[1.375rem] leading-9 font-bold', md: 'text-[1.375rem] leading-9 font-bold',
sm: 'text-[1.125rem] leading-7.5 font-semibold', sm: 'text-body-lg leading-7.5 font-semibold',
}, },
}, },
defaultVariants: { size: 'md' }, defaultVariants: { size: 'md' },

View File

@ -58,7 +58,7 @@ export function ResultPanel({
<Typography <Typography
variant="inherit" variant="inherit"
color="secondary" color="secondary"
className="m-0 max-w-105 text-[0.9375rem] leading-[1.625rem]" className="m-0 max-w-105 text-body-compact leading-[1.625rem]"
> >
{body} {body}
</Typography> </Typography>

View File

@ -7,5 +7,5 @@ export const searchFieldVariants = cva(
/** The bare input inside the pill; the browser's own clear and magnifier are hidden. */ /** The bare input inside the pill; the browser's own clear and magnifier are hidden. */
export const searchFieldInputVariants = cva( export const searchFieldInputVariants = cva(
'h-full min-w-0 flex-1 border-0 bg-transparent p-0 text-[0.9375rem] text-text-primary outline-none placeholder:text-text-tertiary [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none', 'h-full min-w-0 flex-1 border-0 bg-transparent p-0 text-body-compact text-text-primary outline-none placeholder:text-text-tertiary [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none',
); );

View File

@ -35,7 +35,7 @@ export const segmentedChoiceOptionVariants = cva(
tone: { brand: '', neutral: '' }, tone: { brand: '', neutral: '' },
size: { size: {
sm: 'min-h-control-sm px-3.5 text-body-sm leading-6', sm: 'min-h-control-sm px-3.5 text-body-sm leading-6',
md: 'min-h-10 px-4 text-[0.9375rem] leading-6', md: 'min-h-10 px-4 text-body-compact leading-6',
}, },
/** Disabled but not frozen: each option dims, as a disabled chip does (C4 ۱.۶). */ /** Disabled but not frozen: each option dims, as a disabled chip does (C4 ۱.۶). */
disabled: { true: 'frozen', false: '' }, disabled: { true: 'frozen', false: '' },

View File

@ -28,6 +28,7 @@ export function Sheet({
closeLabel, closeLabel,
dismissible = true, dismissible = true,
alert, alert,
popoverWidth,
className, className,
}: SheetProps) { }: SheetProps) {
const titleId = useId(); const titleId = useId();
@ -41,6 +42,7 @@ export function Sheet({
footer={footer} footer={footer}
onClose={onClose} onClose={onClose}
closeLabel={closeLabel} closeLabel={closeLabel}
width={popoverWidth}
className={className} className={className}
> >
{children} {children}

View File

@ -9,10 +9,11 @@ import { cn } from '../../../tools/cn';
import { useDismiss } from '../hooks/use-dismiss'; import { useDismiss } from '../hooks/use-dismiss';
import { useFlip } from '../hooks/use-flip'; import { useFlip } from '../hooks/use-flip';
import type { SheetPopoverProps } from '../types'; import type { SheetPopoverProps } from '../types';
import { sheetPopoverVariants } from '../variants';
import { SheetHead } from './SheetHead'; import { SheetHead } from './SheetHead';
/** /**
* A desktop popover, 320px, anchored by its caller in a positioned container next to the * A desktop popover, 320px (360px `wide`, the DS SharePopover), anchored by its caller in a positioned container next to the
* trigger. It hangs under the trigger at the inline end, and flips above or to the inline start * trigger. It hangs under the trigger at the inline end, and flips above or to the inline start
* when it would run off the screen. No scrim and not modal: Escape, the ✕ or a press outside * when it would run off the screen. No scrim and not modal: Escape, the ✕ or a press outside
* closes it. * closes it.
@ -25,6 +26,7 @@ export function SheetPopover({
footer, footer,
onClose, onClose,
closeLabel, closeLabel,
width,
className, className,
}: SheetPopoverProps) { }: SheetPopoverProps) {
const ref = useRef<HTMLDialogElement>(null); const ref = useRef<HTMLDialogElement>(null);
@ -42,11 +44,7 @@ export function SheetPopover({
ref={ref} ref={ref}
aria-labelledby={titleId} aria-labelledby={titleId}
direction="flex-col" direction="flex-col"
className={cn( className={cn(sheetPopoverVariants({ width }), className)}
'absolute start-auto end-0 top-full z-menu m-0 mt-2 w-80 text-text-primary max-w-[calc(100vw-2rem)] rounded-lg border border-border-subtle bg-surface-raised p-4 shadow-2',
'data-above:top-auto data-above:bottom-full data-above:mt-0 data-above:mb-2 data-align-start:start-0 data-align-start:end-auto',
className,
)}
> >
{icon && <Element className="mb-3">{icon}</Element>} {icon && <Element className="mb-3">{icon}</Element>}
<SheetHead <SheetHead

View File

@ -1,2 +1,2 @@
export { Sheet } from './Sheet'; export { Sheet } from './Sheet';
export type { SheetPlacement, SheetProps } from './types'; export type { SheetPlacement, SheetPopoverWidth, SheetProps } from './types';

View File

@ -26,9 +26,13 @@ export type SheetProps = {
* `role="alertdialog"`. Not for a popover. * `role="alertdialog"`. Not for a popover.
*/ */
alert?: boolean; alert?: boolean;
/** Popover only: 320px by default; `wide` is the DS SharePopover's 360px. */
popoverWidth?: SheetPopoverWidth;
className?: string; className?: string;
}; };
export type SheetPopoverWidth = 'default' | 'wide';
export type SheetHeadProps = { export type SheetHeadProps = {
title: ReactNode; title: ReactNode;
titleId: string; titleId: string;
@ -39,5 +43,7 @@ export type SheetHeadProps = {
export type SheetPopoverProps = Omit< export type SheetPopoverProps = Omit<
SheetProps, SheetProps,
'placement' | 'dismissible' | 'alert' | 'onExited' 'placement' | 'dismissible' | 'alert' | 'onExited' | 'popoverWidth'
>; > & {
width?: SheetPopoverWidth;
};

View File

@ -24,3 +24,14 @@ export const sheetPanelVariants = cva(
}, },
}, },
); );
/** The popover's width: 320px for support and notes, 360px for the DS SharePopover. */
export const sheetPopoverVariants = cva(
'absolute start-auto end-0 top-full z-menu m-0 mt-2 max-w-[calc(100vw-2rem)] rounded-lg border border-border-subtle bg-surface-raised p-4 text-text-primary shadow-2 data-above:top-auto data-above:bottom-full data-above:mt-0 data-above:mb-2 data-align-start:start-0 data-align-start:end-auto',
{
variants: {
width: { default: 'w-80', wide: 'w-90' },
},
defaultVariants: { width: 'default' },
},
);

View File

@ -12,7 +12,7 @@ export const statTileVariants = cva('min-w-0 rounded-lg border p-4', {
}); });
/** The figure, 24/36/700, in a status hue when it carries one. */ /** The figure, 24/36/700, in a status hue when it carries one. */
export const statTileValueVariants = cva('text-[1.5rem] leading-9 font-bold', { export const statTileValueVariants = cva('text-stat', {
variants: { variants: {
valueTone: { valueTone: {
default: 'text-text-primary', default: 'text-text-primary',

View File

@ -11,13 +11,16 @@ import { tabLinksVariants, tabLinkVariants } from './variants';
* «اشتراک‌ها» · «تراکنش‌ها» · «دنبال‌شده‌ها» (U2; U8 ۴.۱, ۶.۱; U8 ۵.۲: the 48px row, not a pill * «اشتراک‌ها» · «تراکنش‌ها» · «دنبال‌شده‌ها» (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 * 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 * 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. * place stays put while a tab's content loads. Tabs that filter one page (`?ledger=payouts`) pass
* `replace` and `scroll={false}`, so a tab neither adds history nor jumps to the top.
*/ */
export function TabLinks({ export function TabLinks({
items, items,
label, label,
fill = false, fill = false,
band, band,
replace,
scroll,
className, className,
}: TabLinksProps) { }: TabLinksProps) {
return ( return (
@ -32,6 +35,8 @@ export function TabLinks({
key={item.href} key={item.href}
tag={NextLink} tag={NextLink}
href={item.href} href={item.href}
replace={replace}
scroll={scroll}
aria-current={item.isActive ? 'page' : undefined} aria-current={item.isActive ? 'page' : undefined}
display="inline-flex" display="inline-flex"
alignItems="items-center" alignItems="items-center"

View File

@ -21,5 +21,12 @@ export type TabLinksProps = VariantProps<typeof tabLinksVariants> & {
* label, as a short filter row does. * label, as a short filter row does.
*/ */
fill?: boolean; fill?: boolean;
/**
* The tabs filter the page they sit on rather than open another section: a tab replaces the
* history entry instead of adding one.
*/
replace?: boolean;
/** false: a tab keeps the page's scroll instead of going to the top. */
scroll?: boolean;
className?: string; className?: string;
}; };

View File

@ -13,7 +13,7 @@ export const tabLinksVariants = cva('min-w-0 border-b border-border-subtle', {
* and the underline; the others are secondary and darken under the pointer. * and the underline; the others are secondary and darken under the pointer.
*/ */
export const tabLinkVariants = cva( 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', '-mb-px h-12 cursor-pointer border-b-2 px-4 text-body-compact leading-6 font-semibold whitespace-nowrap no-underline transition-colors duration-120 ease-standard focus-visible:focus-ring',
{ {
variants: { variants: {
active: { active: {

View File

@ -11,7 +11,10 @@ export type TextInputProps = Omit<
error?: ReactNode; error?: ReactNode;
/** A positive live check, such as «نام کاربری آزاد است». */ /** A positive live check, such as «نام کاربری آزاد است». */
success?: ReactNode; success?: ReactNode;
/** `ltr` for شبا, URLs, usernames, tickers and codes. */ /**
* `ltr` for شبا, URLs, usernames, tickers and codes: direction and alignment only. A شبا or bank
* code also passes `inputClassName="font-latin"` (0011).
*/
dir?: 'rtl' | 'ltr'; dir?: 'rtl' | 'ltr';
/** A fixed affix inside the field, such as `IR` for شبا. */ /** A fixed affix inside the field, such as `IR` for شبا. */
prefix?: ReactNode; prefix?: ReactNode;

View File

@ -38,8 +38,11 @@ export const textInputControlVariants = cva(
variants: { variants: {
multiline: { true: 'min-h-24 resize-y', false: '' }, multiline: { true: 'min-h-24 resize-y', false: '' },
locked: { true: 'text-text-secondary', false: '' }, locked: { true: 'text-text-secondary', false: '' },
/** شبا, URLs, usernames, tickers and codes, in Latin digits as banks print them. */ /**
ltr: { true: 'text-left font-latin tracking-[0.02em]', false: '' }, * URLs, usernames, tickers and codes, left to right. The font stays Yekan Bakh FaNum: only
* شبا and bank codes take the Latin face, through the caller's `inputClassName` (0011).
*/
ltr: { true: 'text-left tracking-[0.02em]', false: '' },
}, },
defaultVariants: { multiline: false, locked: false, ltr: false }, defaultVariants: { multiline: false, locked: false, ltr: false },
}, },

View File

@ -16,7 +16,7 @@ import type { PostCardProps } from './types';
* for the shared LockedTeaser, so locking never changes the feed's rhythm. * for the shared LockedTeaser, so locking never changes the feed's rhythm.
* *
* Server-renderable: only a multi-image carousel, a frozen edit's tooltip and the desktop share * 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`) * popover are client parts. The handlers (`owner`, `onShare`, `onCopyLink`, `onImageClick`, `onCta`)
* need a client caller; a server render passes `href`, `channelHref` and `ctaHref` links instead. * need a client caller; a server render passes `href`, `channelHref` and `ctaHref` links instead.
*/ */
export function PostCard(props: PostCardProps) { export function PostCard(props: PostCardProps) {
@ -35,6 +35,7 @@ export function PostCard(props: PostCardProps) {
owner, owner,
onShare, onShare,
onCopyLink, onCopyLink,
shareUrl,
accessNote, accessNote,
labels, labels,
className, className,
@ -104,6 +105,7 @@ export function PostCard(props: PostCardProps) {
owner={owner} owner={owner}
onShare={onShare} onShare={onShare}
onCopyLink={onCopyLink} onCopyLink={onCopyLink}
shareUrl={shareUrl}
premium={premium} premium={premium}
isPrediction={props.prediction != null} isPrediction={props.prediction != null}
labels={labels} labels={labels}

View File

@ -3,33 +3,34 @@ import { FlexBox } from '../../../atoms/flex-box';
import { cn } from '../../../tools/cn'; import { cn } from '../../../tools/cn';
import { ABOVE_LINK_CLASS } from '../constants'; import { ABOVE_LINK_CLASS } from '../constants';
import type { PostActionsProps } from '../types'; import type { PostActionsProps } from '../types';
import { PostShareMenu } from './PostShareMenu'; import { PostSharePopover } from './PostSharePopover';
/** /**
* Ghost icon buttons at the inline end. Everyone else: share. The creator: preview (premium), * 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, edit (frozen after 15 minutes) and delete; a prediction post keeps only preview and
* share, because predictions can't be edited or deleted. With a copy handler, share opens the * 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 * desktop share popover (C4b ۳.۴, ۶.۱); while it is open the footer rises over the cards after it,
* would otherwise paint over the menu hanging below. * which would otherwise paint over the popover hanging below.
*/ */
export function PostActions({ export function PostActions({
owner, owner,
onShare, onShare,
onCopyLink, onCopyLink,
shareUrl,
premium, premium,
isPrediction, isPrediction,
labels, labels,
}: PostActionsProps) { }: PostActionsProps) {
const share = owner?.onShare ?? onShare; const share = owner?.onShare ?? onShare;
const copy = owner?.onCopyLink ?? onCopyLink; const copy = owner?.onCopyLink ?? onCopyLink;
const { copyLink } = labels; const { copyLink, close } = labels;
const hasMenu = copy != null && copyLink != null; const hasPopover = copy != null && copyLink != null && close != null;
const preview = premium ? owner?.onPreview : undefined; const preview = premium ? owner?.onPreview : undefined;
const mutable = owner != null && !isPrediction; const mutable = owner != null && !isPrediction;
const canEdit = mutable && (owner.onEdit != null || owner.editFrozen); const canEdit = mutable && (owner.onEdit != null || owner.editFrozen);
const canDelete = mutable && owner.onDelete != null; const canDelete = mutable && owner.onDelete != null;
if (!share && !hasMenu && !preview && !canEdit && !canDelete) return null; if (!share && !hasPopover && !preview && !canEdit && !canDelete) return null;
return ( return (
<FlexBox <FlexBox
@ -39,7 +40,7 @@ export function PostActions({
gap="gap-1" gap="gap-1"
className={cn( className={cn(
ABOVE_LINK_CLASS, ABOVE_LINK_CLASS,
'-mx-2 -mb-2 border-t border-border-subtle pt-2 has-[[role=menu]]:z-menu', '-mx-2 -mb-2 border-t border-border-subtle pt-2 has-[dialog[open]]:z-menu',
)} )}
> >
{preview && ( {preview && (
@ -50,11 +51,14 @@ export function PostActions({
onClick={preview} onClick={preview}
/> />
)} )}
{copy && copyLink != null ? ( {hasPopover ? (
<PostShareMenu <PostSharePopover
onCopyLink={copy} onCopyLink={copy}
label={labels.share} label={labels.share}
title={labels.share}
copyLinkLabel={copyLink} copyLinkLabel={copyLink}
closeLabel={close}
url={shareUrl}
/> />
) : ( ) : (
share && ( share && (

View File

@ -1,42 +0,0 @@
'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>
);
}

View File

@ -0,0 +1,72 @@
'use client';
import { useState } from 'react';
import { Button } from '../../../atoms/button';
import { FlexBox } from '../../../atoms/flex-box';
import { Typography } from '../../../atoms/typography';
import { Sheet } from '../../../molecules/sheet';
import type { PostSharePopoverProps } from '../types';
/**
* Desktop share (DS SharePopover, J05-5c, J08-4g): there is no OS share sheet, so the share button
* opens a 360px popover under it at its inline end: «اشتراک‌گذاری پست» with ✕, the post's link
* (LTR) and «کپی لینک». The copy closes it; the caller confirms it with a toast. The wrapper holds
* only the trigger and the popover, the area the popover treats as inside.
*/
export function PostSharePopover({
onCopyLink,
label,
title,
copyLinkLabel,
closeLabel,
url,
}: PostSharePopoverProps) {
const [isOpen, setIsOpen] = useState(false);
return (
<FlexBox display="inline-flex" className="relative">
<Button
variant="ghost"
icon="share"
label={label}
aria-haspopup="dialog"
aria-expanded={isOpen}
onClick={() => setIsOpen((open) => !open)}
/>
<Sheet
placement="popover"
popoverWidth="wide"
open={isOpen}
title={title}
closeLabel={closeLabel}
onClose={() => setIsOpen(false)}
>
<FlexBox direction="flex-col" gap="gap-3">
{url != null && (
<Typography
tag="bdi"
dir="ltr"
variant="caption"
color="secondary"
className="block truncate text-start"
>
{url}
</Typography>
)}
<Button
variant="primary"
icon="link"
block
onClick={() => {
setIsOpen(false);
onCopyLink();
}}
>
{copyLinkLabel}
</Button>
</FlexBox>
</Sheet>
</FlexBox>
);
}

View File

@ -29,7 +29,7 @@ export type PostViewer = 'pending' | 'guest' | 'member';
*/ */
export type PostCardOwner = { export type PostCardOwner = {
onShare?: () => void; onShare?: () => void;
/** Desktop (C4b ۶.۱): share opens a menu with «کپی لینک» instead of calling `onShare`. */ /** Desktop (C4b ۶.۱): share opens the share popover with «کپی لینک» instead of calling `onShare`. */
onCopyLink?: () => void; onCopyLink?: () => void;
/** Never shown on a prediction post: predictions are immutable. */ /** Never shown on a prediction post: predictions are immutable. */
onEdit?: () => void; onEdit?: () => void;
@ -75,10 +75,12 @@ export type PostCardLabels = {
nextImage?: string; nextImage?: string;
/** A locked post's image count, from 2 images: `(n) => <>{n} تصویر</>` → «۳ تصویر». */ /** A locked post's image count, from 2 images: `(n) => <>{n} تصویر</>` → «۳ تصویر». */
imageCount: (count: string) => ReactNode; imageCount: (count: string) => ReactNode;
/** «اشتراک‌گذاری». */ /** The share button's name and the desktop popover's title, «اشتراک‌گذاری پست». */
share: string; share: string;
/** «کپی لینک», the desktop share menu's one item. Required with `onCopyLink`. */ /** «کپی لینک», the desktop share popover's button. Required with `onCopyLink`. */
copyLink?: string; copyLink?: string;
/** The desktop share popover's ✕, «بستن». Required with `onCopyLink`. */
close?: string;
/** The creator's own footer. */ /** The creator's own footer. */
owner: { owner: {
/** «مشاهده به عنوان کاربر». */ /** «مشاهده به عنوان کاربر». */
@ -141,10 +143,15 @@ type PostCardBaseProps = {
/** Everyone else: a share-only footer. Client callers only. */ /** Everyone else: a share-only footer. Client callers only. */
onShare?: () => void; onShare?: () => void;
/** /**
* Desktop, everyone else (C4b ۳.۴): share opens a menu with «کپی لینک» under it instead of * Desktop, everyone else (C4b ۳.۴): share opens the share popover with «کپی لینک» under it
* calling `onShare`. Confirm the copy with a toast. Client callers only. * instead of calling `onShare`. Confirm the copy with a toast. Client callers only.
*/ */
onCopyLink?: () => void; onCopyLink?: () => void;
/**
* The post's link as the desktop share popover shows it, without the scheme:
* `lumina.ir/@sara_gold/posts/1042`. Read in the browser; only an open popover shows it.
*/
shareUrl?: string;
/** /**
* An open post: how the viewer has it, «دسترسی از طریق اشتراک سالانه» (Post--unlocked), with a * 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. * check under a hairline at the end of the body. A locked post ignores it.
@ -255,19 +262,25 @@ export type PostLockedProps = Pick<
export type PostActionsProps = Pick< export type PostActionsProps = Pick<
PostCardBaseProps, PostCardBaseProps,
'owner' | 'onShare' | 'onCopyLink' | 'labels' 'owner' | 'onShare' | 'onCopyLink' | 'shareUrl' | 'labels'
> & { > & {
premium: boolean; premium: boolean;
/** Predictions are immutable: no edit or delete. */ /** Predictions are immutable: no edit or delete. */
isPrediction: boolean; isPrediction: boolean;
}; };
export type PostShareMenuProps = { export type PostSharePopoverProps = {
onCopyLink: () => void; onCopyLink: () => void;
/** The share button's and the menu's accessible name, «اشتراک‌گذاری». */ /** The share button's accessible name, «اشتراک‌گذاری پست». */
label: string; label: string;
/** The popover's title, «اشتراک‌گذاری پست». */
title: string;
/** «کپی لینک». */ /** «کپی لینک». */
copyLinkLabel: string; copyLinkLabel: string;
/** The ✕'s accessible name, «بستن». */
closeLabel: string;
/** The link, shown LTR under the title. */
url?: string;
}; };
export type PostAccessProps = Pick<PostCardBaseProps, 'labels'> & { export type PostAccessProps = Pick<PostCardBaseProps, 'labels'> & {

View File

@ -5,6 +5,7 @@ import { cn } from '../../tools/cn';
import { LockedBody } from './components/LockedBody'; import { LockedBody } from './components/LockedBody';
import { PredictionBody } from './components/PredictionBody'; import { PredictionBody } from './components/PredictionBody';
import { PredictionSeal } from './components/PredictionSeal'; import { PredictionSeal } from './components/PredictionSeal';
import { LINKED_CARD_CLASS } from './constants';
import type { PredictionCardProps } from './types'; import type { PredictionCardProps } from './types';
import { resolveStatus } from './utils'; import { resolveStatus } from './utils';
import { predictionCardVariants } from './variants'; import { predictionCardVariants } from './variants';
@ -14,6 +15,7 @@ import { predictionCardVariants } from './variants';
* signed ROI) or what is at stake (open: to target, to stop, risk to reward), the range bar shows * signed ROI) or what is at stake (open: to target, to stop, risk to reward), the range bar shows
* where it stands between stop loss and final target, and the levels give the exact prices. The * where it stands between stop loss and final target, and the levels give the exact prices. The
* seal with the publish time closes every card, locked ones too, because it is the trust signal. * seal with the publish time closes every card, locked ones too, because it is the trust signal.
* With `href` the card opens its post: the title is the link, stretched over the card.
* Server-renderable: only the owner's close button needs a client caller for its handler. * Server-renderable: only the owner's close button needs a client caller for its handler.
*/ */
export function PredictionCard(props: PredictionCardProps) { export function PredictionCard(props: PredictionCardProps) {
@ -22,6 +24,7 @@ export function PredictionCard(props: PredictionCardProps) {
embedded = false, embedded = false,
premium = false, premium = false,
caption, caption,
href,
publishedAt, publishedAt,
now, now,
onClosePrediction, onClosePrediction,
@ -45,18 +48,24 @@ export function PredictionCard(props: PredictionCardProps) {
<Card <Card
tag="article" tag="article"
padding="none" padding="none"
className={cn(predictionCardVariants({ variant, embedded }), className)} className={cn(
predictionCardVariants({ variant, embedded }),
href && LINKED_CARD_CLASS,
className,
)}
> >
<FlexBox direction="flex-col" gap={expanded ? 'gap-5' : 'gap-4'}> <FlexBox direction="flex-col" gap={expanded ? 'gap-5' : 'gap-4'}>
{props.locked ? ( {props.locked ? (
<LockedBody <LockedBody
prediction={props.prediction} prediction={props.prediction}
href={href}
premium={showPremium} premium={showPremium}
labels={labels} labels={labels}
/> />
) : ( ) : (
<PredictionBody <PredictionBody
prediction={props.prediction} prediction={props.prediction}
href={href}
expanded={expanded} expanded={expanded}
premium={showPremium} premium={showPremium}
caption={caption} caption={caption}

View File

@ -10,10 +10,16 @@ import { PredictionHead } from './PredictionHead';
* Premium and not entitled: only the status (and outcome) is read from the prediction, since * Premium and not entitled: only the status (and outcome) is read from the prediction, since
* results are never hidden behind the paywall. Symbol, direction, prices and horizon never render. * results are never hidden behind the paywall. Symbol, direction, prices and horizon never render.
*/ */
export function LockedBody({ prediction, premium, labels }: LockedBodyProps) { export function LockedBody({
prediction,
href,
premium,
labels,
}: LockedBodyProps) {
return ( return (
<> <>
<PredictionHead <PredictionHead
href={href}
title={ title={
<> <>
<Icon name="lock" size={18} className="text-premium-accent" /> <Icon name="lock" size={18} className="text-premium-accent" />

View File

@ -20,6 +20,7 @@ import { PredictionRange } from './PredictionRange';
/** Header, hero, range bar, then the levels (compact) or the ladder, progress and caption (expanded). */ /** Header, hero, range bar, then the levels (compact) or the ladder, progress and caption (expanded). */
export function PredictionBody({ export function PredictionBody({
prediction: data, prediction: data,
href,
expanded, expanded,
premium, premium,
caption, caption,
@ -39,6 +40,7 @@ export function PredictionBody({
return ( return (
<> <>
<PredictionHead <PredictionHead
href={href}
title={ title={
<> <>
<Typography <Typography

View File

@ -1,14 +1,36 @@
import NextLink from 'next/link';
import { FlexBox } from '../../../atoms/flex-box'; import { FlexBox } from '../../../atoms/flex-box';
import { STRETCHED_LINK_CLASS } from '../constants';
import type { PredictionHeadProps } from '../types'; import type { PredictionHeadProps } from '../types';
/** The title and meta at the start, the badges at the end. */ /** The title and meta at the start, the badges at the end. With `href` the title is the post's link. */
export function PredictionHead({ title, meta, badges }: PredictionHeadProps) { export function PredictionHead({
title,
meta,
badges,
href,
}: PredictionHeadProps) {
return ( return (
<FlexBox alignItems="items-start" gap="gap-3"> <FlexBox alignItems="items-start" gap="gap-3">
<FlexBox direction="flex-col" className="min-w-0 flex-1 gap-1.5"> <FlexBox direction="flex-col" className="min-w-0 flex-1 gap-1.5">
<FlexBox alignItems="items-baseline" gap="gap-2" wrap="flex-wrap"> {href ? (
{title} <FlexBox
</FlexBox> tag={NextLink}
href={href}
data-prediction-link
alignItems="items-baseline"
gap="gap-2"
wrap="flex-wrap"
className={STRETCHED_LINK_CLASS}
>
{title}
</FlexBox>
) : (
<FlexBox alignItems="items-baseline" gap="gap-2" wrap="flex-wrap">
{title}
</FlexBox>
)}
{meta} {meta}
</FlexBox> </FlexBox>
{badges} {badges}

View File

@ -8,6 +8,14 @@ import type {
PredictionTrend, PredictionTrend,
} from './types'; } from './types';
/** With `href`, the title is the post's link and its hit area covers the card; the card draws the ring. */
export const STRETCHED_LINK_CLASS =
'rounded-xs no-underline outline-none after:absolute after:inset-0 after:rounded-lg';
/** A card with a post link: the hover border and, from the link's keyboard focus, the ring. */
export const LINKED_CARD_CLASS =
'transition-[border-color,box-shadow] duration-120 ease-standard hover:border-border-strong has-[[data-prediction-link]:focus-visible]:focus-ring';
/** ±0.05% from entry is breakeven: flat colour, flat arrow. */ /** ±0.05% from entry is breakeven: flat colour, flat arrow. */
export const BREAKEVEN_BAND = 0.05; export const BREAKEVEN_BAND = 0.05;
/** Float slack when a close lands exactly on a level. */ /** Float slack when a close lands exactly on a level. */

View File

@ -184,6 +184,12 @@ type PredictionCardOwnProps = {
premium?: boolean; premium?: boolean;
/** The creator's rationale, expanded only, in a sunken box after the levels. */ /** The creator's rationale, expanded only, in a sunken box after the levels. */
caption?: ReactNode; caption?: ReactNode;
/**
* The prediction's post, as the DS card links to it: the title becomes the link and its hit area
* stretches over the card; «بستن زودهنگام» keeps its own tap. Never inside a PostCard, whose own
* link already covers it.
*/
href?: string;
/** The trust signal: the seal always shows it, with the time. */ /** The trust signal: the seal always shows it, with the time. */
publishedAt: DateInput; publishedAt: DateInput;
/** The time the time left and the horizon progress count from. Pass it from the server render. */ /** The time the time left and the horizon progress count from. Pass it from the server render. */
@ -263,6 +269,8 @@ export type PredictionHeadProps = {
title: ReactNode; title: ReactNode;
meta: ReactNode; meta: ReactNode;
badges: ReactNode; badges: ReactNode;
/** The post: the title row becomes its stretched link. */
href?: string;
}; };
export type PredictionBadgesProps = { export type PredictionBadgesProps = {
@ -346,6 +354,7 @@ export type LadderRow = {
export type LockedBodyProps = { export type LockedBodyProps = {
prediction?: Partial<PredictionData>; prediction?: Partial<PredictionData>;
href?: string;
/** Already false when embedded. */ /** Already false when embedded. */
premium: boolean; premium: boolean;
labels: PredictionCardLabels; labels: PredictionCardLabels;
@ -353,6 +362,7 @@ export type LockedBodyProps = {
export type PredictionBodyProps = { export type PredictionBodyProps = {
prediction: PredictionData; prediction: PredictionData;
href?: string;
expanded: boolean; expanded: boolean;
/** Already false when embedded. */ /** Already false when embedded. */
premium: boolean; premium: boolean;

View File

@ -9,7 +9,7 @@ export function SubscriptionRow({ label, children }: SubscriptionRowProps) {
alignItems="items-baseline" alignItems="items-baseline"
justifyContent="justify-between" justifyContent="justify-between"
gap="gap-3" gap="gap-3"
className="py-1.5 text-[0.9375rem] leading-6.5" className="py-1.5 text-body-compact leading-6.5"
> >
<Typography tag="dt" variant="caption" color="secondary"> <Typography tag="dt" variant="caption" color="secondary">
{label} {label}

View File

@ -50,6 +50,15 @@
--text-micro: 0.6875rem; --text-micro: 0.6875rem;
--text-micro--line-height: 1.125rem; --text-micro--line-height: 1.125rem;
--text-micro--font-weight: 500; --text-micro--font-weight: 500;
/* The v6 compositions' 15px step, between body-sm and body-md: list-row titles, tabs, chips,
key–value values, the header nav. Callers set their own leading and weight where they differ. */
--text-body-compact: 0.9375rem;
--text-body-compact--line-height: 1.5rem;
--text-body-compact--font-weight: 400;
/* A StatTile's figure (DS 24/36/700), one step under display. */
--text-stat: 1.5rem;
--text-stat--line-height: 2.25rem;
--text-stat--font-weight: 700;
/* The landing's own display type (/), a step above `display`: its h1 and its section titles. /* The landing's own display type (/), a step above `display`: its h1 and its section titles.
Typography's `hero` and `section` variants step them up at the tablet and desktop widths. */ Typography's `hero` and `section` variants step them up at the tablet and desktop widths. */
--text-hero: 1.75rem; --text-hero: 1.75rem;

View File

@ -10,6 +10,8 @@ export const TEXT_SIZES = [
'label', 'label',
'caption', 'caption',
'micro', 'micro',
'body-compact',
'stat',
'hero', 'hero',
'hero-md', 'hero-md',
'hero-lg', 'hero-lg',

View File

@ -40,6 +40,10 @@ const timeFormatter = new Intl.DateTimeFormat(LOCALE, {
const relativeFormatter = new Intl.RelativeTimeFormat(LOCALE, { const relativeFormatter = new Intl.RelativeTimeFormat(LOCALE, {
numeric: 'auto', numeric: 'auto',
}); });
const listFormatter = new Intl.ListFormat(LOCALE, {
type: 'conjunction',
style: 'narrow',
});
const numberFormatters = new Map<number, Intl.NumberFormat>(); const numberFormatters = new Map<number, Intl.NumberFormat>();
const unitFormatters = new Map<DurationUnit, Intl.NumberFormat>(); const unitFormatters = new Map<DurationUnit, Intl.NumberFormat>();
@ -103,6 +107,11 @@ function sign(value: number, decimals: number): string {
return value > 0 ? '+' : MINUS_SIGN; return value > 0 ? '+' : MINUS_SIGN;
} }
/** `طلا، فارکس، کریپتو`: items joined with the Persian comma, as the locale lists them. */
export function list(items: readonly string[]): string {
return listFormatter.format(items);
}
/** `1234567.8` → `1٬234٬567٫8`. The font draws the digits in Persian. */ /** `1234567.8` → `1٬234٬567٫8`. The font draws the digits in Persian. */
export function number(value: number, decimals = 0): string { export function number(value: number, decimals = 0): string {
const digits = persianSeparators( const digits = persianSeparators(

View File

@ -5,6 +5,7 @@ export {
horizon, horizon,
iso, iso,
latinDigits, latinDigits,
list,
number, number,
percent, percent,
price, price,

View File

@ -5,6 +5,7 @@ export {
horizon, horizon,
iso, iso,
latinDigits, latinDigits,
list,
LOCALE, LOCALE,
number, number,
percent, percent,