123 lines
3.0 KiB
TypeScript
123 lines
3.0 KiB
TypeScript
import React from "react";
|
|
import { StyleSheet, Text, View } from "react-native";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
|
|
import { Colors } from "@/theme/colors";
|
|
import { Radius } from "@/theme/radius";
|
|
import { Spacing } from "@/theme/spacing";
|
|
|
|
import { ContentLink } from "../../components/navigation/ContentLink";
|
|
import { parseNavigableContentReference } from "../../utils/content-reference";
|
|
|
|
export function ReferenceChipList({ value }: { value: unknown }) {
|
|
const values = Array.isArray(value) ? value : [value];
|
|
const visible = values.filter(
|
|
(item) => item !== null && item !== undefined && item !== "",
|
|
);
|
|
|
|
if (!visible.length) return null;
|
|
|
|
return (
|
|
<View style={styles.list}>
|
|
{visible.map((item, index) => {
|
|
const reference = parseNavigableContentReference(item);
|
|
|
|
if (reference) {
|
|
const label =
|
|
reference.label?.trim() ||
|
|
(reference.type === "content_ref"
|
|
? reference.target.source_key?.trim()
|
|
: null) ||
|
|
"Open";
|
|
|
|
return (
|
|
<ContentLink
|
|
key={
|
|
reference.type === "content_ref"
|
|
? `content-${reference.target.content_id}`
|
|
: `template-${reference.target.module_code}-${reference.target.template_code}`
|
|
}
|
|
reference={reference}
|
|
style={styles.link}
|
|
>
|
|
<View style={styles.linkChip}>
|
|
<Text style={styles.linkText}>{label}</Text>
|
|
<Ionicons
|
|
name="chevron-forward"
|
|
size={14}
|
|
color={Colors.primaryDark}
|
|
/>
|
|
</View>
|
|
</ContentLink>
|
|
);
|
|
}
|
|
|
|
const text = scalarLabel(item);
|
|
if (!text) return null;
|
|
|
|
return (
|
|
<View key={`${text}-${index}`} style={styles.chip}>
|
|
<Text style={styles.text}>{text}</Text>
|
|
</View>
|
|
);
|
|
})}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function scalarLabel(value: unknown): string | null {
|
|
if (
|
|
typeof value === "string" ||
|
|
typeof value === "number" ||
|
|
typeof value === "boolean"
|
|
) {
|
|
const normalized = String(value).trim();
|
|
return normalized || null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
list: {
|
|
flexDirection: "row",
|
|
flexWrap: "wrap",
|
|
gap: Spacing.sm,
|
|
},
|
|
link: {
|
|
alignSelf: "flex-start",
|
|
borderRadius: Radius.full,
|
|
},
|
|
linkChip: {
|
|
minHeight: 34,
|
|
paddingHorizontal: 11,
|
|
paddingVertical: 6,
|
|
borderRadius: Radius.full,
|
|
backgroundColor: "#E8F5E9",
|
|
borderWidth: 1,
|
|
borderColor: "#CDE5D0",
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 4,
|
|
},
|
|
linkText: {
|
|
fontSize: 13,
|
|
lineHeight: 18,
|
|
fontWeight: "800",
|
|
color: Colors.primaryDark,
|
|
},
|
|
chip: {
|
|
borderRadius: Radius.full,
|
|
paddingHorizontal: 11,
|
|
paddingVertical: 6,
|
|
backgroundColor: "#EEF7EF",
|
|
borderWidth: 1,
|
|
borderColor: "#D4E9D6",
|
|
},
|
|
text: {
|
|
fontSize: 13,
|
|
fontWeight: "700",
|
|
color: Colors.primaryDark,
|
|
},
|
|
});
|