feat(m0001): reuse expandable category UI for xi-cleft with yin_yang badge and full point headings #144
|
|
@ -343,6 +343,7 @@ export function YuanSourceDetailRenderer({
|
||||||
{descriptionParagraphs.length > 0 ? (
|
{descriptionParagraphs.length > 0 ? (
|
||||||
<OverviewCard
|
<OverviewCard
|
||||||
title="Overview"
|
title="Overview"
|
||||||
|
variant="bullets"
|
||||||
paragraphs={descriptionParagraphs}
|
paragraphs={descriptionParagraphs}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,60 @@
|
||||||
import React from "react";
|
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";
|
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;
|
if (!items.length) return null;
|
||||||
return (
|
return (
|
||||||
<View style={styles.list}>
|
<View style={[styles.list, listStyle]}>
|
||||||
{items.map((item, index) => (
|
{items.map((item, index) => (
|
||||||
<View key={`${index}-${item}`} style={styles.row}>
|
<View key={`${index}-${item}`} style={styles.row}>
|
||||||
<View style={styles.dot} />
|
<View style={[styles.dot, dotStyle]} />
|
||||||
<Text style={styles.text}>{item}</Text>
|
{renderBulletText(item, textStyle, boldColonPrefix)}
|
||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -28,4 +72,5 @@ const styles = StyleSheet.create({
|
||||||
backgroundColor: Colors.primary,
|
backgroundColor: Colors.primary,
|
||||||
},
|
},
|
||||||
text: { flex: 1, fontSize: 16, lineHeight: 25, color: "#334155" },
|
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 { moderateScale, verticalScale } from "react-native-size-matters";
|
||||||
|
|
||||||
import { Colors } from "@/theme";
|
import { Colors } from "@/theme";
|
||||||
|
import { BulletList } from "./BulletList";
|
||||||
|
|
||||||
export interface OverviewCardProps {
|
export interface OverviewCardProps {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|
@ -19,6 +20,8 @@ export interface OverviewCardProps {
|
||||||
iconSize?: number;
|
iconSize?: number;
|
||||||
text?: string | null;
|
text?: string | null;
|
||||||
paragraphs?: Array<string | null | undefined>;
|
paragraphs?: Array<string | null | undefined>;
|
||||||
|
variant?: "paragraphs" | "bullets";
|
||||||
|
boldBulletPrefix?: boolean;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
style?: StyleProp<ViewStyle>;
|
style?: StyleProp<ViewStyle>;
|
||||||
titleStyle?: StyleProp<TextStyle>;
|
titleStyle?: StyleProp<TextStyle>;
|
||||||
|
|
@ -32,14 +35,16 @@ export function OverviewCard({
|
||||||
iconSize = moderateScale(20),
|
iconSize = moderateScale(20),
|
||||||
text,
|
text,
|
||||||
paragraphs,
|
paragraphs,
|
||||||
|
variant = "paragraphs",
|
||||||
|
boldBulletPrefix = true,
|
||||||
children,
|
children,
|
||||||
style,
|
style,
|
||||||
titleStyle,
|
titleStyle,
|
||||||
textStyle,
|
textStyle,
|
||||||
}: OverviewCardProps) {
|
}: OverviewCardProps) {
|
||||||
const filteredParagraphs = paragraphs?.filter(
|
const filteredParagraphs = paragraphs
|
||||||
(p): p is string => typeof p === "string" && p.trim().length > 0,
|
?.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 hasText = typeof text === "string" && text.trim().length > 0;
|
||||||
const hasParagraphs =
|
const hasParagraphs =
|
||||||
|
|
@ -62,8 +67,16 @@ export function OverviewCard({
|
||||||
<Text style={[styles.text, textStyle]}>{text}</Text>
|
<Text style={[styles.text, textStyle]}>{text}</Text>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{hasParagraphs
|
{hasParagraphs && variant === "bullets" ? (
|
||||||
? filteredParagraphs.map((para, index) => (
|
<BulletList
|
||||||
|
items={filteredParagraphs}
|
||||||
|
listStyle={[styles.bulletList, hasText && styles.paragraphSpacing]}
|
||||||
|
dotStyle={styles.bulletDot}
|
||||||
|
textStyle={[styles.text, textStyle]}
|
||||||
|
boldColonPrefix={boldBulletPrefix}
|
||||||
|
/>
|
||||||
|
) : hasParagraphs ? (
|
||||||
|
filteredParagraphs.map((para, index) => (
|
||||||
<Text
|
<Text
|
||||||
key={index}
|
key={index}
|
||||||
style={[
|
style={[
|
||||||
|
|
@ -74,7 +87,7 @@ export function OverviewCard({
|
||||||
{para}
|
{para}
|
||||||
</Text>
|
</Text>
|
||||||
))
|
))
|
||||||
: null}
|
) : null}
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
</View>
|
</View>
|
||||||
|
|
@ -111,5 +124,17 @@ const styles = StyleSheet.create({
|
||||||
color: Colors.textSecondary,
|
color: Colors.textSecondary,
|
||||||
marginTop: verticalScale(8),
|
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