# 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"
>
{/* 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 →]]