73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import React from "react";
|
|
import { StyleSheet, Text } from "react-native";
|
|
import { asRecord, asRecordArray, asString, asStringArray } from "../helpers/value";
|
|
import { BulletList } from "../shared/BulletList";
|
|
import { ChipList } from "../shared/ChipList";
|
|
import { ImageGallery } from "../shared/ImageGallery";
|
|
import { ObjectSections } from "../shared/ObjectSections";
|
|
import { RecordCards } from "../shared/RecordCards";
|
|
import { RecordTable } from "../shared/RecordTable";
|
|
import { SectionCard } from "../shared/SectionCard";
|
|
|
|
export const PointCodes = ({ data }: { data: Record<string, unknown> }) => (
|
|
<SectionCard title="Points"><ChipList items={asStringArray(data.point_codes)} /></SectionCard>
|
|
);
|
|
|
|
export const DescriptionList = ({ data }: { data: Record<string, unknown> }) => {
|
|
const arr = asStringArray(data.description);
|
|
const text = asString(data.description);
|
|
return (
|
|
<SectionCard title="Description">
|
|
{arr.length ? <BulletList items={arr} /> : <Text style={styles.readingText}>{text}</Text>}
|
|
</SectionCard>
|
|
);
|
|
};
|
|
|
|
export const Images = ({ data }: { data: Record<string, unknown> }) => (
|
|
<ImageGallery images={asRecordArray(data.images)} />
|
|
);
|
|
|
|
export const ObjectCard = ({ title, value }: { title: string; value: unknown }) => {
|
|
const obj = asRecord(value);
|
|
return Object.keys(obj).length ? (
|
|
<SectionCard title={title}><ObjectSections value={obj} /></SectionCard>
|
|
) : null;
|
|
};
|
|
|
|
export const ObjectArrayCards = ({ title, value }: { title: string; value: unknown }) => {
|
|
const rows = asRecordArray(value);
|
|
return rows.length ? (
|
|
<SectionCard title={title}><RecordCards rows={rows} /></SectionCard>
|
|
) : null;
|
|
};
|
|
|
|
export const ObjectArrayTable = ({
|
|
title,
|
|
value,
|
|
columns,
|
|
}: {
|
|
title: string;
|
|
value: unknown;
|
|
columns?: string[];
|
|
}) => {
|
|
const rows = asRecordArray(value);
|
|
return rows.length ? (
|
|
<SectionCard title={title}><RecordTable rows={rows} columns={columns} /></SectionCard>
|
|
) : null;
|
|
};
|
|
|
|
export const Strings = ({ title, value }: { title: string; value: unknown }) => {
|
|
const arr = asStringArray(value);
|
|
const txt = asString(value);
|
|
if (!arr.length && !txt) return null;
|
|
return (
|
|
<SectionCard title={title}>
|
|
{arr.length ? <BulletList items={arr} /> : <Text style={styles.readingText}>{txt}</Text>}
|
|
</SectionCard>
|
|
);
|
|
};
|
|
|
|
const styles = StyleSheet.create({
|
|
readingText: { fontSize: 16, lineHeight: 26, color: "#334155" },
|
|
});
|