# Chapitre 1 : Mise en page ## Page Le composant `Page` est le conteneur principal de chaque écran. Il gère : - Le titre de la page - Les animations de transition - Le scroll ### Syntaxe de base ```javascript import { Page } from '@cap-rel/smartcommon'; function HomePage() { return (

Contenu de la page

); } ``` ### Props principales ^ Prop ^ Type ^ Défaut ^ Description ^ | title | string | - | Titre affiché dans la navbar | | subtitle | string | - | Sous-titre optionnel | | className | string | - | Classes CSS additionnelles | | onRefresh | function | - | Callback pour pull-to-refresh | ### Page avec refresh ```javascript function ItemsPage() { const [items, setItems] = useState([]); const handleRefresh = async () => { const data = await api.private.get('items').json(); setItems(data); }; return ( {items.map(item => (
{item.label}
))}
); } ``` ## Block Le composant `Block` structure le contenu en sections visuelles distinctes. ### Syntaxe de base ```javascript import { Page, Block } from '@cap-rel/smartcommon'; function ProfilePage() { return (

Informations personnelles

Nom : Jean Dupont

Préférences

Langue : Français

); } ``` ### Props ^ Prop ^ Type ^ Défaut ^ Description ^ | title | string | - | Titre du block | | className | string | - | Classes CSS additionnelles | | padding | boolean | true | Ajouter du padding interne | ### Block avec titre ```javascript

Contenu du block

``` ## Panel Le composant `Panel` affiche un panneau coulissant depuis le côté de l'écran. ### Syntaxe ```javascript import { useState } from 'react'; import { Page, Block, Button, Panel } from '@cap-rel/smartcommon'; function MyPage() { const [isPanelOpen, setIsPanelOpen] = useState(false); return ( setIsPanelOpen(false)} position="right" >

Contenu du panneau

Informations supplémentaires

); } ``` ### Props ^ Prop ^ Type ^ Défaut ^ Description ^ | isOpen | boolean | false | Contrôle l'affichage | | onClose | function | - | Callback à la fermeture | | position | string | 'right' | 'left', 'right', 'top', 'bottom' | | title | string | - | Titre du panneau | ## Popup Le composant `Popup` affiche une fenêtre modale centrée. ### Syntaxe ```javascript import { useState } from 'react'; import { Page, Block, Button, Popup } from '@cap-rel/smartcommon'; function MyPage() { const [isPopupOpen, setIsPopupOpen] = useState(false); return ( setIsPopupOpen(false)} title="Confirmation" >

Voulez-vous vraiment supprimer cet élément ?

); } ``` ### Props ^ Prop ^ Type ^ Défaut ^ Description ^ | isOpen | boolean | false | Contrôle l'affichage | | onClose | function | - | Callback à la fermeture | | title | string | - | Titre du popup | | closeOnOverlay | boolean | true | Fermer au clic sur l'overlay | ## Exemple complet ```javascript import { useState } from 'react'; import { Page, Block, Panel, Popup, Button, List, ListItem } from '@cap-rel/smartcommon'; export const ProductsPage = () => { const [selectedProduct, setSelectedProduct] = useState(null); const [showDeletePopup, setShowDeletePopup] = useState(false); const [showFilters, setShowFilters] = useState(false); const products = [ { id: 1, label: 'Produit A', price: 29.99 }, { id: 2, label: 'Produit B', price: 49.99 }, { id: 3, label: 'Produit C', price: 19.99 } ]; const handleDelete = async () => { // Supprimer le produit console.log('Suppression de', selectedProduct); setShowDeletePopup(false); setSelectedProduct(null); }; return ( {/* Actions */} {/* Liste */} {products.map(product => ( setSelectedProduct(product)} actions={ } /> ))} {/* Panneau filtres */} setShowFilters(false)} title="Filtres" position="right" >

Options de filtrage ici

{/* Popup confirmation */} setShowDeletePopup(false)} title="Confirmer la suppression" >

Supprimer "{selectedProduct?.label}" ?

); }; ``` ## Bonnes pratiques 1. **Une seule Page par composant de route** 2. **Utiliser Block pour regrouper** le contenu logiquement 3. **Panel pour les actions secondaires** (filtres, détails) 4. **Popup pour les confirmations** et actions critiques ## Points clés à retenir 1. **Page** = conteneur principal avec titre et animations 2. **Block** = section de contenu avec style 3. **Panel** = panneau coulissant latéral 4. **Popup** = modal centré pour confirmations [[:15_training:module6-smartcommon-composants:start|← Retour au module]] | [[:15_training:module6-smartcommon-composants:navigation|Chapitre suivant : Navigation →]]