import { ReactElement } from "react"; import { ItemContainer } from "./ItemContainer"; import { cn } from "../../../../lib/utils"; import { IconType } from "../../../Icon"; import { PersonAvatar } from "../../../Avatars/PersonAvatar"; import { CompanyAvatar } from "../../../Avatars/CompanyAvatar"; import { TeamAvatar } from "../../../Avatars/TeamAvatar"; import { DotTag, DotTagProps } from "../../../Tags/DotTag"; import { View, Text } from "react-native"; export type DataListProps = { children: ReactElement[] | ReactElement; label?: string; isHorizontalItem?: boolean; tableView?: boolean; }; type Items = | typeof Item | typeof PersonItem | typeof CompanyItem | typeof TeamItem; const _DataList = ({ children, label, isHorizontalItem = false, tableView = false, }: DataListProps) => { return ( {!!label && ( {label} )} {children} ); }; export type ItemProps = { text: string; icon?: IconType; action?: ActionType; }; export type ActionType = CopyActionType | GenericActionType | NoopActionType; export type CopyActionType = { type: "copy"; text?: string; }; export type GenericActionType = { type: "generic"; handlePress?: () => void; }; export type NoopActionType = { type: "noop"; }; const Item = ({ text, icon, action }: ItemProps) => { return ( ); }; type URL = string; type EmployeeItemProps = { firstName: string; lastName: string; avatarUrl?: URL; action?: ActionType; }; const PersonItem = ({ action, avatarUrl, firstName, lastName, }: EmployeeItemProps) => { const fullName = `${firstName} ${lastName}`; return ( ( )} text={fullName} action={getInternalAction(action, fullName)} /> ); }; type CompanyItemProps = { name: string; avatarUrl?: URL; action?: ActionType; }; const CompanyItem = ({ avatarUrl, name, action }: CompanyItemProps) => { return ( ( )} text={name} action={getInternalAction(action, name)} /> ); }; type TeamItemProps = { name: string; action?: ActionType; }; const TeamItem = ({ action, name }: TeamItemProps) => { return ( } text={name} action={getInternalAction(action, name)} /> ); }; type DotTagItemProps = DotTagProps; const DotTagItem = ({ ...props }: DotTagItemProps) => { return ( ); }; /** * convert simplified action type received from user to internal action format * @param action ActionType * @param defaultCopyText what to use if copy text is not present */ const getInternalAction = ( action: ActionType | undefined, defaultCopyText: string, ): ActionType | undefined => { if (action && action.type === "copy") { return { type: "copy", text: action.text ?? defaultCopyText }; } return action; }; export const DataList = Object.assign(_DataList, { Item, CompanyItem, PersonItem, TeamItem, DotTagItem, });