// Shared UI pieces of the design system (styles.css): chips, store badges, app icons, KPI tiles, bars, sparklines, // stars, notices, skeletons, empty states, segmented controls, cards. import { type ReactNode, useId } from 'react'; import type { ReleasePhase, StoreRelease } from '../api'; import { t } from '../i18n'; import { share } from '../lib/format'; import { hueOf, monogram, type Tone } from '../lib/model'; import { Icon, type IconName, StoreGlyph } from './icons'; import { Illo, type IlloName } from './illustrations'; export function Chip({ tone = 'neutral', children, dot = true, title, icon }: { tone?: Tone | 'outline'; children: ReactNode; dot?: boolean; title?: string; icon?: IconName }) { return {icon ? : dot && tone !== 'outline' && }{children}; } const PHASE_TONE: Record = { live: 'ok', rollout: 'accent', halted: 'bad', approved: 'ok', review: 'warn', rejected: 'bad', testing: 'info', draft: 'neutral', other: 'neutral' }; /** Chip of a store release: "Live", "Rollout 20%", "In review" ... (iOS phased release: "Phased 50%", "Paused"). */ export function phaseLabel(r: StoreRelease | null | undefined): { text: string; tone: Tone } { if (!r) return { text: t('phase.none'), tone: 'neutral' }; const pct = r.fraction !== null && r.fraction !== undefined && r.fraction < 1 ? ` ${share(r.fraction)}` : ''; if (r.phase === 'rollout') return { text: (r.store === 'ios' ? t('phase.phased') : t('phase.rollout')) + pct, tone: 'accent' }; if (r.phase === 'halted') return { text: (r.store === 'ios' ? t('phase.paused') : t('phase.halted')) + pct, tone: 'bad' }; if (r.phase === 'testing' && r.track) return { text: `${t('phase.testing')} · ${r.track}`, tone: 'info' }; return { text: t(`phase.${r.phase}`), tone: PHASE_TONE[r.phase] }; } export function PhaseChip({ r }: { r: StoreRelease | null | undefined }) { const p = phaseLabel(r); return {p.text}; } export const storeName = (s: 'ios' | 'android'): string => (s === 'ios' ? 'App Store' : 'Google Play'); /** "App Store · com.example.app" badge, dashed when the app is not on that store. */ export function StoreBadge({ store, id, off, children }: { store: 'ios' | 'android'; id?: string | null; off?: boolean; children?: ReactNode }) { return ( {storeName(store)} {id && <>{id}} {off && · {t('app.notSetUp')}} {children && <>{children}} ); } /** The app's own icon when the project has one, else a monogram on a gradient picked from the name. */ export function AppIcon({ name, src, className = '' }: { name: string; src?: string | null; className?: string }) { if (src) return ; const h = hueOf(name); return ( ); } export function Kpi({ label, value, sub, icon, tone }: { label: string; value: ReactNode; sub?: ReactNode; icon?: IconName; tone?: Tone }) { return (
{icon && }{label}
{value}
{sub !== undefined &&
{sub}
}
); } export function Bar({ value, tone, thin, label }: { value: number; tone?: Tone; thin?: boolean; label?: string }) { const v = Math.max(0, Math.min(1, value)); return (
); } /** Line + area sparkline with a dashed threshold line. Values are fractions; the y range always shows the threshold. */ export function Sparkline({ values, threshold, tone = 'neutral', label }: { values: number[]; threshold?: number; tone?: Tone; label: string }) { const W = 300, H = 72, pad = 4; const gid = useId().replace(/:/g, ''); if (!values.length) return
; const max = Math.max(...values, (threshold ?? 0) * 1.25) * 1.08 || 1; const x = (i: number) => (values.length === 1 ? W / 2 : (i / (values.length - 1)) * W); const y = (v: number) => H - pad - (v / max) * (H - pad * 2); const line = values.map((v, i) => `${i ? 'L' : 'M'}${x(i).toFixed(1)} ${y(v).toFixed(1)}`).join(' '); const area = `${line} L${W} ${H} L0 ${H} Z`; return ( {threshold !== undefined && } ); } export function Stars({ n, label }: { n: number; label?: string }) { return ( {[1, 2, 3, 4, 5].map(i => ( ))} ); } export function Notice({ tone, children, icon, action }: { tone: 'bad' | 'warn' | 'ok' | 'info'; children: ReactNode; icon?: IconName; action?: ReactNode }) { const ic: IconName = icon ?? (tone === 'bad' ? 'alertCircle' : tone === 'warn' ? 'alert' : tone === 'ok' ? 'check' : 'info'); return
{children}
{action}
; } export function Skeleton({ lines = 3, block }: { lines?: number; block?: boolean }) { return (
{block && } {Array.from({ length: lines }, (_, i) => )}
); } export function Empty({ illo, title, children, actions, compact }: { illo: IlloName; title: string; children?: ReactNode; actions?: ReactNode; compact?: boolean }) { return (

{title}

{children &&

{children}

} {actions &&
{actions}
}
); } export function Seg({ value, options, onChange, label }: { value: T; options: [T, string, IconName?][]; onChange: (v: T) => void; label: string }) { return (
{options.map(([v, text, icon]) => )}
); } export function Card({ title, icon, sub, actions, children, foot, className = '', pad = true }: { title?: ReactNode; icon?: IconName; sub?: ReactNode; actions?: ReactNode; children: ReactNode; foot?: ReactNode; className?: string; pad?: boolean }) { return (
{title !== undefined && (

{icon && }{title}

{sub &&
{sub}
}
{actions &&
{actions}
}
)} {pad ?
{children}
: children} {foot &&
{foot}
}
); } export function Kbd({ keys }: { keys: string[] }) { return <>{keys.map(k => {k})}; } /** Platform modifier label (⌘ on macOS, Ctrl elsewhere). */ export const MOD = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform) ? '⌘' : 'Ctrl';