acupedia-mobile-ui/src/features/content/renderers/shared/StandardIndexCard.tsx

140 lines
3.8 KiB
TypeScript

import React from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { moderateScale, verticalScale } from "react-native-size-matters";
import { Colors } from "@/theme";
import {
type PageTone,
toneColors,
usePageTone,
} from "../../context/PageToneContext";
export type StandardIndexCardTone = PageTone;
export const cardTones = toneColors;
export interface StandardIndexCardProps {
title: string;
subtitle?: string | null;
count?: number | null;
countLabel?: string | null;
tone?: StandardIndexCardTone;
icon?: "dot" | "book";
onPress: () => void;
}
/** Canonical soothing index row for CT0002 / CT0004 / CT0006 / CT0008. */
export function StandardIndexCard({
title,
subtitle,
count,
countLabel,
tone,
icon = "dot",
onPress,
}: StandardIndexCardProps) {
const { tone: contextTone } = usePageTone();
const normalizedTitle = title.trim();
const normalizedSubtitle = subtitle?.trim() || null;
const effectiveTone = tone || (icon === "book" ? "green" : contextTone) || "purple";
const currentTone = cardTones[effectiveTone] || cardTones.purple;
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={normalizedTitle}
onPress={onPress}
style={({ pressed }) => [styles.row, pressed && styles.pressed]}
>
<View style={[styles.accent, { backgroundColor: currentTone.soft }]}>
{icon === "book" ? (
<Ionicons name="book-outline" size={19} color={currentTone.accent} />
) : (
<View style={[styles.accentDot, { backgroundColor: currentTone.accent }]} />
)}
</View>
<View style={styles.titleBlock}>
<Text numberOfLines={2} style={styles.title}>
{normalizedTitle}
</Text>
{normalizedSubtitle ? (
<Text numberOfLines={2} style={styles.subtitle}>
{normalizedSubtitle}
</Text>
) : null}
</View>
{count !== null && count !== undefined ? (
<View style={[styles.countBadge, { backgroundColor: currentTone.soft }]}>
<Text style={[styles.countText, { color: currentTone.accent }]}>{count}</Text>
{countLabel ? (
<Text numberOfLines={1} style={[styles.countLabel, { color: currentTone.accent }]}>
{countLabel}
</Text>
) : null}
</View>
) : null}
<Ionicons name="chevron-forward" size={19} color="#94A3B8" />
</Pressable>
);
}
const styles = StyleSheet.create({
row: {
minHeight: verticalScale(68),
flexDirection: "row",
alignItems: "center",
paddingHorizontal: moderateScale(14),
paddingVertical: verticalScale(13),
gap: moderateScale(11),
},
pressed: { opacity: 0.72 },
accent: {
width: moderateScale(38),
height: moderateScale(38),
borderRadius: moderateScale(19),
alignItems: "center",
justifyContent: "center",
},
accentDot: {
width: moderateScale(9),
height: moderateScale(9),
borderRadius: moderateScale(5),
},
titleBlock: { flex: 1, gap: verticalScale(3) },
title: {
fontSize: moderateScale(16),
lineHeight: moderateScale(22),
fontWeight: "700",
color: Colors.textPrimary,
},
subtitle: {
fontSize: moderateScale(12.5),
lineHeight: moderateScale(18),
color: Colors.textSecondary,
},
countBadge: {
minWidth: moderateScale(38),
maxWidth: moderateScale(82),
paddingHorizontal: moderateScale(8),
paddingVertical: verticalScale(5),
borderRadius: moderateScale(12),
alignItems: "center",
justifyContent: "center",
},
countText: {
fontSize: moderateScale(13),
lineHeight: moderateScale(16),
fontWeight: "800",
},
countLabel: {
marginTop: 1,
fontSize: moderateScale(9),
lineHeight: moderateScale(11),
fontWeight: "600",
},
});