import type { ReactNode } from "react"; import React from "react"; import { View } from "react-native"; import type { IconColorNames, IconNames } from "@jobber/design"; import { useStyles } from "./ActionItem.style"; import { ActionItemContainer } from "./components/ActionItemContainer"; import { Typography } from "../Typography"; import { Icon } from "../Icon"; export interface ActionItemProps { /** * Title of the Action Item */ readonly title?: string; /** * Name of the icon to display before content */ readonly icon?: IconNames; /** * Colour of the icon displayed before content */ readonly iconColor?: IconColorNames; /** * Content to display. */ readonly children?: ReactNode; /** * Action icon to display */ readonly actionIcon?: ActionIconNames; /** * Colour of the action icon */ readonly actionIconColour?: ActionIconColour; /** * Alignment of action icon */ readonly actionIconAlignment?: "flex-start" | "flex-end" | "center"; /** * Press handler */ readonly onPress?: () => void; readonly testID?: string; } export function ActionItem({ title, icon, iconColor, children, actionIcon = "edit", actionIconColour = "interactive", actionIconAlignment = "center", onPress, testID = "actionItem", }: ActionItemProps) { const actionIconStyle = { justifyContent: actionIconAlignment, }; const styles = useStyles(); const addIconOffset = icon || onPress ? styles.offsetForIcons : undefined; const titlePadding = children ? styles.titlePadding : undefined; return ( {icon && ( )} {title && ( {title} )} {children} {onPress && ( )} ); } type ActionIconColour = | "interactive" | "destructive" | "informative" | "subtle"; function getActionIconColour( actionIconColour: ActionIconColour, ): IconColorNames { if (actionIconColour === "subtle") { return "interactiveSubtle"; } return actionIconColour; } type ActionIconNames = IconNames | "editpencil"; function getActionIcon(icon: ActionIconNames): IconNames { if (icon === "edit") { return "longArrowRight"; } else if (icon === "editpencil") { return "edit"; } return icon; }