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:
parent
85cedf9f98
commit
907bc23e25
|
|
@ -25,6 +25,7 @@ export function Button({
|
|||
frozenAlign,
|
||||
pressableWhenFrozen = false,
|
||||
isLoading = false,
|
||||
reloadDocument = false,
|
||||
className,
|
||||
children,
|
||||
...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.
|
||||
if (props.href !== undefined && !isBlocked) {
|
||||
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 (
|
||||
<FlexBox
|
||||
tag={NextLink}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ type ButtonOwnProps = Pick<
|
|||
frozenAlign?: FrozenTipAlign;
|
||||
/** An action is in flight: keeps the label, shows a spinner, and blocks repeat taps. */
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export const chipVariants = cva(
|
|||
},
|
||||
size: {
|
||||
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' },
|
||||
|
|
|
|||
|
|
@ -54,7 +54,12 @@ export function Select({
|
|||
{...props}
|
||||
>
|
||||
{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}
|
||||
</Element>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,12 @@ import type { ComponentPropsWithRef, ReactNode } from 'react';
|
|||
|
||||
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'> & {
|
||||
/** The visible label above the control, such as «روز». */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* is a `role="switch"` button in a 44px hit area; with `children` the label is part of it. A locked
|
||||
* switch stays focusable and says why elsewhere; a disabled one is never used.
|
||||
* is a `role="switch"` button in a 44px hit area; with `children` the label (DS body-md 600) is
|
||||
* 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({
|
||||
checked,
|
||||
|
|
@ -46,9 +47,7 @@ export function Switch({
|
|||
}}
|
||||
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',
|
||||
locked
|
||||
? 'cursor-not-allowed opacity-(--opacity-dimmed)'
|
||||
: 'cursor-pointer',
|
||||
locked ? 'cursor-not-allowed' : 'cursor-pointer',
|
||||
hasText && 'justify-between text-start',
|
||||
className,
|
||||
)}
|
||||
|
|
@ -64,7 +63,7 @@ export function Switch({
|
|||
<Typography
|
||||
tag="span"
|
||||
id={labelId}
|
||||
variant="body-sm"
|
||||
variant="body-md"
|
||||
className="font-semibold"
|
||||
>
|
||||
{children}
|
||||
|
|
@ -85,7 +84,7 @@ export function Switch({
|
|||
<Element
|
||||
tag="span"
|
||||
aria-hidden
|
||||
className={switchTrackVariants({ checked })}
|
||||
className={switchTrackVariants({ checked, locked })}
|
||||
>
|
||||
<Element tag="span" className={switchKnobVariants({ checked })} />
|
||||
</Element>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ export type SwitchProps = Omit<
|
|||
* Read out as the switch's description.
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ export const switchTrackVariants = cva(
|
|||
true: 'border-action-primary bg-action-primary',
|
||||
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 },
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ export { AvatarField } from './molecules/avatar-field';
|
|||
export type {
|
||||
AvatarFieldLabels,
|
||||
AvatarFieldProps,
|
||||
AvatarFieldRemoveStyle,
|
||||
AvatarFieldStatus,
|
||||
} from './molecules/avatar-field';
|
||||
export { Banner, bannerVariants } from './molecules/banner';
|
||||
|
|
@ -162,7 +163,7 @@ export type {
|
|||
export { FormSection } from './molecules/form-section';
|
||||
export type { FormSectionProps } from './molecules/form-section';
|
||||
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 type { KeyValueProps, KeyValueTone } from './molecules/key-value';
|
||||
export {
|
||||
|
|
@ -265,7 +266,11 @@ export type {
|
|||
SegmentedChoiceTrack,
|
||||
} from './molecules/segmented-choice';
|
||||
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 type {
|
||||
StateMessageProps,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ export function AvatarField({
|
|||
onRemove,
|
||||
onRetry,
|
||||
disabled = false,
|
||||
size = '2xl',
|
||||
removeStyle = 'link',
|
||||
labels,
|
||||
className,
|
||||
}: AvatarFieldProps) {
|
||||
|
|
@ -51,7 +53,7 @@ export function AvatarField({
|
|||
<Avatar
|
||||
name={name}
|
||||
src={src}
|
||||
size="2xl"
|
||||
size={size}
|
||||
label={src ? labels.preview : undefined}
|
||||
className={cn(
|
||||
'rounded-full transition-opacity duration-120 ease-standard',
|
||||
|
|
@ -80,11 +82,23 @@ export function AvatarField({
|
|||
{labels.uploading(progress)}
|
||||
</Typography>
|
||||
)}
|
||||
{src && onRemove && status === 'idle' && (
|
||||
<LinkButton standalone disabled={disabled} onClick={onRemove}>
|
||||
{labels.remove}
|
||||
</LinkButton>
|
||||
)}
|
||||
{src &&
|
||||
onRemove &&
|
||||
status === 'idle' &&
|
||||
(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>
|
||||
{hasError && (
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
export { AvatarField } from './AvatarField';
|
||||
export type {
|
||||
AvatarFieldLabels,
|
||||
AvatarFieldRemoveStyle,
|
||||
AvatarFieldProps,
|
||||
AvatarFieldStatus,
|
||||
} from './types';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
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. */
|
||||
export type AvatarFieldStatus = 'idle' | 'uploading' | 'failed';
|
||||
|
||||
|
|
@ -38,6 +43,10 @@ export type AvatarFieldProps = {
|
|||
/** Sends the same file again after a failed upload. */
|
||||
onRetry?: () => void;
|
||||
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;
|
||||
className?: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
import { Button } from '../../atoms/button';
|
||||
import { FlexBox } from '../../atoms/flex-box';
|
||||
import { Typography } from '../../atoms/typography';
|
||||
import { Element } from '../../primitives/element';
|
||||
import { cn } from '../../tools/cn';
|
||||
import type { DetailRowProps } from './types';
|
||||
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
|
||||
* 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`.
|
||||
*/
|
||||
export function DetailRow({
|
||||
|
|
@ -22,6 +32,9 @@ export function DetailRow({
|
|||
onCopy,
|
||||
className,
|
||||
}: DetailRowProps) {
|
||||
// Plain text goes through Typography here; parts (an Amount, a badge) bring their own.
|
||||
const isText = isPlainText(children);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
alignItems="items-baseline"
|
||||
|
|
@ -45,9 +58,13 @@ export function DetailRow({
|
|||
className={cn(detailValueVariants({ strong, tone }), 'gap-1.5')}
|
||||
>
|
||||
{ltr ? (
|
||||
<Element tag="bdi" dir="ltr">
|
||||
<Typography tag="bdi" dir="ltr" variant="inherit" color="inherit">
|
||||
{children}
|
||||
</Element>
|
||||
</Typography>
|
||||
) : isText ? (
|
||||
<Typography tag="span" variant="inherit" color="inherit">
|
||||
{children}
|
||||
</Typography>
|
||||
) : (
|
||||
children
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export const detailRowVariants = cva('min-w-0', {
|
|||
* (badge, value, copy) sit in one end-aligned row that wraps.
|
||||
*/
|
||||
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: {
|
||||
strong: { true: 'font-semibold', false: 'font-normal' },
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ export function FileField({
|
|||
<Typography
|
||||
tag="span"
|
||||
variant="inherit"
|
||||
className="text-[0.9375rem] leading-6 font-semibold"
|
||||
className="text-body-compact leading-6 font-semibold"
|
||||
>
|
||||
{labels.pick}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -1,21 +1,30 @@
|
|||
import { useId } from 'react';
|
||||
|
||||
import { FlexBox } from '../../atoms/flex-box';
|
||||
import { Icon } from '../../atoms/icon';
|
||||
import { Typography } from '../../atoms/typography';
|
||||
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
|
||||
* 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({
|
||||
title,
|
||||
tag = 'h2',
|
||||
titleIcon,
|
||||
note,
|
||||
hint,
|
||||
className,
|
||||
children,
|
||||
}: FormSectionProps) {
|
||||
const titleId = useId();
|
||||
const marker = note != null && (
|
||||
<Typography tag="span" variant="caption" color="secondary" className="ms-1">
|
||||
{note}
|
||||
</Typography>
|
||||
);
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
|
|
@ -26,19 +35,29 @@ export function FormSection({
|
|||
className={className}
|
||||
>
|
||||
<FlexBox direction="flex-col" className="gap-0.5">
|
||||
<Typography tag="h2" variant="heading-sm" id={titleId}>
|
||||
{title}
|
||||
{note != null && (
|
||||
<Typography
|
||||
tag="span"
|
||||
variant="caption"
|
||||
color="secondary"
|
||||
className="ms-1"
|
||||
>
|
||||
{note}
|
||||
{titleIcon ? (
|
||||
<FlexBox
|
||||
tag={tag}
|
||||
id={titleId}
|
||||
alignItems="items-center"
|
||||
className="gap-1.5"
|
||||
>
|
||||
<Typography tag="span" variant="heading-sm">
|
||||
{title}
|
||||
</Typography>
|
||||
)}
|
||||
</Typography>
|
||||
<Icon
|
||||
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 && (
|
||||
<Typography tag="p" variant="caption" color="secondary">
|
||||
{hint}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
import type { ReactNode } from 'react';
|
||||
|
||||
import type { IconName } from '../../atoms/icon';
|
||||
|
||||
export type FormSectionProps = {
|
||||
/** The section's name, a level-2 heading. */
|
||||
/** The section's name, a heading at `tag`'s level. */
|
||||
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 «(اختیاری)». */
|
||||
note?: ReactNode;
|
||||
/** One sentence under the title: what to put here. */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* 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 tipId = useId();
|
||||
const rootRef = useRef<HTMLSpanElement>(null);
|
||||
|
|
@ -62,7 +67,7 @@ export function InfoTip({ label, children, className }: InfoTipProps) {
|
|||
role="tooltip"
|
||||
variant="caption"
|
||||
color="inverse"
|
||||
className={infoTipVariants({ open: isOpen })}
|
||||
className={infoTipVariants({ open: isOpen, placement })}
|
||||
>
|
||||
{children}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export { InfoTip } from './InfoTip';
|
||||
export type { InfoTipProps } from './types';
|
||||
export type { InfoTipPlacement, InfoTipProps } from './types';
|
||||
export { infoTipVariants } from './variants';
|
||||
|
|
|
|||
|
|
@ -5,5 +5,9 @@ export type InfoTipProps = {
|
|||
label: string;
|
||||
/** What the figure means, one or two sentences. */
|
||||
children: ReactNode;
|
||||
/** Where the text opens: under the ⓘ (the default), or above it. */
|
||||
placement?: InfoTipPlacement;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export type InfoTipPlacement = 'below' | 'above';
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
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(
|
||||
'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: {
|
||||
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' },
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export function ListRow(props: ListRowProps) {
|
|||
unreadLabel,
|
||||
dimmed = false,
|
||||
disabled = false,
|
||||
selected = false,
|
||||
className,
|
||||
} = props;
|
||||
const hasSecondLine = subtitle != null || meta != null || children != null;
|
||||
|
|
@ -41,6 +42,7 @@ export function ListRow(props: ListRowProps) {
|
|||
unread,
|
||||
dimmed,
|
||||
disabled,
|
||||
selected,
|
||||
interactive: props.href !== undefined || props.onClick !== undefined,
|
||||
}),
|
||||
className,
|
||||
|
|
@ -48,6 +50,7 @@ export function ListRow(props: ListRowProps) {
|
|||
const layout = {
|
||||
alignItems: hasSecondLine ? 'items-start' : 'items-center',
|
||||
gap: 'gap-3',
|
||||
'aria-current': selected || undefined,
|
||||
} as const;
|
||||
|
||||
const content = (
|
||||
|
|
@ -82,7 +85,7 @@ export function ListRow(props: ListRowProps) {
|
|||
tag="span"
|
||||
variant="inherit"
|
||||
color="inherit"
|
||||
className="text-[0.9375rem] leading-6 font-semibold"
|
||||
className="text-body-compact leading-6 font-semibold"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ type ListRowBaseProps = {
|
|||
dimmed?: boolean;
|
||||
/** Can't be opened now: 40%, no pointer, `aria-disabled`; a link row renders no link. */
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* when only a title. An unread row is tinted with a dot at its start; 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
|
||||
* when only a title. An unread row is tinted with a dot at its start; a selected one keeps the
|
||||
* 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.
|
||||
*/
|
||||
export const listRowVariants = cva(
|
||||
|
|
@ -46,6 +46,8 @@ export const listRowVariants = cva(
|
|||
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: [
|
||||
{
|
||||
|
|
@ -53,12 +55,18 @@ export const listRowVariants = cva(
|
|||
interactive: true,
|
||||
className: 'actionable:hover:bg-action-primary-muted',
|
||||
},
|
||||
{
|
||||
selected: true,
|
||||
interactive: true,
|
||||
className: 'actionable:hover:bg-surface-sunken',
|
||||
},
|
||||
],
|
||||
defaultVariants: {
|
||||
unread: false,
|
||||
interactive: false,
|
||||
dimmed: false,
|
||||
disabled: false,
|
||||
selected: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export const pageHeaderTitleVariants = cva('m-0 min-w-0', {
|
|||
variants: {
|
||||
size: {
|
||||
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' },
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ export function ResultPanel({
|
|||
<Typography
|
||||
variant="inherit"
|
||||
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}
|
||||
</Typography>
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ export const searchFieldVariants = cva(
|
|||
|
||||
/** The bare input inside the pill; the browser's own clear and magnifier are hidden. */
|
||||
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',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export const segmentedChoiceOptionVariants = cva(
|
|||
tone: { brand: '', neutral: '' },
|
||||
size: {
|
||||
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: { true: 'frozen', false: '' },
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export function Sheet({
|
|||
closeLabel,
|
||||
dismissible = true,
|
||||
alert,
|
||||
popoverWidth,
|
||||
className,
|
||||
}: SheetProps) {
|
||||
const titleId = useId();
|
||||
|
|
@ -41,6 +42,7 @@ export function Sheet({
|
|||
footer={footer}
|
||||
onClose={onClose}
|
||||
closeLabel={closeLabel}
|
||||
width={popoverWidth}
|
||||
className={className}
|
||||
>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ import { cn } from '../../../tools/cn';
|
|||
import { useDismiss } from '../hooks/use-dismiss';
|
||||
import { useFlip } from '../hooks/use-flip';
|
||||
import type { SheetPopoverProps } from '../types';
|
||||
import { sheetPopoverVariants } from '../variants';
|
||||
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
|
||||
* when it would run off the screen. No scrim and not modal: Escape, the ✕ or a press outside
|
||||
* closes it.
|
||||
|
|
@ -25,6 +26,7 @@ export function SheetPopover({
|
|||
footer,
|
||||
onClose,
|
||||
closeLabel,
|
||||
width,
|
||||
className,
|
||||
}: SheetPopoverProps) {
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
|
|
@ -42,11 +44,7 @@ export function SheetPopover({
|
|||
ref={ref}
|
||||
aria-labelledby={titleId}
|
||||
direction="flex-col"
|
||||
className={cn(
|
||||
'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,
|
||||
)}
|
||||
className={cn(sheetPopoverVariants({ width }), className)}
|
||||
>
|
||||
{icon && <Element className="mb-3">{icon}</Element>}
|
||||
<SheetHead
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
export { Sheet } from './Sheet';
|
||||
export type { SheetPlacement, SheetProps } from './types';
|
||||
export type { SheetPlacement, SheetPopoverWidth, SheetProps } from './types';
|
||||
|
|
|
|||
|
|
@ -26,9 +26,13 @@ export type SheetProps = {
|
|||
* `role="alertdialog"`. Not for a popover.
|
||||
*/
|
||||
alert?: boolean;
|
||||
/** Popover only: 320px by default; `wide` is the DS SharePopover's 360px. */
|
||||
popoverWidth?: SheetPopoverWidth;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export type SheetPopoverWidth = 'default' | 'wide';
|
||||
|
||||
export type SheetHeadProps = {
|
||||
title: ReactNode;
|
||||
titleId: string;
|
||||
|
|
@ -39,5 +43,7 @@ export type SheetHeadProps = {
|
|||
|
||||
export type SheetPopoverProps = Omit<
|
||||
SheetProps,
|
||||
'placement' | 'dismissible' | 'alert' | 'onExited'
|
||||
>;
|
||||
'placement' | 'dismissible' | 'alert' | 'onExited' | 'popoverWidth'
|
||||
> & {
|
||||
width?: SheetPopoverWidth;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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' },
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
export const statTileValueVariants = cva('text-[1.5rem] leading-9 font-bold', {
|
||||
export const statTileValueVariants = cva('text-stat', {
|
||||
variants: {
|
||||
valueTone: {
|
||||
default: 'text-text-primary',
|
||||
|
|
|
|||
|
|
@ -11,13 +11,16 @@ import { tabLinksVariants, tabLinkVariants } from './variants';
|
|||
* «اشتراکها» · «تراکنشها» · «دنبالشدهها» (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.
|
||||
* 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({
|
||||
items,
|
||||
label,
|
||||
fill = false,
|
||||
band,
|
||||
replace,
|
||||
scroll,
|
||||
className,
|
||||
}: TabLinksProps) {
|
||||
return (
|
||||
|
|
@ -32,6 +35,8 @@ export function TabLinks({
|
|||
key={item.href}
|
||||
tag={NextLink}
|
||||
href={item.href}
|
||||
replace={replace}
|
||||
scroll={scroll}
|
||||
aria-current={item.isActive ? 'page' : undefined}
|
||||
display="inline-flex"
|
||||
alignItems="items-center"
|
||||
|
|
|
|||
|
|
@ -21,5 +21,12 @@ export type TabLinksProps = VariantProps<typeof tabLinksVariants> & {
|
|||
* label, as a short filter row does.
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
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: {
|
||||
active: {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ export type TextInputProps = Omit<
|
|||
error?: ReactNode;
|
||||
/** A positive live check, such as «نام کاربری آزاد است». */
|
||||
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';
|
||||
/** A fixed affix inside the field, such as `IR` for شبا. */
|
||||
prefix?: ReactNode;
|
||||
|
|
|
|||
|
|
@ -38,8 +38,11 @@ export const textInputControlVariants = cva(
|
|||
variants: {
|
||||
multiline: { true: 'min-h-24 resize-y', 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 },
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import type { PostCardProps } from './types';
|
|||
* 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
|
||||
* 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.
|
||||
*/
|
||||
export function PostCard(props: PostCardProps) {
|
||||
|
|
@ -35,6 +35,7 @@ export function PostCard(props: PostCardProps) {
|
|||
owner,
|
||||
onShare,
|
||||
onCopyLink,
|
||||
shareUrl,
|
||||
accessNote,
|
||||
labels,
|
||||
className,
|
||||
|
|
@ -104,6 +105,7 @@ export function PostCard(props: PostCardProps) {
|
|||
owner={owner}
|
||||
onShare={onShare}
|
||||
onCopyLink={onCopyLink}
|
||||
shareUrl={shareUrl}
|
||||
premium={premium}
|
||||
isPrediction={props.prediction != null}
|
||||
labels={labels}
|
||||
|
|
|
|||
|
|
@ -3,33 +3,34 @@ 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';
|
||||
import { PostSharePopover } from './PostSharePopover';
|
||||
|
||||
/**
|
||||
* 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. 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.
|
||||
* desktop share popover (C4b ۳.۴, ۶.۱); while it is open the footer rises over the cards after it,
|
||||
* which would otherwise paint over the popover hanging below.
|
||||
*/
|
||||
export function PostActions({
|
||||
owner,
|
||||
onShare,
|
||||
onCopyLink,
|
||||
shareUrl,
|
||||
premium,
|
||||
isPrediction,
|
||||
labels,
|
||||
}: PostActionsProps) {
|
||||
const share = owner?.onShare ?? onShare;
|
||||
const copy = owner?.onCopyLink ?? onCopyLink;
|
||||
const { copyLink } = labels;
|
||||
const hasMenu = copy != null && copyLink != null;
|
||||
const { copyLink, close } = labels;
|
||||
const hasPopover = copy != null && copyLink != null && close != 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 && !hasMenu && !preview && !canEdit && !canDelete) return null;
|
||||
if (!share && !hasPopover && !preview && !canEdit && !canDelete) return null;
|
||||
|
||||
return (
|
||||
<FlexBox
|
||||
|
|
@ -39,7 +40,7 @@ export function PostActions({
|
|||
gap="gap-1"
|
||||
className={cn(
|
||||
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 && (
|
||||
|
|
@ -50,11 +51,14 @@ export function PostActions({
|
|||
onClick={preview}
|
||||
/>
|
||||
)}
|
||||
{copy && copyLink != null ? (
|
||||
<PostShareMenu
|
||||
{hasPopover ? (
|
||||
<PostSharePopover
|
||||
onCopyLink={copy}
|
||||
label={labels.share}
|
||||
title={labels.share}
|
||||
copyLinkLabel={copyLink}
|
||||
closeLabel={close}
|
||||
url={shareUrl}
|
||||
/>
|
||||
) : (
|
||||
share && (
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ export type PostViewer = 'pending' | 'guest' | 'member';
|
|||
*/
|
||||
export type PostCardOwner = {
|
||||
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;
|
||||
/** Never shown on a prediction post: predictions are immutable. */
|
||||
onEdit?: () => void;
|
||||
|
|
@ -75,10 +75,12 @@ export type PostCardLabels = {
|
|||
nextImage?: string;
|
||||
/** A locked post's image count, from 2 images: `(n) => <>{n} تصویر</>` → «۳ تصویر». */
|
||||
imageCount: (count: string) => ReactNode;
|
||||
/** «اشتراکگذاری». */
|
||||
/** The share button's name and the desktop popover's title, «اشتراکگذاری پست». */
|
||||
share: string;
|
||||
/** «کپی لینک», the desktop share menu's one item. Required with `onCopyLink`. */
|
||||
/** «کپی لینک», the desktop share popover's button. Required with `onCopyLink`. */
|
||||
copyLink?: string;
|
||||
/** The desktop share popover's ✕, «بستن». Required with `onCopyLink`. */
|
||||
close?: string;
|
||||
/** The creator's own footer. */
|
||||
owner: {
|
||||
/** «مشاهده به عنوان کاربر». */
|
||||
|
|
@ -141,10 +143,15 @@ type PostCardBaseProps = {
|
|||
/** 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.
|
||||
* Desktop, everyone else (C4b ۳.۴): share opens the share popover with «کپی لینک» under it
|
||||
* instead of calling `onShare`. Confirm the copy with a toast. Client callers only.
|
||||
*/
|
||||
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
|
||||
* 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<
|
||||
PostCardBaseProps,
|
||||
'owner' | 'onShare' | 'onCopyLink' | 'labels'
|
||||
'owner' | 'onShare' | 'onCopyLink' | 'shareUrl' | 'labels'
|
||||
> & {
|
||||
premium: boolean;
|
||||
/** Predictions are immutable: no edit or delete. */
|
||||
isPrediction: boolean;
|
||||
};
|
||||
|
||||
export type PostShareMenuProps = {
|
||||
export type PostSharePopoverProps = {
|
||||
onCopyLink: () => void;
|
||||
/** The share button's and the menu's accessible name, «اشتراکگذاری». */
|
||||
/** The share button's accessible name, «اشتراکگذاری پست». */
|
||||
label: string;
|
||||
/** The popover's title, «اشتراکگذاری پست». */
|
||||
title: string;
|
||||
/** «کپی لینک». */
|
||||
copyLinkLabel: string;
|
||||
/** The ✕'s accessible name, «بستن». */
|
||||
closeLabel: string;
|
||||
/** The link, shown LTR under the title. */
|
||||
url?: string;
|
||||
};
|
||||
|
||||
export type PostAccessProps = Pick<PostCardBaseProps, 'labels'> & {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { cn } from '../../tools/cn';
|
|||
import { LockedBody } from './components/LockedBody';
|
||||
import { PredictionBody } from './components/PredictionBody';
|
||||
import { PredictionSeal } from './components/PredictionSeal';
|
||||
import { LINKED_CARD_CLASS } from './constants';
|
||||
import type { PredictionCardProps } from './types';
|
||||
import { resolveStatus } from './utils';
|
||||
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
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
export function PredictionCard(props: PredictionCardProps) {
|
||||
|
|
@ -22,6 +24,7 @@ export function PredictionCard(props: PredictionCardProps) {
|
|||
embedded = false,
|
||||
premium = false,
|
||||
caption,
|
||||
href,
|
||||
publishedAt,
|
||||
now,
|
||||
onClosePrediction,
|
||||
|
|
@ -45,18 +48,24 @@ export function PredictionCard(props: PredictionCardProps) {
|
|||
<Card
|
||||
tag="article"
|
||||
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'}>
|
||||
{props.locked ? (
|
||||
<LockedBody
|
||||
prediction={props.prediction}
|
||||
href={href}
|
||||
premium={showPremium}
|
||||
labels={labels}
|
||||
/>
|
||||
) : (
|
||||
<PredictionBody
|
||||
prediction={props.prediction}
|
||||
href={href}
|
||||
expanded={expanded}
|
||||
premium={showPremium}
|
||||
caption={caption}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,16 @@ import { PredictionHead } from './PredictionHead';
|
|||
* 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.
|
||||
*/
|
||||
export function LockedBody({ prediction, premium, labels }: LockedBodyProps) {
|
||||
export function LockedBody({
|
||||
prediction,
|
||||
href,
|
||||
premium,
|
||||
labels,
|
||||
}: LockedBodyProps) {
|
||||
return (
|
||||
<>
|
||||
<PredictionHead
|
||||
href={href}
|
||||
title={
|
||||
<>
|
||||
<Icon name="lock" size={18} className="text-premium-accent" />
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { PredictionRange } from './PredictionRange';
|
|||
/** Header, hero, range bar, then the levels (compact) or the ladder, progress and caption (expanded). */
|
||||
export function PredictionBody({
|
||||
prediction: data,
|
||||
href,
|
||||
expanded,
|
||||
premium,
|
||||
caption,
|
||||
|
|
@ -39,6 +40,7 @@ export function PredictionBody({
|
|||
return (
|
||||
<>
|
||||
<PredictionHead
|
||||
href={href}
|
||||
title={
|
||||
<>
|
||||
<Typography
|
||||
|
|
|
|||
|
|
@ -1,14 +1,36 @@
|
|||
import NextLink from 'next/link';
|
||||
|
||||
import { FlexBox } from '../../../atoms/flex-box';
|
||||
import { STRETCHED_LINK_CLASS } from '../constants';
|
||||
import type { PredictionHeadProps } from '../types';
|
||||
|
||||
/** The title and meta at the start, the badges at the end. */
|
||||
export function PredictionHead({ title, meta, badges }: PredictionHeadProps) {
|
||||
/** 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,
|
||||
href,
|
||||
}: PredictionHeadProps) {
|
||||
return (
|
||||
<FlexBox alignItems="items-start" gap="gap-3">
|
||||
<FlexBox direction="flex-col" className="min-w-0 flex-1 gap-1.5">
|
||||
<FlexBox alignItems="items-baseline" gap="gap-2" wrap="flex-wrap">
|
||||
{title}
|
||||
</FlexBox>
|
||||
{href ? (
|
||||
<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}
|
||||
</FlexBox>
|
||||
{badges}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ import type {
|
|||
PredictionTrend,
|
||||
} 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. */
|
||||
export const BREAKEVEN_BAND = 0.05;
|
||||
/** Float slack when a close lands exactly on a level. */
|
||||
|
|
|
|||
|
|
@ -184,6 +184,12 @@ type PredictionCardOwnProps = {
|
|||
premium?: boolean;
|
||||
/** The creator's rationale, expanded only, in a sunken box after the levels. */
|
||||
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. */
|
||||
publishedAt: DateInput;
|
||||
/** 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;
|
||||
meta: ReactNode;
|
||||
badges: ReactNode;
|
||||
/** The post: the title row becomes its stretched link. */
|
||||
href?: string;
|
||||
};
|
||||
|
||||
export type PredictionBadgesProps = {
|
||||
|
|
@ -346,6 +354,7 @@ export type LadderRow = {
|
|||
|
||||
export type LockedBodyProps = {
|
||||
prediction?: Partial<PredictionData>;
|
||||
href?: string;
|
||||
/** Already false when embedded. */
|
||||
premium: boolean;
|
||||
labels: PredictionCardLabels;
|
||||
|
|
@ -353,6 +362,7 @@ export type LockedBodyProps = {
|
|||
|
||||
export type PredictionBodyProps = {
|
||||
prediction: PredictionData;
|
||||
href?: string;
|
||||
expanded: boolean;
|
||||
/** Already false when embedded. */
|
||||
premium: boolean;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export function SubscriptionRow({ label, children }: SubscriptionRowProps) {
|
|||
alignItems="items-baseline"
|
||||
justifyContent="justify-between"
|
||||
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">
|
||||
{label}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,15 @@
|
|||
--text-micro: 0.6875rem;
|
||||
--text-micro--line-height: 1.125rem;
|
||||
--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.
|
||||
Typography's `hero` and `section` variants step them up at the tablet and desktop widths. */
|
||||
--text-hero: 1.75rem;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ export const TEXT_SIZES = [
|
|||
'label',
|
||||
'caption',
|
||||
'micro',
|
||||
'body-compact',
|
||||
'stat',
|
||||
'hero',
|
||||
'hero-md',
|
||||
'hero-lg',
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ const timeFormatter = new Intl.DateTimeFormat(LOCALE, {
|
|||
const relativeFormatter = new Intl.RelativeTimeFormat(LOCALE, {
|
||||
numeric: 'auto',
|
||||
});
|
||||
const listFormatter = new Intl.ListFormat(LOCALE, {
|
||||
type: 'conjunction',
|
||||
style: 'narrow',
|
||||
});
|
||||
const numberFormatters = new Map<number, 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;
|
||||
}
|
||||
|
||||
/** `طلا، فارکس، کریپتو`: 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. */
|
||||
export function number(value: number, decimals = 0): string {
|
||||
const digits = persianSeparators(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export {
|
|||
horizon,
|
||||
iso,
|
||||
latinDigits,
|
||||
list,
|
||||
number,
|
||||
percent,
|
||||
price,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export {
|
|||
horizon,
|
||||
iso,
|
||||
latinDigits,
|
||||
list,
|
||||
LOCALE,
|
||||
number,
|
||||
percent,
|
||||
|
|
|
|||
Loading…
Reference in New Issue