SmarMaker - Documentation
Docs» 15_training:module6-smartcommon-composants:mise-en-page

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

snippet.javascript
import { Page } from '@cap-rel/smartcommon';
 
function HomePage() {
    return (
        <Page title="Accueil">
            <p>Contenu de la page</p>
        </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

snippet.javascript
function ItemsPage() {
    const [items, setItems] = useState([]);
 
    const handleRefresh = async () => {
        const data = await api.private.get('items').json();
        setItems(data);
    };
 
    return (
        <Page title="Mes items" onRefresh={handleRefresh}>
            {items.map(item => (
                <div key={item.id}>{item.label}</div>
            ))}
        </Page>
    );
}

Block

Le composant Block structure le contenu en sections visuelles distinctes.

Syntaxe de base

snippet.javascript
import { Page, Block } from '@cap-rel/smartcommon';
 
function ProfilePage() {
    return (
        <Page title="Profil">
            <Block>
                <h2>Informations personnelles</h2>
                <p>Nom : Jean Dupont</p>
            </Block>
 
            <Block>
                <h2>Préférences</h2>
                <p>Langue : Français</p>
            </Block>
        </Page>
    );
}

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

snippet.javascript
<Block title="Informations">
    <p>Contenu du block</p>
</Block>

Panel

Le composant Panel affiche un panneau coulissant depuis le côté de l'écran.

Syntaxe

snippet.javascript
import { useState } from 'react';
import { Page, Block, Button, Panel } from '@cap-rel/smartcommon';
 
function MyPage() {
    const [isPanelOpen, setIsPanelOpen] = useState(false);
 
    return (
        <Page title="Ma page">
            <Block>
                <Button onClick={() => setIsPanelOpen(true)}>
                    Ouvrir le panneau
                </Button>
            </Block>
 
            <Panel
                isOpen={isPanelOpen}
                onClose={() => setIsPanelOpen(false)}
                position="right"
            >
                <h2>Contenu du panneau</h2>
                <p>Informations supplémentaires</p>
            </Panel>
        </Page>
    );
}

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

snippet.javascript
import { useState } from 'react';
import { Page, Block, Button, Popup } from '@cap-rel/smartcommon';
 
function MyPage() {
    const [isPopupOpen, setIsPopupOpen] = useState(false);
 
    return (
        <Page title="Ma page">
            <Block>
                <Button onClick={() => setIsPopupOpen(true)}>
                    Supprimer
                </Button>
            </Block>
 
            <Popup
                isOpen={isPopupOpen}
                onClose={() => setIsPopupOpen(false)}
                title="Confirmation"
            >
                <p>Voulez-vous vraiment supprimer cet élément ?</p>
                <div className="flex gap-2 mt-4">
                    <Button onClick={() => setIsPopupOpen(false)}>
                        Annuler
                    </Button>
                    <Button variant="danger" onClick={handleDelete}>
                        Supprimer
                    </Button>
                </div>
            </Popup>
        </Page>
    );
}

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

snippet.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 (
        <Page title="Produits">
            {/* Actions */}
            <Block>
                <Button onClick={() => setShowFilters(true)}>
                    Filtres
                </Button>
            </Block>
 
            {/* Liste */}
            <Block title="Catalogue">
                <List>
                    {products.map(product => (
                        <ListItem
                            key={product.id}
                            title={product.label}
                            subtitle={`${product.price} €`}
                            onClick={() => setSelectedProduct(product)}
                            actions={
                                <Button
                                    size="sm"
                                    variant="danger"
                                    onClick={(e) => {
                                        e.stopPropagation();
                                        setSelectedProduct(product);
                                        setShowDeletePopup(true);
                                    }}
                                >
                                    Supprimer
                                </Button>
                            }
                        />
                    ))}
                </List>
            </Block>
 
            {/* Panneau filtres */}
            <Panel
                isOpen={showFilters}
                onClose={() => setShowFilters(false)}
                title="Filtres"
                position="right"
            >
                <p>Options de filtrage ici</p>
            </Panel>
 
            {/* Popup confirmation */}
            <Popup
                isOpen={showDeletePopup}
                onClose={() => setShowDeletePopup(false)}
                title="Confirmer la suppression"
            >
                <p>
                    Supprimer "{selectedProduct?.label}" ?
                </p>
                <div className="flex gap-2 mt-4">
                    <Button onClick={() => setShowDeletePopup(false)}>
                        Annuler
                    </Button>
                    <Button variant="danger" onClick={handleDelete}>
                        Supprimer
                    </Button>
                </div>
            </Popup>
        </Page>
    );
};

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

← Retour au module | Chapitre suivant : Navigation →

Previous Next

Made with ❤ by CAP-REL · SmartMaker · GNU AGPL v3+
Code source · Faire un don
SmarMaker - Documentation
Traductions de cette page:
  • Français
  • Deutsch
  • English
  • Español
  • Italiano
  • Nederlands

Table of Contents

Table des matières

  • Chapitre 1 : Mise en page
    • Page
      • Syntaxe de base
      • Props principales
      • Page avec refresh
    • Block
      • Syntaxe de base
      • Props
      • Block avec titre
    • Panel
      • Syntaxe
      • Props
    • Popup
      • Syntaxe
      • Props
    • Exemple complet
    • Bonnes pratiques
    • Points clés à retenir
  • SmartAuth
  • SmartMaker - Back (PHP)
    • Mapping Dolibarr - React
  • SmartMaker - Front (React)
    • Animations de pages
    • Architecture
    • Astuces
    • Calendar
    • Composants et pages
    • Configuration du Provider
    • Debug et Logs
    • Hooks SmartCommon
    • PWA (Progressive Web App)
    • Requêtes API
    • Routage
    • SmartCommon
    • Stockage de données
    • Thèmes
    • Traductions
  • HowTo - Pas à pas - Votre première application
    • Développement PHP (back)
    • Développement React (front)
    • Première étape : Module Builder Dolibarr
    • SmartAuth
    • SmartBoot : Un "squelette" quasiment prêt à l'emploi
  • Formation SmartMaker
    • Module 1 : Fondamentaux JavaScript ES6+
      • Chapitre 1 : Variables et Scope
      • Chapitre 2 : Fonctions
      • Chapitre 3 : Programmation Asynchrone
      • Chapitre 4 : Modules ES6
    • Module 2 : Introduction à React
      • Chapitre 1 : Philosophie React
      • Chapitre 2 : JSX
      • Chapitre 3 : Composants
    • Module 3 : Hooks React Fondamentaux
      • Chapitre 1 : useState
      • Chapitre 2 : useEffect
      • Chapitre 3 : useRef
      • Chapitre 4 : useContext
    • Module 4 : React Avancé
      • Chapitre 1 : useCallback et useMemo
      • Chapitre 2 : Custom Hooks
      • Chapitre 3 : Redux et Redux Toolkit
    • Module 5 : Architecture SmartMaker
      • Chapitre 1 : Structure du projet
      • Chapitre 2 : Configuration
      • Chapitre 3 : Flux de données
    • Module 6 : SmartCommon - Composants
      • Chapitre 1 : Mise en page
      • Chapitre 2 : Navigation
      • Chapitre 3 : Formulaires
      • Chapitre 4 : Affichage
    • Module 7 : SmartCommon - Hooks
      • Chapitre 1 : useApi
      • Chapitre 2 : Gestion d'état
      • Chapitre 3 : Hooks utilitaires
    • Module 8 : Backend API (PHP)
      • Chapitre 1 : Routage
      • Chapitre 2 : Controllers
      • Chapitre 3 : Mappers
      • Extrafields et formulaires dynamiques
    • Module 9 : Intégration complète
      • Chapitre 1 : Backend
      • Chapitre 2 : Frontend
      • Chapitre 3 : Déploiement
    • Module 10 : Fonctionnalités avancées
      • Chapitre 1 : Mode offline
      • Chapitre 2 : Internationalisation (i18n)
      • Chapitre 3 : Autres fonctionnalités
    • Module 11 : Bonnes pratiques
  • Démonstration
  • Start
  • Composants et pages
  • Afficher le texte source
  • Anciennes révisions
  • Liens de retour
  • Haut de page