feat(m0001): add bulleted Overview variant with bold prefixes for point category renderers
This commit is contained in:
parent
f8308c98ec
commit
5c6180b6b0
|
|
@ -343,6 +343,7 @@ export function YuanSourceDetailRenderer({
|
|||
{descriptionParagraphs.length > 0 ? (
|
||||
<OverviewCard
|
||||
title="Overview"
|
||||
variant="bullets"
|
||||
paragraphs={descriptionParagraphs}
|
||||
/>
|
||||
) : null}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,60 @@
|
|||
import React from "react";
|
||||
import { StyleSheet, Text, View } from "react-native";
|
||||
import {
|
||||
StyleProp,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextStyle,
|
||||
View,
|
||||
ViewStyle,
|
||||
} from "react-native";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
|
||||
export function BulletList({ items }: { items: string[] }) {
|
||||
export interface BulletListProps {
|
||||
items: string[];
|
||||
listStyle?: StyleProp<ViewStyle>;
|
||||
dotStyle?: StyleProp<ViewStyle>;
|
||||
textStyle?: StyleProp<TextStyle>;
|
||||
boldColonPrefix?: boolean;
|
||||
}
|
||||
|
||||
const COLON_PREFIX_RE = /^([A-Za-z][A-Za-z0-9 &/().-]{1,32}:)([\s\S]*)$/;
|
||||
|
||||
function renderBulletText(
|
||||
item: string,
|
||||
textStyle?: StyleProp<TextStyle>,
|
||||
boldColonPrefix?: boolean,
|
||||
) {
|
||||
if (!boldColonPrefix) {
|
||||
return <Text style={[styles.text, textStyle]}>{item}</Text>;
|
||||
}
|
||||
const match = COLON_PREFIX_RE.exec(item);
|
||||
if (!match) {
|
||||
return <Text style={[styles.text, textStyle]}>{item}</Text>;
|
||||
}
|
||||
return (
|
||||
<Text style={[styles.text, textStyle]}>
|
||||
<Text style={styles.prefix}>{match[1]}</Text>
|
||||
{match[2]}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
/** Renders a bulleted list with optional custom typography and bold label prefixes. */
|
||||
export function BulletList({
|
||||
items,
|
||||
listStyle,
|
||||
dotStyle,
|
||||
textStyle,
|
||||
boldColonPrefix = false,
|
||||
}: BulletListProps) {
|
||||
if (!items.length) return null;
|
||||
return (
|
||||
<View style={styles.list}>
|
||||
<View style={[styles.list, listStyle]}>
|
||||
{items.map((item, index) => (
|
||||
<View key={`${index}-${item}`} style={styles.row}>
|
||||
<View style={styles.dot} />
|
||||
<Text style={styles.text}>{item}</Text>
|
||||
<View style={[styles.dot, dotStyle]} />
|
||||
{renderBulletText(item, textStyle, boldColonPrefix)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
|
@ -28,4 +72,5 @@ const styles = StyleSheet.create({
|
|||
backgroundColor: Colors.primary,
|
||||
},
|
||||
text: { flex: 1, fontSize: 16, lineHeight: 25, color: "#334155" },
|
||||
prefix: { fontWeight: "700", color: Colors.textPrimary },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { Ionicons } from "@expo/vector-icons";
|
|||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
import { BulletList } from "./BulletList";
|
||||
|
||||
export interface OverviewCardProps {
|
||||
title?: string;
|
||||
|
|
@ -19,6 +20,8 @@ export interface OverviewCardProps {
|
|||
iconSize?: number;
|
||||
text?: string | null;
|
||||
paragraphs?: Array<string | null | undefined>;
|
||||
variant?: "paragraphs" | "bullets";
|
||||
boldBulletPrefix?: boolean;
|
||||
children?: React.ReactNode;
|
||||
style?: StyleProp<ViewStyle>;
|
||||
titleStyle?: StyleProp<TextStyle>;
|
||||
|
|
@ -32,14 +35,16 @@ export function OverviewCard({
|
|||
iconSize = moderateScale(20),
|
||||
text,
|
||||
paragraphs,
|
||||
variant = "paragraphs",
|
||||
boldBulletPrefix = true,
|
||||
children,
|
||||
style,
|
||||
titleStyle,
|
||||
textStyle,
|
||||
}: OverviewCardProps) {
|
||||
const filteredParagraphs = paragraphs?.filter(
|
||||
(p): p is string => typeof p === "string" && p.trim().length > 0,
|
||||
);
|
||||
const filteredParagraphs = paragraphs
|
||||
?.filter((p): p is string => typeof p === "string" && p.trim().length > 0)
|
||||
.map((p) => p.replace(/\n[ \t]+/g, "\n").trim());
|
||||
|
||||
const hasText = typeof text === "string" && text.trim().length > 0;
|
||||
const hasParagraphs =
|
||||
|
|
@ -62,19 +67,27 @@ export function OverviewCard({
|
|||
<Text style={[styles.text, textStyle]}>{text}</Text>
|
||||
) : null}
|
||||
|
||||
{hasParagraphs
|
||||
? filteredParagraphs.map((para, index) => (
|
||||
<Text
|
||||
key={index}
|
||||
style={[
|
||||
index === 0 && !hasText ? styles.text : styles.paragraph,
|
||||
textStyle,
|
||||
]}
|
||||
>
|
||||
{para}
|
||||
</Text>
|
||||
))
|
||||
: null}
|
||||
{hasParagraphs && variant === "bullets" ? (
|
||||
<BulletList
|
||||
items={filteredParagraphs}
|
||||
listStyle={[styles.bulletList, hasText && styles.paragraphSpacing]}
|
||||
dotStyle={styles.bulletDot}
|
||||
textStyle={[styles.text, textStyle]}
|
||||
boldColonPrefix={boldBulletPrefix}
|
||||
/>
|
||||
) : hasParagraphs ? (
|
||||
filteredParagraphs.map((para, index) => (
|
||||
<Text
|
||||
key={index}
|
||||
style={[
|
||||
index === 0 && !hasText ? styles.text : styles.paragraph,
|
||||
textStyle,
|
||||
]}
|
||||
>
|
||||
{para}
|
||||
</Text>
|
||||
))
|
||||
) : null}
|
||||
|
||||
{children}
|
||||
</View>
|
||||
|
|
@ -111,5 +124,17 @@ const styles = StyleSheet.create({
|
|||
color: Colors.textSecondary,
|
||||
marginTop: verticalScale(8),
|
||||
},
|
||||
paragraphSpacing: {
|
||||
marginTop: verticalScale(8),
|
||||
},
|
||||
bulletList: {
|
||||
gap: verticalScale(7),
|
||||
},
|
||||
bulletDot: {
|
||||
width: moderateScale(5),
|
||||
height: moderateScale(5),
|
||||
borderRadius: moderateScale(2.5),
|
||||
marginTop: moderateScale(7.5),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue