feat(island,tools): form pieces for the profile step

- Atoms: Chip (toggle with aria-pressed), Checkbox, FieldError (alert line
  under a group), LinkButton (a button that looks like a link; SupportLink now
  uses it), RowButton (56px choice row for sheets), and a 96px Avatar size.
- Molecules: ChipGroup (named fieldset of chips with its error), FormSection
  (titled form part with an optional marker and hint), AvatarField (photo
  pick, change, remove, upload progress, failed state with retry).
- Dialog, Sheet and Modal take `onExited`, called once the dialog has left
  the top layer. The page is inert until then, so focus moves there.
- tools/format: `time()` for a time of day in Tehran (`14:05`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-10-05 22:32:43 +04:00
parent f5e0ffb668
commit 9216bc8177
38 changed files with 687 additions and 33 deletions

View File

@ -7,6 +7,7 @@ export const AVATAR_PX: Record<AvatarSize, number> = {
md: 40,
lg: 56,
xl: 80,
'2xl': 96,
};
export const AVATAR_INITIAL_VARIANT: Record<AvatarSize, TypographyVariant> = {
@ -14,6 +15,7 @@ export const AVATAR_INITIAL_VARIANT: Record<AvatarSize, TypographyVariant> = {
md: 'body-md',
lg: 'heading-sm',
xl: 'heading-lg',
'2xl': 'display',
};
export const AVATAR_MARK_PX: Record<AvatarSize, number> = {
@ -21,4 +23,5 @@ export const AVATAR_MARK_PX: Record<AvatarSize, number> = {
md: 14,
lg: 18,
xl: 22,
'2xl': 24,
};

View File

@ -14,6 +14,8 @@ export const avatarVariants = cva(
lg: 'size-14',
/** The channel profile header. */
xl: 'size-20',
/** The profile photo field. */
'2xl': 'size-24',
},
},
defaultVariants: { size: 'md' },

View File

@ -0,0 +1,53 @@
import { Element } from '../../primitives/element';
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { GridBox } from '../grid-box';
import { Icon } from '../icon';
import { Typography } from '../typography';
import type { CheckboxProps } from './types';
import { checkboxVariants } from './variants';
/**
* A labelled checkbox for a consent or an option. The whole row is the hit area (at least 44px
* high). Works with react-hook-form's `register` or as a controlled input; the ref reaches the
* input.
*/
export function Checkbox({
invalid = false,
className,
children,
...props
}: CheckboxProps) {
return (
<FlexBox
tag="label"
alignItems="items-start"
gap="gap-3"
className={cn('min-h-touch-target cursor-pointer', className)}
>
<GridBox
tag="span"
justifyItems="justify-items-center"
alignItems="items-center"
className="mt-px flex-none"
>
<Element
tag="input"
type="checkbox"
aria-invalid={invalid || undefined}
className={checkboxVariants({ invalid })}
{...props}
/>
<Icon
name="check"
size={14}
strokeWidth={3}
className="pointer-events-none invisible text-text-on-action [grid-area:1/1] peer-checked:visible"
/>
</GridBox>
<Typography tag="span" variant="body-sm" className="leading-6">
{children}
</Typography>
</FlexBox>
);
}

View File

@ -0,0 +1,3 @@
export { Checkbox } from './Checkbox';
export type { CheckboxProps } from './types';
export { checkboxVariants } from './variants';

View File

@ -0,0 +1,11 @@
import type { ComponentPropsWithRef, ReactNode } from 'react';
export type CheckboxProps = Omit<
ComponentPropsWithRef<'input'>,
'type' | 'children'
> & {
/** Required and unchecked on submit: a red box; the message goes under it. */
invalid?: boolean;
/** The label, a full sentence the person agrees to. */
children: ReactNode;
};

View File

@ -0,0 +1,15 @@
import { cva } from 'class-variance-authority';
/** The 22px box; the real input draws it, so focus and checked state need no script. */
export const checkboxVariants = cva(
'peer m-0 size-5.5 appearance-none rounded-sm border-[1.5px] bg-surface transition-colors duration-120 ease-standard [grid-area:1/1] checked:border-action-primary checked:bg-action-primary focus-visible:focus-ring actionable:cursor-pointer disabled:frozen',
{
variants: {
invalid: {
true: 'border-danger',
false: 'border-border-default',
},
},
defaultVariants: { invalid: false },
},
);

View File

@ -0,0 +1,35 @@
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { Icon } from '../icon';
import { Typography } from '../typography';
import type { ChipProps } from './types';
import { chipVariants } from './variants';
/**
* A toggle pill for a multiple choice, such as markets. A real button with `aria-pressed`, so
* Tab, Space and screen readers work. Wrap a set in `role="group"` with an accessible name.
*/
export function Chip({
selected,
size = 'md',
className,
children,
...props
}: ChipProps) {
return (
<FlexBox
tag="button"
type="button"
aria-pressed={selected}
display="inline-flex"
alignItems="items-center"
className={cn(chipVariants({ selected, size }), 'gap-1.5', className)}
{...props}
>
{selected && <Icon name="check" size={16} strokeWidth={2.5} />}
<Typography tag="span" variant="label" color="inherit">
{children}
</Typography>
</FlexBox>
);
}

View File

@ -0,0 +1,3 @@
export { Chip } from './Chip';
export type { ChipProps, ChipSize } from './types';
export { chipVariants } from './variants';

View File

@ -0,0 +1,17 @@
import type { VariantProps } from 'class-variance-authority';
import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { chipVariants } from './variants';
export type ChipSize = NonNullable<VariantProps<typeof chipVariants>['size']>;
export type ChipProps = Omit<
ComponentPropsWithRef<'button'>,
'children' | 'type' | 'aria-pressed'
> & {
/** On: filled with a check. Read out as a pressed toggle. */
selected: boolean;
/** `md` (44px) in forms, `sm` (36px) in compact filter rows. */
size?: ChipSize;
children: ReactNode;
};

View File

@ -0,0 +1,20 @@
import { cva } from 'class-variance-authority';
/** A pill you press to pick one of many, such as a market; a set sits in a wrapping row. */
export const chipVariants = cva(
'rounded-full border px-4 whitespace-nowrap transition-colors duration-120 ease-standard focus-visible:focus-ring actionable:cursor-pointer disabled:frozen',
{
variants: {
selected: {
true: 'border-action-primary bg-action-primary text-text-on-action actionable:hover:bg-action-primary-hover',
false:
'border-transparent bg-action-primary-muted text-action-primary-text actionable:hover:border-action-primary',
},
size: {
sm: 'min-h-control-sm px-3.5',
md: 'min-h-control-md',
},
},
defaultVariants: { selected: false, size: 'md' },
},
);

View File

@ -61,6 +61,7 @@ function exitsFinished(dialog: HTMLDialogElement): Promise<unknown> {
export function Dialog({
open,
onClose,
onExited,
dismissible = true,
alert = false,
labelledBy,
@ -81,6 +82,7 @@ export function Dialog({
);
const left = useEffectEvent((dialog: HTMLDialogElement) => {
if (raiseToasts) announce(DIALOG_CLOSE_EVENT, dialog);
onExited?.();
});
useEffect(() => {

View File

@ -4,6 +4,12 @@ export type DialogProps = {
open: boolean;
/** Escape and a tap on the scrim call it, unless `dismissible` is false. */
onClose?: () => void;
/**
* The dialog has left the top layer after its exit transitions and focus went back to the
* trigger. The page is inert until then, so move focus elsewhere here, such as to a field the
* dialog added.
*/
onExited?: () => void;
/** false: Escape and the scrim do nothing, for a halt the user must wait out. */
dismissible?: boolean;
/** An urgent message that interrupts, such as «در حال تأیید پرداخت...»: `role="alertdialog"`. */

View File

@ -0,0 +1,26 @@
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { Icon } from '../icon';
import { Typography } from '../typography';
import type { FieldErrorProps } from './types';
/**
* The error line under a group that has no field of its own, such as a set of chips, a consent
* box or a photo: an alert icon and the message, announced when it appears.
*/
export function FieldError({ id, className, children }: FieldErrorProps) {
return (
<FlexBox
id={id}
role="alert"
alignItems="items-start"
gap="gap-1"
className={cn('text-danger-text', className)}
>
<Icon name="alert" size={16} className="mt-[3px] flex-none" />
<Typography tag="span" variant="caption" color="inherit">
{children}
</Typography>
</FlexBox>
);
}

View File

@ -0,0 +1,2 @@
export { FieldError } from './FieldError';
export type { FieldErrorProps } from './types';

View File

@ -0,0 +1,8 @@
import type { ReactNode } from 'react';
export type FieldErrorProps = {
/** Lets the control point at it with `aria-describedby`. */
id?: string;
className?: string;
children: ReactNode;
};

View File

@ -0,0 +1,41 @@
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { Icon } from '../icon';
import { linkVariants } from '../link';
import { Typography } from '../typography';
import type { LinkButtonProps } from './types';
/**
* Looks like a Link but is a button, because it acts on the page (opens a sheet, removes a photo,
* retries an upload) rather than navigating.
*/
export function LinkButton({
standalone,
icon,
iconStart,
className,
children,
...props
}: LinkButtonProps) {
return (
<FlexBox
tag="button"
type="button"
display="inline-flex"
alignItems="items-center"
gap="gap-1"
className={cn(
linkVariants({ standalone }),
'border-0 bg-transparent p-0 text-start disabled:frozen',
className,
)}
{...props}
>
{iconStart && <Icon name={iconStart} size={18} />}
<Typography tag="span" variant="inherit" color="inherit">
{children}
</Typography>
{icon && <Icon name={icon} size={18} />}
</FlexBox>
);
}

View File

@ -0,0 +1,2 @@
export { LinkButton } from './LinkButton';
export type { LinkButtonProps } from './types';

View File

@ -0,0 +1,16 @@
import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { IconName } from '../icon';
export type LinkButtonProps = Omit<
ComponentPropsWithRef<'button'>,
'children' | 'type'
> & {
/** A 44px hit area for a button on its own line. */
standalone?: boolean;
/** Trailing icon. */
icon?: IconName;
/** Leading icon, for an action named by its verb, such as `refresh` before «تلاش مجدد». */
iconStart?: IconName;
children: ReactNode;
};

View File

@ -0,0 +1,58 @@
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { GridBox } from '../grid-box';
import { Icon } from '../icon';
import { Typography } from '../typography';
import type { RowButtonProps } from './types';
/** A 56px choice row in a sheet or a menu: an icon disc, the name, and an optional note at the end. */
export function RowButton({
icon,
meta,
metaDir,
className,
children,
...props
}: RowButtonProps) {
return (
<FlexBox
tag="button"
type="button"
alignItems="items-center"
gap="gap-3"
className={cn(
'min-h-14 w-full rounded-lg border border-border-subtle bg-surface px-3 py-2 text-start text-text-primary transition-colors duration-120 ease-standard focus-visible:focus-ring actionable:cursor-pointer actionable:hover:border-border-strong actionable:hover:bg-surface-hover disabled:frozen',
className,
)}
{...props}
>
<GridBox
tag="span"
justifyItems="justify-items-center"
alignItems="items-center"
className="size-10 flex-none rounded-full bg-action-primary-subtle text-action-primary"
>
<Icon name={icon} size={20} />
</GridBox>
<Typography
tag="span"
variant="body-md"
color="inherit"
className="min-w-0 flex-1 font-semibold"
>
{children}
</Typography>
{meta != null && (
<Typography
tag="bdi"
variant="caption"
color="secondary"
dir={metaDir}
className="flex-none"
>
{meta}
</Typography>
)}
</FlexBox>
);
}

View File

@ -0,0 +1,2 @@
export { RowButton } from './RowButton';
export type { RowButtonProps } from './types';

View File

@ -0,0 +1,16 @@
import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { IconName } from '../icon';
export type RowButtonProps = Omit<
ComponentPropsWithRef<'button'>,
'children' | 'type'
> & {
icon: IconName;
/** The row's name, such as «تلگرام». */
children: ReactNode;
/** A short note at the end, such as the address prefix `t.me/`. */
meta?: ReactNode;
/** `ltr` for an address or a code in `meta`. */
metaDir?: 'ltr' | 'rtl';
};

View File

@ -1,39 +1,10 @@
import { cn } from '../../tools/cn';
import { FlexBox } from '../flex-box';
import { Icon } from '../icon';
import { linkVariants } from '../link';
import { Typography } from '../typography';
import { LinkButton } from '../link-button';
import type { SupportLinkProps } from './types';
/**
* «تماس با پشتیبانی»: looks like a Link but is a button, because it opens SupportSheet rather
* than navigating. Inside a dimmed card, put it in the card's `action` so it stays live.
*/
export function SupportLink({
icon = true,
standalone,
className,
children,
...props
}: SupportLinkProps) {
return (
<FlexBox
tag="button"
type="button"
display="inline-flex"
alignItems="items-center"
gap="gap-1"
className={cn(
linkVariants({ standalone }),
'border-0 bg-transparent p-0 text-start',
className,
)}
{...props}
>
{icon && <Icon name="headset" size={18} />}
<Typography tag="span" variant="inherit" color="inherit">
{children}
</Typography>
</FlexBox>
);
export function SupportLink({ icon = true, ...props }: SupportLinkProps) {
return <LinkButton iconStart={icon ? 'headset' : undefined} {...props} />;
}

View File

@ -9,6 +9,10 @@ export type {
ButtonAsLinkProps,
ButtonProps,
} from './atoms/button';
export { Checkbox, checkboxVariants } from './atoms/checkbox';
export type { CheckboxProps } from './atoms/checkbox';
export { Chip, chipVariants } from './atoms/chip';
export type { ChipProps, ChipSize } from './atoms/chip';
export { Countdown, countdownTone } from './atoms/countdown';
export type {
CountdownKind,
@ -23,6 +27,8 @@ export {
DIALOG_PANEL_SELECTOR,
} from './atoms/dialog';
export type { DialogProps } from './atoms/dialog';
export { FieldError } from './atoms/field-error';
export type { FieldErrorProps } from './atoms/field-error';
export { FlexBox } from './atoms/flex-box';
export type {
AlignContent,
@ -50,6 +56,10 @@ export { ICON_NAMES, Icon } from './atoms/icon';
export type { IconName, IconProps } from './atoms/icon';
export { Link, linkVariants } from './atoms/link';
export type { LinkProps } from './atoms/link';
export { LinkButton } from './atoms/link-button';
export type { LinkButtonProps } from './atoms/link-button';
export { RowButton } from './atoms/row-button';
export type { RowButtonProps } from './atoms/row-button';
export {
Skeleton,
SkeletonRegion,
@ -87,16 +97,26 @@ export type {
TypographyProps,
TypographyVariant,
} from './atoms/typography';
export { AvatarField } from './molecules/avatar-field';
export type {
AvatarFieldLabels,
AvatarFieldProps,
AvatarFieldStatus,
} from './molecules/avatar-field';
export { Banner, bannerVariants } from './molecules/banner';
export type { BannerProps, BannerTone } from './molecules/banner';
export { Card, cardVariants } from './molecules/card';
export type { CardOwnProps, CardProps } from './molecules/card';
export { ChipGroup } from './molecules/chip-group';
export type { ChipGroupOption, ChipGroupProps } from './molecules/chip-group';
export { ChoiceCard, choiceCardVariants } from './molecules/choice-card';
export type { ChoiceCardProps } from './molecules/choice-card';
export { EmptyState } from './molecules/empty-state';
export type { EmptyStateProps, EmptyStateTone } from './molecules/empty-state';
export { ERROR_KIND_STYLES, ErrorState } from './molecules/error-state';
export type { ErrorKind, ErrorStateProps } from './molecules/error-state';
export { FormSection } from './molecules/form-section';
export type { FormSectionProps } from './molecules/form-section';
export { LockedTeaser } from './molecules/locked-teaser';
export type { LockedTeaserProps } from './molecules/locked-teaser';
export { MediaCarousel } from './molecules/media-carousel';

View File

@ -0,0 +1,117 @@
'use client';
import { useId, useRef } from 'react';
import type { ChangeEvent } from 'react';
import { Avatar } from '../../atoms/avatar';
import { Button } from '../../atoms/button';
import { FieldError } from '../../atoms/field-error';
import { FlexBox } from '../../atoms/flex-box';
import { LinkButton } from '../../atoms/link-button';
import { Typography } from '../../atoms/typography';
import { Element } from '../../primitives/element';
import { cn } from '../../tools/cn';
import type { AvatarFieldProps } from './types';
/**
* A profile photo: the round picture (or the username's initial), a button that opens the picker,
* and remove. A failed upload keeps the picked photo dimmed in a red ring with the message and
* «تلاش مجدد»; the rest of the form is unaffected.
*/
export function AvatarField({
name,
src,
status = 'idle',
progress,
error,
accept,
onPick,
onRemove,
onRetry,
disabled = false,
labels,
className,
}: AvatarFieldProps) {
const inputRef = useRef<HTMLInputElement>(null);
const messageId = useId();
const isUploading = status === 'uploading';
const isFailed = status === 'failed';
const hasError = error != null && error !== false;
const pick = (event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
// The same file can be picked again after it was rejected.
event.target.value = '';
if (file) onPick(file);
};
return (
<FlexBox direction="flex-col" gap="gap-3" className={className}>
<FlexBox alignItems="items-center" gap="gap-4">
<Avatar
name={name}
src={src}
size="2xl"
label={src ? labels.preview : undefined}
className={cn(
'rounded-full transition-opacity duration-120 ease-standard',
isUploading && 'opacity-70',
isFailed && 'opacity-50 ring-2 ring-danger',
)}
/>
<FlexBox direction="flex-col" alignItems="items-start" gap="gap-1">
<Button
variant="secondary"
icon="image"
isLoading={isUploading}
disabled={disabled}
aria-describedby={hasError ? messageId : undefined}
onClick={() => inputRef.current?.click()}
>
{src ? labels.change : labels.pick}
</Button>
{isUploading && progress !== undefined && labels.uploading && (
<Typography
tag="span"
variant="caption"
color="secondary"
aria-live="polite"
>
{labels.uploading(progress)}
</Typography>
)}
{src && onRemove && status === 'idle' && (
<LinkButton standalone disabled={disabled} onClick={onRemove}>
{labels.remove}
</LinkButton>
)}
</FlexBox>
</FlexBox>
{hasError && (
<FlexBox alignItems="items-center" wrap="flex-wrap" gap="gap-2">
<FieldError id={messageId}>{error}</FieldError>
{isFailed && onRetry && (
<LinkButton
standalone
iconStart="refresh"
disabled={disabled}
onClick={onRetry}
>
{labels.retry}
</LinkButton>
)}
</FlexBox>
)}
<Element
tag="input"
ref={inputRef}
type="file"
accept={accept}
tabIndex={-1}
aria-hidden
className="sr-only"
onChange={pick}
/>
</FlexBox>
);
}

View File

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

View File

@ -0,0 +1,43 @@
import type { ReactNode } from 'react';
/** idle: nothing in flight. uploading: the picked photo is on its way. failed: it didn't arrive. */
export type AvatarFieldStatus = 'idle' | 'uploading' | 'failed';
/** Every text the field shows, from the translations. */
export type AvatarFieldLabels = {
/** «انتخاب تصویر», with no photo yet. */
pick: string;
/** «تغییر تصویر», with a photo. */
change: string;
/** «حذف تصویر». */
remove: string;
/** «تلاش مجدد», after a failed upload. */
retry: string;
/** The photo's accessible name: «پیش‌نمایش برش دایره‌ای تصویر پروفایل». */
preview: string;
/** While uploading, given the percent: «در حال بارگذاری… ۶۴٪». */
uploading?: (percent: number) => ReactNode;
};
export type AvatarFieldProps = {
/** The username: its first letter stands in while there is no photo. */
name: string;
/** The photo to show: the uploaded one, or the picked file's preview while it uploads. */
src: string | null;
status?: AvatarFieldStatus;
/** 0–100 while uploading. */
progress?: number;
/** A rejected pick or a failed upload. A rejected pick keeps the current photo. */
error?: ReactNode;
/** MIME types for the picker, such as `image/jpeg,image/png`. */
accept?: string;
/** A picked file. Check its type and size here, when it is picked. */
onPick: (file: File) => void;
/** Omit it when the photo can't be removed. */
onRemove?: () => void;
/** Sends the same file again after a failed upload. */
onRetry?: () => void;
disabled?: boolean;
labels: AvatarFieldLabels;
className?: string;
};

View File

@ -0,0 +1,53 @@
import { useId } from 'react';
import { Chip } from '../../atoms/chip';
import { FieldError } from '../../atoms/field-error';
import { FlexBox } from '../../atoms/flex-box';
import type { ChipGroupProps } from './types';
/**
* A multiple choice as a wrapping row of toggle chips, such as markets, with its error under it.
* The fieldset is named and can take focus, so a form error can send the person to it.
*/
export function ChipGroup<T extends string>({
options,
value,
onToggle,
label,
error,
size = 'md',
disabled = false,
ref,
className,
}: ChipGroupProps<T>) {
const errorId = useId();
const hasError = error != null && error !== false;
return (
<FlexBox direction="flex-col" gap="gap-2" className={className}>
<FlexBox
ref={ref}
tag="fieldset"
tabIndex={-1}
aria-label={label}
aria-describedby={hasError ? errorId : undefined}
wrap="flex-wrap"
gap="gap-2"
className="rounded-md outline-none"
>
{options.map((option) => (
<Chip
key={option.value}
size={size}
selected={value.includes(option.value)}
disabled={disabled}
onClick={() => onToggle(option.value)}
>
{option.label}
</Chip>
))}
</FlexBox>
{hasError && <FieldError id={errorId}>{error}</FieldError>}
</FlexBox>
);
}

View File

@ -0,0 +1,2 @@
export { ChipGroup } from './ChipGroup';
export type { ChipGroupOption, ChipGroupProps } from './types';

View File

@ -0,0 +1,22 @@
import type { ReactNode, Ref } from 'react';
import type { ChipSize } from '../../atoms/chip';
export type ChipGroupOption<T extends string> = { value: T; label: ReactNode };
export type ChipGroupProps<T extends string> = {
options: readonly ChipGroupOption<T>[];
/** The picked values. */
value: readonly T[];
/** A chip was pressed: add or remove its value. */
onToggle: (value: T) => void;
/** The group's accessible name, usually its section title. */
label: string;
/** Under the chips, such as «انتخاب حداقل یک تخصص الزامی است.». */
error?: ReactNode;
size?: ChipSize;
disabled?: boolean;
/** Reaches the fieldset, which takes focus (and scrolls into view) for a form error. */
ref?: Ref<HTMLFieldSetElement>;
className?: string;
};

View File

@ -0,0 +1,51 @@
import { useId } from 'react';
import { FlexBox } from '../../atoms/flex-box';
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.
*/
export function FormSection({
title,
note,
hint,
className,
children,
}: FormSectionProps) {
const titleId = useId();
return (
<FlexBox
tag="section"
aria-labelledby={titleId}
direction="flex-col"
gap="gap-3"
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}
</Typography>
)}
</Typography>
{hint != null && (
<Typography tag="p" variant="caption" color="secondary">
{hint}
</Typography>
)}
</FlexBox>
{children}
</FlexBox>
);
}

View File

@ -0,0 +1,2 @@
export { FormSection } from './FormSection';
export type { FormSectionProps } from './types';

View File

@ -0,0 +1,12 @@
import type { ReactNode } from 'react';
export type FormSectionProps = {
/** The section's name, a level-2 heading. */
title: ReactNode;
/** A quiet marker after the title, such as «(اختیاری)». */
note?: ReactNode;
/** One sentence under the title: what to put here. */
hint?: ReactNode;
className?: string;
children: ReactNode;
};

View File

@ -20,6 +20,7 @@ export function Modal({
actions,
icon,
onClose,
onExited,
closeLabel,
dismissible = true,
alert,
@ -31,6 +32,7 @@ export function Modal({
<Dialog
open={open}
onClose={onClose}
onExited={onExited}
dismissible={dismissible}
alert={alert}
labelledBy={titleId}

View File

@ -11,6 +11,8 @@ export type ModalProps = {
icon?: ReactNode;
/** Escape and the scrim call it, unless `dismissible` is false. */
onClose?: () => void;
/** The modal has closed and focus is back on the page. */
onExited?: () => void;
/** The ✕'s accessible name, such as «بستن». Shows the ✕; omit it when there is a cancel button. */
closeLabel?: string;
/** false: no ✕, and Escape and the scrim do nothing, such as «در حال تأیید پرداخت...». */

View File

@ -24,6 +24,7 @@ export function Sheet({
children,
footer,
onClose,
onExited,
closeLabel,
dismissible = true,
alert,
@ -51,6 +52,7 @@ export function Sheet({
<Dialog
open={open}
onClose={onClose}
onExited={onExited}
dismissible={dismissible}
alert={alert}
labelledBy={titleId}

View File

@ -15,6 +15,8 @@ export type SheetProps = {
footer?: ReactNode;
/** Escape, the scrim and (popover) a tap outside call it. */
onClose?: () => void;
/** Bottom and side only: the sheet has closed and focus is back on the page. */
onExited?: () => void;
/** The ✕'s accessible name, such as «بستن». Shows the ✕; omit it when there is a cancel button. */
closeLabel?: string;
/** false: Escape and the scrim do nothing, for a blocking halt. */
@ -37,5 +39,5 @@ export type SheetHeadProps = {
export type SheetPopoverProps = Omit<
SheetProps,
'placement' | 'dismissible' | 'alert'
'placement' | 'dismissible' | 'alert' | 'onExited'
>;

View File

@ -157,6 +157,11 @@ export function date(
return time ? `${day}${DATE_TIME_JOINER}${timeFormatter.format(at)}` : day;
}
/** Time of day in Tehran: `14:05`, such as when a draft was last saved. */
export function time(value: DateInput): string {
return timeFormatter.format(toDate(value));
}
/** `همین الان`, `5 دقیقه پیش`, `2 ساعت پیش`, `دیروز`; older than that → `date()`. */
export function relative(
value: DateInput,

View File

@ -13,6 +13,7 @@ export {
sheba,
signed,
signedPercent,
time,
} from './format';
export { LOCALE, TIME_ZONE } from './constants';
export type { DateFormatOptions, DateInput, ShebaFormatOptions } from './types';