import React from 'react'; import {Loader as MLoader, Skeleton} from '@mantine/core'; import {Icon} from './Icon'; import {SemanticColorName} from '../../themes/mantine'; /* * Feedback: messages, labels, progress, status text, loaders. * * These carry the design rules that change form (not just color) between * themes, so their markup is ours and their values come from tokens. */ // ------------------------------------------------------------------ Messages export type MessageKind = 'info' | 'success' | 'warning' | 'error'; const messageColors: Record = { info: 'var(--blue)', success: 'var(--green)', warning: 'var(--amber)', error: 'var(--red)', }; export interface MessageProps { kind?: MessageKind; title?: React.ReactNode; children?: React.ReactNode; className?: string; } export function Message({kind = 'info', title, children, className}: MessageProps) { return
{title &&
{title}
} {children &&
{children}
}
} // -------------------------------------------------------------------- Labels export interface LabelProps { color?: SemanticColorName | 'black' | 'white'; icon?: string | React.ComponentType; children?: React.ReactNode; onClick?: React.MouseEventHandler; className?: string; } /** A tag/chip. Filled in light and dark; an outline in night, where a filled * patch would be a bright surface. */ export function Label({color = 'grey', icon, children, onClick, className}: LabelProps) { return {icon && (typeof icon === 'string' ? : )} {children} } // ------------------------------------------------------------------ Progress export interface ProgressProps { /** 0-100. Values outside the range are clamped. */ percent?: number; /** Show the percentage inside the bar. */ showPercent?: boolean; color?: SemanticColorName; /** Replaces the percentage with arbitrary text (e.g. "2.1 GB / 5.3 GB"). */ label?: React.ReactNode; className?: string; } export function Progress({percent = 0, showPercent = true, color = 'blue', label, className}: ProgressProps) { const clamped = Math.min(100, Math.max(0, Number.isFinite(percent) ? percent : 0)); return
{(showPercent || label) && {label ?? `${Math.round(clamped)}%`} }
} // -------------------------------------------------------------------- Status export type StatusKind = 'complete' | 'active' | 'pending' | 'failed'; const statusIcons: Record = { complete: 'check', active: 'circle notch', pending: 'circle', failed: 'x', }; export interface StatusProps { kind: StatusKind; children?: React.ReactNode; /** Hide the leading icon. */ plain?: boolean; } /** * Status text. Encoded by hue in light and dark; night mode has no hue to * spend, so brightness carries it (see ui.css). Callers name the state, never * the color. */ export function Status({kind, children, plain}: StatusProps) { return {!plain && } {children} } // ------------------------------------------------------------------- Loaders export interface LoaderProps { size?: number | 'xs' | 'sm' | 'md' | 'lg' | 'xl'; label?: string; } export function Loader({size = 'sm', label}: LoaderProps) { return } /** Placeholder for content that has not arrived. Replaces Semantic's Placeholder. */ export function Placeholder({lines = 3, height = 12}: {lines?: number; height?: number}) { return
{Array.from({length: lines}, (_, index) => )}
} export {Skeleton};