147 lines
5.1 KiB
Markdown
147 lines
5.1 KiB
Markdown
|
|
# Commit Mode Components Analysis
|
||
|
|
|
||
|
|
## Overview
|
||
|
|
|
||
|
|
This document analyzes the implementation of commit mode related components in Crystal, focusing on their UI patterns, design token usage, and comparison with other similar components.
|
||
|
|
|
||
|
|
## Components Analyzed
|
||
|
|
|
||
|
|
### 1. CommitModeToggle Component
|
||
|
|
**Location**: `/frontend/src/components/CommitModeToggle.tsx`
|
||
|
|
|
||
|
|
#### UI Implementation
|
||
|
|
- **Custom dropdown implementation** - Not using a shared dropdown component
|
||
|
|
- **Manual positioning and z-index management** for dropdown menu
|
||
|
|
- **Hardcoded colors** throughout the component instead of design tokens
|
||
|
|
|
||
|
|
#### Color Usage (Lines 40-59)
|
||
|
|
```typescript
|
||
|
|
// Structured mode
|
||
|
|
color: 'bg-blue-50 dark:bg-blue-950/20 text-blue-700 dark:text-blue-300 hover:bg-blue-100 dark:hover:bg-blue-950/30 border-blue-200 dark:border-blue-800'
|
||
|
|
|
||
|
|
// Checkpoint mode
|
||
|
|
color: 'bg-green-50 dark:bg-green-950/20 text-green-700 dark:text-green-300 hover:bg-green-100 dark:hover:bg-green-950/30 border-green-200 dark:border-green-800'
|
||
|
|
|
||
|
|
// Disabled mode
|
||
|
|
color: 'bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-300 dark:hover:bg-gray-600 border-gray-300 dark:border-gray-600'
|
||
|
|
```
|
||
|
|
|
||
|
|
#### Dropdown Implementation (Lines 118-191)
|
||
|
|
- Uses a fixed overlay div to capture clicks outside
|
||
|
|
- Absolute positioning with manual z-index values (9998, 9999)
|
||
|
|
- Dropdown menu styled with inline Tailwind classes
|
||
|
|
- No shared dropdown/menu component used
|
||
|
|
|
||
|
|
### 2. CommitModeSettings Component
|
||
|
|
**Location**: `/frontend/src/components/CommitModeSettings.tsx`
|
||
|
|
|
||
|
|
#### UI Pattern
|
||
|
|
- Radio button group for mode selection
|
||
|
|
- Custom form controls with Tailwind classes
|
||
|
|
- Inline styled alerts and warnings
|
||
|
|
- No use of shared form components
|
||
|
|
|
||
|
|
#### Color Usage
|
||
|
|
- Similar hardcoded color patterns as CommitModeToggle
|
||
|
|
- Uses raw Tailwind color classes instead of design tokens
|
||
|
|
- Example (lines 93-97): `bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800`
|
||
|
|
|
||
|
|
## Comparison with Model Selector
|
||
|
|
|
||
|
|
### Model Selector Implementation
|
||
|
|
**Location**: `/frontend/src/components/session/SessionInputWithImages.tsx` (Lines 423-453)
|
||
|
|
|
||
|
|
#### Key Differences
|
||
|
|
1. **Native HTML select** element with custom styling
|
||
|
|
2. **Uses design tokens** for consistent theming:
|
||
|
|
```css
|
||
|
|
bg-surface-tertiary text-text-secondary hover:bg-surface-hover
|
||
|
|
```
|
||
|
|
3. **Simpler implementation** - relies on browser's native dropdown
|
||
|
|
4. **Better accessibility** - native select elements have built-in keyboard support
|
||
|
|
|
||
|
|
## Issues Found
|
||
|
|
|
||
|
|
### 1. No Shared Dropdown Component
|
||
|
|
- Both commit mode components implement their own dropdown logic
|
||
|
|
- No reusable dropdown/menu component in the UI library
|
||
|
|
- Results in duplicated positioning, z-index, and click-outside logic
|
||
|
|
|
||
|
|
### 2. Hardcoded Colors vs Design Tokens
|
||
|
|
- **CommitModeToggle & CommitModeSettings**: Use hardcoded Tailwind colors
|
||
|
|
- **Model Selector**: Uses semantic design tokens from the theme system
|
||
|
|
- This creates inconsistency and makes theme changes difficult
|
||
|
|
|
||
|
|
### 3. Z-Index Management
|
||
|
|
- CommitModeToggle uses hardcoded z-index values (9998, 9999, 10000)
|
||
|
|
- No centralized z-index system or tokens
|
||
|
|
- Potential for z-index conflicts with other components
|
||
|
|
|
||
|
|
### 4. Accessibility Concerns
|
||
|
|
- Custom dropdown implementation lacks proper ARIA attributes
|
||
|
|
- No keyboard navigation support (arrow keys, escape key)
|
||
|
|
- Native select element in model selector has better accessibility
|
||
|
|
|
||
|
|
## Design System Gaps
|
||
|
|
|
||
|
|
### Missing UI Components
|
||
|
|
1. **Dropdown/Menu Component** - For consistent dropdown behavior
|
||
|
|
2. **Popover Component** - For floating UI elements
|
||
|
|
3. **Select Component** - For custom styled select inputs
|
||
|
|
4. **Form Components** - Radio groups, checkboxes with consistent styling
|
||
|
|
|
||
|
|
### Missing Design Tokens
|
||
|
|
1. **Semantic tokens for states**:
|
||
|
|
- Structured mode colors (blue variants)
|
||
|
|
- Checkpoint mode colors (green variants)
|
||
|
|
- Disabled state colors
|
||
|
|
|
||
|
|
2. **Z-index tokens** for layering management
|
||
|
|
3. **Component-specific tokens** for dropdowns and menus
|
||
|
|
|
||
|
|
## Recommendations
|
||
|
|
|
||
|
|
### 1. Create Shared Dropdown Component
|
||
|
|
```typescript
|
||
|
|
// Example usage
|
||
|
|
<Dropdown
|
||
|
|
trigger={<Button>Commit Mode</Button>}
|
||
|
|
items={[
|
||
|
|
{ label: 'Structured', icon: Shield, onClick: () => {} },
|
||
|
|
{ label: 'Checkpoint', icon: Zap, onClick: () => {} },
|
||
|
|
]}
|
||
|
|
/>
|
||
|
|
```
|
||
|
|
|
||
|
|
### 2. Use Design Tokens
|
||
|
|
Replace hardcoded colors with semantic tokens:
|
||
|
|
```css
|
||
|
|
/* Instead of: bg-blue-50 dark:bg-blue-950/20 */
|
||
|
|
/* Use: bg-interactive/10 or create specific tokens */
|
||
|
|
--color-mode-structured-bg: var(--blue-50);
|
||
|
|
--color-mode-checkpoint-bg: var(--green-50);
|
||
|
|
```
|
||
|
|
|
||
|
|
### 3. Implement Z-Index System
|
||
|
|
```css
|
||
|
|
:root {
|
||
|
|
--z-dropdown: 1000;
|
||
|
|
--z-modal: 2000;
|
||
|
|
--z-tooltip: 3000;
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### 4. Improve Accessibility
|
||
|
|
- Add ARIA attributes for dropdowns
|
||
|
|
- Implement keyboard navigation
|
||
|
|
- Consider using Radix UI or similar for accessible primitives
|
||
|
|
|
||
|
|
## Conclusion
|
||
|
|
|
||
|
|
The commit mode components demonstrate a pattern of implementing custom UI solutions instead of leveraging shared components and design tokens. This approach leads to:
|
||
|
|
- Inconsistent user experience
|
||
|
|
- Maintenance challenges
|
||
|
|
- Theme switching difficulties
|
||
|
|
- Accessibility gaps
|
||
|
|
|
||
|
|
Moving forward, investing in a proper component library with design token integration would significantly improve code quality and user experience.
|