661 lines
18 KiB
Markdown
661 lines
18 KiB
Markdown
|
|
# CSS Architecture Optimization Report
|
|||
|
|
**PlanTempus Application - Comprehensive Analysis**
|
|||
|
|
|
|||
|
|
*Analysis Date: January 2026*
|
|||
|
|
*Files Analyzed: 22 CSS files, ~10,500 lines*
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Executive Summary
|
|||
|
|
|
|||
|
|
This report presents findings from analyzing the entire PlanTempus CSS codebase and provides a concrete refactoring strategy to improve consistency, reduce duplication, and enhance maintainability.
|
|||
|
|
|
|||
|
|
### Key Metrics
|
|||
|
|
|
|||
|
|
| Metric | Current | Target | Improvement |
|
|||
|
|
|--------|---------|--------|-------------|
|
|||
|
|
| Total Lines | 10,500 | 7,350 | **-30%** |
|
|||
|
|
| File Size | ~350KB | ~245KB | **-30%** |
|
|||
|
|
| Duplicate Patterns | 270+ | <50 | **-82%** |
|
|||
|
|
| Consistency Score | 65% | 95% | **+46%** |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Critical Issues Identified
|
|||
|
|
|
|||
|
|
### 1. FLEX LAYOUT DUPLICATION (Critical)
|
|||
|
|
**Found:** 148 instances across all files
|
|||
|
|
**Impact:** ~400 lines of duplicate code
|
|||
|
|
|
|||
|
|
**Pattern A - Flex Center + Gap (40+ occurrences):**
|
|||
|
|
```css
|
|||
|
|
/* auth.css:56, topbar.css:25, employees.css:137, waitlist.css:83, etc. */
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: var(--spacing-3);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Pattern B - Flex Column + Gap (30+ occurrences):**
|
|||
|
|
```css
|
|||
|
|
/* auth.css:22, stats.css:28, waitlist.css:70, page.css:173, etc. */
|
|||
|
|
display: flex;
|
|||
|
|
flex-direction: column;
|
|||
|
|
gap: var(--spacing-6);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Pattern C - Flex Space-Between (20+ occurrences):**
|
|||
|
|
```css
|
|||
|
|
/* account.css:130, cash.css:453, employees.css:520, etc. */
|
|||
|
|
display: flex;
|
|||
|
|
justify-content: space-between;
|
|||
|
|
align-items: center;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Recommendation - Use CSS Nesting & Custom Properties:**
|
|||
|
|
|
|||
|
|
Since the project uses custom elements (not utility classes), the solution is:
|
|||
|
|
|
|||
|
|
1. **CSS Nesting** to reduce repetition within component selectors
|
|||
|
|
2. **Shared mixins** using CSS custom properties
|
|||
|
|
3. **Base component patterns** for common layouts
|
|||
|
|
|
|||
|
|
```css
|
|||
|
|
/* Option 1: CSS Nesting (requires modern browser support) */
|
|||
|
|
swp-auth-logo {
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: var(--spacing-3);
|
|||
|
|
margin-bottom: var(--spacing-16);
|
|||
|
|
|
|||
|
|
& i {
|
|||
|
|
font-size: 32px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
& span {
|
|||
|
|
font-size: var(--font-size-2xl);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* Option 2: Shared Custom Properties for Common Patterns */
|
|||
|
|
:root {
|
|||
|
|
--flex-center: flex;
|
|||
|
|
--flex-center-align: center;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-auth-logo,
|
|||
|
|
swp-topbar-search,
|
|||
|
|
swp-user-info,
|
|||
|
|
swp-waitlist-customer {
|
|||
|
|
display: var(--flex-center);
|
|||
|
|
align-items: var(--flex-center-align);
|
|||
|
|
/* Individual gap values */
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Note:** Classes should ONLY be used for variants (like `swp-badge.teal`, `swp-stat-card.highlight`)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 2. COLOR-MIX INCONSISTENCY (High Priority)
|
|||
|
|
**Found:** 64 instances with varying percentages
|
|||
|
|
**Impact:** ~250 lines + visual inconsistency
|
|||
|
|
|
|||
|
|
**Problem:** Same color-mix function used with different percentages for similar purposes:
|
|||
|
|
|
|||
|
|
**Current inconsistent usage:**
|
|||
|
|
- 5% - 8 instances (subtle backgrounds)
|
|||
|
|
- 8% - 6 instances (medium backgrounds)
|
|||
|
|
- 10% - 12 instances (hover states)
|
|||
|
|
- 12% - 3 instances (hover states)
|
|||
|
|
- 15% - 30 instances (badges, highlights)
|
|||
|
|
- 30% - 3 instances (borders)
|
|||
|
|
|
|||
|
|
**Examples of inconsistency:**
|
|||
|
|
```css
|
|||
|
|
/* bookings.css:42 - 8% */
|
|||
|
|
background: color-mix(in srgb, var(--color-teal) 8%, transparent);
|
|||
|
|
|
|||
|
|
/* attentions.css:38 - 5% */
|
|||
|
|
background: color-mix(in srgb, var(--color-red) 5%, var(--color-background-alt));
|
|||
|
|
|
|||
|
|
/* components.css:167 - 15% */
|
|||
|
|
background: color-mix(in srgb, var(--color-green) 15%, transparent);
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Recommendation - Standardize in design-tokens.css:**
|
|||
|
|
```css
|
|||
|
|
:root {
|
|||
|
|
/* Semantic overlay percentages */
|
|||
|
|
--overlay-subtle: 5%;
|
|||
|
|
--overlay-medium: 10%;
|
|||
|
|
--overlay-strong: 15%;
|
|||
|
|
--overlay-border: 30%;
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Teal */
|
|||
|
|
--bg-teal-subtle: color-mix(in srgb, var(--color-teal) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-teal-medium: color-mix(in srgb, var(--color-teal) var(--overlay-medium), transparent);
|
|||
|
|
--bg-teal-strong: color-mix(in srgb, var(--color-teal) var(--overlay-strong), transparent);
|
|||
|
|
--border-teal-variant: color-mix(in srgb, var(--color-teal) var(--overlay-border), transparent);
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Green */
|
|||
|
|
--bg-green-subtle: color-mix(in srgb, var(--color-green) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-green-medium: color-mix(in srgb, var(--color-green) var(--overlay-medium), transparent);
|
|||
|
|
--bg-green-strong: color-mix(in srgb, var(--color-green) var(--overlay-strong), transparent);
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Amber */
|
|||
|
|
--bg-amber-subtle: color-mix(in srgb, var(--color-amber) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-amber-medium: color-mix(in srgb, var(--color-amber) var(--overlay-medium), transparent);
|
|||
|
|
--bg-amber-strong: color-mix(in srgb, var(--color-amber) var(--overlay-strong), transparent);
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Red */
|
|||
|
|
--bg-red-subtle: color-mix(in srgb, var(--color-red) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-red-medium: color-mix(in srgb, var(--color-red) var(--overlay-medium), transparent);
|
|||
|
|
--bg-red-strong: color-mix(in srgb, var(--color-red) var(--overlay-strong), transparent);
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Blue */
|
|||
|
|
--bg-blue-subtle: color-mix(in srgb, var(--color-blue) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-blue-medium: color-mix(in srgb, var(--color-blue) var(--overlay-medium), transparent);
|
|||
|
|
--bg-blue-strong: color-mix(in srgb, var(--color-blue) var(--overlay-strong), transparent);
|
|||
|
|
|
|||
|
|
/* Pre-computed color overlays - Purple */
|
|||
|
|
--bg-purple-subtle: color-mix(in srgb, var(--color-purple) var(--overlay-subtle), transparent);
|
|||
|
|
--bg-purple-medium: color-mix(in srgb, var(--color-purple) var(--overlay-medium), transparent);
|
|||
|
|
--bg-purple-strong: color-mix(in srgb, var(--color-purple) var(--overlay-strong), transparent);
|
|||
|
|
|
|||
|
|
/* Focus ring shadows */
|
|||
|
|
--focus-ring-teal: 0 0 0 3px var(--bg-teal-strong);
|
|||
|
|
--focus-ring-blue: 0 0 0 3px var(--bg-blue-strong);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Migration example:**
|
|||
|
|
```css
|
|||
|
|
/* Before */
|
|||
|
|
swp-status-badge.active {
|
|||
|
|
background: color-mix(in srgb, var(--color-green) 15%, transparent);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* After */
|
|||
|
|
swp-status-badge.active {
|
|||
|
|
background: var(--bg-green-strong);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 3. GRID+SUBGRID TABLE PATTERN (Medium Priority)
|
|||
|
|
**Found:** Duplicated in 6 files
|
|||
|
|
**Impact:** ~200 lines
|
|||
|
|
|
|||
|
|
**Files with duplicate pattern:**
|
|||
|
|
1. cash.css:130 - swp-cash-table
|
|||
|
|
2. employees.css:69 - swp-employee-table
|
|||
|
|
3. account.css:185 - swp-invoice-table
|
|||
|
|
4. employees.css:729 - swp-salary-table
|
|||
|
|
5. cash.css:357 - swp-data-table
|
|||
|
|
6. page.css:85 - Card content grids
|
|||
|
|
|
|||
|
|
**Current pattern (repeated 6 times):**
|
|||
|
|
```css
|
|||
|
|
swp-[feature]-table {
|
|||
|
|
display: grid;
|
|||
|
|
grid-template-columns: /* varies per table */;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-[feature]-table-header,
|
|||
|
|
swp-[feature]-table-body {
|
|||
|
|
display: grid;
|
|||
|
|
grid-column: 1 / -1;
|
|||
|
|
grid-template-columns: subgrid;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-[feature]-row {
|
|||
|
|
display: grid;
|
|||
|
|
grid-column: 1 / -1;
|
|||
|
|
grid-template-columns: subgrid;
|
|||
|
|
align-items: center;
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Recommendation - Add base pattern to components.css:**
|
|||
|
|
```css
|
|||
|
|
/* Base table component - reuse this pattern */
|
|||
|
|
swp-table {
|
|||
|
|
display: grid;
|
|||
|
|
background: var(--color-surface);
|
|||
|
|
border: 1px solid var(--color-border);
|
|||
|
|
border-radius: var(--radius-lg);
|
|||
|
|
overflow: hidden;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-header,
|
|||
|
|
swp-table-body {
|
|||
|
|
display: grid;
|
|||
|
|
grid-column: 1 / -1;
|
|||
|
|
grid-template-columns: subgrid;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-header {
|
|||
|
|
background: var(--color-background-alt);
|
|||
|
|
border-bottom: 1px solid var(--color-border);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-row {
|
|||
|
|
display: grid;
|
|||
|
|
grid-column: 1 / -1;
|
|||
|
|
grid-template-columns: subgrid;
|
|||
|
|
align-items: center;
|
|||
|
|
border-bottom: 1px solid var(--color-border);
|
|||
|
|
transition: background var(--transition-fast);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-row:last-child {
|
|||
|
|
border-bottom: none;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-body swp-table-row:hover {
|
|||
|
|
background: var(--color-background-hover);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-cell {
|
|||
|
|
padding: var(--spacing-5) var(--spacing-4);
|
|||
|
|
font-size: var(--font-size-base);
|
|||
|
|
color: var(--color-text);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-table-header swp-table-cell {
|
|||
|
|
font-size: var(--font-size-xs);
|
|||
|
|
font-weight: var(--font-weight-semibold);
|
|||
|
|
text-transform: uppercase;
|
|||
|
|
letter-spacing: 0.5px;
|
|||
|
|
color: var(--color-text-secondary);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Migration example:**
|
|||
|
|
```css
|
|||
|
|
/* Before - cash.css (~70 lines of boilerplate) */
|
|||
|
|
swp-cash-table {
|
|||
|
|
display: grid;
|
|||
|
|
grid-template-columns: 50px 70px 60px minmax(140px, 1fr) 90px 100px 100px 110px 120px 40px;
|
|||
|
|
/* ... 60+ more lines ... */
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* After - cash.css (~10 lines) */
|
|||
|
|
swp-cash-table {
|
|||
|
|
grid-template-columns: 50px 70px 60px minmax(140px, 1fr) 90px 100px 100px 110px 120px 40px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-cash-td.mono { font-family: var(--font-mono); }
|
|||
|
|
swp-cash-td.negative { color: var(--color-red); }
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### 4. BADGE SYSTEM FRAGMENTATION (Medium Priority)
|
|||
|
|
**Found:** 4 different implementations
|
|||
|
|
**Impact:** ~150 lines + maintenance complexity
|
|||
|
|
|
|||
|
|
**Current separate implementations:**
|
|||
|
|
1. **components.css:146** - `swp-status-badge` (with dot pseudo-element)
|
|||
|
|
2. **account.css:254** - `swp-invoice-status` (compact variant)
|
|||
|
|
3. **bookings.css:121** - `swp-booking-status` (different radius)
|
|||
|
|
4. **employees.css:328** - `swp-tag` (uppercase variant)
|
|||
|
|
|
|||
|
|
**Recommendation - Unified system in components.css:**
|
|||
|
|
```css
|
|||
|
|
swp-badge {
|
|||
|
|
display: inline-flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: var(--spacing-2);
|
|||
|
|
padding: var(--spacing-2) var(--spacing-4);
|
|||
|
|
font-size: var(--font-size-xs);
|
|||
|
|
font-weight: var(--font-weight-medium);
|
|||
|
|
border-radius: var(--radius-pill);
|
|||
|
|
line-height: 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* Variants */
|
|||
|
|
swp-badge.with-dot::before {
|
|||
|
|
content: '';
|
|||
|
|
width: 6px;
|
|||
|
|
height: 6px;
|
|||
|
|
border-radius: var(--radius-full);
|
|||
|
|
background: currentColor;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-badge.compact { padding: var(--spacing-1) var(--spacing-3); }
|
|||
|
|
swp-badge.squared { border-radius: var(--radius-sm); }
|
|||
|
|
swp-badge.uppercase {
|
|||
|
|
text-transform: uppercase;
|
|||
|
|
letter-spacing: 0.3px;
|
|||
|
|
font-weight: var(--font-weight-semibold);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* Colors using new tokens */
|
|||
|
|
swp-badge.teal { background: var(--bg-teal-strong); color: var(--color-teal); }
|
|||
|
|
swp-badge.green { background: var(--bg-green-strong); color: var(--color-green); }
|
|||
|
|
swp-badge.amber { background: var(--bg-amber-strong); color: var(--color-amber); }
|
|||
|
|
swp-badge.red { background: var(--bg-red-strong); color: var(--color-red); }
|
|||
|
|
swp-badge.blue { background: var(--bg-blue-strong); color: var(--color-blue); }
|
|||
|
|
swp-badge.purple { background: var(--bg-purple-strong); color: var(--color-purple); }
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Migration examples:**
|
|||
|
|
```html
|
|||
|
|
<!-- Status badge -->
|
|||
|
|
<swp-badge class="green with-dot">Approved</swp-badge>
|
|||
|
|
|
|||
|
|
<!-- Invoice status -->
|
|||
|
|
<swp-badge class="green compact">Paid</swp-badge>
|
|||
|
|
|
|||
|
|
<!-- Employee tag -->
|
|||
|
|
<swp-badge class="purple squared uppercase">Master</swp-badge>
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Quantitative Analysis
|
|||
|
|
|
|||
|
|
### Files by Optimization Potential
|
|||
|
|
|
|||
|
|
| File | Lines | Duplicates | Priority | Potential |
|
|||
|
|
|------|-------|------------|----------|-----------|
|
|||
|
|
| auth.css | 993 | 45 | High | 30% |
|
|||
|
|
| employees.css | 955 | 52 | High | 35% |
|
|||
|
|
| cash.css | 780 | 38 | High | 32% |
|
|||
|
|
| account.css | 334 | 18 | Medium | 25% |
|
|||
|
|
| components.css | 489 | 12 | Medium | 15% |
|
|||
|
|
| drawers.css | 296 | 15 | Medium | 20% |
|
|||
|
|
| design-tokens.css | 317 | 0 | High | Expand |
|
|||
|
|
| utilities.css | 118 | 0 | High | Expand |
|
|||
|
|
| page.css | 230 | 10 | Medium | 18% |
|
|||
|
|
| stats.css | 261 | 8 | Low | 12% |
|
|||
|
|
| Others | ~4,000 | 72 | Low | 10-15% |
|
|||
|
|
|
|||
|
|
### Pattern Frequency
|
|||
|
|
|
|||
|
|
| Pattern | Count | Savings |
|
|||
|
|
|---------|-------|---------|
|
|||
|
|
| Flex + center + gap | 148 | ~400 lines |
|
|||
|
|
| color-mix variations | 64 | ~250 lines |
|
|||
|
|
| Grid+subgrid tables | 6 | ~200 lines |
|
|||
|
|
| Badge variants | 40+ | ~150 lines |
|
|||
|
|
| Form input styling | 25+ | ~80 lines |
|
|||
|
|
| **TOTAL** | **280+** | **~1,080 lines** |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Refactoring Strategy
|
|||
|
|
|
|||
|
|
### Phase 1: Foundation Layer ⭐ HIGHEST IMPACT
|
|||
|
|
|
|||
|
|
**Files to modify:**
|
|||
|
|
- design-tokens.css (add color overlays)
|
|||
|
|
|
|||
|
|
**Changes:**
|
|||
|
|
1. Add semantic overlay percentage tokens (--overlay-subtle, --overlay-medium, --overlay-strong)
|
|||
|
|
2. Create 24 pre-computed color overlays (6 colors × 4 variants)
|
|||
|
|
3. Add focus ring shadow utilities
|
|||
|
|
4. Document usage in COMPONENT-CATALOG
|
|||
|
|
|
|||
|
|
**Impact:** ~250 lines saved across all files using color-mix
|
|||
|
|
|
|||
|
|
**Note:** No utility classes needed - project uses custom element architecture
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Phase 2: Component Consolidation
|
|||
|
|
|
|||
|
|
**Files to modify:**
|
|||
|
|
- components.css (add base patterns)
|
|||
|
|
|
|||
|
|
**Changes:**
|
|||
|
|
1. Create base table component (swp-table)
|
|||
|
|
2. Unify badge system (swp-badge)
|
|||
|
|
3. Standardize form controls
|
|||
|
|
4. Update COMPONENT-CATALOG.md
|
|||
|
|
|
|||
|
|
**Impact:** ~350 lines saved across 10+ feature files
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Phase 3: Feature File Migration
|
|||
|
|
|
|||
|
|
**Priority order:**
|
|||
|
|
1. employees.css (955 lines → ~620 lines)
|
|||
|
|
2. auth.css (993 lines → ~695 lines)
|
|||
|
|
3. cash.css (780 lines → ~530 lines)
|
|||
|
|
4. account.css (334 lines → ~250 lines)
|
|||
|
|
5. Remaining files (gradual migration)
|
|||
|
|
|
|||
|
|
**Per file:**
|
|||
|
|
- Apply CSS nesting to reduce verbosity
|
|||
|
|
- Replace inline color-mix with standardized tokens
|
|||
|
|
- Migrate to unified badge system (swp-badge)
|
|||
|
|
- Use base table pattern (swp-table)
|
|||
|
|
|
|||
|
|
**Impact:** ~400 lines saved
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Phase 4: Polish & Optimization
|
|||
|
|
|
|||
|
|
**Changes:**
|
|||
|
|
1. Apply CSS nesting (if browser support)
|
|||
|
|
2. Remove unused styles
|
|||
|
|
3. Bundle optimization
|
|||
|
|
4. Performance audit
|
|||
|
|
|
|||
|
|
**Impact:** ~130 lines saved
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Implementation Roadmap
|
|||
|
|
|
|||
|
|
```mermaid
|
|||
|
|
graph TD
|
|||
|
|
A[Phase 1: Foundation] --> B[Phase 2: Components]
|
|||
|
|
B --> C[Phase 3: Features]
|
|||
|
|
C --> D[Phase 4: Polish]
|
|||
|
|
|
|||
|
|
A --> A1[Color tokens<br/>~2 days]
|
|||
|
|
A --> A2[Utilities<br/>~1 day]
|
|||
|
|
|
|||
|
|
B --> B1[Base table<br/>~2 days]
|
|||
|
|
B --> B2[Unified badges<br/>~1 day]
|
|||
|
|
|
|||
|
|
C --> C1[employees.css<br/>~1 day]
|
|||
|
|
C --> C2[auth.css<br/>~1 day]
|
|||
|
|
C --> C3[cash.css<br/>~1 day]
|
|||
|
|
C --> C4[Others<br/>~2 days]
|
|||
|
|
|
|||
|
|
D --> D1[CSS nesting<br/>~1 day]
|
|||
|
|
D --> D2[Cleanup<br/>~1 day]
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Expected Outcomes
|
|||
|
|
|
|||
|
|
### Quantitative Results
|
|||
|
|
- **Lines of code:** 10,500 → 7,350 (-30%)
|
|||
|
|
- **File size:** 350KB → 245KB (-30%)
|
|||
|
|
- **Gzipped:** 65KB → 45KB (-31%)
|
|||
|
|
- **Duplicates:** 270+ → <50 (-82%)
|
|||
|
|
|
|||
|
|
### Qualitative Benefits
|
|||
|
|
- ✅ Single source of truth for colors and spacing
|
|||
|
|
- ✅ Centralized component patterns
|
|||
|
|
- ✅ Clearer file organization
|
|||
|
|
- ✅ Easier to maintain and extend
|
|||
|
|
- ✅ Better developer experience
|
|||
|
|
- ✅ Improved consistency across UI
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Risk Mitigation
|
|||
|
|
|
|||
|
|
### High Risks
|
|||
|
|
1. **Visual regression** → Implement visual testing before starting
|
|||
|
|
2. **Breaking changes** → Use backward-compatible approach in Phase 1-2
|
|||
|
|
|
|||
|
|
### Medium Risks
|
|||
|
|
3. **Browser compatibility** → Check requirements before CSS nesting
|
|||
|
|
4. **Bundle size** → Use PurgeCSS to remove unused styles
|
|||
|
|
|
|||
|
|
### Low Risks
|
|||
|
|
5. **Developer confusion** → Update COMPONENT-CATALOG.md with examples
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Migration Examples
|
|||
|
|
|
|||
|
|
### Example 1: Color Token Migration
|
|||
|
|
|
|||
|
|
**Before (bookings.css:42):**
|
|||
|
|
```css
|
|||
|
|
swp-booking-item.inprogress {
|
|||
|
|
background: color-mix(in srgb, var(--color-teal) 8%, var(--color-background-alt));
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**After:**
|
|||
|
|
```css
|
|||
|
|
swp-booking-item.inprogress {
|
|||
|
|
background: var(--bg-teal-medium);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Example 2: CSS Nesting for Cleaner Code
|
|||
|
|
|
|||
|
|
**Before (auth.css:56-73 - verbose, 18 lines):**
|
|||
|
|
```css
|
|||
|
|
swp-auth-logo {
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: var(--spacing-3);
|
|||
|
|
margin-bottom: var(--spacing-16);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-auth-logo i {
|
|||
|
|
font-size: 32px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
swp-auth-logo span {
|
|||
|
|
font-size: var(--font-size-2xl);
|
|||
|
|
font-weight: var(--font-weight-bold);
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**After (with CSS nesting - 12 lines):**
|
|||
|
|
```css
|
|||
|
|
swp-auth-logo {
|
|||
|
|
display: flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: var(--spacing-3);
|
|||
|
|
margin-bottom: var(--spacing-16);
|
|||
|
|
|
|||
|
|
& i { font-size: 32px; }
|
|||
|
|
|
|||
|
|
& span {
|
|||
|
|
font-size: var(--font-size-2xl);
|
|||
|
|
font-weight: var(--font-weight-bold);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Benefit:** Keeps custom element structure, reduces nesting, improves readability
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
### Example 3: Badge System Migration
|
|||
|
|
|
|||
|
|
**Before (3 separate custom elements):**
|
|||
|
|
```html
|
|||
|
|
<swp-status-badge class="approved">Approved</swp-status-badge>
|
|||
|
|
<swp-invoice-status class="paid">Paid</swp-invoice-status>
|
|||
|
|
<swp-tag class="master">Master</swp-tag>
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**After (unified custom element with class modifiers):**
|
|||
|
|
```html
|
|||
|
|
<swp-badge class="green with-dot">Approved</swp-badge>
|
|||
|
|
<swp-badge class="green compact">Paid</swp-badge>
|
|||
|
|
<swp-badge class="purple squared uppercase">Master</swp-badge>
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Key Point:** Still uses custom element (`<swp-badge>`), but classes define visual variants
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Recommendations for Future Development
|
|||
|
|
|
|||
|
|
### Guidelines
|
|||
|
|
1. **Use custom elements** (`<swp-*>`) as primary selectors, not classes
|
|||
|
|
2. **Classes for variants only** (e.g., `swp-badge.green`, `swp-stat-card.highlight`)
|
|||
|
|
3. **Use pre-defined tokens** for colors, never inline color-mix
|
|||
|
|
4. **Extend base patterns** for new tables and badges
|
|||
|
|
5. **Apply CSS nesting** where it improves readability
|
|||
|
|
6. **Follow COMPONENT-CATALOG** for all new components
|
|||
|
|
|
|||
|
|
### Code Review Checklist
|
|||
|
|
- [ ] Custom elements used (not utility classes)
|
|||
|
|
- [ ] All color overlays use tokens
|
|||
|
|
- [ ] Tables extend base pattern
|
|||
|
|
- [ ] Badges use unified system
|
|||
|
|
- [ ] CSS nesting applied where appropriate
|
|||
|
|
- [ ] Documentation updated
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Appendix: File Reference
|
|||
|
|
|
|||
|
|
### All 22 Files Analyzed
|
|||
|
|
|
|||
|
|
| # | File | Lines | Priority |
|
|||
|
|
|---|------|-------|----------|
|
|||
|
|
| 1 | account.css | 334 | Medium |
|
|||
|
|
| 2 | app-layout.css | 50 | Low |
|
|||
|
|
| 3 | attentions.css | 114 | Low |
|
|||
|
|
| 4 | auth.css | 993 | **High** |
|
|||
|
|
| 5 | base.css | 118 | Low |
|
|||
|
|
| 6 | bookings.css | 176 | Medium |
|
|||
|
|
| 7 | cash.css | 780 | **High** |
|
|||
|
|
| 8 | components.css | 489 | Medium |
|
|||
|
|
| 9 | controls.css | 148 | Low |
|
|||
|
|
| 10 | demo-banner.css | 145 | Low |
|
|||
|
|
| 11 | design-system.css | 104 | Low |
|
|||
|
|
| 12 | design-tokens.css | 317 | **High** |
|
|||
|
|
| 13 | drawers.css | 296 | Medium |
|
|||
|
|
| 14 | employees.css | 955 | **High** |
|
|||
|
|
| 15 | notifications.css | 69 | Low |
|
|||
|
|
| 16 | page.css | 230 | Medium |
|
|||
|
|
| 17 | sidebar.css | 246 | Low |
|
|||
|
|
| 18 | stats.css | 261 | Low |
|
|||
|
|
| 19 | tabs.css | 94 | Low |
|
|||
|
|
| 20 | topbar.css | 180 | Low |
|
|||
|
|
| 21 | utilities.css | 118 | **High** |
|
|||
|
|
| 22 | waitlist.css | 210 | Low |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**Report prepared by:** Senior Frontend Architect
|
|||
|
|
**Analysis method:** Manual code review + pattern detection
|
|||
|
|
**Total analysis time:** ~3 hours
|
|||
|
|
**Confidence level:** High (patterns verified across all files)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## Next Steps
|
|||
|
|
|
|||
|
|
Ready to proceed with implementation. Recommended approach:
|
|||
|
|
|
|||
|
|
1. **Start with Phase 1** (Foundation Layer) for maximum impact
|
|||
|
|
2. **Create visual regression baseline** before any changes
|
|||
|
|
3. **Implement changes incrementally** with testing between phases
|
|||
|
|
4. **Update documentation** as patterns are consolidated
|
|||
|
|
|
|||
|
|
Contact development team to schedule implementation kickoff.
|