# Chapitre 4 : Affichage ## Composants de formatage SmartCommon fournit des composants pour afficher les données de manière formatée et cohérente. ## String Affichage de texte court. ```javascript import { String } from '@cap-rel/smartcommon'; // Avec troncature ``` ## Text Affichage de texte long avec préservation des sauts de ligne. ```javascript import { Text } from '@cap-rel/smartcommon'; // Avec limite de lignes ``` ## Number Affichage de nombre formaté selon la locale. ```javascript import { Number } from '@cap-rel/smartcommon'; // Nombre simple // Affiche : 1 234,56 // Avec décimales fixées // Affiche : 99,90 // Prix // Affiche : 29,99 € // Pourcentage // Affiche : 15,6 % ``` ## Datetime Affichage de date et heure formatées. ```javascript import { Datetime } from '@cap-rel/smartcommon'; // Date complète // Affiche : 15 mars 2024 à 14:30 // Date seule // Affiche : 15 mars 2024 // Heure seule // Affiche : 14:30 // Format court // Affiche : 15/03/2024 // Format relatif // Affiche : il y a 2 jours ``` ## Duration Affichage de durée. ```javascript import { Duration } from '@cap-rel/smartcommon'; // Durée en secondes // Affiche : 1h 1min 1s // Durée en minutes // Affiche : 1h 30min // Format compact // Affiche : 1:00:00 ``` ## Email Affichage d'email avec lien cliquable. ```javascript import { Email } from '@cap-rel/smartcommon'; // Crée un lien mailto: ``` ## Url Affichage d'URL avec lien cliquable. ```javascript import { Url } from '@cap-rel/smartcommon'; ``` ## PhoneNumber Affichage de numéro de téléphone cliquable. ```javascript import { PhoneNumber } from '@cap-rel/smartcommon'; // Affiche : +33 6 12 34 56 78 (formaté) // Crée un lien tel: ``` ## Address Affichage d'adresse formatée. ```javascript import { Address } from '@cap-rel/smartcommon';
// Avec lien vers Google Maps
``` ## Coordinates Affichage de coordonnées GPS. ```javascript import { Coordinates } from '@cap-rel/smartcommon'; // Avec lien vers carte ``` ## Color Affichage d'une couleur. ```javascript import { Color } from '@cap-rel/smartcommon'; // Affiche un carré de couleur + le code // Affiche uniquement le carré ``` ## Icon Affichage d'icône. ```javascript import { Icon } from '@cap-rel/smartcommon'; // Avec react-icons import { FiCheck, FiX } from 'react-icons/fi'; ``` ## Tags Affichage d'étiquettes. ```javascript import { Tags } from '@cap-rel/smartcommon'; ``` ## Tag Étiquette unique. ```javascript import { Tag } from '@cap-rel/smartcommon'; Nouveau Actif Urgent // Avec icône Validé ``` ## Files Affichage de fichiers avec téléchargement. ```javascript import { Files } from '@cap-rel/smartcommon'; ``` ## Signature Affichage d'une signature. ```javascript import { Signature } from '@cap-rel/smartcommon'; ``` ## List et ListItem Affichage de listes. ```javascript import { List, ListItem } from '@cap-rel/smartcommon'; import { useNavigation } from '@cap-rel/smartcommon'; function ProductsList({ products }) { const navigate = useNavigation(); return ( {products.map(product => ( navigate(`/products/${product.id}`)} chevron /> ))} ); } ``` ### Props ListItem ^ Prop ^ Type ^ Description ^ | title | string | Titre principal | | subtitle | string | Sous-titre | | image | string | URL de l'image | | icon | Component | Icône à gauche | | onClick | function | Action au clic | | chevron | boolean | Afficher flèche droite | | actions | ReactNode | Actions à droite | ## Button Bouton d'action. ```javascript import { Button } from '@cap-rel/smartcommon'; // Variantes // Tailles // États // Avec icône ``` ## Spinner Indicateur de chargement. ```javascript import { Spinner } from '@cap-rel/smartcommon'; // Page de chargement function LoadingPage() { return (
); } ``` ## Exemple complet : Fiche produit ```javascript import { Page, Block, String, Text, Number, Datetime, Tags, Tag, Files, Button, Carousel, CarouselItem } from '@cap-rel/smartcommon'; import { useNavigation } from '@cap-rel/smartcommon'; export const ProductDetailPage = ({ product }) => { const navigate = useNavigation(); return ( {/* Photos */} {product.photos?.length > 0 && ( {product.photos.map((photo, index) => ( {`Photo ))} )} {/* Informations principales */}

{product.isActive ? 'Actif' : 'Inactif'}
{/* Description */} {/* Détails */}
Référence
Stock
Créé le
Modifié le
{/* Documents */} {product.documents?.length > 0 && ( )} {/* Actions */}
); }; ``` ## Points clés à retenir 1. **Composants de format** pour affichage cohérent 2. **Number** avec locale française automatique 3. **Datetime** avec formats relatifs pratiques 4. **List/ListItem** pour les listes navigables 5. **Button** avec variantes et états [[:15_training:module6-smartcommon-composants:formulaires|← Chapitre précédent]] | [[:15_training:module6-smartcommon-composants:start|Retour au module]] | [[:15_training:module7-smartcommon-hooks:start|Module suivant : SmartCommon Hooks →]]