From 025c68dd0db85934e5b7b5ad68b241a4bc341ac9 Mon Sep 17 00:00:00 2001 From: Amiram_se Date: Mon, 5 Oct 2026 20:06:42 +0400 Subject: [PATCH] feat(island): file field, form skeleton, toast details and link start icon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FileField molecule: one file for a form, with a picker box, thumbnail, name, size, remove button, inline error and upload progress. - SkeletonPreset gains a `form` preset (heading, n fields, button, link). - Toast takes a second `description` line; showToast takes a stable `id`, so a repeated failure replaces its toast instead of stacking. - Link takes a leading `iconStart`, such as edit before «ویرایش شماره». Co-Authored-By: Claude Opus 5.5 --- packages/island/src/atoms/link/Link.tsx | 2 + packages/island/src/atoms/link/types.ts | 2 + .../src/molecules/file-field/FileField.tsx | 192 ++++++++++++++++++ .../island/src/molecules/file-field/index.ts | 3 + .../island/src/molecules/file-field/types.ts | 36 ++++ .../src/molecules/file-field/variants.ts | 28 +++ packages/island/src/molecules/toast/Toast.tsx | 14 +- .../island/src/molecules/toast/show-toast.tsx | 6 +- packages/island/src/molecules/toast/types.ts | 4 + .../skeleton-preset/SkeletonPreset.tsx | 2 + .../components/FormSkeleton.tsx | 31 +++ .../organisms/skeleton-preset/constants.ts | 1 + .../src/organisms/skeleton-preset/types.ts | 11 +- 13 files changed, 325 insertions(+), 7 deletions(-) create mode 100644 packages/island/src/molecules/file-field/FileField.tsx create mode 100644 packages/island/src/molecules/file-field/index.ts create mode 100644 packages/island/src/molecules/file-field/types.ts create mode 100644 packages/island/src/molecules/file-field/variants.ts create mode 100644 packages/island/src/organisms/skeleton-preset/components/FormSkeleton.tsx 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 && ( +