feat(island): focusable choice cards and file fields, state skeleton, timed toasts

- ChoiceCard and FileField forward a ref to their real input, so a form can move focus to the first empty card or upload box.
- SkeletonPreset gains a `state` preset (art, heading, line, action).
- Every toast closes by itself: errors after 8 s (10 with an action), others after 4 s (6 with an action).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-10-06 21:47:18 +04:00
parent cfa8cce1b0
commit 297f0b2cbd
10 changed files with 77 additions and 11 deletions

View File

@ -24,6 +24,7 @@ export function ChoiceCard({
checked = false, checked = false,
multiple = false, multiple = false,
onChange, onChange,
ref,
title, title,
description, description,
icon, icon,
@ -41,6 +42,7 @@ export function ChoiceCard({
> >
<Element <Element
tag="input" tag="input"
ref={ref}
type={multiple ? 'checkbox' : 'radio'} type={multiple ? 'checkbox' : 'radio'}
name={name} name={name}
value={value} value={value}

View File

@ -1,4 +1,4 @@
import type { ChangeEvent, ReactNode } from 'react'; import type { ChangeEvent, ReactNode, Ref } from 'react';
import type { IconName } from '../../atoms/icon'; import type { IconName } from '../../atoms/icon';
@ -9,6 +9,8 @@ export type ChoiceCardProps = {
/** A checkbox instead of a radio, for a many-of choice. */ /** A checkbox instead of a radio, for a many-of choice. */
multiple?: boolean; multiple?: boolean;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void; onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** The real radio, so a form can move focus to the first card when nothing was chosen. */
ref?: Ref<HTMLInputElement>;
title: ReactNode; title: ReactNode;
description?: ReactNode; description?: ReactNode;
/** `investor` and `analyst` for the account type. */ /** `investor` and `analyst` for the account type. */

View File

@ -24,6 +24,7 @@ export function FileField({
size, size,
onChange, onChange,
onBlur, onBlur,
ref,
accept, accept,
error, error,
progress, progress,
@ -130,6 +131,7 @@ export function FileField({
</Typography> </Typography>
<Element <Element
tag="input" tag="input"
ref={ref}
type="file" type="file"
id={id} id={id}
name={name} name={name}

View File

@ -1,4 +1,4 @@
import type { ReactNode } from 'react'; import type { ReactNode, Ref } from 'react';
/** Every text the field shows, from the translations. */ /** Every text the field shows, from the translations. */
export type FileFieldLabels = { export type FileFieldLabels = {
@ -22,6 +22,8 @@ export type FileFieldProps = {
/** A picked file, or `null` when removed. Check type and size here, when it is picked. */ /** A picked file, or `null` when removed. Check type and size here, when it is picked. */
onChange: (file: File | null) => void; onChange: (file: File | null) => void;
onBlur?: () => void; onBlur?: () => void;
/** The picker input, so a form can move focus to an empty required box. */
ref?: Ref<HTMLInputElement>;
/** MIME types for the picker, such as `image/jpeg,image/png`. */ /** MIME types for the picker, such as `image/jpeg,image/png`. */
accept?: string; accept?: string;
/** Inline error under the box; a rejected file leaves the box empty. */ /** Inline error under the box; a rejected file leaves the box empty. */

View File

@ -7,6 +7,13 @@ export const TOAST_ICONS: Record<ToastTone, IconName> = {
error: 'alert', error: 'alert',
}; };
/** About 4 seconds to read one line; 6 when there is an action to reach. */ /**
* Every toast closes by itself (0019); sonner pauses the clock while it is hovered or focused, or
* the tab is hidden. About 4
* seconds to read one line, 6 when there is an action to reach. An error says what failed, why
* and what to do, so it stays 8 seconds, 10 with its action.
*/
export const TOAST_DURATION_MS = 4000; export const TOAST_DURATION_MS = 4000;
export const TOAST_WITH_ACTION_DURATION_MS = 6000; export const TOAST_WITH_ACTION_DURATION_MS = 6000;
export const TOAST_ERROR_DURATION_MS = 8000;
export const TOAST_ERROR_WITH_ACTION_DURATION_MS = 10000;

View File

@ -1,12 +1,31 @@
import { toast } from 'sonner'; import { toast } from 'sonner';
import { TOAST_DURATION_MS, TOAST_WITH_ACTION_DURATION_MS } from './constants'; import {
TOAST_DURATION_MS,
TOAST_ERROR_DURATION_MS,
TOAST_ERROR_WITH_ACTION_DURATION_MS,
TOAST_WITH_ACTION_DURATION_MS,
} from './constants';
import { Toast } from './Toast'; import { Toast } from './Toast';
import type { ShowToastOptions } from './types'; import type { ShowToastOptions } from './types';
/** How long a toast stays when the caller doesn't say: longer for an error, longer with an action. */
function defaultDuration(
tone: ShowToastOptions['tone'],
hasAction: boolean,
): number {
if (tone === 'error') {
return hasAction
? TOAST_ERROR_WITH_ACTION_DURATION_MS
: TOAST_ERROR_DURATION_MS;
}
return hasAction ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS;
}
/** /**
* Shows a toast after an action completes or fails; never for a read. Tapping the action also * Shows a toast after an action completes or fails; never for a read. Every toast closes by
* closes the toast. Returns the toast's id for `dismissToast`. * itself (0019). Tapping the action also closes the toast. Returns the toast's id for
* `dismissToast`.
*/ */
export function showToast({ export function showToast({
id, id,
@ -36,9 +55,7 @@ export function showToast({
), ),
{ {
id, id,
duration: duration: duration ?? defaultDuration(props.tone, Boolean(action)),
duration ??
(action ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS),
}, },
); );
} }

View File

@ -36,7 +36,7 @@ export type ShowToastOptions = Omit<
message: ReactNode; message: ReactNode;
/** A toast shown again under the same id replaces the old one instead of stacking. */ /** A toast shown again under the same id replaces the old one instead of stacking. */
id?: string; id?: string;
/** Defaults to 4 seconds, 6 with an action. */ /** Defaults to 4 seconds (6 with an action); an error to 8 (10 with an action). */
duration?: number; duration?: number;
}; };

View File

@ -5,6 +5,7 @@ import { HeaderSkeleton } from './components/HeaderSkeleton';
import { ListSkeleton } from './components/ListSkeleton'; import { ListSkeleton } from './components/ListSkeleton';
import { PostSkeleton } from './components/PostSkeleton'; import { PostSkeleton } from './components/PostSkeleton';
import { PredictionSkeleton } from './components/PredictionSkeleton'; import { PredictionSkeleton } from './components/PredictionSkeleton';
import { StateSkeleton } from './components/StateSkeleton';
import { StatsSkeleton } from './components/StatsSkeleton'; import { StatsSkeleton } from './components/StatsSkeleton';
import { TableSkeleton } from './components/TableSkeleton'; import { TableSkeleton } from './components/TableSkeleton';
import { DEFAULT_TABLE_COLUMNS, PRESET_REPEATS } from './constants'; import { DEFAULT_TABLE_COLUMNS, PRESET_REPEATS } from './constants';
@ -46,6 +47,7 @@ export function SkeletonPreset({
{preset === 'list' && <ListSkeleton rows={n} avatar={avatar} />} {preset === 'list' && <ListSkeleton rows={n} avatar={avatar} />}
{preset === 'table' && <TableSkeleton rows={n} columns={columns} />} {preset === 'table' && <TableSkeleton rows={n} columns={columns} />}
{preset === 'form' && <FormSkeleton fields={n} />} {preset === 'form' && <FormSkeleton fields={n} />}
{preset === 'state' && <StateSkeleton />}
</SkeletonRegion> </SkeletonRegion>
); );
} }

View File

@ -0,0 +1,30 @@
import { FlexBox } from '../../../atoms/flex-box';
import { Skeleton } from '../../../atoms/skeleton';
/**
* A full-page state, such as a suspended account: the 104px art, the heading, one line of text and
* the full-width action under them, centred. No card: it fills whatever frame the screen draws.
*/
export function StateSkeleton() {
return (
<FlexBox
direction="flex-col"
alignItems="items-center"
gap="gap-4"
className="pt-6"
aria-hidden
>
<Skeleton shape="circle" className="size-26" />
<FlexBox
direction="flex-col"
alignItems="items-center"
gap="gap-2"
className="w-full"
>
<Skeleton className="h-6 w-[55%]" />
<Skeleton className="w-[75%]" />
</FlexBox>
<Skeleton shape="pill" className="mt-2 h-control-lg w-full" />
</FlexBox>
);
}

View File

@ -19,7 +19,9 @@ export type SkeletonPresetName =
/** A money hero («قابل واریز») with two tiles under it. */ /** A money hero («قابل واریز») with two tiles under it. */
| 'figure' | 'figure'
/** A form step: heading, description, `count` fields, the submit button and a link. */ /** A form step: heading, description, `count` fields, the submit button and a link. */
| 'form'; | 'form'
/** A full-page state: the art, heading, one line and the action (a suspended account). */
| 'state';
export type SkeletonPresetProps = { export type SkeletonPresetProps = {
/** The component the screen is waiting for. */ /** The component the screen is waiting for. */