diff --git a/packages/island/src/atoms/link/Link.tsx b/packages/island/src/atoms/link/Link.tsx
index 54e9a25..5aa91fc 100644
--- a/packages/island/src/atoms/link/Link.tsx
+++ b/packages/island/src/atoms/link/Link.tsx
@@ -11,6 +11,7 @@ import { linkVariants } from './variants';
export function Link({
standalone,
icon,
+ iconStart,
className,
children,
...props
@@ -24,6 +25,7 @@ export function Link({
className={cn(linkVariants({ standalone }), className)}
{...props}
>
+ {iconStart && }
{children}
diff --git a/packages/island/src/atoms/link/types.ts b/packages/island/src/atoms/link/types.ts
index 4121b9c..f40105a 100644
--- a/packages/island/src/atoms/link/types.ts
+++ b/packages/island/src/atoms/link/types.ts
@@ -9,4 +9,6 @@ export type LinkProps = ComponentPropsWithRef &
VariantProps & {
/** Trailing icon, such as `external` or `chevron-left` ("go to" points left in RTL). */
icon?: IconName;
+ /** Leading icon, for an action named by its verb, such as `edit` before «ویرایش شماره». */
+ iconStart?: IconName;
};
diff --git a/packages/island/src/molecules/file-field/FileField.tsx b/packages/island/src/molecules/file-field/FileField.tsx
new file mode 100644
index 0000000..33c83ef
--- /dev/null
+++ b/packages/island/src/molecules/file-field/FileField.tsx
@@ -0,0 +1,192 @@
+'use client';
+
+import { useEffect, useId, useRef } from 'react';
+import type { ChangeEvent } from 'react';
+
+import { Button } from '../../atoms/button';
+import { FlexBox } from '../../atoms/flex-box';
+import { Icon } from '../../atoms/icon';
+import { Typography } from '../../atoms/typography';
+import { Element } from '../../primitives/element';
+import { cn } from '../../tools/cn';
+import type { FileFieldProps } from './types';
+import { fileDropVariants, filePickedVariants } from './variants';
+
+/**
+ * One file to send with a form, such as a national ID card image. Empty, the whole dashed box
+ * opens the picker; picked, it shows a thumbnail (for images), the name and the size with a
+ * remove button; uploading, a bar with the percent replaces remove. The file stays in memory.
+ */
+export function FileField({
+ label,
+ hint,
+ file,
+ size,
+ onChange,
+ onBlur,
+ accept,
+ error,
+ progress,
+ disabled = false,
+ labels,
+ id: idProp,
+ name,
+ className,
+}: FileFieldProps) {
+ const generatedId = useId();
+ const id = idProp ?? generatedId;
+ const messageId = `${id}-message`;
+ const isInvalid = error != null && error !== false;
+ const isUploading = progress !== undefined;
+
+ const pick = (event: ChangeEvent) => {
+ onChange(event.target.files?.[0] ?? null);
+ // The same file can be picked again after it was removed or rejected.
+ event.target.value = '';
+ };
+
+ return (
+
+
+ {label}
+
+ {file ? (
+
+ {file.type.startsWith('image/') ? (
+
+ ) : (
+
+ )}
+
+
+ {file.name}
+
+ {isUploading ? (
+ <>
+
+ {labels.uploading && (
+
+ {labels.uploading(progress)}
+
+ )}
+ >
+ ) : (
+ size != null && (
+
+ {size}
+
+ )
+ )}
+
+ {!isUploading && (
+
+ ) : (
+
+
+
+ {labels.pick}
+
+
+ {labels.rules}
+
+
+
+ )}
+ {isInvalid && error !== true ? (
+
+
+
+ {error}
+
+
+ ) : (
+ hint != null && (
+
+ {hint}
+
+ )
+ )}
+
+ );
+}
+
+/** An image file's thumbnail from an object URL, revoked when the file changes or leaves. */
+function Thumbnail({ file }: { file: File }) {
+ const ref = useRef(null);
+ useEffect(() => {
+ const url = URL.createObjectURL(file);
+ if (ref.current) ref.current.src = url;
+ return () => URL.revokeObjectURL(url);
+ }, [file]);
+ return (
+
+ );
+}
diff --git a/packages/island/src/molecules/file-field/index.ts b/packages/island/src/molecules/file-field/index.ts
new file mode 100644
index 0000000..2dcb736
--- /dev/null
+++ b/packages/island/src/molecules/file-field/index.ts
@@ -0,0 +1,3 @@
+export { FileField } from './FileField';
+export type { FileFieldLabels, FileFieldProps } from './types';
+export { fileDropVariants, filePickedVariants } from './variants';
diff --git a/packages/island/src/molecules/file-field/types.ts b/packages/island/src/molecules/file-field/types.ts
new file mode 100644
index 0000000..571b149
--- /dev/null
+++ b/packages/island/src/molecules/file-field/types.ts
@@ -0,0 +1,36 @@
+import type { ReactNode } from 'react';
+
+/** Every text the field shows, from the translations. */
+export type FileFieldLabels = {
+ /** «انتخاب فایل». */
+ pick: ReactNode;
+ /** The accepted types and size, under the pick text: «JPG یا PNG، حداکثر ۵ مگابایت». */
+ rules: ReactNode;
+ /** The remove button's accessible name: «حذف تصویر». */
+ remove: string;
+ /** While uploading, given the percent: «در حال بارگذاری… ۶۴٪». */
+ uploading?: (percent: number) => ReactNode;
+};
+
+export type FileFieldProps = {
+ label: ReactNode;
+ /** A rule given before picking: «یک تصویر واضح … آپلود کنید.». */
+ hint?: ReactNode;
+ file: File | null;
+ /** The picked file's size, formatted by the caller: «۱٫۸ مگابایت». */
+ size?: ReactNode;
+ /** A picked file, or `null` when removed. Check type and size here, when it is picked. */
+ onChange: (file: File | null) => void;
+ onBlur?: () => void;
+ /** MIME types for the picker, such as `image/jpeg,image/png`. */
+ accept?: string;
+ /** Inline error under the box; a rejected file leaves the box empty. */
+ error?: ReactNode;
+ /** 0–100 while the file uploads: the bar replaces the remove button. */
+ progress?: number;
+ disabled?: boolean;
+ labels: FileFieldLabels;
+ id?: string;
+ name?: string;
+ className?: string;
+};
diff --git a/packages/island/src/molecules/file-field/variants.ts b/packages/island/src/molecules/file-field/variants.ts
new file mode 100644
index 0000000..3f4fddc
--- /dev/null
+++ b/packages/island/src/molecules/file-field/variants.ts
@@ -0,0 +1,28 @@
+import { cva } from 'class-variance-authority';
+
+/** The empty box: the whole box is the picker's label, so it is one large target. */
+export const fileDropVariants = cva(
+ 'min-h-30 rounded-md border border-dashed bg-surface-sunken px-4 py-5 text-center transition-colors duration-120 ease-standard has-focus-visible:focus-ring',
+ {
+ variants: {
+ invalid: {
+ true: 'border-danger',
+ false:
+ 'border-border-default actionable:cursor-pointer hover:border-text-secondary',
+ },
+ disabled: { true: 'frozen', false: '' },
+ },
+ defaultVariants: { invalid: false, disabled: false },
+ },
+);
+
+/** The picked file's row: thumbnail, name and size, then remove or the upload bar. */
+export const filePickedVariants = cva(
+ 'min-h-18 rounded-md border bg-surface p-3',
+ {
+ variants: {
+ invalid: { true: 'border-danger', false: 'border-border-default' },
+ },
+ defaultVariants: { invalid: false },
+ },
+);
diff --git a/packages/island/src/molecules/toast/Toast.tsx b/packages/island/src/molecules/toast/Toast.tsx
index 4de3812..32dcb68 100644
--- a/packages/island/src/molecules/toast/Toast.tsx
+++ b/packages/island/src/molecules/toast/Toast.tsx
@@ -18,6 +18,7 @@ export function Toast({
action,
announce = true,
children,
+ description,
className,
}: ToastProps) {
const role = tone === 'error' ? 'alert' : 'status';
@@ -29,9 +30,16 @@ export function Toast({
className={cn(toastVariants(), className)}
>
{icon && }
-
- {children}
-
+
+
+ {children}
+
+ {description != null && (
+
+ {description}
+
+ )}
+
{action && (
(
+ (toastId) => (
{
- toast.dismiss(id);
+ toast.dismiss(toastId);
action.onClick();
},
}
@@ -34,6 +35,7 @@ export function showToast({
),
{
+ id,
duration:
duration ??
(action ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS),
diff --git a/packages/island/src/molecules/toast/types.ts b/packages/island/src/molecules/toast/types.ts
index 218b9ac..eb55f32 100644
--- a/packages/island/src/molecules/toast/types.ts
+++ b/packages/island/src/molecules/toast/types.ts
@@ -24,6 +24,8 @@ export type ToastProps = {
announce?: boolean;
/** One line, past tense, no exclamation mark: «اشتراک شما فعال شد.» */
children: ReactNode;
+ /** A second line under it: a failed action's reason and what to do, or the reference code. */
+ description?: ReactNode;
className?: string;
};
@@ -32,6 +34,8 @@ export type ShowToastOptions = Omit<
'announce' | 'children' | 'className'
> & {
message: ReactNode;
+ /** A toast shown again under the same id replaces the old one instead of stacking. */
+ id?: string;
/** Defaults to 4 seconds, 6 with an action. */
duration?: number;
};
diff --git a/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx b/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx
index 4573a0b..eb22620 100644
--- a/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx
+++ b/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx
@@ -1,5 +1,6 @@
import { SkeletonRegion } from '../../atoms/skeleton';
import { FigureSkeleton } from './components/FigureSkeleton';
+import { FormSkeleton } from './components/FormSkeleton';
import { HeaderSkeleton } from './components/HeaderSkeleton';
import { ListSkeleton } from './components/ListSkeleton';
import { PostSkeleton } from './components/PostSkeleton';
@@ -44,6 +45,7 @@ export function SkeletonPreset({
{preset === 'figure' && }
{preset === 'list' && }
{preset === 'table' && }
+ {preset === 'form' && }
);
}
diff --git a/packages/island/src/organisms/skeleton-preset/components/FormSkeleton.tsx b/packages/island/src/organisms/skeleton-preset/components/FormSkeleton.tsx
new file mode 100644
index 0000000..9c2db36
--- /dev/null
+++ b/packages/island/src/organisms/skeleton-preset/components/FormSkeleton.tsx
@@ -0,0 +1,31 @@
+import { FlexBox } from '../../../atoms/flex-box';
+import { Skeleton } from '../../../atoms/skeleton';
+import type { FormSkeletonProps } from '../types';
+
+/**
+ * A form step: the heading and its one-line description, n labelled fields, the full-width submit
+ * button and the switch link under it. No card: it fills whatever frame the screen draws.
+ */
+export function FormSkeleton({ fields }: FormSkeletonProps) {
+ return (
+
+
+
+
+
+ {Array.from({ length: fields }, (_, field) => (
+
+
+
+
+ ))}
+
+
+
+ );
+}
diff --git a/packages/island/src/organisms/skeleton-preset/constants.ts b/packages/island/src/organisms/skeleton-preset/constants.ts
index be216ee..4587a17 100644
--- a/packages/island/src/organisms/skeleton-preset/constants.ts
+++ b/packages/island/src/organisms/skeleton-preset/constants.ts
@@ -9,6 +9,7 @@ export const PRESET_REPEATS: Partial<
prediction: { initial: 1, max: 3 },
list: { initial: 4, max: 4 },
table: { initial: 5, max: 5 },
+ form: { initial: 1, max: 6 },
};
export const DEFAULT_TABLE_COLUMNS = 5;
diff --git a/packages/island/src/organisms/skeleton-preset/types.ts b/packages/island/src/organisms/skeleton-preset/types.ts
index 5cdb204..0a27b8f 100644
--- a/packages/island/src/organisms/skeleton-preset/types.ts
+++ b/packages/island/src/organisms/skeleton-preset/types.ts
@@ -17,14 +17,17 @@ export type SkeletonPresetName =
/** Admin tables, with a sunken header row. */
| 'table'
/** A money hero («قابل واریز») with two tiles under it. */
- | 'figure';
+ | 'figure'
+ /** A form step: heading, description, `count` fields, the submit button and a link. */
+ | 'form';
export type SkeletonPresetProps = {
/** The component the screen is waiting for. */
preset: SkeletonPresetName;
/**
* Repeats, capped at one screen: posts and predictions (default 1, at most 3), list rows
- * (default 4, at most 4), table rows (default 5, at most 5). Other presets ignore it.
+ * (default 4, at most 4), table rows (default 5, at most 5), form fields (default 1, at most 6).
+ * Other presets ignore it.
*/
count?: number;
/** `table` only (default 5). */
@@ -52,6 +55,10 @@ export type ListSkeletonProps = {
avatar: boolean;
};
+export type FormSkeletonProps = {
+ fields: number;
+};
+
export type TableSkeletonProps = {
rows: number;
columns: number;