File size: 2,153 Bytes
5c876be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import React from 'react';
import { StyleSheet, View } from 'react-native';
import { useTheme, Text, IconButton, Button, Surface } from 'react-native-paper';
export interface EmptyStateProps {
/** MaterialCommunityIcons icon name */
icon: string;
/** Title displayed prominently */
title: string;
/** Optional description below the title */
description?: string;
/** Label for the optional action button */
actionLabel?: string;
/** Callback when the action button is pressed */
onAction?: () => void;
}
/**
* Reusable empty-state placeholder with an icon, title, description,
* and an optional call-to-action button.
*/
export function EmptyState({
icon,
title,
description,
actionLabel,
onAction,
}: EmptyStateProps) {
const theme = useTheme();
return (
<Surface
style={[styles.container, { backgroundColor: theme.colors.surface }]}
elevation={0}
>
<View style={styles.content}>
<IconButton
icon={icon}
size={64}
iconColor={theme.colors.onSurfaceVariant}
style={styles.icon}
disabled
/>
<Text
variant="titleMedium"
style={[styles.title, { color: theme.colors.onSurface }]}
>
{title}
</Text>
{description ? (
<Text
variant="bodyMedium"
style={[styles.description, { color: theme.colors.onSurfaceVariant }]}
>
{description}
</Text>
) : null}
{actionLabel && onAction ? (
<Button
mode="contained"
onPress={onAction}
style={styles.actionButton}
>
{actionLabel}
</Button>
) : null}
</View>
</Surface>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
borderRadius: 12,
},
content: {
alignItems: 'center',
justifyContent: 'center',
padding: 24,
gap: 8,
},
icon: {
margin: 0,
},
title: {
textAlign: 'center',
},
description: {
textAlign: 'center',
maxWidth: 280,
},
actionButton: {
marginTop: 8,
},
});
|