ViewComponents - Passe Marché
What is ViewComponent?
Directory Structure
app/components/
├── market_attribute_response/
│ ├── base_component.rb # Shared base class
│ ├── fields/ # Reusable field components
│ │ ├── file_upload_field_component.rb
│ │ └── textarea_field_component.rb
│ ├── shared/ # Shared utility components
│ │ ├── document_item_component.rb
│ │ └── progress_bar_component.rb
│ │
│ │ # Simple Input Components
│ ├── text_input_component.rb # Text input field
│ ├── textarea_component.rb # Multi-line text area
│ ├── email_input_component.rb # Email input field
│ ├── phone_input_component.rb # Phone number input
│ │
│ │ # File Upload Components
│ ├── file_upload_component.rb # Standard file upload
│ ├── inline_file_upload_component.rb # Inline file upload (auto-fillable)
│ ├── inline_url_input_component.rb # URL input field
│ │
│ │ # Composite Input Components
│ ├── file_or_textarea_component.rb # File OR text choice
│ ├── checkbox_with_document_component.rb # Checkbox with document upload
│ ├── radio_with_file_and_text_component.rb # Radio with file/text options
│ │
│ │ # Financial/Workforce Components
│ ├── capacite_economique_financiere_chiffre_affaires_global_annuel_component.rb
│ ├── capacite_economique_financiere_effectifs_moyens_annuels_component.rb
│ │
│ │ # Complex Repeatable Components
│ ├── capacites_techniques_professionnelles_outillage_echantillons_component.rb
│ ├── presentation_intervenants_component.rb
│ └── realisations_livraisons_component.rb
│
├── source_badge_component.rb # Badge showing data source
└── source_badge_component.html.erb
app/views/market_attribute_response/{component_name}_component/
├── _form.html.erb # Form mode sub-template
├── _display.html.erb # Display mode sub-template
└── _{nested}.html.erb # Optional nested field templates (for repeatable components)
spec/components/
├── market_attribute_response/
│ ├── base_component_spec.rb
│ ├── fields/
│ │ └── {field}_component_spec.rb
│ ├── shared/
│ │ └── {shared}_component_spec.rb
│ └── {component}_component_spec.rb
└── source_badge_component_spec.rb
spec/components/previews/
└── market_attribute_response/
└── {component}_component_preview.rb # Lookbook previewsUsing Components
In Views
Direct Usage
Component Architecture
BaseComponent
Component Parameters
Form Mode vs Display Mode
Context-Aware Rendering
Testing Components
Unit Tests (RSpec)
Integration Tests (Cucumber)
Lookbook Previews
Creating Previews
Creating New Components
1. Create Component Class
2. Create Component Template
3. Create Sub-templates
4. Create Component Spec
5. Create Lookbook Preview
6. Delete Old Partials
Best Practices
DO:
DON'T:
CSS Classes Reference
DSFR (French Design System)
Custom (PDF Generation)
Running Tests
Migration Status
Category
Components
Status
Additional Resources
Questions?
Mis à jour
Ce contenu vous a-t-il été utile ?

