#atom

Subtitle:

The practice of isolating reusable UI elements into modular, self-contained components


Core Idea:

Component abstraction is the process of identifying repeating UI patterns and encapsulating them into reusable, maintainable components with defined interfaces, promoting code reuse and separation of concerns.


Key Principles:

  1. Single Responsibility:
    • Each component should ideally do one thing well, with clear boundaries for its functionality and appearance.
  2. Parameterization:
    • Components accept properties (props/parameters) that allow customization without changing the component's internal implementation.
  3. Composition Over Inheritance:
    • Complex interfaces are built by combining simpler components rather than extending them through inheritance hierarchies.

Why It Matters:


How to Implement:

  1. Identify Patterns:
    • Recognize repeated UI elements across designs that share visual or functional similarities.
  2. Define Props Interface:
    • Determine which aspects of the component should be customizable through external properties.
  3. Extract and Refactor:
    • Isolate the component code, replacing specific values with props and ensuring it works in all required contexts.

Example:

function Card({ title, description, icon, image, className }) {
  return (
    <div className={`bg-blue-600 rounded-xl p-6 ${className}`}>
      <div className="flex gap-4">
        <div className="space-y-2">
          {icon && <div className="text-3xl">{icon}</div>}
          <h3 className="text-2xl font-bold">{title}</h3>
          <p>{description}</p>
          <button className="border rounded-3xl py-2 px-4 flex items-center gap-1">
            View More <ChevronRight />
          </button>
        </div>
        {image && <img src={image} className="w-64" />}
      </div>
    </div>
  );
}

Connections:


References:

  1. Primary Source:
    • "Thinking in React" - React Documentation
  2. Additional Resources:
    • "Atomic Design" by Brad Frost
    • "Component-Driven Development" - Storybook Documentation

Tags:

#frontend #architecture #reusability #components #softwaredesign #ui


Connections:


Sources: