Part 57: Building Primitive UI Components: Buttons, Badges & Avatars

Part 57 Technology Updated September 12, 2026

Part 57: Building Primitive UI Components: Buttons, Badges & Avatars

Let's build a suite of accessible, production-ready primitive design system components.


1. Button Component with Variants

export function Button({ variant = 'primary', size = 'md', children, ...props }) {
  const base = "inline-flex items-center justify-center font-semibold rounded-xl transition duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2";

  const variants = {
    primary: "bg-blue-600 hover:bg-blue-700 text-white shadow-sm shadow-blue-500/30 focus-visible:ring-blue-600",
    secondary: "bg-slate-100 hover:bg-slate-200 text-slate-700 focus-visible:ring-slate-400",
    danger: "bg-red-600 hover:bg-red-700 text-white shadow-sm shadow-red-500/30 focus-visible:ring-red-600",
    ghost: "text-slate-600 hover:bg-slate-100 focus-visible:ring-slate-400"
  };

  const sizes = {
    sm: "px-3 py-1.5 text-xs",
    md: "px-4 py-2 text-sm",
    lg: "px-6 py-3 text-base"
  };

  return (
    <button className={`${base} ${variants[variant]} ${sizes[size]}`} {...props}>
      {children}
    </button>
  );
}

Key Takeaways

  • Organize component styling using base styles and dictionary lookup variants.

In Part 58, we will build Form Components: Floating Labels, Custom Inputs & Checkboxes!