feat(island): v6 compositions — list rows, page header, section title, pinned footer, result panel, stat tile, meter, search field, avatar stack, timeline, code input, key-value, analyst card; new chips, segmented, avatar sizes, toast placement, account menu items, post and prediction card names and close reason
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
@ -5,23 +5,26 @@ import type { AvatarSize } from './types';
|
||||||
export const AVATAR_PX: Record<AvatarSize, number> = {
|
export const AVATAR_PX: Record<AvatarSize, number> = {
|
||||||
sm: 32,
|
sm: 32,
|
||||||
md: 40,
|
md: 40,
|
||||||
lg: 56,
|
lg: 52,
|
||||||
xl: 80,
|
xl: 72,
|
||||||
'2xl': 96,
|
'2xl': 96,
|
||||||
|
xxl: 96,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AVATAR_INITIAL_VARIANT: Record<AvatarSize, TypographyVariant> = {
|
export const AVATAR_INITIAL_VARIANT: Record<AvatarSize, TypographyVariant> = {
|
||||||
sm: 'label',
|
sm: 'label',
|
||||||
md: 'body-md',
|
md: 'body-md',
|
||||||
lg: 'heading-sm',
|
lg: 'heading-md',
|
||||||
xl: 'heading-lg',
|
xl: 'heading-lg',
|
||||||
'2xl': 'display',
|
'2xl': 'display',
|
||||||
|
xxl: 'display',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AVATAR_MARK_PX: Record<AvatarSize, number> = {
|
export const AVATAR_MARK_PX: Record<AvatarSize, number> = {
|
||||||
sm: 12,
|
sm: 12,
|
||||||
md: 14,
|
md: 14,
|
||||||
lg: 18,
|
lg: 18,
|
||||||
xl: 22,
|
xl: 20,
|
||||||
'2xl': 24,
|
'2xl': 24,
|
||||||
|
xxl: 24,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ export const avatarVariants = cva(
|
||||||
sm: 'size-8',
|
sm: 'size-8',
|
||||||
/** Post headers, subscription cards, list rows. */
|
/** Post headers, subscription cards, list rows. */
|
||||||
md: 'size-10',
|
md: 'size-10',
|
||||||
/** Sheet and checkout headers. */
|
/** Analyst cards, sheet and checkout headers (DS lg, 52px). */
|
||||||
lg: 'size-14',
|
lg: 'size-13',
|
||||||
/** The channel profile header. */
|
/** The channel header (DS xl, 72px). */
|
||||||
xl: 'size-20',
|
xl: 'size-18',
|
||||||
/** The profile photo field. */
|
/** The profile photo field (96px). */
|
||||||
'2xl': 'size-24',
|
'2xl': 'size-24',
|
||||||
|
/** The DS name for `2xl` (96px). */
|
||||||
|
xxl: 'size-24',
|
||||||
},
|
},
|
||||||
/** An account that can't be used, such as a suspended creator's own avatar: no brand colour. */
|
/** An account that can't be used, such as a suspended creator's own avatar: no brand colour. */
|
||||||
muted: {
|
muted: {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export function Chip({
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{selected && <Icon name="check" size={16} strokeWidth={2.5} />}
|
{selected && <Icon name="check" size={16} strokeWidth={2.5} />}
|
||||||
<Typography tag="span" variant="label" color="inherit">
|
<Typography tag="span" variant="inherit" color="inherit">
|
||||||
{children}
|
{children}
|
||||||
</Typography>
|
</Typography>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export { Chip } from './Chip';
|
export { Chip } from './Chip';
|
||||||
export type { ChipProps, ChipSize } from './types';
|
export type { ChipProps, ChipSize } from './types';
|
||||||
export { chipVariants } from './variants';
|
export { chipRowVariants, chipVariants } from './variants';
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,35 @@
|
||||||
import { cva } from 'class-variance-authority';
|
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. */
|
/**
|
||||||
|
* A pill you press to pick one of many, such as a market; a set sits in a wrapping row (DS Chips).
|
||||||
|
* Off, it is white with a `border-default` outline; on, filled brand. 15/600, 14 at `sm`.
|
||||||
|
*/
|
||||||
export const chipVariants = cva(
|
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',
|
'rounded-full border px-4 font-semibold whitespace-nowrap transition-colors duration-120 ease-standard focus-visible:focus-ring actionable:cursor-pointer disabled:frozen',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
selected: {
|
selected: {
|
||||||
true: 'border-action-primary bg-action-primary text-text-on-action actionable:hover:bg-action-primary-hover',
|
true: 'border-action-primary bg-action-primary text-text-on-action actionable:hover:bg-action-primary-hover',
|
||||||
false:
|
false:
|
||||||
'border-transparent bg-action-primary-muted text-action-primary-text actionable:hover:border-action-primary',
|
'border-border-default bg-surface text-text-primary actionable:hover:border-text-secondary actionable:hover:bg-surface-hover',
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
sm: 'min-h-control-sm px-3.5',
|
sm: 'min-h-control-sm px-3.5 text-body-sm leading-6',
|
||||||
md: 'min-h-control-md',
|
md: 'min-h-control-md text-[0.9375rem] leading-6',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: { selected: false, size: 'md' },
|
defaultVariants: { selected: false, size: 'md' },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** A set of chips: wrapping rows, or one row that scrolls sideways (DS `scroll`). */
|
||||||
|
export const chipRowVariants = cva('', {
|
||||||
|
variants: {
|
||||||
|
scroll: {
|
||||||
|
// The 4px padding keeps each chip's focus ring inside the scroller's clip.
|
||||||
|
true: '-m-1 overflow-x-auto p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { scroll: false },
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,17 @@ export const ICON_NAMES = [
|
||||||
'chevron-down',
|
'chevron-down',
|
||||||
'chevron-left',
|
'chevron-left',
|
||||||
'chevron-right',
|
'chevron-right',
|
||||||
|
'chevron-up',
|
||||||
'clock',
|
'clock',
|
||||||
'close',
|
'close',
|
||||||
'copy',
|
'copy',
|
||||||
'dashboard',
|
'dashboard',
|
||||||
'download',
|
'download',
|
||||||
'edit',
|
'edit',
|
||||||
|
'expand',
|
||||||
'external',
|
'external',
|
||||||
'eye',
|
'eye',
|
||||||
|
'file',
|
||||||
'filter',
|
'filter',
|
||||||
'flag',
|
'flag',
|
||||||
'grip',
|
'grip',
|
||||||
|
|
@ -43,12 +46,16 @@ export const ICON_NAMES = [
|
||||||
'minus',
|
'minus',
|
||||||
'more',
|
'more',
|
||||||
'pause',
|
'pause',
|
||||||
|
'phone',
|
||||||
|
'plus-square',
|
||||||
'plus',
|
'plus',
|
||||||
'receipt',
|
'receipt',
|
||||||
'refresh',
|
'refresh',
|
||||||
'search-x',
|
'search-x',
|
||||||
'search',
|
'search',
|
||||||
'server',
|
'server',
|
||||||
|
'settings',
|
||||||
|
'share-ios',
|
||||||
'share',
|
'share',
|
||||||
'shield-check',
|
'shield-check',
|
||||||
'sort',
|
'sort',
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,14 @@ import { Typography } from '../typography';
|
||||||
import type { SelectProps } from './types';
|
import type { SelectProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A labelled native select, 44px high. On phones the system draws its own wheel or list, so a
|
* A labelled native select with the DS SelectField look: 48px, 16px padding, an optional leading
|
||||||
* date or time picker built from these needs no script of its own.
|
* icon and the chevron at the end. On phones the system draws its own wheel or list, so a date or
|
||||||
|
* time picker built from these needs no script of its own (0035).
|
||||||
*/
|
*/
|
||||||
export function Select({
|
export function Select({
|
||||||
label,
|
label,
|
||||||
options,
|
options,
|
||||||
|
icon,
|
||||||
className,
|
className,
|
||||||
id,
|
id,
|
||||||
...props
|
...props
|
||||||
|
|
@ -36,10 +38,19 @@ export function Select({
|
||||||
{label}
|
{label}
|
||||||
</Typography>
|
</Typography>
|
||||||
<FlexBox tag="span" alignItems="items-center" className="relative">
|
<FlexBox tag="span" alignItems="items-center" className="relative">
|
||||||
|
{icon && (
|
||||||
|
<Icon
|
||||||
|
name={icon}
|
||||||
|
className="pointer-events-none absolute start-4 text-text-secondary"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Element
|
<Element
|
||||||
tag="select"
|
tag="select"
|
||||||
id={selectId}
|
id={selectId}
|
||||||
className="h-touch-target w-full cursor-pointer appearance-none rounded-md border border-border-default bg-surface ps-3 pe-8 text-body-md text-text-primary outline-none transition-colors duration-120 ease-standard hover:border-border-strong focus-visible:focus-ring disabled:cursor-not-allowed disabled:opacity-(--opacity-dimmed)"
|
className={cn(
|
||||||
|
'h-input-height w-full cursor-pointer appearance-none rounded-md border border-border-default bg-surface ps-4 pe-11 text-body-md text-text-primary outline-none transition-colors duration-120 ease-standard hover:border-text-secondary focus-visible:focus-ring disabled:cursor-not-allowed disabled:opacity-(--opacity-dimmed)',
|
||||||
|
icon && 'ps-11',
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
|
|
@ -50,8 +61,7 @@ export function Select({
|
||||||
</Element>
|
</Element>
|
||||||
<Icon
|
<Icon
|
||||||
name="chevron-down"
|
name="chevron-down"
|
||||||
size={16}
|
className="pointer-events-none absolute end-4 text-text-secondary"
|
||||||
className="pointer-events-none absolute end-3 text-text-secondary"
|
|
||||||
/>
|
/>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
import type { ComponentPropsWithRef, ReactNode } from 'react';
|
import type { ComponentPropsWithRef, ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { IconName } from '../icon';
|
||||||
|
|
||||||
export type SelectOption = { value: string; label: ReactNode };
|
export type SelectOption = { value: string; label: ReactNode };
|
||||||
|
|
||||||
export type SelectProps = Omit<ComponentPropsWithRef<'select'>, 'children'> & {
|
export type SelectProps = Omit<ComponentPropsWithRef<'select'>, 'children'> & {
|
||||||
/** The visible label above the control, such as «روز». */
|
/** The visible label above the control, such as «روز». */
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
options: readonly SelectOption[];
|
options: readonly SelectOption[];
|
||||||
|
/** A 20px icon at the start of the control, such as `clock` (DS SelectField). */
|
||||||
|
icon?: IconName;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useId } from 'react';
|
||||||
|
|
||||||
import { Element } from '../../primitives/element';
|
import { Element } from '../../primitives/element';
|
||||||
import { cn } from '../../tools/cn';
|
import { cn } from '../../tools/cn';
|
||||||
|
import { FlexBox } from '../flex-box';
|
||||||
import { Typography } from '../typography';
|
import { Typography } from '../typography';
|
||||||
import type { SwitchProps } from './types';
|
import type { SwitchProps } from './types';
|
||||||
import { switchKnobVariants, switchTrackVariants } from './variants';
|
import { switchKnobVariants, switchTrackVariants } from './variants';
|
||||||
|
|
@ -16,10 +19,15 @@ export function Switch({
|
||||||
onCheckedChange,
|
onCheckedChange,
|
||||||
locked = false,
|
locked = false,
|
||||||
children,
|
children,
|
||||||
|
description,
|
||||||
className,
|
className,
|
||||||
onClick,
|
onClick,
|
||||||
...props
|
...props
|
||||||
}: SwitchProps) {
|
}: SwitchProps) {
|
||||||
|
const labelId = useId();
|
||||||
|
const descriptionId = useId();
|
||||||
|
const hasText = children != null || description != null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Element
|
<Element
|
||||||
tag="button"
|
tag="button"
|
||||||
|
|
@ -27,6 +35,11 @@ export function Switch({
|
||||||
role="switch"
|
role="switch"
|
||||||
aria-checked={checked}
|
aria-checked={checked}
|
||||||
aria-disabled={locked || undefined}
|
aria-disabled={locked || undefined}
|
||||||
|
// The label alone names it; the description is announced after it, not inside the name.
|
||||||
|
aria-labelledby={
|
||||||
|
children != null && description != null ? labelId : undefined
|
||||||
|
}
|
||||||
|
aria-describedby={description != null ? descriptionId : undefined}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
onClick?.(event);
|
onClick?.(event);
|
||||||
if (!locked && !event.defaultPrevented) onCheckedChange?.(!checked);
|
if (!locked && !event.defaultPrevented) onCheckedChange?.(!checked);
|
||||||
|
|
@ -36,15 +49,38 @@ export function Switch({
|
||||||
locked
|
locked
|
||||||
? 'cursor-not-allowed opacity-(--opacity-dimmed)'
|
? 'cursor-not-allowed opacity-(--opacity-dimmed)'
|
||||||
: 'cursor-pointer',
|
: 'cursor-pointer',
|
||||||
children && 'justify-between text-start',
|
hasText && 'justify-between text-start',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children && (
|
{hasText && (
|
||||||
<Typography tag="span" variant="body-sm" className="font-semibold">
|
<FlexBox
|
||||||
{children}
|
tag="span"
|
||||||
</Typography>
|
direction="flex-col"
|
||||||
|
className="min-w-0 flex-1 gap-0.5"
|
||||||
|
>
|
||||||
|
{children != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
id={labelId}
|
||||||
|
variant="body-sm"
|
||||||
|
className="font-semibold"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{description != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
id={descriptionId}
|
||||||
|
variant="caption"
|
||||||
|
color="secondary"
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
)}
|
)}
|
||||||
<Element
|
<Element
|
||||||
tag="span"
|
tag="span"
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ export type SwitchProps = Omit<
|
||||||
* Without it, give the switch an `aria-label`.
|
* Without it, give the switch an `aria-label`.
|
||||||
*/
|
*/
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
/**
|
||||||
|
* A muted caption under the label, such as what turning it on does (DS Switch `description`).
|
||||||
|
* Read out as the switch's description.
|
||||||
|
*/
|
||||||
|
description?: ReactNode;
|
||||||
/** Can't change now, such as a period during the 7-day lock: 50%, `aria-disabled`, still focusable. */
|
/** Can't change now, such as a period during the 7-day lock: 50%, `aria-disabled`, still focusable. */
|
||||||
locked?: boolean;
|
locked?: boolean;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
* Raise it with every change to `icons/*.svg` or to the svgo step in `icon-sprite-plugin`, in the
|
* Raise it with every change to `icons/*.svg` or to the svgo step in `icon-sprite-plugin`, in the
|
||||||
* same commit. Never reuse or lower it.
|
* same commit. Never reuse or lower it.
|
||||||
*/
|
*/
|
||||||
export const ICON_SPRITE_VERSION = 1;
|
export const ICON_SPRITE_VERSION = 2;
|
||||||
|
|
||||||
/** Where `icon-sprite-plugin` writes the sprite, under each app's `public/`. Its name never changes. */
|
/** Where `icon-sprite-plugin` writes the sprite, under each app's `public/`. Its name never changes. */
|
||||||
export const ICON_SPRITE_PATH = '/icons/symbol-defs.svg';
|
export const ICON_SPRITE_PATH = '/icons/symbol-defs.svg';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M6 15l6-6 6 6" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 198 B |
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 223 B |
|
|
@ -0,0 +1,4 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M6 3h8l4 4v14H6z" />
|
||||||
|
<path d="M14 3v4h4M9 12h6M9 16h6" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 240 B |
|
|
@ -0,0 +1,4 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<rect x="6.5" y="2.5" width="11" height="19" rx="2.5" />
|
||||||
|
<path d="M10.5 18.5h3" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 256 B |
|
|
@ -0,0 +1,4 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<rect x="3.5" y="3.5" width="17" height="17" rx="3" />
|
||||||
|
<path d="M12 8v8M8 12h8" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 256 B |
|
|
@ -0,0 +1,4 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<circle cx="12" cy="12" r="3" />
|
||||||
|
<path d="M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 326 B |
|
|
@ -0,0 +1,4 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M12 3v12M8 7l4-4 4 4" />
|
||||||
|
<path d="M8.5 10H6a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1h-2.5" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 299 B |
|
|
@ -11,7 +11,7 @@ export type {
|
||||||
} from './atoms/button';
|
} from './atoms/button';
|
||||||
export { Checkbox, checkboxVariants } from './atoms/checkbox';
|
export { Checkbox, checkboxVariants } from './atoms/checkbox';
|
||||||
export type { CheckboxProps } from './atoms/checkbox';
|
export type { CheckboxProps } from './atoms/checkbox';
|
||||||
export { Chip, chipVariants } from './atoms/chip';
|
export { Chip, chipRowVariants, chipVariants } from './atoms/chip';
|
||||||
export type { ChipProps, ChipSize } from './atoms/chip';
|
export type { ChipProps, ChipSize } from './atoms/chip';
|
||||||
export { CountBadge } from './atoms/count-badge';
|
export { CountBadge } from './atoms/count-badge';
|
||||||
export type { CountBadgeProps } from './atoms/count-badge';
|
export type { CountBadgeProps } from './atoms/count-badge';
|
||||||
|
|
@ -109,6 +109,15 @@ export type {
|
||||||
TypographyProps,
|
TypographyProps,
|
||||||
TypographyVariant,
|
TypographyVariant,
|
||||||
} from './atoms/typography';
|
} from './atoms/typography';
|
||||||
|
export {
|
||||||
|
AvatarStack,
|
||||||
|
avatarStackFaceVariants,
|
||||||
|
avatarStackVariants,
|
||||||
|
} from './molecules/avatar-stack';
|
||||||
|
export type {
|
||||||
|
AvatarStackItem,
|
||||||
|
AvatarStackProps,
|
||||||
|
} from './molecules/avatar-stack';
|
||||||
export { AvatarField } from './molecules/avatar-field';
|
export { AvatarField } from './molecules/avatar-field';
|
||||||
export type {
|
export type {
|
||||||
AvatarFieldLabels,
|
AvatarFieldLabels,
|
||||||
|
|
@ -125,8 +134,19 @@ export { ChipGroup } from './molecules/chip-group';
|
||||||
export type { ChipGroupOption, ChipGroupProps } from './molecules/chip-group';
|
export type { ChipGroupOption, ChipGroupProps } from './molecules/chip-group';
|
||||||
export { ChoiceCard, choiceCardVariants } from './molecules/choice-card';
|
export { ChoiceCard, choiceCardVariants } from './molecules/choice-card';
|
||||||
export type { ChoiceCardProps } from './molecules/choice-card';
|
export type { ChoiceCardProps } from './molecules/choice-card';
|
||||||
export { DetailRow, detailRowVariants } from './molecules/detail-row';
|
export {
|
||||||
export type { DetailRowProps } from './molecules/detail-row';
|
DetailRow,
|
||||||
|
detailRowVariants,
|
||||||
|
detailValueVariants,
|
||||||
|
} from './molecules/detail-row';
|
||||||
|
export type { DetailRowProps, DetailRowTone } from './molecules/detail-row';
|
||||||
|
export { CodeInput, codeInputButtonVariants } from './molecules/code-input';
|
||||||
|
export type {
|
||||||
|
CodeInputLabels,
|
||||||
|
CodeInputProps,
|
||||||
|
CodeInputSource,
|
||||||
|
CodeInputStatus,
|
||||||
|
} from './molecules/code-input';
|
||||||
export { EmptyState } from './molecules/empty-state';
|
export { EmptyState } from './molecules/empty-state';
|
||||||
export type { EmptyStateProps, EmptyStateTone } from './molecules/empty-state';
|
export type { EmptyStateProps, EmptyStateTone } from './molecules/empty-state';
|
||||||
export { ERROR_KIND_STYLES, ErrorState } from './molecules/error-state';
|
export { ERROR_KIND_STYLES, ErrorState } from './molecules/error-state';
|
||||||
|
|
@ -142,10 +162,31 @@ export { FormSection } from './molecules/form-section';
|
||||||
export type { FormSectionProps } from './molecules/form-section';
|
export type { FormSectionProps } from './molecules/form-section';
|
||||||
export { InfoTip, infoTipVariants } from './molecules/info-tip';
|
export { InfoTip, infoTipVariants } from './molecules/info-tip';
|
||||||
export type { InfoTipProps } from './molecules/info-tip';
|
export type { InfoTipProps } from './molecules/info-tip';
|
||||||
|
export { KeyValue, keyValueVariants } from './molecules/key-value';
|
||||||
|
export type { KeyValueProps, KeyValueTone } from './molecules/key-value';
|
||||||
|
export {
|
||||||
|
List,
|
||||||
|
ListRow,
|
||||||
|
listHeaderVariants,
|
||||||
|
listItemsVariants,
|
||||||
|
listRowIconVariants,
|
||||||
|
listRowVariants,
|
||||||
|
listVariants,
|
||||||
|
} from './molecules/list-row';
|
||||||
|
export type {
|
||||||
|
ListProps,
|
||||||
|
ListRowAsButtonProps,
|
||||||
|
ListRowAsLinkProps,
|
||||||
|
ListRowIconTone,
|
||||||
|
ListRowProps,
|
||||||
|
ListTone,
|
||||||
|
} from './molecules/list-row';
|
||||||
export { LockedTeaser } from './molecules/locked-teaser';
|
export { LockedTeaser } from './molecules/locked-teaser';
|
||||||
export type { LockedTeaserProps } from './molecules/locked-teaser';
|
export type { LockedTeaserProps } from './molecules/locked-teaser';
|
||||||
export { MediaCarousel } from './molecules/media-carousel';
|
export { MediaCarousel } from './molecules/media-carousel';
|
||||||
export type { MediaCarouselProps, MediaItem } from './molecules/media-carousel';
|
export type { MediaCarouselProps, MediaItem } from './molecules/media-carousel';
|
||||||
|
export { Meter, meterBarVariants } from './molecules/meter';
|
||||||
|
export type { MeterProps, MeterTone } from './molecules/meter';
|
||||||
export { Modal } from './molecules/modal';
|
export { Modal } from './molecules/modal';
|
||||||
export type { ModalProps, ModalSize } from './molecules/modal';
|
export type { ModalProps, ModalSize } from './molecules/modal';
|
||||||
export {
|
export {
|
||||||
|
|
@ -157,6 +198,17 @@ export type {
|
||||||
NetworkStatusProps,
|
NetworkStatusProps,
|
||||||
} from './molecules/network-status';
|
} from './molecules/network-status';
|
||||||
export { OtpInput } from './molecules/otp-input';
|
export { OtpInput } from './molecules/otp-input';
|
||||||
|
export { PageHeader, pageHeaderTitleVariants } from './molecules/page-header';
|
||||||
|
export type { PageHeaderProps, PageHeaderSize } from './molecules/page-header';
|
||||||
|
export {
|
||||||
|
PINNED_FOOTER_TOAST_OFFSET,
|
||||||
|
PinnedFooter,
|
||||||
|
pinnedFooterVariants,
|
||||||
|
} from './molecules/pinned-footer';
|
||||||
|
export type {
|
||||||
|
PinnedFooterLayout,
|
||||||
|
PinnedFooterProps,
|
||||||
|
} from './molecules/pinned-footer';
|
||||||
export type { OtpInputProps, OtpStatus } from './molecules/otp-input';
|
export type { OtpInputProps, OtpStatus } from './molecules/otp-input';
|
||||||
export { ResendCode } from './molecules/resend-code';
|
export { ResendCode } from './molecules/resend-code';
|
||||||
export type {
|
export type {
|
||||||
|
|
@ -164,13 +216,30 @@ export type {
|
||||||
ResendCodeProps,
|
ResendCodeProps,
|
||||||
ResendStatus,
|
ResendStatus,
|
||||||
} from './molecules/resend-code';
|
} from './molecules/resend-code';
|
||||||
|
export {
|
||||||
|
RESULT_PANEL_ICONS,
|
||||||
|
ResultPanel,
|
||||||
|
resultPanelIconVariants,
|
||||||
|
} from './molecules/result-panel';
|
||||||
|
export type {
|
||||||
|
ResultPanelProps,
|
||||||
|
ResultPanelTone,
|
||||||
|
} from './molecules/result-panel';
|
||||||
export { SampleFrame, sampleTagVariants } from './molecules/sample-frame';
|
export { SampleFrame, sampleTagVariants } from './molecules/sample-frame';
|
||||||
|
export {
|
||||||
|
SearchField,
|
||||||
|
searchFieldInputVariants,
|
||||||
|
searchFieldVariants,
|
||||||
|
} from './molecules/search-field';
|
||||||
|
export type { SearchFieldProps } from './molecules/search-field';
|
||||||
export type { SampleFrameProps } from './molecules/sample-frame';
|
export type { SampleFrameProps } from './molecules/sample-frame';
|
||||||
export {
|
export {
|
||||||
SectionHeading,
|
SectionHeading,
|
||||||
sectionHeadingVariants,
|
sectionHeadingVariants,
|
||||||
} from './molecules/section-heading';
|
} from './molecules/section-heading';
|
||||||
export type { SectionHeadingProps } from './molecules/section-heading';
|
export type { SectionHeadingProps } from './molecules/section-heading';
|
||||||
|
export { SectionTitle, sectionTitleVariants } from './molecules/section-title';
|
||||||
|
export type { SectionTitleProps } from './molecules/section-title';
|
||||||
export {
|
export {
|
||||||
SegmentedChoice,
|
SegmentedChoice,
|
||||||
segmentedChoiceOptionVariants,
|
segmentedChoiceOptionVariants,
|
||||||
|
|
@ -180,6 +249,7 @@ export type {
|
||||||
SegmentedChoiceOption,
|
SegmentedChoiceOption,
|
||||||
SegmentedChoiceProps,
|
SegmentedChoiceProps,
|
||||||
SegmentedChoiceSize,
|
SegmentedChoiceSize,
|
||||||
|
SegmentedChoiceTone,
|
||||||
SegmentedChoiceTrack,
|
SegmentedChoiceTrack,
|
||||||
} from './molecules/segmented-choice';
|
} from './molecules/segmented-choice';
|
||||||
export { Sheet } from './molecules/sheet';
|
export { Sheet } from './molecules/sheet';
|
||||||
|
|
@ -189,9 +259,31 @@ export type {
|
||||||
StateMessageProps,
|
StateMessageProps,
|
||||||
StateMessageSize,
|
StateMessageSize,
|
||||||
} from './molecules/state-message';
|
} from './molecules/state-message';
|
||||||
|
export {
|
||||||
|
StatTile,
|
||||||
|
statTileValueVariants,
|
||||||
|
statTileVariants,
|
||||||
|
} from './molecules/stat-tile';
|
||||||
|
export type {
|
||||||
|
StatTileProps,
|
||||||
|
StatTileTone,
|
||||||
|
StatTileValueTone,
|
||||||
|
} from './molecules/stat-tile';
|
||||||
export { StepProgress } from './molecules/step-progress';
|
export { StepProgress } from './molecules/step-progress';
|
||||||
export type { StepProgressProps } from './molecules/step-progress';
|
export type { StepProgressProps } from './molecules/step-progress';
|
||||||
export { TabLinks } from './molecules/tab-links';
|
export { TabLinks } from './molecules/tab-links';
|
||||||
|
export {
|
||||||
|
Timeline,
|
||||||
|
TimelineItem,
|
||||||
|
timelineDotVariants,
|
||||||
|
timelineItemVariants,
|
||||||
|
timelineVariants,
|
||||||
|
} from './molecules/timeline';
|
||||||
|
export type {
|
||||||
|
TimelineItemProps,
|
||||||
|
TimelineProps,
|
||||||
|
TimelineTone,
|
||||||
|
} from './molecules/timeline';
|
||||||
export type { TabLinkItem, TabLinksProps } from './molecules/tab-links';
|
export type { TabLinkItem, TabLinksProps } from './molecules/tab-links';
|
||||||
export {
|
export {
|
||||||
TextInput,
|
TextInput,
|
||||||
|
|
@ -199,14 +291,32 @@ export {
|
||||||
textInputControlVariants,
|
textInputControlVariants,
|
||||||
} from './molecules/text-input';
|
} from './molecules/text-input';
|
||||||
export type { TextInputProps } from './molecules/text-input';
|
export type { TextInputProps } from './molecules/text-input';
|
||||||
export { dismissToast, showToast, Toast, Toaster } from './molecules/toast';
|
export {
|
||||||
|
dismissToast,
|
||||||
|
showToast,
|
||||||
|
Toast,
|
||||||
|
TOAST_OFFSETS,
|
||||||
|
Toaster,
|
||||||
|
ToastPlacementMarker,
|
||||||
|
useToastPlacement,
|
||||||
|
} from './molecules/toast';
|
||||||
export type {
|
export type {
|
||||||
|
DeclaredToastPlacement,
|
||||||
ShowToastOptions,
|
ShowToastOptions,
|
||||||
ToastAction,
|
ToastAction,
|
||||||
ToasterProps,
|
ToasterProps,
|
||||||
|
ToastPlacement,
|
||||||
|
ToastPlacementMarkerProps,
|
||||||
ToastProps,
|
ToastProps,
|
||||||
ToastTone,
|
ToastTone,
|
||||||
} from './molecules/toast';
|
} from './molecules/toast';
|
||||||
|
export { AnalystCard } from './organisms/analyst-card';
|
||||||
|
export type {
|
||||||
|
AnalystCardAnalyst,
|
||||||
|
AnalystCardLabels,
|
||||||
|
AnalystCardProps,
|
||||||
|
AnalystCardStats,
|
||||||
|
} from './organisms/analyst-card';
|
||||||
export { CreatorStats } from './organisms/creator-stats';
|
export { CreatorStats } from './organisms/creator-stats';
|
||||||
export type {
|
export type {
|
||||||
CreatorStatsData,
|
CreatorStatsData,
|
||||||
|
|
@ -233,6 +343,7 @@ export { PredictionCard } from './organisms/prediction-card';
|
||||||
export type {
|
export type {
|
||||||
PredictionCardLabels,
|
PredictionCardLabels,
|
||||||
PredictionCardProps,
|
PredictionCardProps,
|
||||||
|
PredictionCloseReason,
|
||||||
PredictionData,
|
PredictionData,
|
||||||
PredictionDirection,
|
PredictionDirection,
|
||||||
PredictionOutcome,
|
PredictionOutcome,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { useEffect, useEffectEvent, useRef } from 'react';
|
import { useEffect, useEffectEvent, useRef } from 'react';
|
||||||
import type { KeyboardEvent } from 'react';
|
import type { KeyboardEvent } from 'react';
|
||||||
|
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
import { Element } from '../../primitives/element';
|
import { Element } from '../../primitives/element';
|
||||||
import { cn } from '../../tools/cn';
|
import { cn } from '../../tools/cn';
|
||||||
import { ActionMenuItem } from './components/ActionMenuItem';
|
import { ActionMenuItem } from './components/ActionMenuItem';
|
||||||
|
|
@ -11,8 +12,9 @@ import { actionMenuVariants } from './variants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A short list of destinations or actions anchored to its trigger, such as «انتشار» → «پست جدید»
|
* A short list of destinations or actions anchored to its trigger, such as «انتشار» → «پست جدید»
|
||||||
* / «پیشبینی جدید», or a post's share → «کپی لینک». Put it in a positioned container that holds
|
* / «پیشبینی جدید», a post's share → «کپی لینک», or the desktop account menu with its identity
|
||||||
* only the trigger and the menu, and give the trigger `aria-haspopup="menu"`. It takes focus when
|
* `header`, links and a danger «خروج از حساب» after a separator. Put it in a positioned container
|
||||||
|
* that holds only the trigger and the menu, and give the trigger `aria-haspopup="menu"`. It takes focus when
|
||||||
* it opens; ↑ ↓ move, and the trigger keeps its own press. Escape or a choice closes it and puts
|
* it opens; ↑ ↓ move, and the trigger keeps its own press. Escape or a choice closes it and puts
|
||||||
* focus back on that container's `[aria-haspopup]` trigger; a press outside, or Tab out of the
|
* focus back on that container's `[aria-haspopup]` trigger; a press outside, or Tab out of the
|
||||||
* menu and its trigger, closes it and leaves focus where the press or Tab put it.
|
* menu and its trigger, closes it and leaves focus where the press or Tab put it.
|
||||||
|
|
@ -22,10 +24,11 @@ export function ActionMenu({
|
||||||
onClose,
|
onClose,
|
||||||
items,
|
items,
|
||||||
label,
|
label,
|
||||||
|
header,
|
||||||
placement = 'below',
|
placement = 'below',
|
||||||
className,
|
className,
|
||||||
}: ActionMenuProps) {
|
}: ActionMenuProps) {
|
||||||
const ref = useRef<HTMLUListElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const close = useEffectEvent(onClose);
|
const close = useEffectEvent(onClose);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -61,7 +64,7 @@ export function ActionMenu({
|
||||||
trigger?.focus();
|
trigger?.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onKeyDown = (event: KeyboardEvent<HTMLUListElement>) => {
|
const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
||||||
const options = Array.from(
|
const options = Array.from(
|
||||||
ref.current?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? [],
|
ref.current?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? [],
|
||||||
);
|
);
|
||||||
|
|
@ -79,19 +82,33 @@ export function ActionMenu({
|
||||||
return (
|
return (
|
||||||
<Element
|
<Element
|
||||||
ref={ref}
|
ref={ref}
|
||||||
tag="ul"
|
tag="div"
|
||||||
role="menu"
|
|
||||||
aria-label={label}
|
|
||||||
onKeyDown={onKeyDown}
|
|
||||||
className={cn(actionMenuVariants({ placement }), className)}
|
className={cn(actionMenuVariants({ placement }), className)}
|
||||||
>
|
>
|
||||||
{items.map((item) => (
|
{header != null && (
|
||||||
<ActionMenuItem
|
<FlexBox
|
||||||
key={item.href ?? item.label}
|
alignItems="items-center"
|
||||||
{...item}
|
gap="gap-3"
|
||||||
onClose={closeToTrigger}
|
className="mb-1.5 border-b border-border-subtle px-3 pt-2 pb-3"
|
||||||
/>
|
>
|
||||||
))}
|
{header}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
<Element
|
||||||
|
tag="ul"
|
||||||
|
role="menu"
|
||||||
|
aria-label={label}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
className="m-0"
|
||||||
|
>
|
||||||
|
{items.map((item) => (
|
||||||
|
<ActionMenuItem
|
||||||
|
key={item.href ?? item.label}
|
||||||
|
{...item}
|
||||||
|
onClose={closeToTrigger}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Element>
|
||||||
</Element>
|
</Element>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,19 @@ import { Typography } from '../../../atoms/typography';
|
||||||
import { Element } from '../../../primitives/element';
|
import { Element } from '../../../primitives/element';
|
||||||
import { cn } from '../../../tools/cn';
|
import { cn } from '../../../tools/cn';
|
||||||
import type { ActionMenuItemProps } from '../types';
|
import type { ActionMenuItemProps } from '../types';
|
||||||
|
import { actionMenuIconVariants, actionMenuItemVariants } from '../variants';
|
||||||
/** A link row and a button row look the same. */
|
|
||||||
const ROW_CLASS =
|
|
||||||
'min-h-touch-target rounded-md px-3 text-text-primary no-underline outline-none hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:focus-ring';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One destination or action: its icon in the brand colour and its name, a 44px row. A link
|
* One destination or action: its icon in the brand colour (red on a danger item) and its name, a
|
||||||
* navigates; a button closes the menu, then runs its `onSelect`.
|
* 48px row. A link navigates; a button closes the menu, then runs its `onSelect`. A separator
|
||||||
|
* before it starts a new group.
|
||||||
*/
|
*/
|
||||||
export function ActionMenuItem({
|
export function ActionMenuItem({
|
||||||
href,
|
href,
|
||||||
label,
|
label,
|
||||||
icon,
|
icon,
|
||||||
|
tone = 'default',
|
||||||
|
separatorBefore = false,
|
||||||
onSelect,
|
onSelect,
|
||||||
onClose,
|
onClose,
|
||||||
}: ActionMenuItemProps) {
|
}: ActionMenuItemProps) {
|
||||||
|
|
@ -27,44 +27,52 @@ export function ActionMenuItem({
|
||||||
<Icon
|
<Icon
|
||||||
name={icon}
|
name={icon}
|
||||||
size={20}
|
size={20}
|
||||||
className="flex-none text-action-primary-text"
|
className={actionMenuIconVariants({ tone })}
|
||||||
/>
|
/>
|
||||||
<Typography tag="span" color="inherit" className="font-semibold">
|
<Typography tag="span" color="inherit" className="font-semibold">
|
||||||
{label}
|
{label}
|
||||||
</Typography>
|
</Typography>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
const rowClass = actionMenuItemVariants({ tone });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Element tag="li" role="none">
|
<>
|
||||||
{href != null ? (
|
{separatorBefore && (
|
||||||
<FlexBox
|
<Element tag="li" role="none">
|
||||||
tag={NextLink}
|
<Element tag="hr" className="my-1.5 h-px border-0 bg-border-subtle" />
|
||||||
href={href}
|
</Element>
|
||||||
role="menuitem"
|
|
||||||
onClick={onClose}
|
|
||||||
alignItems="items-center"
|
|
||||||
gap="gap-3"
|
|
||||||
className={ROW_CLASS}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</FlexBox>
|
|
||||||
) : (
|
|
||||||
<FlexBox
|
|
||||||
tag="button"
|
|
||||||
type="button"
|
|
||||||
role="menuitem"
|
|
||||||
onClick={() => {
|
|
||||||
onClose();
|
|
||||||
onSelect?.();
|
|
||||||
}}
|
|
||||||
alignItems="items-center"
|
|
||||||
gap="gap-3"
|
|
||||||
className={cn(ROW_CLASS, 'w-full cursor-pointer text-start')}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</FlexBox>
|
|
||||||
)}
|
)}
|
||||||
</Element>
|
<Element tag="li" role="none">
|
||||||
|
{href != null ? (
|
||||||
|
<FlexBox
|
||||||
|
tag={NextLink}
|
||||||
|
href={href}
|
||||||
|
role="menuitem"
|
||||||
|
onClick={onClose}
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-3"
|
||||||
|
className={rowClass}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
) : (
|
||||||
|
<FlexBox
|
||||||
|
tag="button"
|
||||||
|
type="button"
|
||||||
|
role="menuitem"
|
||||||
|
onClick={() => {
|
||||||
|
onClose();
|
||||||
|
onSelect?.();
|
||||||
|
}}
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-3"
|
||||||
|
className={cn(rowClass, 'cursor-pointer')}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
</Element>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
import type { IconName } from '../../atoms/icon';
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
|
||||||
/** A destination (`href`, a link) or an action (`onSelect`, a button), never both. */
|
/** A destination (`href`, a link) or an action (`onSelect`, a button), never both. */
|
||||||
export type ActionMenuItem = {
|
export type ActionMenuItem = {
|
||||||
label: string;
|
label: string;
|
||||||
icon: IconName;
|
icon: IconName;
|
||||||
|
/** danger: a destructive choice in red, such as «خروج از حساب». */
|
||||||
|
tone?: 'default' | 'danger';
|
||||||
|
/** A hairline above the item, which starts a new group, such as sign-out under the links. */
|
||||||
|
separatorBefore?: boolean;
|
||||||
} & (
|
} & (
|
||||||
| { href: string; onSelect?: never }
|
| { href: string; onSelect?: never }
|
||||||
| {
|
| {
|
||||||
|
|
@ -20,6 +26,11 @@ export type ActionMenuProps = {
|
||||||
items: readonly ActionMenuItem[];
|
items: readonly ActionMenuItem[];
|
||||||
/** The menu's accessible name, such as «انتشار». */
|
/** The menu's accessible name, such as «انتشار». */
|
||||||
label: string;
|
label: string;
|
||||||
|
/**
|
||||||
|
* Shown above the items over a hairline, never focused: who the menu belongs to, such as the
|
||||||
|
* account's avatar, name and @username.
|
||||||
|
*/
|
||||||
|
header?: ReactNode;
|
||||||
/** above: over a bottom-nav button. below: under a header button. */
|
/** above: over a bottom-nav button. below: under a header button. */
|
||||||
placement?: 'above' | 'below';
|
placement?: 'above' | 'below';
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
/** A card that hangs off its trigger: centred over it, or under it at the inline end. */
|
/** A card that hangs off its trigger: centred over it, or under it at the inline end. */
|
||||||
export const actionMenuVariants = cva(
|
export const actionMenuVariants = cva(
|
||||||
'absolute z-menu m-0 min-w-55 rounded-lg border border-border-subtle bg-surface-raised p-1 shadow-2',
|
'absolute z-menu min-w-55 rounded-lg border border-border-subtle bg-surface-raised p-1.5 shadow-2',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
placement: {
|
placement: {
|
||||||
|
|
@ -13,3 +13,28 @@ export const actionMenuVariants = cva(
|
||||||
defaultVariants: { placement: 'below' },
|
defaultVariants: { placement: 'below' },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** A 48px row, 16/600; a link row and a button row look the same. */
|
||||||
|
export const actionMenuItemVariants = cva(
|
||||||
|
'min-h-12 w-full rounded-md px-3 text-start no-underline outline-none hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:focus-ring',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
default: 'text-text-primary',
|
||||||
|
danger: 'text-danger-text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'default' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The item's icon: the brand colour, or red on a danger item. */
|
||||||
|
export const actionMenuIconVariants = cva('flex-none', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
default: 'text-action-primary-text',
|
||||||
|
danger: 'text-danger-text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'default' },
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
import { number } from '@lumina/tools/format';
|
||||||
|
import NextLink from 'next/link';
|
||||||
|
|
||||||
|
import { Avatar } from '../../atoms/avatar';
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { GridBox } from '../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { AvatarStackProps } from './types';
|
||||||
|
import { avatarStackFaceVariants, avatarStackVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overlapping 32px avatars with «+N» for the rest (DS AvatarStack). With a `title` it is the strip
|
||||||
|
* on خانه, «تحلیلگران منتخب», and with `href` the whole strip is a link.
|
||||||
|
*/
|
||||||
|
export function AvatarStack({
|
||||||
|
avatars,
|
||||||
|
max = 4,
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
href,
|
||||||
|
label,
|
||||||
|
className,
|
||||||
|
}: AvatarStackProps) {
|
||||||
|
const shown = avatars.slice(0, max);
|
||||||
|
const rest = avatars.length - shown.length;
|
||||||
|
const strip = title != null;
|
||||||
|
|
||||||
|
const faces = (
|
||||||
|
<FlexBox
|
||||||
|
tag="span"
|
||||||
|
display="inline-flex"
|
||||||
|
alignItems="items-center"
|
||||||
|
role={!strip && label ? 'img' : undefined}
|
||||||
|
aria-label={!strip ? label : undefined}
|
||||||
|
aria-hidden={strip || !label ? true : undefined}
|
||||||
|
className={cn('flex-none', !strip && className)}
|
||||||
|
>
|
||||||
|
{shown.map((avatar, index) => (
|
||||||
|
<Avatar
|
||||||
|
key={avatar.name}
|
||||||
|
name={avatar.name}
|
||||||
|
src={avatar.src}
|
||||||
|
size="sm"
|
||||||
|
className={avatarStackFaceVariants({ overlap: index > 0 })}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{rest > 0 && (
|
||||||
|
<GridBox
|
||||||
|
tag="span"
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className={cn(
|
||||||
|
avatarStackFaceVariants({ overlap: shown.length > 0 }),
|
||||||
|
'size-8 bg-surface-sunken text-text-secondary',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
tag="bdi"
|
||||||
|
dir="ltr"
|
||||||
|
variant="micro"
|
||||||
|
color="inherit"
|
||||||
|
className="font-semibold"
|
||||||
|
>
|
||||||
|
{`+${number(rest)}`}
|
||||||
|
</Typography>
|
||||||
|
</GridBox>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!strip) return faces;
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
<>
|
||||||
|
{faces}
|
||||||
|
<FlexBox tag="span" direction="flex-col" className="min-w-0 flex-1">
|
||||||
|
<Typography tag="span" className="font-semibold">
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{subtitle != null && (
|
||||||
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
|
{subtitle}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
{href && (
|
||||||
|
<Icon name="chevron-left" size={20} className="text-text-tertiary" />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
const classes = cn(
|
||||||
|
avatarStackVariants({ strip: true, link: href != null }),
|
||||||
|
className,
|
||||||
|
);
|
||||||
|
|
||||||
|
return href ? (
|
||||||
|
<FlexBox
|
||||||
|
tag={NextLink}
|
||||||
|
href={href}
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-3"
|
||||||
|
className={classes}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
) : (
|
||||||
|
<FlexBox alignItems="items-center" gap="gap-3" className={classes}>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { AvatarStack } from './AvatarStack';
|
||||||
|
export type { AvatarStackItem, AvatarStackProps } from './types';
|
||||||
|
export { avatarStackFaceVariants, avatarStackVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
export type AvatarStackItem = {
|
||||||
|
/** The username: unique in the stack, and the placeholder's letter. */
|
||||||
|
name: string;
|
||||||
|
src?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AvatarStackProps = {
|
||||||
|
/** In order; the first `max` show, the rest count as «+N». */
|
||||||
|
avatars: readonly AvatarStackItem[];
|
||||||
|
/** 4 by default. */
|
||||||
|
max?: number;
|
||||||
|
/** Makes it the DS strip, such as «تحلیلگران منتخب». */
|
||||||
|
title?: ReactNode;
|
||||||
|
/** Under the title, such as «۱۲ تحلیلگر فعال». */
|
||||||
|
subtitle?: ReactNode;
|
||||||
|
/** The strip opens this page, with a chevron. */
|
||||||
|
href?: string;
|
||||||
|
/** The faces' accessible name when there is no title, such as «۵ مشترک». */
|
||||||
|
label?: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With a title, the DS AvatarStack strip: a bordered radius-lg row, at least 56px, that opens a
|
||||||
|
* list as a link. Without one, only the faces.
|
||||||
|
*/
|
||||||
|
export const avatarStackVariants = cva('min-w-0', {
|
||||||
|
variants: {
|
||||||
|
strip: {
|
||||||
|
true: 'min-h-14 rounded-lg border border-border-subtle bg-surface px-4 py-2 text-text-primary no-underline',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
true: 'transition-[border-color,box-shadow] duration-120 ease-standard focus-visible:focus-ring hover:border-border-strong hover:shadow-1',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { strip: false, link: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
/** One 32px face, ringed in the surface so overlapping faces stay apart; each after the first tucks 10px under. */
|
||||||
|
export const avatarStackFaceVariants = cva('rounded-full ring-2 ring-surface', {
|
||||||
|
variants: {
|
||||||
|
overlap: { true: '-ms-2.5', false: '' },
|
||||||
|
},
|
||||||
|
defaultVariants: { overlap: false },
|
||||||
|
});
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { useId } from 'react';
|
import { useId } from 'react';
|
||||||
|
|
||||||
import { Chip } from '../../atoms/chip';
|
import { Chip, chipRowVariants } from '../../atoms/chip';
|
||||||
import { FieldError } from '../../atoms/field-error';
|
import { FieldError } from '../../atoms/field-error';
|
||||||
import { FlexBox } from '../../atoms/flex-box';
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
import type { ChipGroupProps } from './types';
|
import type { ChipGroupProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,6 +17,7 @@ export function ChipGroup<T extends string>({
|
||||||
label,
|
label,
|
||||||
error,
|
error,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
|
scroll = false,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
ref,
|
ref,
|
||||||
className,
|
className,
|
||||||
|
|
@ -31,15 +33,19 @@ export function ChipGroup<T extends string>({
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
aria-describedby={hasError ? errorId : undefined}
|
aria-describedby={hasError ? errorId : undefined}
|
||||||
wrap="flex-wrap"
|
wrap={scroll ? 'flex-nowrap' : 'flex-wrap'}
|
||||||
gap="gap-2"
|
gap="gap-2"
|
||||||
className="rounded-md outline-none"
|
className={cn(
|
||||||
|
'min-w-0 rounded-md outline-none',
|
||||||
|
chipRowVariants({ scroll }),
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
<Chip
|
<Chip
|
||||||
key={option.value}
|
key={option.value}
|
||||||
size={size}
|
size={size}
|
||||||
selected={value.includes(option.value)}
|
selected={value.includes(option.value)}
|
||||||
|
className="flex-none"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={() => onToggle(option.value)}
|
onClick={() => onToggle(option.value)}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ export type ChipGroupProps<T extends string> = {
|
||||||
/** Under the chips, such as «انتخاب حداقل یک تخصص الزامی است.». */
|
/** Under the chips, such as «انتخاب حداقل یک تخصص الزامی است.». */
|
||||||
error?: ReactNode;
|
error?: ReactNode;
|
||||||
size?: ChipSize;
|
size?: ChipSize;
|
||||||
|
/** One row that scrolls sideways instead of wrapping. */
|
||||||
|
scroll?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
/** Reaches the fieldset, which takes focus (and scrolls into view) for a form error. */
|
/** Reaches the fieldset, which takes focus (and scrolls into view) for a form error. */
|
||||||
ref?: Ref<HTMLFieldSetElement>;
|
ref?: Ref<HTMLFieldSetElement>;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useId, useState } 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 { textInputBoxVariants, textInputControlVariants } from '../text-input';
|
||||||
|
import { CODE_INPUT_BOX_STATE } from './constants';
|
||||||
|
import type { CodeInputProps } from './types';
|
||||||
|
import { codeInputButtonVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An invite code with its own «ثبت» (DS CodeInput): left to right, the button checks the code and
|
||||||
|
* so does Enter, which never submits the outer form. Checking locks the field with a spinner;
|
||||||
|
* a valid code turns green and read-only, and the button becomes «تغییر». The status and every
|
||||||
|
* text come from the caller.
|
||||||
|
*/
|
||||||
|
export function CodeInput({
|
||||||
|
label,
|
||||||
|
labels,
|
||||||
|
status = 'idle',
|
||||||
|
source = 'typed',
|
||||||
|
value,
|
||||||
|
defaultValue = '',
|
||||||
|
onValueChange,
|
||||||
|
onCheck,
|
||||||
|
onEdit,
|
||||||
|
onBlur,
|
||||||
|
hint,
|
||||||
|
message,
|
||||||
|
placeholder,
|
||||||
|
frozen = false,
|
||||||
|
ref,
|
||||||
|
id: idProp,
|
||||||
|
name,
|
||||||
|
className,
|
||||||
|
}: CodeInputProps) {
|
||||||
|
const autoId = useId();
|
||||||
|
const id = idProp ?? autoId;
|
||||||
|
const messageId = `${id}-message`;
|
||||||
|
const [ownValue, setOwnValue] = useState(defaultValue);
|
||||||
|
const code = (value ?? ownValue).trim();
|
||||||
|
const isValid = status === 'valid';
|
||||||
|
const isChecking = status === 'checking';
|
||||||
|
const isLocked = status === 'locked';
|
||||||
|
const isError = status === 'invalid' || status === 'error';
|
||||||
|
const isFixed = isValid || isChecking || isLocked;
|
||||||
|
|
||||||
|
const shown =
|
||||||
|
message ??
|
||||||
|
(isValid && source === 'link'
|
||||||
|
? (labels.validFromLink ?? labels.valid)
|
||||||
|
: status === 'idle'
|
||||||
|
? hint
|
||||||
|
: labels[status]);
|
||||||
|
|
||||||
|
const check = () => {
|
||||||
|
if (!isFixed && !frozen && code !== '') onCheck(code);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
direction="flex-col"
|
||||||
|
gap="gap-2"
|
||||||
|
className={cn('min-w-0', className)}
|
||||||
|
>
|
||||||
|
<Typography tag="label" variant="label" htmlFor={id}>
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
<FlexBox alignItems="items-stretch" gap="gap-2">
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-2"
|
||||||
|
dir="ltr"
|
||||||
|
className={cn(
|
||||||
|
textInputBoxVariants({
|
||||||
|
state: CODE_INPUT_BOX_STATE[status],
|
||||||
|
frozen,
|
||||||
|
}),
|
||||||
|
'min-w-0 flex-1',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Element
|
||||||
|
tag="input"
|
||||||
|
ref={ref}
|
||||||
|
id={id}
|
||||||
|
name={name}
|
||||||
|
type="text"
|
||||||
|
dir="ltr"
|
||||||
|
value={value ?? ownValue}
|
||||||
|
placeholder={placeholder}
|
||||||
|
readOnly={isFixed}
|
||||||
|
disabled={frozen}
|
||||||
|
autoComplete="off"
|
||||||
|
autoCapitalize="characters"
|
||||||
|
spellCheck={false}
|
||||||
|
enterKeyHint="done"
|
||||||
|
aria-invalid={isError || undefined}
|
||||||
|
aria-describedby={shown != null ? messageId : undefined}
|
||||||
|
onChange={(event) => {
|
||||||
|
if (value === undefined) setOwnValue(event.target.value);
|
||||||
|
onValueChange?.(event.target.value);
|
||||||
|
}}
|
||||||
|
onBlur={() => onBlur?.(code)}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key !== 'Enter') return;
|
||||||
|
event.preventDefault();
|
||||||
|
check();
|
||||||
|
}}
|
||||||
|
className={textInputControlVariants({
|
||||||
|
ltr: true,
|
||||||
|
locked: isChecking || isLocked,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
{isValid ? (
|
||||||
|
<Icon name="check-circle" className="text-success-text" />
|
||||||
|
) : isError ? (
|
||||||
|
<Icon name="alert" className="text-danger" />
|
||||||
|
) : isLocked ? (
|
||||||
|
<Icon name="lock" size={18} className="text-text-secondary" />
|
||||||
|
) : null}
|
||||||
|
</FlexBox>
|
||||||
|
{isValid ? (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
frozen={frozen || !onEdit}
|
||||||
|
onClick={onEdit}
|
||||||
|
className={codeInputButtonVariants()}
|
||||||
|
>
|
||||||
|
{labels.change}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
!isLocked && (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
isLoading={isChecking}
|
||||||
|
frozen={frozen || (code === '' && !isChecking)}
|
||||||
|
onClick={check}
|
||||||
|
className={codeInputButtonVariants()}
|
||||||
|
>
|
||||||
|
{labels.check}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
{shown != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="caption"
|
||||||
|
id={messageId}
|
||||||
|
role={isError ? 'alert' : status !== 'idle' ? 'status' : undefined}
|
||||||
|
color={isError ? 'danger' : isValid ? 'success' : 'secondary'}
|
||||||
|
>
|
||||||
|
{shown}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import type { CodeInputStatus } from './types';
|
||||||
|
|
||||||
|
/** The box's frame for each status (TextInput's box states). */
|
||||||
|
export const CODE_INPUT_BOX_STATE = {
|
||||||
|
idle: 'default',
|
||||||
|
checking: 'locked',
|
||||||
|
valid: 'valid',
|
||||||
|
invalid: 'invalid',
|
||||||
|
error: 'invalid',
|
||||||
|
locked: 'locked',
|
||||||
|
} as const satisfies Record<CodeInputStatus, string>;
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
export { CodeInput } from './CodeInput';
|
||||||
|
export type {
|
||||||
|
CodeInputLabels,
|
||||||
|
CodeInputProps,
|
||||||
|
CodeInputSource,
|
||||||
|
CodeInputStatus,
|
||||||
|
} from './types';
|
||||||
|
export { codeInputButtonVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
import type { ReactNode, Ref } from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* idle: typed, not checked. checking: «ثبت» was pressed. valid: accepted, read-only until «تغییر».
|
||||||
|
* invalid: the code doesn't exist. error: the check failed. locked: fixed for this flow.
|
||||||
|
*/
|
||||||
|
export type CodeInputStatus =
|
||||||
|
| 'idle'
|
||||||
|
| 'checking'
|
||||||
|
| 'valid'
|
||||||
|
| 'invalid'
|
||||||
|
| 'error'
|
||||||
|
| 'locked';
|
||||||
|
|
||||||
|
/** Where the code came from: typed here, or applied from an invite link. */
|
||||||
|
export type CodeInputSource = 'typed' | 'link';
|
||||||
|
|
||||||
|
/** Every text the field shows, from the translations. A state without its text shows none. */
|
||||||
|
export type CodeInputLabels = {
|
||||||
|
/** The button that checks the code: «ثبت». */
|
||||||
|
check: ReactNode;
|
||||||
|
/** The button on a valid code that unlocks the field: «تغییر». */
|
||||||
|
change: ReactNode;
|
||||||
|
/** «در حال بررسی کد…». */
|
||||||
|
checking?: ReactNode;
|
||||||
|
/** «کد دعوت معتبر است.». */
|
||||||
|
valid?: ReactNode;
|
||||||
|
/** A valid code from an invite link: «کد دعوت از لینک دعوت اعمال شد.». */
|
||||||
|
validFromLink?: ReactNode;
|
||||||
|
/** «کد دعوت واردشده معتبر نیست.». */
|
||||||
|
invalid?: ReactNode;
|
||||||
|
/** «بررسی کد انجام نشد. دوباره «ثبت» را بزنید.». */
|
||||||
|
error?: ReactNode;
|
||||||
|
/** Why a locked code can't change. */
|
||||||
|
locked?: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CodeInputProps = {
|
||||||
|
/** «کد دعوت». */
|
||||||
|
label: ReactNode;
|
||||||
|
labels: CodeInputLabels;
|
||||||
|
status?: CodeInputStatus;
|
||||||
|
source?: CodeInputSource;
|
||||||
|
/** Controlled: the code now. Leave it out to let the field keep its own. */
|
||||||
|
value?: string;
|
||||||
|
defaultValue?: string;
|
||||||
|
onValueChange?: (value: string) => void;
|
||||||
|
/** «ثبت» or Enter, with the trimmed code; never while checking, valid, locked or empty. */
|
||||||
|
onCheck: (code: string) => void;
|
||||||
|
/** «تغییر» on a valid code: the caller sets the status back to idle. */
|
||||||
|
onEdit?: () => void;
|
||||||
|
/** Leaving the field, with the trimmed code, such as for a quiet check. */
|
||||||
|
onBlur?: (code: string) => void;
|
||||||
|
/** Under the field while idle. */
|
||||||
|
hint?: ReactNode;
|
||||||
|
/** Replaces the status's text. */
|
||||||
|
message?: ReactNode;
|
||||||
|
placeholder?: string;
|
||||||
|
/** Visible but unusable now, at 40%. */
|
||||||
|
frozen?: boolean;
|
||||||
|
/** Reaches the input, such as react-hook-form's field ref. */
|
||||||
|
ref?: Ref<HTMLInputElement>;
|
||||||
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** «ثبت» and «تغییر» as tall as the field beside them (48px). */
|
||||||
|
export const codeInputButtonVariants = cva('min-h-input-height flex-none');
|
||||||
|
|
@ -1,29 +1,66 @@
|
||||||
|
import { Button } from '../../atoms/button';
|
||||||
import { FlexBox } from '../../atoms/flex-box';
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
import { Typography } from '../../atoms/typography';
|
import { Typography } from '../../atoms/typography';
|
||||||
import { Element } from '../../primitives/element';
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
import type { DetailRowProps } from './types';
|
import type { DetailRowProps } from './types';
|
||||||
import { detailRowVariants } from './variants';
|
import { detailRowVariants, detailValueVariants } from './variants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One line of a `<dl>`, such as a receipt or a payment's detail: the label at the start, its
|
* One line of a `<dl>` (DS KV), such as a receipt or a payment's detail: the key at the start in
|
||||||
* value at the end, on one baseline.
|
* 13px secondary, its value at the end on one baseline. Put rows in a KeyValue for the DS group with
|
||||||
|
* hairlines, or in any `dl`.
|
||||||
*/
|
*/
|
||||||
export function DetailRow({ label, children, size }: DetailRowProps) {
|
export function DetailRow({
|
||||||
|
label,
|
||||||
|
children,
|
||||||
|
size,
|
||||||
|
strong = false,
|
||||||
|
tone,
|
||||||
|
ltr = false,
|
||||||
|
copyLabel,
|
||||||
|
onCopy,
|
||||||
|
className,
|
||||||
|
}: DetailRowProps) {
|
||||||
return (
|
return (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
alignItems="items-baseline"
|
alignItems="items-baseline"
|
||||||
justifyContent="justify-between"
|
justifyContent="justify-between"
|
||||||
gap="gap-3"
|
gap="gap-3"
|
||||||
className={detailRowVariants({ size })}
|
className={cn(detailRowVariants({ size }), className)}
|
||||||
>
|
>
|
||||||
<Element tag="dt">
|
<Typography
|
||||||
<Typography tag="span" variant="body-sm" color="secondary">
|
tag="dt"
|
||||||
{label}
|
variant="caption"
|
||||||
</Typography>
|
color="secondary"
|
||||||
</Element>
|
className="max-w-1/2 flex-none"
|
||||||
<Element tag="dd" className="m-0 text-end font-semibold">
|
>
|
||||||
{children}
|
{label}
|
||||||
</Element>
|
</Typography>
|
||||||
|
<FlexBox
|
||||||
|
tag="dd"
|
||||||
|
alignItems="items-center"
|
||||||
|
justifyContent="justify-end"
|
||||||
|
wrap="flex-wrap"
|
||||||
|
className={cn(detailValueVariants({ strong, tone }), 'gap-1.5')}
|
||||||
|
>
|
||||||
|
{ltr ? (
|
||||||
|
<Element tag="bdi" dir="ltr">
|
||||||
|
{children}
|
||||||
|
</Element>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
{copyLabel && onCopy && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
icon="copy"
|
||||||
|
label={copyLabel}
|
||||||
|
onClick={onCopy}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export { DetailRow } from './DetailRow';
|
export { DetailRow } from './DetailRow';
|
||||||
export type { DetailRowProps } from './types';
|
export type { DetailRowProps, DetailRowTone } from './types';
|
||||||
export { detailRowVariants } from './variants';
|
export { detailRowVariants, detailValueVariants } from './variants';
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,29 @@
|
||||||
import type { VariantProps } from 'class-variance-authority';
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
import type { detailRowVariants } from './variants';
|
import type { detailRowVariants, detailValueVariants } from './variants';
|
||||||
|
|
||||||
|
export type DetailRowTone = NonNullable<
|
||||||
|
VariantProps<typeof detailValueVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
export type DetailRowProps = VariantProps<typeof detailRowVariants> & {
|
export type DetailRowProps = VariantProps<typeof detailRowVariants> & {
|
||||||
|
/** The key: 13/22 secondary, at most half the row. */
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
/** The value, at the end. */
|
/**
|
||||||
children: ReactNode;
|
* The value, at the end: text, an `Amount` or a `StatusBadge` (put the badge before the text
|
||||||
|
* when both show).
|
||||||
|
*/
|
||||||
|
children?: ReactNode;
|
||||||
|
/** 600 instead of regular, such as a total or the period bought. */
|
||||||
|
strong?: boolean;
|
||||||
|
/** A status hue for the value, always 600, such as «بازگشت داده شد» in success. */
|
||||||
|
tone?: DetailRowTone;
|
||||||
|
/** Left to right in its own isolate: a reference, a شبا, a username. */
|
||||||
|
ltr?: boolean;
|
||||||
|
/** Shows a ghost copy button after the value; its accessible name, such as «کپی کد پیگیری». */
|
||||||
|
copyLabel?: string;
|
||||||
|
/** Called by the copy button; copy and toast in the caller. */
|
||||||
|
onCopy?: () => void;
|
||||||
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import { cva } from 'class-variance-authority';
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
/** `sm` for a receipt card, `md` for a detail sheet's divided list. */
|
/**
|
||||||
export const detailRowVariants = cva('', {
|
* One key–value line (DS KV). `sm` for a receipt card, `md` (8px, the DS) for a detail sheet or a
|
||||||
|
* KeyValue group.
|
||||||
|
*/
|
||||||
|
export const detailRowVariants = cva('min-w-0', {
|
||||||
variants: {
|
variants: {
|
||||||
size: {
|
size: {
|
||||||
sm: 'py-1.5',
|
sm: 'py-1.5',
|
||||||
|
|
@ -10,3 +13,23 @@ export const detailRowVariants = cva('', {
|
||||||
},
|
},
|
||||||
defaultVariants: { size: 'md' },
|
defaultVariants: { size: 'md' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value at the end, 15/26: regular unless `strong`; a status tone is always 600. Its parts
|
||||||
|
* (badge, value, copy) sit in one end-aligned row that wraps.
|
||||||
|
*/
|
||||||
|
export const detailValueVariants = cva(
|
||||||
|
'm-0 min-w-0 text-end text-[0.9375rem] leading-[1.625rem]',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
strong: { true: 'font-semibold', false: 'font-normal' },
|
||||||
|
tone: {
|
||||||
|
default: 'text-text-primary',
|
||||||
|
success: 'font-semibold text-success-text',
|
||||||
|
danger: 'font-semibold text-danger-text',
|
||||||
|
warning: 'font-semibold text-warning-text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { strong: false, tone: 'default' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,10 @@ import type { FileFieldProps } from './types';
|
||||||
import { fileDropVariants, filePickedVariants } from './variants';
|
import { fileDropVariants, filePickedVariants } from './variants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One file to send with a form, such as a national ID card image. Empty, the whole dashed box
|
* One file to send with a form, such as a national ID card image (DS UploadTile). Empty, the whole
|
||||||
* opens the picker; picked, it shows a thumbnail (for images), the name and the size with a
|
* dashed box opens the picker; picked, an image shows whole above its name and size, with
|
||||||
* remove button; uploading, a bar with the percent replaces remove. The file stays in memory.
|
* «تغییر تصویر» (`labels.change`) and remove; uploading, a bar with the percent replaces them. The
|
||||||
|
* file stays in memory.
|
||||||
*/
|
*/
|
||||||
export function FileField({
|
export function FileField({
|
||||||
label,
|
label,
|
||||||
|
|
@ -39,6 +40,15 @@ export function FileField({
|
||||||
const messageId = `${id}-message`;
|
const messageId = `${id}-message`;
|
||||||
const isInvalid = error != null && error !== false;
|
const isInvalid = error != null && error !== false;
|
||||||
const isUploading = progress !== undefined;
|
const isUploading = progress !== undefined;
|
||||||
|
const isImage = file?.type.startsWith('image/') ?? false;
|
||||||
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
// The input stays mounted, so «تغییر تصویر» can open it; the form's ref reaches it too.
|
||||||
|
const attachInput = (node: HTMLInputElement | null) => {
|
||||||
|
inputRef.current = node;
|
||||||
|
if (typeof ref === 'function') ref(node);
|
||||||
|
else if (ref) ref.current = node;
|
||||||
|
};
|
||||||
|
|
||||||
const pick = (event: ChangeEvent<HTMLInputElement>) => {
|
const pick = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
onChange(event.target.files?.[0] ?? null);
|
onChange(event.target.files?.[0] ?? null);
|
||||||
|
|
@ -55,62 +65,97 @@ export function FileField({
|
||||||
<Typography tag="span" variant="label" id={`${id}-label`}>
|
<Typography tag="span" variant="label" id={`${id}-label`}>
|
||||||
{label}
|
{label}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Element
|
||||||
|
tag="input"
|
||||||
|
ref={attachInput}
|
||||||
|
type="file"
|
||||||
|
id={id}
|
||||||
|
name={name}
|
||||||
|
accept={accept}
|
||||||
|
disabled={disabled}
|
||||||
|
// Picked, the change button opens it; it leaves the tab order.
|
||||||
|
tabIndex={file ? -1 : undefined}
|
||||||
|
onChange={pick}
|
||||||
|
onBlur={onBlur}
|
||||||
|
aria-labelledby={`${id}-label`}
|
||||||
|
aria-invalid={isInvalid || undefined}
|
||||||
|
aria-describedby={isInvalid || hint != null ? messageId : undefined}
|
||||||
|
className="peer sr-only"
|
||||||
|
/>
|
||||||
{file ? (
|
{file ? (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
alignItems="items-center"
|
direction="flex-col"
|
||||||
gap="gap-3"
|
gap="gap-2"
|
||||||
className={filePickedVariants({ invalid: isInvalid })}
|
className={filePickedVariants({ invalid: isInvalid })}
|
||||||
>
|
>
|
||||||
{file.type.startsWith('image/') ? (
|
{isImage && <Preview file={file} />}
|
||||||
<Thumbnail file={file} />
|
<FlexBox alignItems="items-center" gap="gap-3" className="ps-2">
|
||||||
) : (
|
{!isImage && (
|
||||||
<Icon
|
<Icon
|
||||||
name="upload"
|
name="file"
|
||||||
size={24}
|
size={24}
|
||||||
className="flex-none text-text-secondary"
|
className="flex-none text-text-secondary"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<FlexBox direction="flex-col" gap="gap-1" className="min-w-0 flex-1">
|
<FlexBox
|
||||||
<Typography
|
direction="flex-col"
|
||||||
tag="span"
|
gap="gap-1"
|
||||||
variant="body-sm"
|
className="min-w-0 flex-1"
|
||||||
dir="ltr"
|
|
||||||
className="truncate text-start font-semibold"
|
|
||||||
>
|
>
|
||||||
{file.name}
|
<Typography
|
||||||
</Typography>
|
tag="span"
|
||||||
{isUploading ? (
|
variant="body-sm"
|
||||||
<>
|
dir="ltr"
|
||||||
<Element
|
className="truncate text-start font-semibold"
|
||||||
tag="progress"
|
>
|
||||||
value={progress}
|
{file.name}
|
||||||
max={100}
|
</Typography>
|
||||||
aria-labelledby={`${id}-label`}
|
{isUploading ? (
|
||||||
className="h-1 w-full appearance-none overflow-hidden rounded-full bg-surface-sunken [&::-moz-progress-bar]:bg-action-primary [&::-webkit-progress-bar]:bg-surface-sunken [&::-webkit-progress-value]:bg-action-primary"
|
<>
|
||||||
/>
|
<Element
|
||||||
{labels.uploading && (
|
tag="progress"
|
||||||
|
value={progress}
|
||||||
|
max={100}
|
||||||
|
aria-labelledby={`${id}-label`}
|
||||||
|
className="h-2 w-full appearance-none overflow-hidden rounded-full bg-surface-sunken [&::-moz-progress-bar]:bg-action-primary [&::-webkit-progress-bar]:bg-surface-sunken [&::-webkit-progress-value]:bg-action-primary"
|
||||||
|
/>
|
||||||
|
{labels.uploading && (
|
||||||
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
|
{labels.uploading(progress)}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
size != null && (
|
||||||
<Typography tag="span" variant="caption" color="secondary">
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
{labels.uploading(progress)}
|
{size}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)
|
||||||
</>
|
)}
|
||||||
) : (
|
</FlexBox>
|
||||||
size != null && (
|
{!isUploading && labels.change != null && (
|
||||||
<Typography tag="span" variant="caption" color="secondary">
|
<Button
|
||||||
{size}
|
variant="secondary"
|
||||||
</Typography>
|
size="sm"
|
||||||
)
|
icon="refresh"
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => inputRef.current?.click()}
|
||||||
|
className="flex-none"
|
||||||
|
>
|
||||||
|
{labels.change}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{!isUploading && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
icon="trash"
|
||||||
|
label={labels.remove}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => onChange(null)}
|
||||||
|
className="flex-none"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
{!isUploading && (
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
icon="trash"
|
|
||||||
label={labels.remove}
|
|
||||||
disabled={disabled}
|
|
||||||
onClick={() => onChange(null)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
) : (
|
) : (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
|
|
@ -119,31 +164,22 @@ export function FileField({
|
||||||
direction="flex-col"
|
direction="flex-col"
|
||||||
alignItems="items-center"
|
alignItems="items-center"
|
||||||
justifyContent="justify-center"
|
justifyContent="justify-center"
|
||||||
gap="gap-1"
|
className={cn(
|
||||||
className={fileDropVariants({ invalid: isInvalid, disabled })}
|
fileDropVariants({ invalid: isInvalid, disabled }),
|
||||||
|
'gap-1.5',
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<Icon name="upload" size={24} className="text-text-secondary" />
|
<Icon name="upload" size={28} className="text-text-secondary" />
|
||||||
<Typography tag="span" variant="label" color="link">
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="inherit"
|
||||||
|
className="text-[0.9375rem] leading-6 font-semibold"
|
||||||
|
>
|
||||||
{labels.pick}
|
{labels.pick}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography tag="span" variant="caption" color="secondary">
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
{labels.rules}
|
{labels.rules}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Element
|
|
||||||
tag="input"
|
|
||||||
ref={ref}
|
|
||||||
type="file"
|
|
||||||
id={id}
|
|
||||||
name={name}
|
|
||||||
accept={accept}
|
|
||||||
disabled={disabled}
|
|
||||||
onChange={pick}
|
|
||||||
onBlur={onBlur}
|
|
||||||
aria-labelledby={`${id}-label`}
|
|
||||||
aria-invalid={isInvalid || undefined}
|
|
||||||
aria-describedby={isInvalid || hint != null ? messageId : undefined}
|
|
||||||
className="sr-only"
|
|
||||||
/>
|
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
)}
|
)}
|
||||||
{isInvalid && error !== true ? (
|
{isInvalid && error !== true ? (
|
||||||
|
|
@ -175,8 +211,11 @@ export function FileField({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An image file's thumbnail from an object URL, revoked when the file changes or leaves. */
|
/**
|
||||||
function Thumbnail({ file }: { file: File }) {
|
* An image file shown whole, at most 220px tall, from an object URL revoked when the file changes
|
||||||
|
* or leaves.
|
||||||
|
*/
|
||||||
|
function Preview({ file }: { file: File }) {
|
||||||
const ref = useRef<HTMLImageElement>(null);
|
const ref = useRef<HTMLImageElement>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const url = URL.createObjectURL(file);
|
const url = URL.createObjectURL(file);
|
||||||
|
|
@ -188,7 +227,7 @@ function Thumbnail({ file }: { file: File }) {
|
||||||
tag="img"
|
tag="img"
|
||||||
ref={ref}
|
ref={ref}
|
||||||
alt=""
|
alt=""
|
||||||
className="size-12 flex-none rounded-sm bg-surface-sunken object-cover"
|
className="max-h-55 w-full rounded-md bg-surface-sunken object-cover"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ export type FileFieldLabels = {
|
||||||
rules: ReactNode;
|
rules: ReactNode;
|
||||||
/** The remove button's accessible name: «حذف تصویر». */
|
/** The remove button's accessible name: «حذف تصویر». */
|
||||||
remove: string;
|
remove: string;
|
||||||
|
/** Shows a button on the picked file that picks another: «تغییر تصویر». */
|
||||||
|
change?: ReactNode;
|
||||||
/** While uploading, given the percent: «در حال بارگذاری… ۶۴٪». */
|
/** While uploading, given the percent: «در حال بارگذاری… ۶۴٪». */
|
||||||
uploading?: (percent: number) => ReactNode;
|
uploading?: (percent: number) => ReactNode;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import { cva } from 'class-variance-authority';
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
/** The empty box: the whole box is the picker's label, so it is one large target. */
|
/**
|
||||||
|
* The empty box (DS UploadTile): 140px, a 1.5px dashed outline on surface. The whole box is the
|
||||||
|
* picker's label, so it is one large target; it shows the hidden input's keyboard focus.
|
||||||
|
*/
|
||||||
export const fileDropVariants = cva(
|
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',
|
'min-h-35 rounded-lg border-[1.5px] border-dashed bg-surface p-4 text-center transition-colors duration-120 ease-standard peer-focus-visible:focus-ring',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
invalid: {
|
invalid: {
|
||||||
|
|
@ -16,12 +19,15 @@ export const fileDropVariants = cva(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
/** The picked file's row: thumbnail, name and size, then remove or the upload bar. */
|
/**
|
||||||
|
* The picked file (DS UploadTile `done`): a solid hairline frame with an image's whole preview,
|
||||||
|
* then its name and size with «تغییر تصویر» and remove, or the upload bar.
|
||||||
|
*/
|
||||||
export const filePickedVariants = cva(
|
export const filePickedVariants = cva(
|
||||||
'min-h-18 rounded-md border bg-surface p-3',
|
'min-h-18 rounded-lg border bg-surface p-2',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
invalid: { true: 'border-danger', false: 'border-border-default' },
|
invalid: { true: 'border-danger', false: 'border-border-subtle' },
|
||||||
},
|
},
|
||||||
defaultVariants: { invalid: false },
|
defaultVariants: { invalid: false },
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useId } from 'react';
|
import { useId } from 'react';
|
||||||
|
|
||||||
import { chipVariants } from '../../atoms/chip';
|
import { chipRowVariants, chipVariants } from '../../atoms/chip';
|
||||||
import { FlexBox } from '../../atoms/flex-box';
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
import { Typography } from '../../atoms/typography';
|
import { Typography } from '../../atoms/typography';
|
||||||
import { Element } from '../../primitives/element';
|
import { Element } from '../../primitives/element';
|
||||||
|
|
@ -19,6 +19,7 @@ export function FilterChips<T extends string>({
|
||||||
onChange,
|
onChange,
|
||||||
label,
|
label,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
|
scroll = false,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
className,
|
className,
|
||||||
}: FilterChipsProps<T>) {
|
}: FilterChipsProps<T>) {
|
||||||
|
|
@ -30,9 +31,13 @@ export function FilterChips<T extends string>({
|
||||||
role="radiogroup"
|
role="radiogroup"
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
wrap="flex-wrap"
|
wrap={scroll ? 'flex-nowrap' : 'flex-wrap'}
|
||||||
gap="gap-2"
|
gap="gap-2"
|
||||||
className={cn('m-0 min-w-0 border-0 p-0', className)}
|
className={cn(
|
||||||
|
'm-0 min-w-0 border-0 p-0',
|
||||||
|
chipRowVariants({ scroll }),
|
||||||
|
className,
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
|
|
@ -42,7 +47,7 @@ export function FilterChips<T extends string>({
|
||||||
alignItems="items-center"
|
alignItems="items-center"
|
||||||
className={cn(
|
className={cn(
|
||||||
chipVariants({ selected: option.value === value, size }),
|
chipVariants({ selected: option.value === value, size }),
|
||||||
'relative has-[input:focus-visible]:focus-ring',
|
'relative flex-none has-[input:focus-visible]:focus-ring',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Element
|
<Element
|
||||||
|
|
@ -54,7 +59,7 @@ export function FilterChips<T extends string>({
|
||||||
onChange={() => onChange(option.value)}
|
onChange={() => onChange(option.value)}
|
||||||
className="pointer-events-none absolute m-0 size-px opacity-0"
|
className="pointer-events-none absolute m-0 size-px opacity-0"
|
||||||
/>
|
/>
|
||||||
<Typography tag="span" variant="label" color="inherit">
|
<Typography tag="span" variant="inherit" color="inherit">
|
||||||
{option.label}
|
{option.label}
|
||||||
</Typography>
|
</Typography>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ export type FilterChipsProps<T extends string> = {
|
||||||
label: string;
|
label: string;
|
||||||
/** `md` (44px) on a page, `sm` (36px) in a compact row. */
|
/** `md` (44px) on a page, `sm` (36px) in a compact row. */
|
||||||
size?: ChipSize;
|
size?: ChipSize;
|
||||||
|
/** One row that scrolls sideways instead of wrapping, such as a filter under a top bar. */
|
||||||
|
scroll?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { KeyValueProps } from './types';
|
||||||
|
import { keyValueVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A `dl` of DetailRows (DS KeyValue), such as a payment's receipt or a payout's detail: on its own,
|
||||||
|
* in a sunken block, or in a card, with hairlines between rows.
|
||||||
|
*/
|
||||||
|
export function KeyValue({
|
||||||
|
tone = 'plain',
|
||||||
|
lines = true,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: KeyValueProps) {
|
||||||
|
return (
|
||||||
|
<Element
|
||||||
|
tag="dl"
|
||||||
|
className={cn(
|
||||||
|
keyValueVariants({ tone, lines: lines && tone !== 'soft' }),
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Element>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { KeyValue } from './KeyValue';
|
||||||
|
export type { KeyValueProps, KeyValueTone } from './types';
|
||||||
|
export { keyValueVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ComponentPropsWithRef, ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { keyValueVariants } from './variants';
|
||||||
|
|
||||||
|
export type KeyValueTone = NonNullable<
|
||||||
|
VariantProps<typeof keyValueVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type KeyValueProps = Omit<ComponentPropsWithRef<'dl'>, 'children'> & {
|
||||||
|
/** `plain` (default), `soft` sunken (never with hairlines) or `card`. */
|
||||||
|
tone?: KeyValueTone;
|
||||||
|
/** Hairlines between rows; on by default, always off in `soft`. */
|
||||||
|
lines?: boolean;
|
||||||
|
/** DetailRows. */
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DS KeyValue group of DetailRows: `plain` on its own, `soft` a sunken block (no hairlines),
|
||||||
|
* `card` a bordered radius-lg surface. `lines` draws a hairline between rows.
|
||||||
|
*/
|
||||||
|
export const keyValueVariants = cva('m-0 min-w-0', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
plain: '',
|
||||||
|
soft: 'rounded-md bg-surface-sunken px-4 py-1',
|
||||||
|
card: 'rounded-lg border border-border-subtle bg-surface px-4 py-1',
|
||||||
|
},
|
||||||
|
lines: {
|
||||||
|
true: '[&>*+*]:border-t [&>*+*]:border-border-subtle',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'plain', lines: true },
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { ListProps } from './types';
|
||||||
|
import {
|
||||||
|
listHeaderVariants,
|
||||||
|
listItemsVariants,
|
||||||
|
listVariants,
|
||||||
|
} from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The grouped list that ListRows sit in: notifications, transactions, ledger lines, following, a
|
||||||
|
* plan's subscribers. A real `ul`, with a hairline between rows and an optional header strip
|
||||||
|
* inside the group. Name it with `aria-label` when no heading precedes it.
|
||||||
|
*/
|
||||||
|
export function List({
|
||||||
|
tone,
|
||||||
|
header,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: ListProps) {
|
||||||
|
if (header == null) {
|
||||||
|
return (
|
||||||
|
<Element
|
||||||
|
tag="ul"
|
||||||
|
className={cn(listVariants({ tone }), listItemsVariants(), className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Element>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
direction="flex-col"
|
||||||
|
className={cn(listVariants({ tone }), className)}
|
||||||
|
>
|
||||||
|
<Element className={listHeaderVariants()}>{header}</Element>
|
||||||
|
<Element tag="ul" className={listItemsVariants()} {...props}>
|
||||||
|
{children}
|
||||||
|
</Element>
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,174 @@
|
||||||
|
import NextLink from 'next/link';
|
||||||
|
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { GridBox } from '../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { ListRowProps } from './types';
|
||||||
|
import { listRowIconVariants, listRowVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One row of a List (DS ListRow): a lead (avatar or a 40px icon tile), the title with an optional
|
||||||
|
* subtitle and meta, an end column (an Amount, a StatusBadge, a caption) and a chevron for a link.
|
||||||
|
* With `href` the whole row is a link, with `onClick` a button (such as one that opens a detail
|
||||||
|
* sheet), otherwise a plain row. Renders its own `li`, so it always sits in a List. Every text
|
||||||
|
* comes from the caller.
|
||||||
|
*/
|
||||||
|
export function ListRow(props: ListRowProps) {
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
meta,
|
||||||
|
children,
|
||||||
|
leading,
|
||||||
|
icon,
|
||||||
|
iconTone,
|
||||||
|
end,
|
||||||
|
chevron,
|
||||||
|
unread = false,
|
||||||
|
unreadLabel,
|
||||||
|
dimmed = false,
|
||||||
|
disabled = false,
|
||||||
|
className,
|
||||||
|
} = props;
|
||||||
|
const hasSecondLine = subtitle != null || meta != null || children != null;
|
||||||
|
const showChevron = chevron ?? props.href !== undefined;
|
||||||
|
const classes = cn(
|
||||||
|
listRowVariants({
|
||||||
|
unread,
|
||||||
|
dimmed,
|
||||||
|
disabled,
|
||||||
|
interactive: props.href !== undefined || props.onClick !== undefined,
|
||||||
|
}),
|
||||||
|
className,
|
||||||
|
);
|
||||||
|
const layout = {
|
||||||
|
alignItems: hasSecondLine ? 'items-start' : 'items-center',
|
||||||
|
gap: 'gap-3',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
<>
|
||||||
|
{unread && (
|
||||||
|
<Element
|
||||||
|
tag="span"
|
||||||
|
role={unreadLabel ? 'img' : undefined}
|
||||||
|
aria-label={unreadLabel}
|
||||||
|
aria-hidden={unreadLabel ? undefined : true}
|
||||||
|
className="absolute start-1.5 top-4.5 size-1.5 rounded-full bg-action-primary"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{leading ??
|
||||||
|
(icon && (
|
||||||
|
<GridBox
|
||||||
|
tag="span"
|
||||||
|
aria-hidden
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className={listRowIconVariants({ tone: iconTone })}
|
||||||
|
>
|
||||||
|
<Icon name={icon} size={20} />
|
||||||
|
</GridBox>
|
||||||
|
))}
|
||||||
|
<FlexBox
|
||||||
|
tag="span"
|
||||||
|
direction="flex-col"
|
||||||
|
className="min-w-0 flex-1 gap-0.5"
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="inherit"
|
||||||
|
color="inherit"
|
||||||
|
className="text-[0.9375rem] leading-6 font-semibold"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{subtitle != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="body-sm"
|
||||||
|
color="secondary"
|
||||||
|
className="leading-[1.375rem]"
|
||||||
|
>
|
||||||
|
{subtitle}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
{meta != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="inherit"
|
||||||
|
color="tertiary"
|
||||||
|
className="text-[0.75rem] leading-5"
|
||||||
|
>
|
||||||
|
{meta}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
{end != null && (
|
||||||
|
<FlexBox
|
||||||
|
tag="span"
|
||||||
|
direction="flex-col"
|
||||||
|
alignItems="items-end"
|
||||||
|
gap="gap-1"
|
||||||
|
className="flex-none"
|
||||||
|
>
|
||||||
|
{end}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
{showChevron && (
|
||||||
|
<Icon
|
||||||
|
name="chevron-left"
|
||||||
|
size={20}
|
||||||
|
className="self-center text-text-tertiary"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
let row;
|
||||||
|
if (props.href !== undefined && !disabled) {
|
||||||
|
row = (
|
||||||
|
<FlexBox
|
||||||
|
tag={NextLink}
|
||||||
|
href={props.href}
|
||||||
|
onClick={props.onClick}
|
||||||
|
{...layout}
|
||||||
|
className={classes}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
} else if (props.href === undefined && props.onClick !== undefined) {
|
||||||
|
row = (
|
||||||
|
<FlexBox
|
||||||
|
tag="button"
|
||||||
|
type="button"
|
||||||
|
onClick={props.onClick}
|
||||||
|
disabled={disabled}
|
||||||
|
{...layout}
|
||||||
|
className={classes}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
row = (
|
||||||
|
<FlexBox
|
||||||
|
aria-disabled={disabled || undefined}
|
||||||
|
{...layout}
|
||||||
|
className={classes}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Element tag="li" className="min-w-0">
|
||||||
|
{row}
|
||||||
|
</Element>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
export { List } from './List';
|
||||||
|
export { ListRow } from './ListRow';
|
||||||
|
export type {
|
||||||
|
ListProps,
|
||||||
|
ListRowAsButtonProps,
|
||||||
|
ListRowAsLinkProps,
|
||||||
|
ListRowIconTone,
|
||||||
|
ListRowProps,
|
||||||
|
ListTone,
|
||||||
|
} from './types';
|
||||||
|
export {
|
||||||
|
listHeaderVariants,
|
||||||
|
listItemsVariants,
|
||||||
|
listRowIconVariants,
|
||||||
|
listRowVariants,
|
||||||
|
listVariants,
|
||||||
|
} from './variants';
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ComponentPropsWithRef, MouseEvent, ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
import type { listRowIconVariants, listVariants } from './variants';
|
||||||
|
|
||||||
|
export type ListTone = NonNullable<VariantProps<typeof listVariants>['tone']>;
|
||||||
|
|
||||||
|
export type ListRowIconTone = NonNullable<
|
||||||
|
VariantProps<typeof listRowIconVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type ListProps = Omit<ComponentPropsWithRef<'ul'>, 'children'> & {
|
||||||
|
/** `card` (default) on a page, `soft` inside a card or a sheet, `flush` edge to edge. */
|
||||||
|
tone?: ListTone;
|
||||||
|
/**
|
||||||
|
* A strip above the rows inside the group, such as a SectionTitle or a filter. For a heading
|
||||||
|
* outside the group, put a SectionTitle before the List instead.
|
||||||
|
*/
|
||||||
|
header?: ReactNode;
|
||||||
|
/** ListRows. */
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ListRowBaseProps = {
|
||||||
|
/** 15/600 primary, such as a channel's name or «پرداخت اشتراک». */
|
||||||
|
title: ReactNode;
|
||||||
|
/** 14 secondary under the title, such as the plan or the notification's text. */
|
||||||
|
subtitle?: ReactNode;
|
||||||
|
/** 12 tertiary, last, such as a date. */
|
||||||
|
meta?: ReactNode;
|
||||||
|
/** Anything else under the subtitle, before `meta`. */
|
||||||
|
children?: ReactNode;
|
||||||
|
/** The lead slot, such as an `Avatar`; wins over `icon`. */
|
||||||
|
leading?: ReactNode;
|
||||||
|
/** A 40px icon tile as the lead, in `iconTone`. */
|
||||||
|
icon?: IconName;
|
||||||
|
iconTone?: ListRowIconTone;
|
||||||
|
/** The end column, stacked and end-aligned: an `Amount`, a `StatusBadge`, a caption. */
|
||||||
|
end?: ReactNode;
|
||||||
|
/** The `chevron-left` at the end. On by itself for a link row; pass false to hide it. */
|
||||||
|
chevron?: boolean;
|
||||||
|
/** Tinted with a dot at the inline start. */
|
||||||
|
unread?: boolean;
|
||||||
|
/** The dot's accessible name, such as «خواندهنشده». */
|
||||||
|
unreadLabel?: string;
|
||||||
|
/** An unavailable item: every child but those marked `data-keep` drops to 50%. */
|
||||||
|
dimmed?: boolean;
|
||||||
|
/** Can't be opened now: 40%, no pointer, `aria-disabled`; a link row renders no link. */
|
||||||
|
disabled?: boolean;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** A link row: the whole row goes to `href`. */
|
||||||
|
export type ListRowAsLinkProps = ListRowBaseProps & {
|
||||||
|
href: string;
|
||||||
|
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** A button row, such as one that opens a detail sheet; a plain row when `onClick` is absent too. */
|
||||||
|
export type ListRowAsButtonProps = ListRowBaseProps & {
|
||||||
|
href?: undefined;
|
||||||
|
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ListRowProps = ListRowAsLinkProps | ListRowAsButtonProps;
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The group the rows sit in, with a hairline between rows. `card` is a bordered radius-lg surface;
|
||||||
|
* `soft` a sunken radius-md block inside a card or a sheet; `flush` reaches the screen's edges, with
|
||||||
|
* no radius or side borders.
|
||||||
|
*/
|
||||||
|
export const listVariants = cva('min-w-0 overflow-hidden', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
card: 'rounded-lg border border-border-subtle bg-surface',
|
||||||
|
soft: 'rounded-md bg-surface-sunken',
|
||||||
|
flush: 'border-y border-border-subtle bg-surface',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'card' },
|
||||||
|
});
|
||||||
|
|
||||||
|
/** The `ul` itself: no bullets or indent, a hairline between rows. */
|
||||||
|
export const listItemsVariants = cva(
|
||||||
|
'm-0 list-none p-0 [&>li+li]:border-t [&>li+li]:border-border-subtle',
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The optional header strip above the rows, over its own hairline. */
|
||||||
|
export const listHeaderVariants = cva(
|
||||||
|
'min-h-12 border-b border-border-subtle px-4 py-2',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One 64px row: lead, text, end column, chevron. Top-aligned when it has a second line, centred
|
||||||
|
* when only a title. An unread row is tinted with a dot at its start; a dimmed one fades every child
|
||||||
|
* but those marked `data-keep`. As a link or a button the whole row is the hit area, and its focus
|
||||||
|
* ring sits inside, so the list's rounded clip never cuts it.
|
||||||
|
*/
|
||||||
|
export const listRowVariants = cva(
|
||||||
|
'relative min-h-16 w-full px-4 py-3 text-start text-text-primary no-underline transition-colors duration-120 ease-standard',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
unread: { true: 'bg-action-primary-subtle', false: 'bg-transparent' },
|
||||||
|
interactive: {
|
||||||
|
true: 'focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-action-primary actionable:cursor-pointer actionable:hover:bg-surface-hover',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
dimmed: {
|
||||||
|
true: '[&>:not([data-keep])]:opacity-(--opacity-dimmed)',
|
||||||
|
false: '',
|
||||||
|
},
|
||||||
|
disabled: { true: 'frozen', false: '' },
|
||||||
|
},
|
||||||
|
compoundVariants: [
|
||||||
|
{
|
||||||
|
unread: true,
|
||||||
|
interactive: true,
|
||||||
|
className: 'actionable:hover:bg-action-primary-muted',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
defaultVariants: {
|
||||||
|
unread: false,
|
||||||
|
interactive: false,
|
||||||
|
dimmed: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The 40px lead tile, radius 12, in a tone's subtle ground. */
|
||||||
|
export const listRowIconVariants = cva('size-10 flex-none rounded-lg', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
neutral: 'bg-surface-sunken text-text-secondary',
|
||||||
|
brand: 'bg-action-primary-subtle text-action-primary-text',
|
||||||
|
success: 'bg-success-subtle text-success-text',
|
||||||
|
danger: 'bg-danger-subtle text-danger-text',
|
||||||
|
warning: 'bg-warning-subtle text-warning-text',
|
||||||
|
premium: 'bg-premium text-premium-on',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'neutral' },
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
import { useId } from 'react';
|
||||||
|
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { MeterProps } from './types';
|
||||||
|
import { meterBarVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A progress bar with its label and value (DS Meter), such as an invite code's capacity or an
|
||||||
|
* upload: the label and caption on one row, the 8px bar, then a hint.
|
||||||
|
*/
|
||||||
|
export function Meter({
|
||||||
|
value,
|
||||||
|
max = 100,
|
||||||
|
label,
|
||||||
|
caption,
|
||||||
|
hint,
|
||||||
|
tone,
|
||||||
|
ariaLabel,
|
||||||
|
valueText,
|
||||||
|
className,
|
||||||
|
}: MeterProps) {
|
||||||
|
const labelId = useId();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox direction="flex-col" className={cn('min-w-0 gap-1.5', className)}>
|
||||||
|
{(label != null || caption != null) && (
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-baseline"
|
||||||
|
justifyContent="justify-between"
|
||||||
|
gap="gap-2"
|
||||||
|
>
|
||||||
|
{label != null && (
|
||||||
|
<Typography tag="span" variant="label" id={labelId}>
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{caption != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="caption"
|
||||||
|
color="secondary"
|
||||||
|
className="ms-auto"
|
||||||
|
>
|
||||||
|
{caption}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
<Element
|
||||||
|
tag="progress"
|
||||||
|
value={Math.max(0, Math.min(value, max))}
|
||||||
|
max={max}
|
||||||
|
aria-valuetext={valueText}
|
||||||
|
aria-labelledby={label != null ? labelId : undefined}
|
||||||
|
aria-label={label != null ? undefined : ariaLabel}
|
||||||
|
className={meterBarVariants({ tone })}
|
||||||
|
/>
|
||||||
|
{hint != null && (
|
||||||
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
|
{hint}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { Meter } from './Meter';
|
||||||
|
export type { MeterProps, MeterTone } from './types';
|
||||||
|
export { meterBarVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { meterBarVariants } from './variants';
|
||||||
|
|
||||||
|
export type MeterTone = NonNullable<
|
||||||
|
VariantProps<typeof meterBarVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type MeterProps = {
|
||||||
|
value: number;
|
||||||
|
/** 100 by default. */
|
||||||
|
max?: number;
|
||||||
|
/** 14/600 above the bar at the start, and the bar's accessible name. */
|
||||||
|
label?: ReactNode;
|
||||||
|
/** The value in words at the end of the label row, such as «۱۲ از ۲۰ ظرفیت». */
|
||||||
|
caption?: ReactNode;
|
||||||
|
/** A caption under the bar. */
|
||||||
|
hint?: ReactNode;
|
||||||
|
tone?: MeterTone;
|
||||||
|
/** The accessible name when there is no visible `label`. */
|
||||||
|
ariaLabel?: string;
|
||||||
|
/** What a screen reader says for the value, such as «۱۲ از ۲۰». */
|
||||||
|
valueText?: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The native `progress`, drawn as the DS Meter: an 8px sunken track whose filled part takes the
|
||||||
|
* tone's hue, brand by default.
|
||||||
|
*/
|
||||||
|
export const meterBarVariants = cva(
|
||||||
|
'block h-2 w-full appearance-none overflow-hidden rounded-full border-0 bg-surface-sunken [&::-moz-progress-bar]:rounded-full [&::-webkit-progress-bar]:bg-surface-sunken [&::-webkit-progress-value]:rounded-full',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
brand:
|
||||||
|
'[&::-moz-progress-bar]:bg-action-primary [&::-webkit-progress-value]:bg-action-primary',
|
||||||
|
success:
|
||||||
|
'[&::-moz-progress-bar]:bg-success [&::-webkit-progress-value]:bg-success',
|
||||||
|
warning:
|
||||||
|
'[&::-moz-progress-bar]:bg-warning [&::-webkit-progress-value]:bg-warning',
|
||||||
|
danger:
|
||||||
|
'[&::-moz-progress-bar]:bg-danger [&::-webkit-progress-value]:bg-danger',
|
||||||
|
neutral:
|
||||||
|
'[&::-moz-progress-bar]:bg-text-tertiary [&::-webkit-progress-value]:bg-text-tertiary',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'brand' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
@ -15,7 +15,8 @@ import { modalPanelVariants } from './variants';
|
||||||
* focus returns to the trigger when it closes.
|
* focus returns to the trigger when it closes.
|
||||||
*
|
*
|
||||||
* `size="wide"` is the desktop form dialog (C4 ۷.۳, «پست جدید»): 640px, a header row with the
|
* `size="wide"` is the desktop form dialog (C4 ۷.۳, «پست جدید»): 640px, a header row with the
|
||||||
* title and `headerAction`, then the caller's body and footer bar, edge to edge.
|
* title and `headerAction`, then the caller's body and footer bar, edge to edge. `size="xwide"`
|
||||||
|
* is the same at 960px.
|
||||||
*/
|
*/
|
||||||
export function Modal({
|
export function Modal({
|
||||||
open,
|
open,
|
||||||
|
|
@ -44,7 +45,7 @@ export function Modal({
|
||||||
labelledBy={titleId}
|
labelledBy={titleId}
|
||||||
className="items-center justify-center p-4"
|
className="items-center justify-center p-4"
|
||||||
>
|
>
|
||||||
{size === 'wide' ? (
|
{size === 'wide' || size === 'xwide' ? (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
data-dialog-panel=""
|
data-dialog-panel=""
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
/** default: a short decision at 420px. wide: a desktop form at the 640px column (C4 ۷.۳). */
|
/**
|
||||||
export type ModalSize = 'default' | 'wide';
|
* default: a short decision at 420px. wide: a desktop form at the 640px column (C4 ۷.۳). xwide:
|
||||||
|
* the 960px workspace, such as the desktop prediction composer (DS Dialog `width="wide"`); laid
|
||||||
|
* out as wide.
|
||||||
|
*/
|
||||||
|
export type ModalSize = 'default' | 'wide' | 'xwide';
|
||||||
|
|
||||||
export type ModalProps = {
|
export type ModalProps = {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
title: ReactNode;
|
title: ReactNode;
|
||||||
/**
|
/**
|
||||||
* The body. default: in body-md under the title. wide: edge to edge with no padding; lay out
|
* The body. default: in body-md under the title. wide and xwide: edge to edge with no padding; lay out
|
||||||
* the scrolling body and the footer bar yourself (a `min-h-0` flex column, so the body scrolls).
|
* the scrolling body and the footer bar yourself (a `min-h-0` flex column, so the body scrolls).
|
||||||
*/
|
*/
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ export const modalPanelVariants = cva(
|
||||||
default: 'max-w-105 overflow-auto px-5 pt-6 pb-5',
|
default: 'max-w-105 overflow-auto px-5 pt-6 pb-5',
|
||||||
/** C4 ۷.۳: no padding, so the header row and the caller's footer bar reach the edges. */
|
/** C4 ۷.۳: no padding, so the header row and the caller's footer bar reach the edges. */
|
||||||
wide: 'max-w-content overflow-hidden',
|
wide: 'max-w-content overflow-hidden',
|
||||||
|
/** The DS 960px dialog with no padding, such as the desktop prediction composer (J09). */
|
||||||
|
xwide: 'max-w-240 overflow-hidden',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: { size: 'default' },
|
defaultVariants: { size: 'default' },
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { Button } from '../../atoms/button';
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { PageHeaderProps } from './types';
|
||||||
|
import { pageHeaderTitleVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A page's title row (DS PageHeader): an optional back button, the h1 with an optional subtitle,
|
||||||
|
* and actions at the end. Desktop pages and in-page titles; the mobile top bar has its own title.
|
||||||
|
*/
|
||||||
|
export function PageHeader({
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
actions,
|
||||||
|
size,
|
||||||
|
backHref,
|
||||||
|
backLabel,
|
||||||
|
titleId,
|
||||||
|
titleRef,
|
||||||
|
className,
|
||||||
|
}: PageHeaderProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-3"
|
||||||
|
className={cn('min-w-0', className)}
|
||||||
|
>
|
||||||
|
{backHref && backLabel && (
|
||||||
|
<Button
|
||||||
|
href={backHref}
|
||||||
|
variant="ghost"
|
||||||
|
icon="chevron-right"
|
||||||
|
label={backLabel}
|
||||||
|
className="-ms-2 text-text-primary"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<FlexBox direction="flex-col" className="min-w-0 flex-1 gap-0.5">
|
||||||
|
<Typography
|
||||||
|
tag="h1"
|
||||||
|
id={titleId}
|
||||||
|
ref={titleRef}
|
||||||
|
tabIndex={titleRef ? -1 : undefined}
|
||||||
|
variant="inherit"
|
||||||
|
className={cn(pageHeaderTitleVariants({ size }), 'outline-none')}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{subtitle != null && (
|
||||||
|
<Typography variant="body-sm" color="secondary" className="m-0">
|
||||||
|
{subtitle}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
{actions != null && (
|
||||||
|
<FlexBox alignItems="items-center" gap="gap-2" className="flex-none">
|
||||||
|
{actions}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { PageHeader } from './PageHeader';
|
||||||
|
export type { PageHeaderProps, PageHeaderSize } from './types';
|
||||||
|
export { pageHeaderTitleVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ReactNode, Ref } from 'react';
|
||||||
|
|
||||||
|
import type { pageHeaderTitleVariants } from './variants';
|
||||||
|
|
||||||
|
export type PageHeaderSize = NonNullable<
|
||||||
|
VariantProps<typeof pageHeaderTitleVariants>['size']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type PageHeaderProps = {
|
||||||
|
/** The page's h1. */
|
||||||
|
title: ReactNode;
|
||||||
|
/** 14/24 secondary under the title. */
|
||||||
|
subtitle?: ReactNode;
|
||||||
|
/** Buttons at the end, such as «پست جدید». */
|
||||||
|
actions?: ReactNode;
|
||||||
|
/** `md` (default, 22px) or `sm` (18px). */
|
||||||
|
size?: PageHeaderSize;
|
||||||
|
/** A back icon button before the title goes here; needs `backLabel`. */
|
||||||
|
backHref?: string;
|
||||||
|
/** The back button's accessible name, such as «بازگشت». */
|
||||||
|
backLabel?: string;
|
||||||
|
/** The h1's id, so a section can be labelled by it. */
|
||||||
|
titleId?: string;
|
||||||
|
/** A page that moves focus to its title gets `tabIndex={-1}` on it. */
|
||||||
|
titleRef?: Ref<HTMLHeadingElement>;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page's h1: `md` 22/36/700 (DS default: desktop pages, in-page titles), `sm` 18/30/600 (a
|
||||||
|
* compact title, such as on mobile under a tab bar).
|
||||||
|
*/
|
||||||
|
export const pageHeaderTitleVariants = cva('m-0 min-w-0', {
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
md: 'text-[1.375rem] leading-9 font-bold',
|
||||||
|
sm: 'text-[1.125rem] leading-7.5 font-semibold',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { size: 'md' },
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { PinnedFooterProps } from './types';
|
||||||
|
import { pinnedFooterVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bottom bar of a task flow on mobile (DS PinnedFooter), such as checkout's «پرداخت»: an
|
||||||
|
* optional total row, an optional centred note, then the actions. Sticky at the bottom of its
|
||||||
|
* scrolling column, clear of the home indicator. A toast over it sits at
|
||||||
|
* `PINNED_FOOTER_TOAST_OFFSET`; the footer carries `data-pinned-footer` for that.
|
||||||
|
*/
|
||||||
|
export function PinnedFooter({
|
||||||
|
children,
|
||||||
|
total,
|
||||||
|
totalLabel,
|
||||||
|
note,
|
||||||
|
layout = 'stack',
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: PinnedFooterProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
tag="footer"
|
||||||
|
data-pinned-footer=""
|
||||||
|
direction={layout === 'row' ? 'flex-row' : 'flex-col'}
|
||||||
|
alignItems={layout === 'row' ? 'items-center' : undefined}
|
||||||
|
gap="gap-2"
|
||||||
|
className={cn(pinnedFooterVariants(), className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{total != null && (
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-baseline"
|
||||||
|
justifyContent="justify-between"
|
||||||
|
gap="gap-3"
|
||||||
|
className={layout === 'row' ? 'min-w-0 flex-1' : undefined}
|
||||||
|
>
|
||||||
|
{totalLabel != null && (
|
||||||
|
<Typography tag="span" color="secondary">
|
||||||
|
{totalLabel}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{total}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
{note != null && (
|
||||||
|
<Typography
|
||||||
|
variant="caption"
|
||||||
|
color="secondary"
|
||||||
|
className="m-0 text-center"
|
||||||
|
>
|
||||||
|
{note}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
/**
|
||||||
|
* px from the screen's bottom edge to a toast shown over a pinned footer (DS ShellToast `footer`),
|
||||||
|
* so the toast never covers the footer's actions. The footer marks itself with
|
||||||
|
* `data-pinned-footer`, so the toast layer can find it with `:has()`.
|
||||||
|
*/
|
||||||
|
export const PINNED_FOOTER_TOAST_OFFSET = 152;
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
export { PINNED_FOOTER_TOAST_OFFSET } from './constants';
|
||||||
|
export { PinnedFooter } from './PinnedFooter';
|
||||||
|
export type { PinnedFooterLayout, PinnedFooterProps } from './types';
|
||||||
|
export { pinnedFooterVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
import type { ComponentPropsWithRef, ReactNode } from 'react';
|
||||||
|
|
||||||
|
export type PinnedFooterLayout = 'stack' | 'row';
|
||||||
|
|
||||||
|
export type PinnedFooterProps = Omit<
|
||||||
|
ComponentPropsWithRef<'footer'>,
|
||||||
|
'children'
|
||||||
|
> & {
|
||||||
|
/** The actions, primary first: one block Button, or a row with `layout="row"`. */
|
||||||
|
children: ReactNode;
|
||||||
|
/** The figure on the total row's end, usually an `Amount` at `title` size. */
|
||||||
|
total?: ReactNode;
|
||||||
|
/** The total row's start, such as «مبلغ قابل پرداخت»; shown only with `total`. */
|
||||||
|
totalLabel?: ReactNode;
|
||||||
|
/** A centred caption under the total, such as «با پرداخت، شرایط اشتراک را میپذیرید.». */
|
||||||
|
note?: ReactNode;
|
||||||
|
/** `stack` (default): total, note and actions in a column; `row`: everything on one line. */
|
||||||
|
layout?: PinnedFooterLayout;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The task flow's bottom bar (DS PinnedFooter): surface over a hairline, 12/16/16 padding plus the
|
||||||
|
* home indicator's inset, stuck to the bottom of its scrolling column above the content.
|
||||||
|
*/
|
||||||
|
export const pinnedFooterVariants = cva(
|
||||||
|
'sticky bottom-0 z-sticky min-w-0 border-t border-border-subtle bg-surface px-4 pt-3 pb-[max(1rem,env(safe-area-inset-bottom))]',
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { GridBox } from '../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import { RESULT_PANEL_ICONS } from './constants';
|
||||||
|
import type { ResultPanelProps } from './types';
|
||||||
|
import { resultPanelIconVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The outcome of a flow, centred (DS ResultPanel): a tonal disc, the title, a short body, then
|
||||||
|
* anything else and the actions. Payment results, a suspended account, registration done, a
|
||||||
|
* channel that isn't available.
|
||||||
|
*/
|
||||||
|
export function ResultPanel({
|
||||||
|
tone = 'success',
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
children,
|
||||||
|
actions,
|
||||||
|
tag = 'h1',
|
||||||
|
titleRef,
|
||||||
|
role,
|
||||||
|
className,
|
||||||
|
}: ResultPanelProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
role={role}
|
||||||
|
direction="flex-col"
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-2"
|
||||||
|
className={cn('pt-2 text-center', className)}
|
||||||
|
>
|
||||||
|
<GridBox
|
||||||
|
tag="span"
|
||||||
|
aria-hidden
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className={resultPanelIconVariants({ tone })}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icon ?? RESULT_PANEL_ICONS[tone]}
|
||||||
|
size={36}
|
||||||
|
strokeWidth={2}
|
||||||
|
/>
|
||||||
|
</GridBox>
|
||||||
|
<Typography
|
||||||
|
tag={tag}
|
||||||
|
ref={titleRef}
|
||||||
|
tabIndex={titleRef ? -1 : undefined}
|
||||||
|
variant="inherit"
|
||||||
|
className="m-0 mt-1 text-[1.375rem] leading-[2.125rem] font-bold outline-none"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{body != null && (
|
||||||
|
<Typography
|
||||||
|
variant="inherit"
|
||||||
|
color="secondary"
|
||||||
|
className="m-0 max-w-105 text-[0.9375rem] leading-[1.625rem]"
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
{actions != null && (
|
||||||
|
<FlexBox direction="flex-col" gap="gap-2" className="mt-4 w-full">
|
||||||
|
{actions}
|
||||||
|
</FlexBox>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
import type { ResultPanelTone } from './types';
|
||||||
|
|
||||||
|
/** Each tone's icon, unless the caller names another (DS ResultPanel). */
|
||||||
|
export const RESULT_PANEL_ICONS: Record<ResultPanelTone, IconName> = {
|
||||||
|
success: 'check',
|
||||||
|
danger: 'x-circle',
|
||||||
|
warning: 'clock',
|
||||||
|
info: 'info',
|
||||||
|
neutral: 'info',
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
export { RESULT_PANEL_ICONS } from './constants';
|
||||||
|
export { ResultPanel } from './ResultPanel';
|
||||||
|
export type { ResultPanelProps, ResultPanelTone } from './types';
|
||||||
|
export { resultPanelIconVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ReactNode, Ref } from 'react';
|
||||||
|
|
||||||
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
import type { resultPanelIconVariants } from './variants';
|
||||||
|
|
||||||
|
export type ResultPanelTone = NonNullable<
|
||||||
|
VariantProps<typeof resultPanelIconVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type ResultPanelProps = {
|
||||||
|
/** success (default), danger, warning, info (the DS `brand`) or neutral. */
|
||||||
|
tone?: ResultPanelTone;
|
||||||
|
/** Replaces the tone's icon (check, x-circle, clock, info). */
|
||||||
|
icon?: IconName;
|
||||||
|
/** The page's h1, 22/34/700. */
|
||||||
|
title: ReactNode;
|
||||||
|
/** 15/26 secondary, at most 420px wide. */
|
||||||
|
body?: ReactNode;
|
||||||
|
/** Under the body, such as a receipt or a support link. */
|
||||||
|
children?: ReactNode;
|
||||||
|
/** Buttons under everything, stacked full width, primary first. */
|
||||||
|
actions?: ReactNode;
|
||||||
|
/** `h1` by default; `h2` when the page already has one. */
|
||||||
|
tag?: 'h1' | 'h2';
|
||||||
|
/** A result page moves focus to its title; it then gets `tabIndex={-1}`. */
|
||||||
|
titleRef?: Ref<HTMLHeadingElement>;
|
||||||
|
/** `status` for a result that just arrived, `alert` for a failure. */
|
||||||
|
role?: 'status' | 'alert';
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** The plain 72px disc in the tone's subtle ground; no ring or dot. `info` is the DS `brand`. */
|
||||||
|
export const resultPanelIconVariants = cva('size-18 flex-none rounded-full', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
success: 'bg-success-subtle text-success-text',
|
||||||
|
danger: 'bg-danger-subtle text-danger-text',
|
||||||
|
warning: 'bg-warning-subtle text-warning-text',
|
||||||
|
info: 'bg-action-primary-subtle text-action-primary-text',
|
||||||
|
neutral: 'bg-surface-sunken text-text-secondary',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'success' },
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRef, useState } from 'react';
|
||||||
|
|
||||||
|
import { Button } from '../../atoms/button';
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { SearchFieldProps } from './types';
|
||||||
|
import { searchFieldInputVariants, searchFieldVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A search box (DS SearchField): a `search` landmark pill with the magnifier, the input and a ✕
|
||||||
|
* once it has text. Enter (the keyboard's search key) calls `onSubmit` and never submits an outer
|
||||||
|
* form. Controlled with `value`, or keeping its own text.
|
||||||
|
*/
|
||||||
|
export function SearchField({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
defaultValue = '',
|
||||||
|
onValueChange,
|
||||||
|
onSubmit,
|
||||||
|
clearLabel,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: SearchFieldProps) {
|
||||||
|
const [ownValue, setOwnValue] = useState(defaultValue);
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const text = value ?? ownValue;
|
||||||
|
|
||||||
|
const change = (next: string) => {
|
||||||
|
if (value === undefined) setOwnValue(next);
|
||||||
|
onValueChange?.(next);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
tag="search"
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-2"
|
||||||
|
className={cn(searchFieldVariants(), className)}
|
||||||
|
>
|
||||||
|
<Icon name="search" className="flex-none" />
|
||||||
|
<Element
|
||||||
|
tag="input"
|
||||||
|
ref={inputRef}
|
||||||
|
type="search"
|
||||||
|
aria-label={label}
|
||||||
|
enterKeyHint="search"
|
||||||
|
autoComplete="off"
|
||||||
|
value={text}
|
||||||
|
onChange={(event) => change(event.target.value)}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key !== 'Enter') return;
|
||||||
|
event.preventDefault();
|
||||||
|
onSubmit?.(text.trim());
|
||||||
|
}}
|
||||||
|
className={searchFieldInputVariants()}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
{text !== '' && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
icon="close"
|
||||||
|
label={clearLabel}
|
||||||
|
onClick={() => {
|
||||||
|
change('');
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}}
|
||||||
|
className="-me-2.5 flex-none"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { SearchField } from './SearchField';
|
||||||
|
export type { SearchFieldProps } from './types';
|
||||||
|
export { searchFieldInputVariants, searchFieldVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import type { ComponentPropsWithoutRef } from 'react';
|
||||||
|
|
||||||
|
export type SearchFieldProps = Omit<
|
||||||
|
ComponentPropsWithoutRef<'input'>,
|
||||||
|
'type' | 'value' | 'defaultValue' | 'onChange' | 'onSubmit' | 'size'
|
||||||
|
> & {
|
||||||
|
/** The field's accessible name, such as «جستجوی تحلیلگر». */
|
||||||
|
label: string;
|
||||||
|
/** Controlled: the text now. Leave it out to let the field keep its own. */
|
||||||
|
value?: string;
|
||||||
|
defaultValue?: string;
|
||||||
|
/** Every edit, and '' when cleared. */
|
||||||
|
onValueChange?: (value: string) => void;
|
||||||
|
/** Enter or the keyboard's search key, with the trimmed text. */
|
||||||
|
onSubmit?: (value: string) => void;
|
||||||
|
/** The ✕'s accessible name, such as «پاک کردن». */
|
||||||
|
clearLabel: string;
|
||||||
|
/** On the pill. */
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** The 44px pill (DS SearchField): its border turns brand with a halo while the input has focus. */
|
||||||
|
export const searchFieldVariants = cva(
|
||||||
|
'h-11 w-full min-w-0 rounded-full border border-border-default bg-surface ps-3.5 pe-3.5 text-text-secondary transition-[border-color,box-shadow] duration-120 ease-standard focus-within:border-action-primary focus-within:shadow-focus-field',
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The bare input inside the pill; the browser's own clear and magnifier are hidden. */
|
||||||
|
export const searchFieldInputVariants = cva(
|
||||||
|
'h-full min-w-0 flex-1 border-0 bg-transparent p-0 text-[0.9375rem] text-text-primary outline-none placeholder:text-text-tertiary [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none',
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
import { number } from '@lumina/tools/format';
|
||||||
|
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Link } from '../../atoms/link';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { SectionTitleProps } from './types';
|
||||||
|
import { sectionTitleVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A section's title inside a page (DS SectionTitle): the heading, an optional count in secondary,
|
||||||
|
* and an optional «همه ‹» link at the end. Not the landing's SectionHeading.
|
||||||
|
*/
|
||||||
|
export function SectionTitle({
|
||||||
|
title,
|
||||||
|
count,
|
||||||
|
actionLabel,
|
||||||
|
actionHref,
|
||||||
|
tag = 'h2',
|
||||||
|
titleId,
|
||||||
|
className,
|
||||||
|
}: SectionTitleProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-center"
|
||||||
|
gap="gap-2"
|
||||||
|
className={cn('min-h-8 min-w-0', className)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
tag={tag}
|
||||||
|
id={titleId}
|
||||||
|
variant="inherit"
|
||||||
|
className={sectionTitleVariants()}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
{count != null && (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="inherit"
|
||||||
|
color="secondary"
|
||||||
|
className="font-semibold"
|
||||||
|
>
|
||||||
|
{` (${number(count)})`}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Typography>
|
||||||
|
{actionLabel != null && actionHref && (
|
||||||
|
<Link
|
||||||
|
href={actionHref}
|
||||||
|
standalone
|
||||||
|
icon="chevron-left"
|
||||||
|
className="flex-none text-caption"
|
||||||
|
>
|
||||||
|
{actionLabel}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { SectionTitle } from './SectionTitle';
|
||||||
|
export type { SectionTitleProps } from './types';
|
||||||
|
export { sectionTitleVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
export type SectionTitleProps = {
|
||||||
|
title: ReactNode;
|
||||||
|
/** Shown after the title in secondary, as «(۱۲)». */
|
||||||
|
count?: number;
|
||||||
|
/** A text link at the end with `chevron-left`, such as «همه»; needs `actionHref`. */
|
||||||
|
actionLabel?: ReactNode;
|
||||||
|
actionHref?: string;
|
||||||
|
/** `h2` by default; `h3` under another section heading. */
|
||||||
|
tag?: 'h2' | 'h3';
|
||||||
|
/** The heading's id, so its section can be labelled by it. */
|
||||||
|
titleId?: string;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** A section's h2 inside a page (DS SectionTitle): 16/26/700, at least 32px tall with its action. */
|
||||||
|
export const sectionTitleVariants = cva(
|
||||||
|
'm-0 min-w-0 flex-1 text-body-md leading-[1.625rem] font-bold',
|
||||||
|
);
|
||||||
|
|
@ -15,7 +15,7 @@ import {
|
||||||
* A one-of choice as chips on a pill track, such as a post's «رایگان» / «پریمیوم» (C4 ۷.۳, C5 ۱.۱,
|
* A one-of choice as chips on a pill track, such as a post's «رایگان» / «پریمیوم» (C4 ۷.۳, C5 ۱.۱,
|
||||||
* ۱.۵, ۱.۶, ۱.۷, ۷.۱). A named radiogroup fieldset of real radios, so Tab reaches the chosen one,
|
* ۱.۵, ۱.۶, ۱.۷, ۷.۱). A named radiogroup fieldset of real radios, so Tab reaches the chosen one,
|
||||||
* the arrow keys pick, and disabling the fieldset disables them all. A chosen option fills brand
|
* the arrow keys pick, and disabling the fieldset disables them all. A chosen option fills brand
|
||||||
* with no check.
|
* with no check, or turns white with `tone="neutral"`.
|
||||||
*/
|
*/
|
||||||
export function SegmentedChoice<T extends string>({
|
export function SegmentedChoice<T extends string>({
|
||||||
options,
|
options,
|
||||||
|
|
@ -24,6 +24,8 @@ export function SegmentedChoice<T extends string>({
|
||||||
label,
|
label,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
track = 'sunken',
|
track = 'sunken',
|
||||||
|
tone = 'brand',
|
||||||
|
block = false,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
frozen = false,
|
frozen = false,
|
||||||
className,
|
className,
|
||||||
|
|
@ -37,20 +39,26 @@ export function SegmentedChoice<T extends string>({
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
disabled={disabled || frozen}
|
disabled={disabled || frozen}
|
||||||
gap="gap-1"
|
gap="gap-1"
|
||||||
className={cn(segmentedChoiceVariants({ track, frozen }), className)}
|
className={cn(
|
||||||
|
segmentedChoiceVariants({ track, frozen, block }),
|
||||||
|
className,
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
<FlexBox
|
<FlexBox
|
||||||
key={option.value}
|
key={option.value}
|
||||||
tag="label"
|
tag="label"
|
||||||
alignItems="items-center"
|
alignItems="items-center"
|
||||||
|
justifyContent={block ? 'justify-center' : undefined}
|
||||||
className={cn(
|
className={cn(
|
||||||
segmentedChoiceOptionVariants({
|
segmentedChoiceOptionVariants({
|
||||||
selected: option.value === value,
|
selected: option.value === value,
|
||||||
|
tone,
|
||||||
size,
|
size,
|
||||||
disabled: disabled && !frozen,
|
disabled: disabled && !frozen,
|
||||||
}),
|
}),
|
||||||
'gap-1.5',
|
'gap-1.5',
|
||||||
|
block && 'flex-1',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Element
|
<Element
|
||||||
|
|
@ -63,8 +71,8 @@ export function SegmentedChoice<T extends string>({
|
||||||
readOnly={!onChange}
|
readOnly={!onChange}
|
||||||
className="pointer-events-none absolute m-0 size-px opacity-0"
|
className="pointer-events-none absolute m-0 size-px opacity-0"
|
||||||
/>
|
/>
|
||||||
{option.icon && <Icon name={option.icon} size={16} />}
|
{option.icon && <Icon name={option.icon} size={18} />}
|
||||||
<Typography tag="span" variant="label" color="inherit">
|
<Typography tag="span" variant="inherit" color="inherit">
|
||||||
{option.label}
|
{option.label}
|
||||||
</Typography>
|
</Typography>
|
||||||
</FlexBox>
|
</FlexBox>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ export type {
|
||||||
SegmentedChoiceOption,
|
SegmentedChoiceOption,
|
||||||
SegmentedChoiceProps,
|
SegmentedChoiceProps,
|
||||||
SegmentedChoiceSize,
|
SegmentedChoiceSize,
|
||||||
|
SegmentedChoiceTone,
|
||||||
SegmentedChoiceTrack,
|
SegmentedChoiceTrack,
|
||||||
} from './types';
|
} from './types';
|
||||||
export {
|
export {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ export type SegmentedChoiceTrack = NonNullable<
|
||||||
VariantProps<typeof segmentedChoiceVariants>['track']
|
VariantProps<typeof segmentedChoiceVariants>['track']
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export type SegmentedChoiceTone = NonNullable<
|
||||||
|
VariantProps<typeof segmentedChoiceOptionVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
export type SegmentedChoiceOption<T extends string> = {
|
export type SegmentedChoiceOption<T extends string> = {
|
||||||
value: T;
|
value: T;
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
|
|
@ -31,8 +35,15 @@ export type SegmentedChoiceProps<T extends string> = {
|
||||||
onChange?: (value: T) => void;
|
onChange?: (value: T) => void;
|
||||||
/** The group's accessible name, such as «سطح دسترسی پست». */
|
/** The group's accessible name, such as «سطح دسترسی پست». */
|
||||||
label: string;
|
label: string;
|
||||||
/** `md` (44px) in forms such as the composer, `sm` (36px) inside a card. */
|
/** `md` (40px, DS) in forms such as the composer, `sm` (36px) inside a card. */
|
||||||
size?: SegmentedChoiceSize;
|
size?: SegmentedChoiceSize;
|
||||||
|
/**
|
||||||
|
* The chosen option: `brand` (default) fills it indigo, for a setting such as «رایگان» /
|
||||||
|
* «پریمیوم»; `neutral` turns it white with a ring, for a view switch.
|
||||||
|
*/
|
||||||
|
tone?: SegmentedChoiceTone;
|
||||||
|
/** Stretches across its column, each option an equal share. */
|
||||||
|
block?: boolean;
|
||||||
/** `sunken` on a card or a form; `surface` on a tinted ground, such as the preview banner (C5 ۶.۲). */
|
/** `sunken` on a card or a form; `surface` on a tinted ground, such as the preview banner (C5 ۶.۲). */
|
||||||
track?: SegmentedChoiceTrack;
|
track?: SegmentedChoiceTrack;
|
||||||
/** Out of reach for now, such as while the post publishes (C4 ۱.۶): each option dims. */
|
/** Out of reach for now, such as while the post publishes (C4 ۱.۶): each option dims. */
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,64 @@
|
||||||
import { cva } from 'class-variance-authority';
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
/** The track the options sit in (C5 ۱.۱); frozen, it dims as one (C5 ۱.۶). */
|
/**
|
||||||
|
* The track the options sit in (C5 ۱.۱; DS Segmented); frozen, it dims as one (C5 ۱.۶). `block`
|
||||||
|
* stretches it across its column, each option taking an equal share.
|
||||||
|
*/
|
||||||
export const segmentedChoiceVariants = cva(
|
export const segmentedChoiceVariants = cva(
|
||||||
'w-fit min-w-0 rounded-full border border-border-subtle p-1',
|
'min-w-0 rounded-full border border-border-subtle p-1',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
/** sunken on a card or a form; surface on a tinted ground, such as a banner (C5 ۶.۲). */
|
/** sunken on a card or a form; surface on a tinted ground, such as a banner (C5 ۶.۲). */
|
||||||
track: { sunken: 'bg-surface-sunken', surface: 'bg-surface' },
|
track: { sunken: 'bg-surface-sunken', surface: 'bg-surface' },
|
||||||
frozen: { true: 'frozen', false: '' },
|
frozen: { true: 'frozen', false: '' },
|
||||||
|
block: { true: 'w-full', false: 'w-fit' },
|
||||||
},
|
},
|
||||||
defaultVariants: { track: 'sunken', frozen: false },
|
defaultVariants: { track: 'sunken', frozen: false, block: false },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One option, a chip with the real radio hidden inside: filled brand when chosen, bare on the
|
* One option, a pill with the real radio hidden inside: 40px at 15/600 (DS), secondary when not
|
||||||
* track when not. The label is the hit area and shows the radio's keyboard focus.
|
* chosen. Chosen, it fills brand (`tone="brand"`), or turns white with a hairline ring and a
|
||||||
|
* shadow (`tone="neutral"`, for a view switch rather than a setting). The label is the hit area and
|
||||||
|
* shows the radio's keyboard focus.
|
||||||
*/
|
*/
|
||||||
export const segmentedChoiceOptionVariants = cva(
|
export const segmentedChoiceOptionVariants = cva(
|
||||||
'relative rounded-full border whitespace-nowrap transition-colors duration-120 ease-standard has-[input:enabled]:cursor-pointer has-[input:focus-visible]:focus-ring',
|
'relative rounded-full border border-transparent font-semibold whitespace-nowrap transition-colors duration-120 ease-standard has-[input:enabled]:cursor-pointer has-[input:focus-visible]:focus-ring',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
selected: {
|
selected: {
|
||||||
true: 'border-action-primary bg-action-primary text-text-on-action',
|
true: '',
|
||||||
false:
|
false:
|
||||||
'border-transparent bg-transparent text-text-primary has-[input:enabled]:hover:border-action-primary',
|
'bg-transparent text-text-secondary has-[input:enabled]:hover:text-text-primary',
|
||||||
},
|
},
|
||||||
|
tone: { brand: '', neutral: '' },
|
||||||
size: {
|
size: {
|
||||||
sm: 'min-h-control-sm px-3.5',
|
sm: 'min-h-control-sm px-3.5 text-body-sm leading-6',
|
||||||
md: 'min-h-control-md px-4',
|
md: 'min-h-10 px-4 text-[0.9375rem] leading-6',
|
||||||
},
|
},
|
||||||
/** Disabled but not frozen: each option dims, as a disabled chip does (C4 ۱.۶). */
|
/** Disabled but not frozen: each option dims, as a disabled chip does (C4 ۱.۶). */
|
||||||
disabled: { true: 'frozen', false: '' },
|
disabled: { true: 'frozen', false: '' },
|
||||||
},
|
},
|
||||||
defaultVariants: { selected: false, size: 'md', disabled: false },
|
compoundVariants: [
|
||||||
|
{
|
||||||
|
selected: true,
|
||||||
|
tone: 'brand',
|
||||||
|
className:
|
||||||
|
'border-action-primary bg-action-primary text-text-on-action',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
selected: true,
|
||||||
|
tone: 'neutral',
|
||||||
|
className:
|
||||||
|
'bg-surface text-text-primary shadow-[0_0_0_1px_var(--border-default),var(--shadow-1)]',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
defaultVariants: {
|
||||||
|
selected: false,
|
||||||
|
tone: 'brand',
|
||||||
|
size: 'md',
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { StatTileProps } from './types';
|
||||||
|
import { statTileValueVariants, statTileVariants } from './variants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One figure with its label (DS StatTile), such as a balance or a count on a dashboard: the label
|
||||||
|
* with an icon, the value, then an optional meter and hint.
|
||||||
|
*/
|
||||||
|
export function StatTile({
|
||||||
|
label,
|
||||||
|
icon,
|
||||||
|
value,
|
||||||
|
valueTone,
|
||||||
|
hint,
|
||||||
|
children,
|
||||||
|
tone,
|
||||||
|
className,
|
||||||
|
}: StatTileProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox
|
||||||
|
direction="flex-col"
|
||||||
|
className={cn(statTileVariants({ tone }), 'gap-1.5', className)}
|
||||||
|
>
|
||||||
|
<FlexBox
|
||||||
|
alignItems="items-center"
|
||||||
|
className="gap-1.5 text-text-secondary"
|
||||||
|
>
|
||||||
|
{icon && <Icon name={icon} size={16} />}
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="caption"
|
||||||
|
color="inherit"
|
||||||
|
className="font-semibold"
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
</FlexBox>
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="inherit"
|
||||||
|
color="inherit"
|
||||||
|
className={statTileValueVariants({ valueTone })}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
</Typography>
|
||||||
|
{children}
|
||||||
|
{hint != null && (
|
||||||
|
<Typography tag="span" variant="caption" color="secondary">
|
||||||
|
{hint}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { StatTile } from './StatTile';
|
||||||
|
export type { StatTileProps, StatTileTone, StatTileValueTone } from './types';
|
||||||
|
export { statTileValueVariants, statTileVariants } from './variants';
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
import type { statTileValueVariants, statTileVariants } from './variants';
|
||||||
|
|
||||||
|
export type StatTileTone = NonNullable<
|
||||||
|
VariantProps<typeof statTileVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type StatTileValueTone = NonNullable<
|
||||||
|
VariantProps<typeof statTileValueVariants>['valueTone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type StatTileProps = {
|
||||||
|
/** 13/600 secondary, such as «قابل واریز». */
|
||||||
|
label: ReactNode;
|
||||||
|
/** 16px before the label. */
|
||||||
|
icon?: IconName;
|
||||||
|
/** The figure: text at 24/700, or an `Amount` at `title` size. */
|
||||||
|
value: ReactNode;
|
||||||
|
valueTone?: StatTileValueTone;
|
||||||
|
/** 13/22 secondary under the value, such as «واریز بعدی: ۱۵ مهر». */
|
||||||
|
hint?: ReactNode;
|
||||||
|
/** Between the value and the hint, such as a Meter. */
|
||||||
|
children?: ReactNode;
|
||||||
|
tone?: StatTileTone;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** `card`: a bordered radius-lg surface; `soft`: sunken with no border (DS StatTile). */
|
||||||
|
export const statTileVariants = cva('min-w-0 rounded-lg border p-4', {
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
card: 'border-border-subtle bg-surface',
|
||||||
|
soft: 'border-transparent bg-surface-sunken',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'card' },
|
||||||
|
});
|
||||||
|
|
||||||
|
/** The figure, 24/36/700, in a status hue when it carries one. */
|
||||||
|
export const statTileValueVariants = cva('text-[1.5rem] leading-9 font-bold', {
|
||||||
|
variants: {
|
||||||
|
valueTone: {
|
||||||
|
default: 'text-text-primary',
|
||||||
|
success: 'text-success-text',
|
||||||
|
danger: 'text-danger-text',
|
||||||
|
warning: 'text-warning-text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { valueTone: 'default' },
|
||||||
|
});
|
||||||
|
|
@ -22,6 +22,9 @@ export const textInputBoxVariants = cva(
|
||||||
*/
|
*/
|
||||||
locked:
|
locked:
|
||||||
'border-border-subtle bg-surface-sunken focus-within:border-border-default',
|
'border-border-subtle bg-surface-sunken focus-within:border-border-default',
|
||||||
|
/** A checked, accepted value, such as a valid invite code (CodeInput): green, focused or not. */
|
||||||
|
valid:
|
||||||
|
'border-success bg-surface focus-within:shadow-focus-field-success',
|
||||||
},
|
},
|
||||||
frozen: { true: 'frozen', false: '' },
|
frozen: { true: 'frozen', false: '' },
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Element } from '../../primitives/element';
|
||||||
|
import { cn } from '../../tools/cn';
|
||||||
|
import type { TimelineProps } from './types';
|
||||||
|
import { timelineVariants } from './variants';
|
||||||
|
|
||||||
|
/** Steps or events in order (DS Timeline), such as the install-app steps; holds TimelineItems. */
|
||||||
|
export function Timeline({ className, children, ...props }: TimelineProps) {
|
||||||
|
return (
|
||||||
|
<Element tag="ol" className={cn(timelineVariants(), className)} {...props}>
|
||||||
|
{children}
|
||||||
|
</Element>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { FlexBox } from '../../atoms/flex-box';
|
||||||
|
import { GridBox } from '../../atoms/grid-box';
|
||||||
|
import { Icon } from '../../atoms/icon';
|
||||||
|
import { Typography } from '../../atoms/typography';
|
||||||
|
import type { TimelineItemProps } from './types';
|
||||||
|
import { timelineDotVariants, timelineItemVariants } from './variants';
|
||||||
|
|
||||||
|
/** One step of a Timeline: a tonal dot on the connector, then the title, body and time. */
|
||||||
|
export function TimelineItem({
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
time,
|
||||||
|
children,
|
||||||
|
tone,
|
||||||
|
icon = 'check',
|
||||||
|
step,
|
||||||
|
}: TimelineItemProps) {
|
||||||
|
return (
|
||||||
|
<FlexBox tag="li" gap="gap-3" className={timelineItemVariants()}>
|
||||||
|
<GridBox
|
||||||
|
tag="span"
|
||||||
|
aria-hidden
|
||||||
|
justifyItems="justify-items-center"
|
||||||
|
alignItems="items-center"
|
||||||
|
className={timelineDotVariants({ tone })}
|
||||||
|
>
|
||||||
|
{step != null ? (
|
||||||
|
<Typography
|
||||||
|
tag="span"
|
||||||
|
variant="caption"
|
||||||
|
color="inherit"
|
||||||
|
className="font-bold"
|
||||||
|
>
|
||||||
|
{step}
|
||||||
|
</Typography>
|
||||||
|
) : (
|
||||||
|
<Icon name={icon} size={14} strokeWidth={2.25} />
|
||||||
|
)}
|
||||||
|
</GridBox>
|
||||||
|
<FlexBox direction="flex-col" className="min-w-0 flex-1 gap-0.5 pt-0.5">
|
||||||
|
<Typography variant="body-sm" className="m-0 font-semibold">
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{body != null && (
|
||||||
|
<Typography variant="caption" color="secondary" className="m-0">
|
||||||
|
{body}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
{time != null && (
|
||||||
|
<Typography
|
||||||
|
variant="inherit"
|
||||||
|
color="tertiary"
|
||||||
|
className="m-0 text-[0.75rem] leading-5"
|
||||||
|
>
|
||||||
|
{time}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</FlexBox>
|
||||||
|
</FlexBox>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
export { Timeline } from './Timeline';
|
||||||
|
export { TimelineItem } from './TimelineItem';
|
||||||
|
export type { TimelineItemProps, TimelineProps, TimelineTone } from './types';
|
||||||
|
export {
|
||||||
|
timelineDotVariants,
|
||||||
|
timelineItemVariants,
|
||||||
|
timelineVariants,
|
||||||
|
} from './variants';
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
|
import type { ComponentPropsWithRef, ReactNode } from 'react';
|
||||||
|
|
||||||
|
import type { IconName } from '../../atoms/icon';
|
||||||
|
import type { timelineDotVariants } from './variants';
|
||||||
|
|
||||||
|
export type TimelineTone = NonNullable<
|
||||||
|
VariantProps<typeof timelineDotVariants>['tone']
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type TimelineProps = Omit<ComponentPropsWithRef<'ol'>, 'children'> & {
|
||||||
|
/** TimelineItems, in order. */
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TimelineItemProps = {
|
||||||
|
/** 14/600, such as «دکمه اشتراکگذاری را بزنید». */
|
||||||
|
title: ReactNode;
|
||||||
|
/** 13/22 secondary under the title. */
|
||||||
|
body?: ReactNode;
|
||||||
|
/** 12/20 tertiary, last, such as a date. */
|
||||||
|
time?: ReactNode;
|
||||||
|
/** Anything else, between the body and the time. */
|
||||||
|
children?: ReactNode;
|
||||||
|
/** The dot's tone: neutral by default. */
|
||||||
|
tone?: TimelineTone;
|
||||||
|
/** The dot's icon; `check` by default. */
|
||||||
|
icon?: IconName;
|
||||||
|
/** A step number in the dot instead of the icon, such as «۱». */
|
||||||
|
step?: ReactNode;
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
/** The ordered list: no bullets or indent. */
|
||||||
|
export const timelineVariants = cva('m-0 min-w-0 list-none p-0');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One step: 16px under it, and a 2px connector from under its dot to the next step's. The last
|
||||||
|
* step has neither.
|
||||||
|
*/
|
||||||
|
export const timelineItemVariants = cva(
|
||||||
|
'relative pb-4 last:pb-0 before:absolute before:start-3.25 before:top-7 before:bottom-0 before:w-0.5 before:bg-border-subtle last:before:hidden',
|
||||||
|
);
|
||||||
|
|
||||||
|
/** The 28px dot in the step's tone. */
|
||||||
|
export const timelineDotVariants = cva(
|
||||||
|
'relative size-7 flex-none rounded-full',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
tone: {
|
||||||
|
neutral: 'bg-surface-sunken text-text-secondary',
|
||||||
|
brand: 'bg-action-primary-subtle text-action-primary-text',
|
||||||
|
success: 'bg-success-subtle text-success-text',
|
||||||
|
danger: 'bg-danger-subtle text-danger-text',
|
||||||
|
warning: 'bg-warning-subtle text-warning-text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: { tone: 'neutral' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useToastPlacement } from './hooks/use-toast-placement';
|
||||||
|
import type { ToastPlacementMarkerProps } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `useToastPlacement` for a server layout or template: renders nothing and declares its edge while
|
||||||
|
* it is mounted, such as `desktop` in the desktop app's root layout.
|
||||||
|
*/
|
||||||
|
export function ToastPlacementMarker({ placement }: ToastPlacementMarkerProps) {
|
||||||
|
useToastPlacement(placement);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,12 @@ import { useEffect, useState, useSyncExternalStore } from 'react';
|
||||||
import type { CSSProperties } from 'react';
|
import type { CSSProperties } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { Toaster as SonnerToaster } from 'sonner';
|
import { Toaster as SonnerToaster } from 'sonner';
|
||||||
|
import { useStore } from 'zustand';
|
||||||
|
|
||||||
import { DIALOG_CLOSE_EVENT, DIALOG_OPEN_EVENT } from '../../atoms/dialog';
|
import { DIALOG_CLOSE_EVENT, DIALOG_OPEN_EVENT } from '../../atoms/dialog';
|
||||||
|
import { TOAST_OFFSETS } from './constants';
|
||||||
import { CloseLabelContext } from './hooks/use-close-label';
|
import { CloseLabelContext } from './hooks/use-close-label';
|
||||||
|
import { resolveToastPlacement, toastPlacementStore } from './placement-store';
|
||||||
import { syncKeyboardFocus, trackToastRegion } from './region-store';
|
import { syncKeyboardFocus, trackToastRegion } from './region-store';
|
||||||
import type { ToasterProps } from './types';
|
import type { ToasterProps } from './types';
|
||||||
|
|
||||||
|
|
@ -34,14 +37,22 @@ const TOAST_SLOT_STYLE = {
|
||||||
* `data-removed` on the slot and unmounts it 200ms later (sonner 2.0.8), so the toast inside plays
|
* `data-removed` on the slot and unmounts it 200ms later (sonner 2.0.8), so the toast inside plays
|
||||||
* its 160ms exit. The toast sits two wrappers down, so the selector looks for `[data-toast]`.
|
* its 160ms exit. The toast sits two wrappers down, so the selector looks for `[data-toast]`.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* A pinned footer on screen (`data-pinned-footer`) lifts the toasts above it, wherever it is
|
||||||
|
* rendered: the box carries the footer's offset (`PINNED_FOOTER_TOAST_OFFSET`, 152px) only then.
|
||||||
|
*/
|
||||||
|
const FOOTER_AWARE_CLASS =
|
||||||
|
'[:root:has([data-pinned-footer])_&]:[--toast-footer-offset:152px]';
|
||||||
|
|
||||||
const TOAST_SLOT_CLASS =
|
const TOAST_SLOT_CLASS =
|
||||||
'data-[removed=true]:pointer-events-none data-[removed=true]:[&_[data-toast]]:animate-toast-out';
|
'data-[removed=true]:pointer-events-none data-[removed=true]:[&_[data-toast]]:animate-toast-out';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The one toast region, rendered once by the app shell. Bottom centre, 24px from the bottom
|
* The one toast region, rendered once by the app shell. Bottom centre, never at the top, 16px from
|
||||||
* (sonner would use 16px on phones), never at the top. Bull shows the bottom nav up to 1024px, so
|
* the sides on a phone and at most 420px wide. Its distance from the bottom follows the edges the
|
||||||
* while the nav or a pinned footer is visible the shell passes both `offset` and `mobileOffset`
|
* screen declares with `useToastPlacement` (`TOAST_OFFSETS`): above the bottom nav (80px) or a
|
||||||
* with its height plus 24px.
|
* pinned footer (152px), low (24px) on a task page and over an open sheet, which covers both, and
|
||||||
|
* 32px in the desktop app whatever else is on screen. `placement` forces one, for previews.
|
||||||
*
|
*
|
||||||
* Sheets and modals are `<dialog>`s in the browser's top layer, above every z-index, and they make
|
* Sheets and modals are `<dialog>`s in the browser's top layer, above every z-index, and they make
|
||||||
* the rest of the page inert. So the region lives in a box of its own that moves into the topmost
|
* the rest of the page inert. So the region lives in a box of its own that moves into the topmost
|
||||||
|
|
@ -50,16 +61,36 @@ const TOAST_SLOT_CLASS =
|
||||||
* The lightbox doesn't host toasts, so it stays above them. The box also reports the pointer and
|
* The lightbox doesn't host toasts, so it stays above them. The box also reports the pointer and
|
||||||
* keyboard focus on the region, which pause the toasts' clocks.
|
* keyboard focus on the region, which pause the toasts' clocks.
|
||||||
*/
|
*/
|
||||||
export function Toaster({ label, closeLabel, style, ...props }: ToasterProps) {
|
export function Toaster({
|
||||||
|
label,
|
||||||
|
closeLabel,
|
||||||
|
placement,
|
||||||
|
style,
|
||||||
|
...props
|
||||||
|
}: ToasterProps) {
|
||||||
// The box exists only in the browser; the region renders after hydration, as sonner does anyway.
|
// The box exists only in the browser; the region renders after hydration, as sonner does anyway.
|
||||||
const [box] = useState(() =>
|
const [box] = useState(() => {
|
||||||
typeof document === 'undefined' ? null : document.createElement('div'),
|
if (typeof document === 'undefined') return null;
|
||||||
);
|
const element = document.createElement('div');
|
||||||
|
element.className = FOOTER_AWARE_CLASS;
|
||||||
|
return element;
|
||||||
|
});
|
||||||
const isHydrated = useSyncExternalStore(
|
const isHydrated = useSyncExternalStore(
|
||||||
noSubscription,
|
noSubscription,
|
||||||
() => true,
|
() => true,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
const declared = useStore(toastPlacementStore, resolveToastPlacement);
|
||||||
|
// The region is inside an open sheet or modal, which covers the nav and any footer.
|
||||||
|
const [isInDialog, setInDialog] = useState(false);
|
||||||
|
const resolved = placement ?? declared;
|
||||||
|
const settled = isInDialog && resolved !== 'desktop' ? 'low' : resolved;
|
||||||
|
const offset = `${TOAST_OFFSETS[settled]}px`;
|
||||||
|
// A pinned footer can't sit under a dialog's toasts or in the desktop app's way.
|
||||||
|
const bottom =
|
||||||
|
settled === 'desktop' || isInDialog
|
||||||
|
? offset
|
||||||
|
: `var(--toast-footer-offset, ${offset})`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!box) return undefined;
|
if (!box) return undefined;
|
||||||
|
|
@ -68,6 +99,7 @@ export function Toaster({ label, closeLabel, style, ...props }: ToasterProps) {
|
||||||
const stack: HTMLDialogElement[] = [];
|
const stack: HTMLDialogElement[] = [];
|
||||||
const place = () => {
|
const place = () => {
|
||||||
(stack.at(-1) ?? document.body).append(box);
|
(stack.at(-1) ?? document.body).append(box);
|
||||||
|
setInDialog(stack.length > 0);
|
||||||
// Moving the box drops the focus inside it without a focusout.
|
// Moving the box drops the focus inside it without a focusout.
|
||||||
syncKeyboardFocus();
|
syncKeyboardFocus();
|
||||||
};
|
};
|
||||||
|
|
@ -100,8 +132,8 @@ export function Toaster({ label, closeLabel, style, ...props }: ToasterProps) {
|
||||||
<CloseLabelContext value={closeLabel}>
|
<CloseLabelContext value={closeLabel}>
|
||||||
<SonnerToaster
|
<SonnerToaster
|
||||||
position="bottom-center"
|
position="bottom-center"
|
||||||
offset={24}
|
offset={{ bottom }}
|
||||||
mobileOffset={24}
|
mobileOffset={{ bottom }}
|
||||||
gap={8}
|
gap={8}
|
||||||
containerAriaLabel={label}
|
containerAriaLabel={label}
|
||||||
toastOptions={{
|
toastOptions={{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import type { IconName } from '../../atoms/icon';
|
import type { IconName } from '../../atoms/icon';
|
||||||
import type { ToastTone } from './types';
|
import { PINNED_FOOTER_TOAST_OFFSET } from '../pinned-footer';
|
||||||
|
import type { ToastPlacement, ToastTone } from './types';
|
||||||
|
|
||||||
export const TOAST_ICONS: Record<ToastTone, IconName> = {
|
export const TOAST_ICONS: Record<ToastTone, IconName> = {
|
||||||
info: 'info',
|
info: 'info',
|
||||||
|
|
@ -16,3 +17,14 @@ 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_DURATION_MS = 8000;
|
||||||
export const TOAST_ERROR_WITH_ACTION_DURATION_MS = 10000;
|
export const TOAST_ERROR_WITH_ACTION_DURATION_MS = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each placement's distance from the bottom edge, in px: clear of the 64px bottom nav, of a pinned
|
||||||
|
* footer with one button and its note, near the edge on a task page or a sheet, and on desktop.
|
||||||
|
*/
|
||||||
|
export const TOAST_OFFSETS: Record<ToastPlacement, number> = {
|
||||||
|
nav: 80,
|
||||||
|
footer: PINNED_FOOTER_TOAST_OFFSET,
|
||||||
|
low: 24,
|
||||||
|
desktop: 32,
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
import { declareToastPlacement } from '../placement-store';
|
||||||
|
import type { DeclaredToastPlacement } from '../types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares, while the calling part is on screen and `active`, the bottom edge the toasts must sit
|
||||||
|
* above: `nav` (the mobile bottom nav, 80px), `footer` (a pinned footer, 152px) or `desktop` (the
|
||||||
|
* desktop app, centred at 32px). With none declared they sit low (24px), as on a task page or over
|
||||||
|
* a sheet.
|
||||||
|
*/
|
||||||
|
export function useToastPlacement(
|
||||||
|
placement: DeclaredToastPlacement,
|
||||||
|
active = true,
|
||||||
|
): void {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!active) return undefined;
|
||||||
|
return declareToastPlacement(placement);
|
||||||
|
}, [placement, active]);
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
|
export { TOAST_OFFSETS } from './constants';
|
||||||
|
export { useToastPlacement } from './hooks/use-toast-placement';
|
||||||
export { dismissToast, showToast } from './show-toast';
|
export { dismissToast, showToast } from './show-toast';
|
||||||
export { Toast } from './Toast';
|
export { Toast } from './Toast';
|
||||||
export { Toaster } from './Toaster';
|
export { Toaster } from './Toaster';
|
||||||
|
export { ToastPlacementMarker } from './ToastPlacementMarker';
|
||||||
export type {
|
export type {
|
||||||
|
DeclaredToastPlacement,
|
||||||
ShowToastOptions,
|
ShowToastOptions,
|
||||||
ToastAction,
|
ToastAction,
|
||||||
ToasterProps,
|
ToasterProps,
|
||||||
|
ToastPlacement,
|
||||||
|
ToastPlacementMarkerProps,
|
||||||
ToastProps,
|
ToastProps,
|
||||||
ToastTone,
|
ToastTone,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
|
||||||