Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

2.6 KB
Raw Blame
import MicroGlyph from './micrographics/MicroGlyph';

const statusConfig = {
  online: {
    badge: 'bg-port-success/15 text-port-success',
    dot: 'bg-port-success',
    text: 'Online',
    pulse: true,
    glyph: { variant: 'pulse-dot', state: 'success', animated: true },
  },
  stopped: {
    badge: 'bg-port-warning/15 text-port-warning',
    dot: 'bg-port-warning',
    text: 'Stopped',
    pulse: false,
    glyph: { variant: 'bracket-pair', state: 'warn', animated: false },
  },
  not_started: {
    badge: 'bg-gray-500/20 text-gray-400',
    dot: 'bg-gray-500',
    text: 'Offline',
    pulse: false,
    glyph: { variant: 'reticle', state: 'idle', animated: false },
  },
  not_found: {
    badge: 'bg-gray-500/20 text-gray-400',
    dot: 'bg-gray-500',
    text: 'Not Found',
    pulse: false,
    glyph: { variant: 'reticle', state: 'idle', animated: false },
  },
  error: {
    badge: 'bg-port-error/15 text-port-error',
    dot: 'bg-port-error',
    text: 'Error',
    pulse: false,
    glyph: { variant: 'warning-tri', state: 'error', animated: true },
  },
  unknown: {
    badge: 'bg-gray-600/20 text-gray-400',
    dot: 'bg-gray-600',
    text: 'Unknown',
    pulse: false,
    glyph: { variant: 'reticle', state: 'idle', animated: false },
  },
};

// `glyph`: false (default) keeps the legacy dot; true uses the per-status
// micrographic; a string overrides the variant; an object overrides any field.
export default function StatusBadge({ status, size = 'md', glyph = false }) {
  const config = statusConfig[status] || statusConfig.unknown;

  const sizeClasses = {
    sm: 'text-xs px-2 py-0.5',
    md: 'text-sm px-2.5 py-1',
    lg: 'text-base px-3 py-1.5'
  };

  const glyphSize = size === 'lg' ? 14 : size === 'sm' ? 10 : 12;

  let glyphSpec = null;
  if (glyph === true) {
    glyphSpec = config.glyph;
  } else if (typeof glyph === 'string') {
    glyphSpec = { ...config.glyph, variant: glyph };
  } else if (glyph && typeof glyph === 'object') {
    glyphSpec = { ...config.glyph, ...glyph };
  }

  return (
    <span
      role="status"
      aria-label={`Status: ${config.text}`}
      className={`inline-flex items-center gap-1.5 rounded-full font-medium ${config.badge} ${sizeClasses[size]}`}
    >
      {glyphSpec ? (
        <MicroGlyph
          variant={glyphSpec.variant}
          state={glyphSpec.state}
          animated={glyphSpec.animated}
          size={glyphSize}
        />
      ) : (
        config.pulse && (
          <span className={`w-2 h-2 rounded-full ${config.dot} animate-pulse-soft`} aria-hidden="true" />
        )
      )}
      {config.text}
    </span>
  );
}