Files
TREK/client/src/components/Help/HelpBadge.tsx
T
Maurice ba70ad28b8 fix(client): spacing and alignment follow the reading direction
Arabic runs the app right to left, but margins, paddings, insets, text
alignment, borders and corner radii were written for the left side, so
icons sat against the wrong edge of their labels, indents and badges
pointed the wrong way and amount columns aligned left. They now use the
logical forms (ms-, ps-, start-, text-start, marginInlineStart,
insetInlineEnd and their CSS equivalents), which are the very same sides
in a left to right language. Geometry stays physical on purpose: maps,
positions measured from the pointer or a bounding box, time axes,
sliders, transforms and print output.

Amounts drawn as several spans keep their order in a right to left row,
the time picker keeps hours before minutes, and two switches whose thumb
slid out of its track in Arabic now move the right way.

lint:rtl counts what is still physical per file against a baseline that
may only shrink (1512 uses in 370 files before, 319 in 113 now), and CI
runs it, so new code reaches for the logical forms.
2026-10-07 22:33:58 +00:00

63 lines
2.1 KiB
TypeScript

import React from 'react'
import type { LucideIcon } from 'lucide-react'
/**
* The one pill the help center is built from: section markers, counters,
* breadcrumbs, step numbers. Tones map onto the appearance tokens so a user's
* accent reaches every badge, and a badge can nest another (`count`) for the
* "3 steps" pattern without a second component.
*/
export type HelpBadgeTone = 'neutral' | 'accent' | 'soft' | 'success' | 'warning' | 'outline'
const TONES: Record<HelpBadgeTone, string> = {
neutral: 'bg-surface-tertiary text-content-secondary',
accent: 'bg-accent text-accent-text',
soft: 'bg-accent-subtle text-accent-on',
success: 'bg-success-soft text-success',
warning: 'bg-warning-soft text-warning',
outline: 'border border-edge bg-surface-card text-content-secondary',
}
/** The nested counter inverts against its parent so it reads as a badge in a badge. */
const COUNT_TONES: Record<HelpBadgeTone, string> = {
neutral: 'bg-surface-card text-content',
accent: 'bg-accent-text text-accent',
soft: 'bg-surface-card text-content',
success: 'bg-surface-card text-success',
warning: 'bg-surface-card text-warning',
outline: 'bg-surface-tertiary text-content',
}
export default function HelpBadge({
tone = 'neutral',
icon: Icon,
count,
uppercase = false,
children,
className = '',
}: {
tone?: HelpBadgeTone
icon?: LucideIcon
/** A nested badge on the right, e.g. a number. */
count?: React.ReactNode
uppercase?: boolean
children?: React.ReactNode
className?: string
}): React.ReactElement {
return (
<span
className={`inline-flex items-center gap-1.5 h-7 rounded-full ps-2.5 text-caption font-semibold leading-none whitespace-nowrap ${
count === undefined ? 'pe-2.5' : 'pe-1'
} ${uppercase ? 'uppercase tracking-[0.08em]' : ''} ${TONES[tone]} ${className}`}
>
{Icon && <Icon className="w-3.5 h-3.5 flex-shrink-0" />}
{children}
{count !== undefined && (
<span className={`inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 rounded-full text-caption font-bold ${COUNT_TONES[tone]}`}>
{count}
</span>
)}
</span>
)
}