import React from "react"; import { ChecklistItem, ChecklistProps, iconColors, } from "@shared/components/checklist/types"; import { List, ListItem } from "@shared/components/list"; import { MaterialIcon } from "@shared/components/material-icon"; import { Text } from "@shared/components/text"; import { cx } from "@shared/utils/cx"; function isChecklistItem( item: React.ReactNode | ChecklistItem ): item is ChecklistItem { return ( item !== null && typeof item === "object" && !React.isValidElement(item) && "title" in (item as Record) ); } export const Checklist: React.FC = props => { const { items, listIconName = "check", listItemClassName, listContainerClassName, iconSize = 20, iconPosition = "center", iconColor = "green", iconClassName, } = props; const showIcons = listIconName !== "disc"; if (!items?.length) return null; const renderContent = (content: React.ReactNode | string) => { if ( typeof content === "string" && content.includes("|") && (content.match(/\|/g) || []).length % 2 === 0 ) { const parts = content.split("|"); const count = (content.match(/\|/g) || []).length; return parts.map((part, index) => { if (!part) return null; const isBold = count > 1 ? index % 2 === 1 : false; return isBold ? ( {part} ) : ( {part} ); }); } return content; }; return ( {items.map((item, idx) => { const structured = isChecklistItem(item); const hasCustomIcon = structured && !!item.iconUrl; const content = structured ? item.title : item; return ( {showIcons && hasCustomIcon ? (
{item.iconAlt
) : showIcons ? (
) : null} {renderContent(content)}
); })}
); }; Checklist.displayName = "Checklist"; export type { ChecklistItem, ChecklistProps };