diff --git a/packages/island/src/atoms/avatar/constants.ts b/packages/island/src/atoms/avatar/constants.ts index a4491ec..80823f8 100644 --- a/packages/island/src/atoms/avatar/constants.ts +++ b/packages/island/src/atoms/avatar/constants.ts @@ -7,6 +7,7 @@ export const AVATAR_PX: Record = { md: 40, lg: 56, xl: 80, + '2xl': 96, }; export const AVATAR_INITIAL_VARIANT: Record = { @@ -14,6 +15,7 @@ export const AVATAR_INITIAL_VARIANT: Record = { md: 'body-md', lg: 'heading-sm', xl: 'heading-lg', + '2xl': 'display', }; export const AVATAR_MARK_PX: Record = { @@ -21,4 +23,5 @@ export const AVATAR_MARK_PX: Record = { md: 14, lg: 18, xl: 22, + '2xl': 24, }; diff --git a/packages/island/src/atoms/avatar/variants.ts b/packages/island/src/atoms/avatar/variants.ts index 09e2ef8..df74a67 100644 --- a/packages/island/src/atoms/avatar/variants.ts +++ b/packages/island/src/atoms/avatar/variants.ts @@ -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' }, diff --git a/packages/island/src/atoms/checkbox/Checkbox.tsx b/packages/island/src/atoms/checkbox/Checkbox.tsx new file mode 100644 index 0000000..2e9a3ae --- /dev/null +++ b/packages/island/src/atoms/checkbox/Checkbox.tsx @@ -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 ( + + + + + + + {children} + + + ); +} diff --git a/packages/island/src/atoms/checkbox/index.ts b/packages/island/src/atoms/checkbox/index.ts new file mode 100644 index 0000000..2ae23d0 --- /dev/null +++ b/packages/island/src/atoms/checkbox/index.ts @@ -0,0 +1,3 @@ +export { Checkbox } from './Checkbox'; +export type { CheckboxProps } from './types'; +export { checkboxVariants } from './variants'; diff --git a/packages/island/src/atoms/checkbox/types.ts b/packages/island/src/atoms/checkbox/types.ts new file mode 100644 index 0000000..6d79c8c --- /dev/null +++ b/packages/island/src/atoms/checkbox/types.ts @@ -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; +}; diff --git a/packages/island/src/atoms/checkbox/variants.ts b/packages/island/src/atoms/checkbox/variants.ts new file mode 100644 index 0000000..a235e9e --- /dev/null +++ b/packages/island/src/atoms/checkbox/variants.ts @@ -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 }, + }, +); diff --git a/packages/island/src/atoms/chip/Chip.tsx b/packages/island/src/atoms/chip/Chip.tsx new file mode 100644 index 0000000..24ac463 --- /dev/null +++ b/packages/island/src/atoms/chip/Chip.tsx @@ -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 ( + + {selected && } + + {children} + + + ); +} diff --git a/packages/island/src/atoms/chip/index.ts b/packages/island/src/atoms/chip/index.ts new file mode 100644 index 0000000..5aec666 --- /dev/null +++ b/packages/island/src/atoms/chip/index.ts @@ -0,0 +1,3 @@ +export { Chip } from './Chip'; +export type { ChipProps, ChipSize } from './types'; +export { chipVariants } from './variants'; diff --git a/packages/island/src/atoms/chip/types.ts b/packages/island/src/atoms/chip/types.ts new file mode 100644 index 0000000..73ce10b --- /dev/null +++ b/packages/island/src/atoms/chip/types.ts @@ -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['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; +}; diff --git a/packages/island/src/atoms/chip/variants.ts b/packages/island/src/atoms/chip/variants.ts new file mode 100644 index 0000000..d08c536 --- /dev/null +++ b/packages/island/src/atoms/chip/variants.ts @@ -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' }, + }, +); diff --git a/packages/island/src/atoms/dialog/Dialog.tsx b/packages/island/src/atoms/dialog/Dialog.tsx index 11d1a95..656e472 100644 --- a/packages/island/src/atoms/dialog/Dialog.tsx +++ b/packages/island/src/atoms/dialog/Dialog.tsx @@ -61,6 +61,7 @@ function exitsFinished(dialog: HTMLDialogElement): Promise { 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(() => { diff --git a/packages/island/src/atoms/dialog/types.ts b/packages/island/src/atoms/dialog/types.ts index ef8bc2a..79c2eed 100644 --- a/packages/island/src/atoms/dialog/types.ts +++ b/packages/island/src/atoms/dialog/types.ts @@ -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"`. */ diff --git a/packages/island/src/atoms/field-error/FieldError.tsx b/packages/island/src/atoms/field-error/FieldError.tsx new file mode 100644 index 0000000..1bdc202 --- /dev/null +++ b/packages/island/src/atoms/field-error/FieldError.tsx @@ -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 ( + + + + {children} + + + ); +} diff --git a/packages/island/src/atoms/field-error/index.ts b/packages/island/src/atoms/field-error/index.ts new file mode 100644 index 0000000..954e818 --- /dev/null +++ b/packages/island/src/atoms/field-error/index.ts @@ -0,0 +1,2 @@ +export { FieldError } from './FieldError'; +export type { FieldErrorProps } from './types'; diff --git a/packages/island/src/atoms/field-error/types.ts b/packages/island/src/atoms/field-error/types.ts new file mode 100644 index 0000000..2490625 --- /dev/null +++ b/packages/island/src/atoms/field-error/types.ts @@ -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; +}; diff --git a/packages/island/src/atoms/link-button/LinkButton.tsx b/packages/island/src/atoms/link-button/LinkButton.tsx new file mode 100644 index 0000000..f6bd60e --- /dev/null +++ b/packages/island/src/atoms/link-button/LinkButton.tsx @@ -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 ( + + {iconStart && } + + {children} + + {icon && } + + ); +} diff --git a/packages/island/src/atoms/link-button/index.ts b/packages/island/src/atoms/link-button/index.ts new file mode 100644 index 0000000..55a0cde --- /dev/null +++ b/packages/island/src/atoms/link-button/index.ts @@ -0,0 +1,2 @@ +export { LinkButton } from './LinkButton'; +export type { LinkButtonProps } from './types'; diff --git a/packages/island/src/atoms/link-button/types.ts b/packages/island/src/atoms/link-button/types.ts new file mode 100644 index 0000000..cfe780c --- /dev/null +++ b/packages/island/src/atoms/link-button/types.ts @@ -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; +}; diff --git a/packages/island/src/atoms/row-button/RowButton.tsx b/packages/island/src/atoms/row-button/RowButton.tsx new file mode 100644 index 0000000..7cf0357 --- /dev/null +++ b/packages/island/src/atoms/row-button/RowButton.tsx @@ -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 ( + + + + + + {children} + + {meta != null && ( + + {meta} + + )} + + ); +} diff --git a/packages/island/src/atoms/row-button/index.ts b/packages/island/src/atoms/row-button/index.ts new file mode 100644 index 0000000..c4b6df6 --- /dev/null +++ b/packages/island/src/atoms/row-button/index.ts @@ -0,0 +1,2 @@ +export { RowButton } from './RowButton'; +export type { RowButtonProps } from './types'; diff --git a/packages/island/src/atoms/row-button/types.ts b/packages/island/src/atoms/row-button/types.ts new file mode 100644 index 0000000..ec7d3cc --- /dev/null +++ b/packages/island/src/atoms/row-button/types.ts @@ -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'; +}; diff --git a/packages/island/src/atoms/support-link/SupportLink.tsx b/packages/island/src/atoms/support-link/SupportLink.tsx index 434d4d4..fa71ad5 100644 --- a/packages/island/src/atoms/support-link/SupportLink.tsx +++ b/packages/island/src/atoms/support-link/SupportLink.tsx @@ -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 ( - - {icon && } - - {children} - - - ); +export function SupportLink({ icon = true, ...props }: SupportLinkProps) { + return ; } diff --git a/packages/island/src/index.ts b/packages/island/src/index.ts index 3765bb1..11f458d 100644 --- a/packages/island/src/index.ts +++ b/packages/island/src/index.ts @@ -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'; diff --git a/packages/island/src/molecules/avatar-field/AvatarField.tsx b/packages/island/src/molecules/avatar-field/AvatarField.tsx new file mode 100644 index 0000000..3bb5dd3 --- /dev/null +++ b/packages/island/src/molecules/avatar-field/AvatarField.tsx @@ -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(null); + const messageId = useId(); + const isUploading = status === 'uploading'; + const isFailed = status === 'failed'; + const hasError = error != null && error !== false; + + const pick = (event: ChangeEvent) => { + 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 ( + + + + + + {isUploading && progress !== undefined && labels.uploading && ( + + {labels.uploading(progress)} + + )} + {src && onRemove && status === 'idle' && ( + + {labels.remove} + + )} + + + {hasError && ( + + {error} + {isFailed && onRetry && ( + + {labels.retry} + + )} + + )} + + + ); +} diff --git a/packages/island/src/molecules/avatar-field/index.ts b/packages/island/src/molecules/avatar-field/index.ts new file mode 100644 index 0000000..0d0d4af --- /dev/null +++ b/packages/island/src/molecules/avatar-field/index.ts @@ -0,0 +1,6 @@ +export { AvatarField } from './AvatarField'; +export type { + AvatarFieldLabels, + AvatarFieldProps, + AvatarFieldStatus, +} from './types'; diff --git a/packages/island/src/molecules/avatar-field/types.ts b/packages/island/src/molecules/avatar-field/types.ts new file mode 100644 index 0000000..46b4ea6 --- /dev/null +++ b/packages/island/src/molecules/avatar-field/types.ts @@ -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; +}; diff --git a/packages/island/src/molecules/chip-group/ChipGroup.tsx b/packages/island/src/molecules/chip-group/ChipGroup.tsx new file mode 100644 index 0000000..7bc3e9b --- /dev/null +++ b/packages/island/src/molecules/chip-group/ChipGroup.tsx @@ -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({ + options, + value, + onToggle, + label, + error, + size = 'md', + disabled = false, + ref, + className, +}: ChipGroupProps) { + const errorId = useId(); + const hasError = error != null && error !== false; + + return ( + + + {options.map((option) => ( + onToggle(option.value)} + > + {option.label} + + ))} + + {hasError && {error}} + + ); +} diff --git a/packages/island/src/molecules/chip-group/index.ts b/packages/island/src/molecules/chip-group/index.ts new file mode 100644 index 0000000..7973785 --- /dev/null +++ b/packages/island/src/molecules/chip-group/index.ts @@ -0,0 +1,2 @@ +export { ChipGroup } from './ChipGroup'; +export type { ChipGroupOption, ChipGroupProps } from './types'; diff --git a/packages/island/src/molecules/chip-group/types.ts b/packages/island/src/molecules/chip-group/types.ts new file mode 100644 index 0000000..02a69ea --- /dev/null +++ b/packages/island/src/molecules/chip-group/types.ts @@ -0,0 +1,22 @@ +import type { ReactNode, Ref } from 'react'; + +import type { ChipSize } from '../../atoms/chip'; + +export type ChipGroupOption = { value: T; label: ReactNode }; + +export type ChipGroupProps = { + options: readonly ChipGroupOption[]; + /** 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; + className?: string; +}; diff --git a/packages/island/src/molecules/form-section/FormSection.tsx b/packages/island/src/molecules/form-section/FormSection.tsx new file mode 100644 index 0000000..9409d40 --- /dev/null +++ b/packages/island/src/molecules/form-section/FormSection.tsx @@ -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 ( + + + + {title} + {note != null && ( + + {note} + + )} + + {hint != null && ( + + {hint} + + )} + + {children} + + ); +} diff --git a/packages/island/src/molecules/form-section/index.ts b/packages/island/src/molecules/form-section/index.ts new file mode 100644 index 0000000..368fcb9 --- /dev/null +++ b/packages/island/src/molecules/form-section/index.ts @@ -0,0 +1,2 @@ +export { FormSection } from './FormSection'; +export type { FormSectionProps } from './types'; diff --git a/packages/island/src/molecules/form-section/types.ts b/packages/island/src/molecules/form-section/types.ts new file mode 100644 index 0000000..55ecdfa --- /dev/null +++ b/packages/island/src/molecules/form-section/types.ts @@ -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; +}; diff --git a/packages/island/src/molecules/modal/Modal.tsx b/packages/island/src/molecules/modal/Modal.tsx index 65672c2..2aa3d39 100644 --- a/packages/island/src/molecules/modal/Modal.tsx +++ b/packages/island/src/molecules/modal/Modal.tsx @@ -20,6 +20,7 @@ export function Modal({ actions, icon, onClose, + onExited, closeLabel, dismissible = true, alert, @@ -31,6 +32,7 @@ export function Modal({ 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 «در حال تأیید پرداخت...». */ diff --git a/packages/island/src/molecules/sheet/Sheet.tsx b/packages/island/src/molecules/sheet/Sheet.tsx index f040341..06607be 100644 --- a/packages/island/src/molecules/sheet/Sheet.tsx +++ b/packages/island/src/molecules/sheet/Sheet.tsx @@ -24,6 +24,7 @@ export function Sheet({ children, footer, onClose, + onExited, closeLabel, dismissible = true, alert, @@ -51,6 +52,7 @@ export function Sheet({ 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' >; diff --git a/packages/tools/src/format/format.ts b/packages/tools/src/format/format.ts index 47ed751..eb03843 100644 --- a/packages/tools/src/format/format.ts +++ b/packages/tools/src/format/format.ts @@ -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, diff --git a/packages/tools/src/format/index.ts b/packages/tools/src/format/index.ts index e6214f2..925ac3b 100644 --- a/packages/tools/src/format/index.ts +++ b/packages/tools/src/format/index.ts @@ -13,6 +13,7 @@ export { sheba, signed, signedPercent, + time, } from './format'; export { LOCALE, TIME_ZONE } from './constants'; export type { DateFormatOptions, DateInput, ShebaFormatOptions } from './types';