feat(renderers): render reference points vertically as bullet list with chips
This commit is contained in:
parent
c40e4cd254
commit
263650d03d
|
|
@ -38,7 +38,7 @@ function RelationshipRow({ label, value, chips = false }: RelationshipRowProps)
|
||||||
return (
|
return (
|
||||||
<View style={styles.relationshipRow}>
|
<View style={styles.relationshipRow}>
|
||||||
<Text style={styles.relationshipLabel}>{label}</Text>
|
<Text style={styles.relationshipLabel}>{label}</Text>
|
||||||
{chips ? <ReferenceChipList value={value} /> : <ContentValue value={value} />}
|
{chips ? <ReferenceChipList value={value} asBulletList={false} /> : <ContentValue value={value} />}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,15 @@ import { Spacing } from "@/theme/spacing";
|
||||||
import { ContentLink } from "../../components/navigation/ContentLink";
|
import { ContentLink } from "../../components/navigation/ContentLink";
|
||||||
import { parseNavigableContentReference } from "../../utils/content-reference";
|
import { parseNavigableContentReference } from "../../utils/content-reference";
|
||||||
|
|
||||||
export function ReferenceChipList({ value }: { value: unknown }) {
|
export interface ReferenceChipListProps {
|
||||||
|
value: unknown;
|
||||||
|
asBulletList?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReferenceChipList({
|
||||||
|
value,
|
||||||
|
asBulletList = true,
|
||||||
|
}: ReferenceChipListProps) {
|
||||||
const values = Array.isArray(value) ? value : [value];
|
const values = Array.isArray(value) ? value : [value];
|
||||||
const visible = values.filter(
|
const visible = values.filter(
|
||||||
(item) => item !== null && item !== undefined && item !== "",
|
(item) => item !== null && item !== undefined && item !== "",
|
||||||
|
|
@ -18,10 +26,11 @@ export function ReferenceChipList({ value }: { value: unknown }) {
|
||||||
if (!visible.length) return null;
|
if (!visible.length) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.list}>
|
<View style={asBulletList ? styles.bulletList : styles.list}>
|
||||||
{visible.map((item, index) => {
|
{visible.map((item, index) => {
|
||||||
const reference = parseNavigableContentReference(item);
|
const reference = parseNavigableContentReference(item);
|
||||||
|
|
||||||
|
const renderChip = () => {
|
||||||
if (reference) {
|
if (reference) {
|
||||||
const label =
|
const label =
|
||||||
reference.label?.trim() ||
|
reference.label?.trim() ||
|
||||||
|
|
@ -60,6 +69,28 @@ export function ReferenceChipList({ value }: { value: unknown }) {
|
||||||
<Text style={styles.text}>{text}</Text>
|
<Text style={styles.text}>{text}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (asBulletList) {
|
||||||
|
const key = reference
|
||||||
|
? (reference.type === "content_ref"
|
||||||
|
? `bullet-${reference.target.content_id}-${index}`
|
||||||
|
: `bullet-${reference.target.module_code}-${reference.target.template_code}-${index}`)
|
||||||
|
: `bullet-${index}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={key} style={styles.bulletRow}>
|
||||||
|
<View style={styles.dot} />
|
||||||
|
{renderChip()}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
{renderChip()}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
@ -84,6 +115,21 @@ const styles = StyleSheet.create({
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
gap: Spacing.sm,
|
gap: Spacing.sm,
|
||||||
},
|
},
|
||||||
|
bulletList: {
|
||||||
|
gap: 10,
|
||||||
|
alignItems: "flex-start",
|
||||||
|
},
|
||||||
|
bulletRow: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 10,
|
||||||
|
},
|
||||||
|
dot: {
|
||||||
|
width: 6,
|
||||||
|
height: 6,
|
||||||
|
borderRadius: 3,
|
||||||
|
backgroundColor: Colors.primary,
|
||||||
|
},
|
||||||
link: {
|
link: {
|
||||||
alignSelf: "flex-start",
|
alignSelf: "flex-start",
|
||||||
borderRadius: Radius.full,
|
borderRadius: Radius.full,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue