import { ComponentProps, useCallback, useMemo } from "react"; import { View } from "react-native"; import { useIOTheme } from "../../context"; import { IOListItemStyles, IOListItemVisualParams, IOSelectionListItemVisualParams, IOSpacingScale, IOVisualCostants } from "../../core"; import { useIOFontDynamicScale } from "../../utils/accessibility"; import { WithTestID } from "../../utils/types"; import { Badge } from "../badge"; import { IOButton, IOButtonLinkSpecificProps, IconButton } from "../buttons"; import { IOIcons, Icon } from "../icons"; import { VSpacer } from "../layout"; import { BodySmall, H6 } from "../typography"; type ButtonLinkActionProps = { type: "buttonLink"; componentProps: Omit; }; type IconButtonActionProps = { type: "iconButton"; componentProps: ComponentProps; }; type BadgeProps = { type: "badge"; componentProps: ComponentProps; }; type IconProps = | { iconName: IOIcons; iconColor?: ComponentProps["color"]; } | { iconName?: never; iconColor?: never }; type EndElementProps = | ButtonLinkActionProps | IconButtonActionProps | BadgeProps; export type ListItemHeader = WithTestID<{ label: string; numberOfLines?: number; endElement?: EndElementProps; description?: string; // Accessibility accessibilityLabel?: string; }> & IconProps; const iconMargin: IOSpacingScale = IOVisualCostants.iconMargin; export const ListItemHeader = ({ label, iconName, iconColor, endElement, description, accessibilityLabel, testID }: ListItemHeader) => { const theme = useIOTheme(); const { dynamicFontScale, spacingScaleMultiplier, hugeFontEnabled } = useIOFontDynamicScale(); const itemInfoTextComponent = useMemo( () => (
{label}
), [label, accessibilityLabel, theme] ); const listItemAction = useCallback(() => { if (endElement) { const { type, componentProps } = endElement; switch (type) { case "buttonLink": return ; case "iconButton": return ; case "badge": return ; default: return <>; } } return <>; }, [endElement]); return ( {iconName && !hugeFontEnabled && ( )} {itemInfoTextComponent} {endElement && ( {listItemAction()} )} {description && ( {description} )} ); };