mobileapp / src /components /common /StatusChip.tsx
Antaram Dev Bot
feat: complete ANTARAM.ORG ride-sharing app frontend
5c876be
import React from 'react';
import { useTheme, Chip } from 'react-native-paper';
import type { RideStatus } from '../../types/ride';
import { RIDE_STATUS_LABELS } from '../../utils/constants';
export interface StatusChipProps {
/** The ride status to visualise */
status: RideStatus;
}
/**
* Coloured chip that displays the human-readable label for a ride status.
*
* Colour mapping (M3 tokens):
* - active β†’ primary
* - ongoing β†’ rideActive (amber via tertiary)
* - matched β†’ primary
* - completed β†’ outline variant
* - cancelled β†’ error
* - draft β†’ outline variant
*/
export function StatusChip({ status }: StatusChipProps) {
const theme = useTheme();
const chipStyle: Record<RideStatus, { bgColor: string; textColor: string }> = {
active: {
bgColor: theme.colors.primaryContainer,
textColor: theme.colors.onPrimaryContainer,
},
ongoing: {
bgColor: theme.colors.tertiaryContainer,
textColor: theme.colors.onTertiaryContainer,
},
matched: {
bgColor: theme.colors.secondaryContainer,
textColor: theme.colors.onSecondaryContainer,
},
completed: {
bgColor: 'transparent',
textColor: theme.colors.outline,
},
cancelled: {
bgColor: theme.colors.errorContainer,
textColor: theme.colors.onErrorContainer,
},
draft: {
bgColor: 'transparent',
textColor: theme.colors.outline,
},
};
const variant: Record<RideStatus, 'flat' | 'outlined'> = {
active: 'flat',
ongoing: 'flat',
matched: 'flat',
completed: 'outlined',
cancelled: 'flat',
draft: 'outlined',
};
const colors = chipStyle[status];
return (
<Chip
mode={variant[status]}
style={[
styles.chip,
{
backgroundColor: colors.bgColor,
},
]}
textStyle={{
color: colors.textColor,
fontSize: 12,
}}
compact
>
{RIDE_STATUS_LABELS[status]}
</Chip>
);
}
const styles = {
chip: {
height: 28,
justifyContent: 'center',
} as const,
};