diff --git a/packages/island/src/molecules/choice-card/ChoiceCard.tsx b/packages/island/src/molecules/choice-card/ChoiceCard.tsx index a8836b8..6de2256 100644 --- a/packages/island/src/molecules/choice-card/ChoiceCard.tsx +++ b/packages/island/src/molecules/choice-card/ChoiceCard.tsx @@ -24,6 +24,7 @@ export function ChoiceCard({ checked = false, multiple = false, onChange, + ref, title, description, icon, @@ -41,6 +42,7 @@ export function ChoiceCard({ > ) => void; + /** The real radio, so a form can move focus to the first card when nothing was chosen. */ + ref?: Ref; title: ReactNode; description?: ReactNode; /** `investor` and `analyst` for the account type. */ diff --git a/packages/island/src/molecules/file-field/FileField.tsx b/packages/island/src/molecules/file-field/FileField.tsx index 33c83ef..9cb5ba6 100644 --- a/packages/island/src/molecules/file-field/FileField.tsx +++ b/packages/island/src/molecules/file-field/FileField.tsx @@ -24,6 +24,7 @@ export function FileField({ size, onChange, onBlur, + ref, accept, error, progress, @@ -130,6 +131,7 @@ export function FileField({ void; onBlur?: () => void; + /** The picker input, so a form can move focus to an empty required box. */ + ref?: Ref; /** 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. */ diff --git a/packages/island/src/molecules/toast/constants.ts b/packages/island/src/molecules/toast/constants.ts index b2f9e11..c925ad1 100644 --- a/packages/island/src/molecules/toast/constants.ts +++ b/packages/island/src/molecules/toast/constants.ts @@ -7,6 +7,13 @@ export const TOAST_ICONS: Record = { 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_WITH_ACTION_DURATION_MS = 6000; +export const TOAST_ERROR_DURATION_MS = 8000; +export const TOAST_ERROR_WITH_ACTION_DURATION_MS = 10000; diff --git a/packages/island/src/molecules/toast/show-toast.tsx b/packages/island/src/molecules/toast/show-toast.tsx index b3a8da2..9a15f6a 100644 --- a/packages/island/src/molecules/toast/show-toast.tsx +++ b/packages/island/src/molecules/toast/show-toast.tsx @@ -1,12 +1,31 @@ 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 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 - * closes the toast. Returns the toast's id for `dismissToast`. + * Shows a toast after an action completes or fails; never for a read. Every toast closes by + * itself (0019). Tapping the action also closes the toast. Returns the toast's id for + * `dismissToast`. */ export function showToast({ id, @@ -36,9 +55,7 @@ export function showToast({ ), { id, - duration: - duration ?? - (action ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS), + duration: duration ?? defaultDuration(props.tone, Boolean(action)), }, ); } diff --git a/packages/island/src/molecules/toast/types.ts b/packages/island/src/molecules/toast/types.ts index eb55f32..673fe0f 100644 --- a/packages/island/src/molecules/toast/types.ts +++ b/packages/island/src/molecules/toast/types.ts @@ -36,7 +36,7 @@ export type ShowToastOptions = Omit< 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. */ + /** Defaults to 4 seconds (6 with an action); an error to 8 (10 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 eb22620..e2a002d 100644 --- a/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx +++ b/packages/island/src/organisms/skeleton-preset/SkeletonPreset.tsx @@ -5,6 +5,7 @@ import { HeaderSkeleton } from './components/HeaderSkeleton'; import { ListSkeleton } from './components/ListSkeleton'; import { PostSkeleton } from './components/PostSkeleton'; import { PredictionSkeleton } from './components/PredictionSkeleton'; +import { StateSkeleton } from './components/StateSkeleton'; import { StatsSkeleton } from './components/StatsSkeleton'; import { TableSkeleton } from './components/TableSkeleton'; import { DEFAULT_TABLE_COLUMNS, PRESET_REPEATS } from './constants'; @@ -46,6 +47,7 @@ export function SkeletonPreset({ {preset === 'list' && } {preset === 'table' && } {preset === 'form' && } + {preset === 'state' && } ); } diff --git a/packages/island/src/organisms/skeleton-preset/components/StateSkeleton.tsx b/packages/island/src/organisms/skeleton-preset/components/StateSkeleton.tsx new file mode 100644 index 0000000..b198a53 --- /dev/null +++ b/packages/island/src/organisms/skeleton-preset/components/StateSkeleton.tsx @@ -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 ( + + + + + + + + + ); +} diff --git a/packages/island/src/organisms/skeleton-preset/types.ts b/packages/island/src/organisms/skeleton-preset/types.ts index 0a27b8f..bb3d68a 100644 --- a/packages/island/src/organisms/skeleton-preset/types.ts +++ b/packages/island/src/organisms/skeleton-preset/types.ts @@ -19,7 +19,9 @@ export type SkeletonPresetName = /** A money hero («قابل واریز») with two tiles under it. */ | 'figure' /** 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 = { /** The component the screen is waiting for. */