console.log(files)}
/>
```
### FilesUploader
```javascript
import { FilesUploader } from '@cap-rel/smartcommon';
```
### Redimensionner une image
```javascript
import { useFile } from '@cap-rel/smartcommon';
function ImageUploader() {
const { resizeImage } = useFile();
const handleFile = async (e) => {
const file = e.target.files[0];
const base64 = await resizeImage(file, {
maxWidth: 1200,
maxHeight: 1200,
quality: 80
});
// Envoyer au serveur
await api.private.post('files', {
json: {
filename: file.name,
content: base64
}
});
};
return ;
}
```
## Thème sombre
### Configuration globale
```javascript
// appConfig.js
export const config = {
globalState: {
reducers: {
settings: {
theme: 'light' // 'light' ou 'dark'
}
}
}
};
```
### Appliquer le thème
```javascript
import { useEffect } from 'react';
import { useGlobalStates } from '@cap-rel/smartcommon';
function ThemeProvider({ children }) {
const [settings] = useGlobalStates('settings');
useEffect(() => {
document.documentElement.classList.toggle(
'dark',
settings.theme === 'dark'
);
}, [settings.theme]);
return children;
}
```
### Toggle de thème
```javascript
import { useGlobalStates } from '@cap-rel/smartcommon';
import { Boolean } from '@cap-rel/smartcommon';
function ThemeToggle() {
const [settings, setSettings] = useGlobalStates('settings');
const toggleTheme = () => {
setSettings({
...settings,
theme: settings.theme === 'light' ? 'dark' : 'light'
});
};
return (
);
}
```
## Signature manuscrite
```javascript
import { SignaturePad } from '@cap-rel/smartcommon';
```
## Scan de code-barres
Utiliser une bibliothèque comme `@zxing/browser` :
```bash
npm install @zxing/browser @zxing/library
```
```javascript
import { useState, useRef, useEffect } from 'react';
import { BrowserMultiFormatReader } from '@zxing/browser';
function BarcodeScanner({ onScan }) {
const videoRef = useRef(null);
const [scanning, setScanning] = useState(false);
useEffect(() => {
let reader;
if (scanning) {
reader = new BrowserMultiFormatReader();
reader.decodeFromVideoDevice(
undefined,
videoRef.current,
(result, error) => {
if (result) {
onScan(result.getText());
setScanning(false);
}
}
);
}
return () => {
if (reader) {
reader.reset();
}
};
}, [scanning]);
return (
{scanning ? (
) : (
)}
);
}
```
## Notifications locales
```javascript
function requestNotificationPermission() {
if ('Notification' in window) {
Notification.requestPermission().then(permission => {
console.log('Permission:', permission);
});
}
}
function showNotification(title, body) {
if (Notification.permission === 'granted') {
new Notification(title, { body });
}
}
```
## Points clés à retenir
1. **Géolocalisation** avec navigator.geolocation ou composant Gps
2. **Upload** avec PhotosUploader, FilesUploader, useFile
3. **Thème sombre** via useGlobalStates et classes CSS
4. **Signature** avec SignaturePad
5. Intégrer des **bibliothèques tierces** selon les besoins
[[:15_training:module10-fonctionnalites-avancees:i18n|← Chapitre précédent]] | [[:15_training:module10-fonctionnalites-avancees:start|Retour au module]] | [[:15_training:module11-bonnes-pratiques:start|Module suivant : Bonnes pratiques →]]