Overview
TheFilterSidebar component provides a comprehensive filtering interface for property searches. It fetches metadata from the API, displays collapsible filter sections, and manages filter state with real-time updates.
Import
Props
Controls the visibility of the sidebar on mobile devices. On desktop (lg breakpoint), the sidebar is always visible.
Callback function triggered when the user closes the sidebar (mobile only).
Current filter state object containing all active filters.
Function to update the filter state.
PropertyFilters Type
ThePropertyFilters interface includes:
Array of property type slugs (e.g., [“casa”, “departamento”])
Array of listing type slugs (e.g., [“venta”, “alquiler”])
Minimum number of bedrooms
Minimum number of bathrooms
Minimum price filter
Maximum price filter
Search query string
Location search string
Features
Metadata Integration
The component automatically fetches filter options from the API on mount:- Property types (casa, departamento, terreno, local)
- Operation types (venta, alquiler, venta-y-alquiler)
- Fallback to hardcoded values if API fails
Collapsible Sections
All filter sections can be expanded/collapsed:- Default expanded: Property Type, Listing Type, Price, Bedrooms, Bathrooms
- Chevron icons indicate section state
- Smooth transitions for expand/collapse
Filter Sections
Property Type (Tipo de Propiedad)
Checkbox list of available property types:- Casa (House)
- Departamento (Apartment)
- Terreno (Land)
- Local (Commercial space)
Listing Type (Tipo de Operación)
Checkbox list of operation types:- Venta (Sale)
- Alquiler (Rent)
- Venta y Alquiler (Sale and Rent)
Bedrooms (Dormitorios)
Button group for minimum bedroom count:- Options: 1+, 2+, 3+, 4+, 5+
- Click to select, click again to deselect
- Red highlight for selected option
Bathrooms (Baños)
Button group for minimum bathroom count:- Options: 1+, 2+, 3+, 4+
- Click to select, click again to deselect
- Red highlight for selected option
Responsive Design
- Mobile
- Desktop
- Fixed overlay sidebar
- Slides in from left
- Dark overlay backdrop
- Close button in header
- Full height design
Usage Examples
Internal Components
FilterSection
Internal component for collapsible filter sections:CheckboxOption
Internal component for checkbox filter items:Loading State
While fetching metadata, displays:- Skeleton sidebar structure
- Loading spinner (using
Loader2icon) - Same header layout
Error Handling
If metadata fetch fails:- Displays yellow warning banner
- Falls back to basic filter options
- App remains functional
Styling
Desktop Styles
- Width:
w-80(320px) - Position:
stickywithtop-4 - Max height:
max-h-[calc(100vh-120px)] - Border and rounded corners
Mobile Styles
- Full height overlay
- Slide-in animation from left
- Dark backdrop (
bg-black bg-opacity-60) - Z-index:
z-50for sidebar,z-40for backdrop
Accessibility
- All buttons have
aria-labelattributes - Keyboard navigation support with
tabIndex={0} - Section toggles have descriptive labels
- Semantic HTML structure
- Focus states on all interactive elements
Dependencies
lucide-react- Icons (X, ChevronDown, ChevronUp, Loader2)react- State managementapi- Metadata fetching
API Integration
Fetches metadata using:Source Code
View the full implementation atsrc/components/FilterSidebar.tsx:1