MonEspacePro/pro/src/ui.tsx
Tony AVERTY 567d9fb877 App : pastille de validation sous la Dynamic Island, bouton retour, finitions visuelles
- Écrans sans en-tête (confirmation, autorisation caméra) : marge haute de sécurité
- Récompenses : bouton « Retour » ; confirmation : « Retour à la fiche client »
- Fiche client rechargée à chaque affichage (solde à jour)
- Cartes à ombre légère, boutons plus arrondis, halo de validation,
  accueil avec salutation et chiffres du jour sur fond teinté

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 14:12:46 +02:00

141 lines
4.9 KiB
TypeScript

import { ReactNode } from 'react';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextProps, View, ViewStyle } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Circle, Path } from 'react-native-svg';
import { font, useColors } from './theme';
/**
* Écran standard. `noHeader` : écran sans barre de titre, le contenu reste sous
* la Dynamic Island / l'encoche (marge haute de sécurité).
*/
export function Screen({ children, scroll = false, style, noHeader = false }: { children: ReactNode; scroll?: boolean; style?: ViewStyle; noHeader?: boolean }) {
const c = useColors();
const inner = <View style={[{ padding: 20, gap: 20, flexGrow: 1 }, style]}>{children}</View>;
return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }} edges={noHeader ? ['top', 'bottom', 'left', 'right'] : ['bottom', 'left', 'right']}>
{scroll ? <ScrollView contentContainerStyle={{ flexGrow: 1 }}>{inner}</ScrollView> : inner}
</SafeAreaView>
);
}
type Variant = 'h1' | 'h2' | 'body' | 'label' | 'muted' | 'big';
export function T({ v = 'body', style, ...props }: TextProps & { v?: Variant }) {
const c = useColors();
const s = {
h1: { fontFamily: font.bold, fontSize: 28, lineHeight: 34, color: c.text },
h2: { fontFamily: font.bold, fontSize: 20, lineHeight: 26, color: c.text },
body: { fontFamily: font.regular, fontSize: 17, lineHeight: 24, color: c.text },
label: { fontFamily: font.semibold, fontSize: 15, lineHeight: 20, color: c.text },
muted: { fontFamily: font.regular, fontSize: 15, lineHeight: 21, color: c.text3 },
big: { fontFamily: font.extrabold, fontSize: 56, lineHeight: 62, color: c.text },
}[v];
return <Text {...props} style={[s, style]} />;
}
export function Button({
label,
onPress,
variant = 'primary',
disabled,
loading,
icon,
large,
}: {
label: string;
onPress: () => void;
variant?: 'primary' | 'secondary' | 'danger';
disabled?: boolean;
loading?: boolean;
icon?: ReactNode;
large?: boolean;
}) {
const c = useColors();
const bg = { primary: c.primary, secondary: c.surface, danger: c.err }[variant];
const fg = variant === 'secondary' ? c.text : c.onPrimary;
return (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: !!disabled || !!loading }}
disabled={disabled || loading}
onPress={onPress}
style={({ pressed }) => [
styles.btn,
{
backgroundColor: variant === 'primary' && pressed ? c.primaryPressed : bg,
borderColor: variant === 'secondary' ? c.border : bg,
minHeight: large ? 72 : 56,
opacity: disabled ? 0.5 : pressed && variant !== 'primary' ? 0.8 : 1,
},
]}
>
{loading ? (
<ActivityIndicator color={fg} />
) : (
<>
{icon}
<Text style={{ fontFamily: font.bold, fontSize: large ? 20 : 17, color: fg }}>{label}</Text>
</>
)}
</Pressable>
);
}
export function Card({ children, style }: { children: ReactNode; style?: ViewStyle }) {
const c = useColors();
return (
<View
style={[
{
backgroundColor: c.surface,
borderColor: c.border,
borderWidth: StyleSheet.hairlineWidth,
borderRadius: 18,
padding: 18,
gap: 8,
// Ombre légère : les cartes se détachent du fond sans trait épais.
shadowColor: '#000',
shadowOpacity: 0.05,
shadowRadius: 10,
shadowOffset: { width: 0, height: 3 },
elevation: 1,
},
style,
]}
>
{children}
</View>
);
}
export function Banner({ tone, children }: { tone: 'error' | 'warn' | 'ok'; children: ReactNode }) {
const c = useColors();
const [bg, fg] = { error: [c.errBg, c.err], warn: [c.warnBg, c.warn], ok: [c.okBg, c.ok] }[tone];
return (
<View accessibilityRole="alert" style={{ backgroundColor: bg, borderRadius: 12, padding: 14 }}>
<Text style={{ color: fg, fontFamily: font.semibold, fontSize: 15, lineHeight: 21 }}>{children}</Text>
</View>
);
}
/** Symbole officiel MonEspacePro. */
export function BrandSymbol({ size = 32, arch }: { size?: number; arch?: string }) {
const c = useColors();
return (
<Svg width={size} height={size} viewBox="0.5 -2 64 64">
<Path d="M12 54V32a9 9 0 0 1 18 0v22M30 32a9 9 0 0 1 18 0v22" fill="none" stroke={arch ?? c.primary} strokeWidth={8} />
<Circle cx={51} cy={12} r={6} fill="#F2B544" />
</Svg>
);
}
export const euros = (cents: number) => (cents / 100).toLocaleString('fr-FR', { style: 'currency', currency: 'EUR' });
export function unit(mode: 'AMOUNT' | 'STAMP', n = 2) {
if (mode === 'STAMP') return n > 1 ? 'tampons' : 'tampon';
return n > 1 ? 'points' : 'point';
}
const styles = StyleSheet.create({
btn: { borderRadius: 16, borderWidth: 1, paddingHorizontal: 20, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 10 },
});