import type { FC, ReactNode } from 'react'; import RocketIcon from '@patternfly/react-icons/dist/js/icons/rocket-icon'; import OutlinedBookmarkIcon from '@patternfly/react-icons/dist/js/icons/outlined-bookmark-icon'; import { Card, CardBody, CardHeader, CardFooter, CardTitle, Icon, Button, Flex, Stack, Label, pluralize } from '@patternfly/react-core'; import OutlinedClockIcon from '@patternfly/react-icons/dist/js/icons/outlined-clock-icon'; import QuickStartTileHeader from './QuickStartTileHeader'; import QuickStartTileDescription from './QuickStartTileDescription'; import { QuickStart, QuickstartAction } from './types'; import FallbackImg from './FallbackImg'; export const camelize = (str: string) => str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) { if (+match === 0) { return ''; } // or if (/\s+/.test(match)) for white spaces return index === 0 ? match.toLowerCase() : match.toUpperCase(); }); export interface QuickStartTileProps { /** ClassName applied to the card */ className?: string; /** The quickstart object triggered by this tile */ quickStart: QuickStart; /** Event handler attached to the tile */ onClick?: () => void; /** Action config for button rendered next to title */ action?: QuickstartAction; /** Callback that returns active quick start value when clicked */ onSelectQuickStart: (id?: string) => void; /** Label for the English word "minute". */ minuteWord?: string; /** Label for the English word "minutes". */ minuteWordPlural?: string; /** Label for the English word "Prerequisite" */ prerequisiteWord?: string; /** Label for the English word "Prerequisites" */ prerequisiteWordPlural?: string; /** Aria-label for the quick start description button */ quickStartButtonAriaLabel?: string; /** Sets the tile to compact styling */ isCompact?: boolean; } export const QuickStartTile: FC = ({ className, quickStart, onClick, onSelectQuickStart, minuteWord = 'minute', minuteWordPlural = 'minutes', prerequisiteWord, prerequisiteWordPlural, quickStartButtonAriaLabel, action, isCompact }) => { const { metadata: { name: id }, spec: { icon, displayName, description, durationMinutes, prerequisites, link, type } } = quickStart; let quickStartIcon: ReactNode; if (typeof icon === 'object') { quickStartIcon = {icon}; } else { quickStartIcon = ( } /> ); } const onSelect = () => { if (!link) { onSelectQuickStart(id); } else { window.open(link.href, '_blank', 'noopener,noreferrer'); } onClick && onClick(); }; const ActionIcon = action?.icon || OutlinedBookmarkIcon; const additionalAction = action ? ( ); }; export default QuickStartTile;