# ๐ง API Standardization Plan
**Priority**: ๐ด **CRITICAL**
**Timeline**: Week 1-2
**Impact**: Ensures consistent, type-safe APIs across all components
## ๐จ Current API Inconsistencies
### **Type System Issues**
```rust
// Inconsistent prop types across components:
// Some components use &str
// Others use MaybeProp
// Inconsistent callback patterns:
on_click=Some(callback) // Some use Option>
on_change=callback // Others use Callback directly
```
### **Signal Management Inconsistencies**
```rust
// Mixed signal creation patterns:
let (value, set_value) = create_signal(initial); // Deprecated
let (value, set_value) = signal(initial); // Current
```
## ๐ฏ Standardization Strategy
### **Phase 1: Prop Type Standardization**
#### **1.1 Standardize String Props**
```rust
// Standard pattern for all string props:
#[component]
pub fn ComponentName(
#[prop(into, optional)] placeholder: MaybeProp,
#[prop(into, optional)] label: MaybeProp,
#[prop(into, optional)] class: MaybeProp,
) -> impl IntoView {
// Implementation
}
// Usage with helper macros:
```
#### **1.2 Standardize Boolean Props**
```rust
// Standard pattern for all boolean props:
#[component]
pub fn ComponentName(
#[prop(into, optional)] disabled: MaybeProp,
#[prop(into, optional)] required: MaybeProp,
#[prop(into, optional)] checked: MaybeProp,
) -> impl IntoView {
// Implementation
}
// Usage with helper macros:
```
#### **1.3 Standardize Numeric Props**
```rust
// Standard pattern for all numeric props:
#[component]
pub fn ComponentName(
#[prop(into, optional)] min: MaybeProp,
#[prop(into, optional)] max: MaybeProp,
#[prop(into, optional)] step: MaybeProp,
) -> impl IntoView {
// Implementation
}
// Usage:
```
### **Phase 2: Callback Standardization**
#### **2.1 Standardize Callback Patterns**
```rust
// Standard pattern for all callbacks:
#[component]
pub fn ComponentName(
#[prop(optional)] on_click: Option>,
#[prop(optional)] on_change: Option>,
#[prop(optional)] on_submit: Option>,
) -> impl IntoView {
// Implementation
}
// Usage:
```
#### **2.2 Create Callback Helper Macros**
```rust
// Helper macros for common callback patterns:
#[macro_export]
macro_rules! callback {
($closure:expr) => {
Some(Callback::new($closure))
};
}
// Usage:
```
### **Phase 3: Signal Management Standardization**
#### **3.1 Standardize Signal Creation**
```rust
// Standard pattern for all signal creation:
use leptos::prelude::*;
// Always use signal() instead of create_signal():
let (value, set_value) = signal(initial_value);
let (is_loading, set_is_loading) = signal(false);
let (items, set_items) = signal(Vec::::new());
```
#### **3.2 Create Signal Helper Functions**
```rust
// Helper functions for common signal patterns:
pub fn create_string_signal(initial: &str) -> (Signal, WriteSignal) {
signal(initial.to_string())
}
pub fn create_bool_signal(initial: bool) -> (Signal, WriteSignal) {
signal(initial)
}
pub fn create_vec_signal(initial: Vec) -> (Signal>, WriteSignal>)
where
T: Clone + 'static,
{
signal(initial)
}
```
## ๐ Implementation Checklist
### **Week 1: Core Standardization**
#### **Day 1-2: Prop Type Standardization**
- [ ] Create prop helper macros (`prop_string!`, `prop_bool!`, `prop_number!`)
- [ ] Update all component prop definitions
- [ ] Standardize string prop usage across components
- [ ] Test prop type consistency
#### **Day 3-4: Callback Standardization**
- [ ] Create callback helper macros
- [ ] Standardize callback patterns across components
- [ ] Update all callback prop definitions
- [ ] Test callback consistency
#### **Day 5: Signal Management**
- [ ] Replace all `create_signal` with `signal()`
- [ ] Create signal helper functions
- [ ] Update all signal creation patterns
- [ ] Test signal management consistency
### **Week 2: Component Updates**
#### **Day 6-7: Core Components**
- [ ] Update button component API
- [ ] Update input component API
- [ ] Update card component API
- [ ] Test core component consistency
#### **Day 8-9: Form Components**
- [ ] Update form component API
- [ ] Update select component API
- [ ] Update checkbox component API
- [ ] Test form component consistency
#### **Day 10: Advanced Components**
- [ ] Update dialog component API
- [ ] Update popover component API
- [ ] Update tooltip component API
- [ ] Test advanced component consistency
## ๐งช Testing Strategy
### **API Consistency Tests**
```rust
#[cfg(test)]
mod api_consistency_tests {
use super::*;
#[test]
fn test_prop_type_consistency() {
// Test that all components use consistent prop types
// Verify MaybeProp usage for optional props
// Check string literal conversion
}
#[test]
fn test_callback_consistency() {
// Test that all components use consistent callback patterns
// Verify Option> usage
// Check callback creation patterns
}
#[test]
fn test_signal_consistency() {
// Test that all components use signal() instead of create_signal()
// Verify signal creation patterns
// Check signal management consistency
}
}
```
### **Integration Tests**
```rust
#[test]
fn test_component_api_integration() {
// Test that components work together with standardized APIs
// Verify prop passing between components
// Check callback communication
}
```
## ๐ Success Criteria
- โ
**Consistent prop types** across all components
- โ
**Standardized callback patterns** throughout codebase
- โ
**Unified signal management** using `signal()` only
- โ
**Helper macros** for common patterns
- โ
**Comprehensive test coverage** for API consistency
## ๐จ Risk Mitigation
### **Backward Compatibility**
- Maintain existing component functionality
- Provide migration guide for API changes
- Test all existing usage patterns
### **Type Safety**
- Ensure all prop types are properly validated
- Test type conversion edge cases
- Verify compile-time type checking
### **Performance**
- Ensure helper macros don't impact performance
- Test signal management efficiency
- Verify callback performance
## ๐ Related Documents
- [Build System Remediation](./build-system-remediation.md) - Fix compilation issues
- [Command Component Fix](./component-fixes/command-component-fix.md) - Example implementation
- [Component API Guidelines](./component-api-guidelines.md) - Detailed API standards
---
**Next Steps**: After completing API standardization, proceed to [Stub Implementation Plan](./stub-implementation.md) for completing todo! items.