// ============================================================================ // Chatbot Main - Messages - Sources Card // ============================================================================ import React from 'react'; // Import PatternFly components import { Button, ButtonVariant, Card, CardBody, CardFooter, CardProps, CardTitle, Icon, pluralize, Truncate } from '@patternfly/react-core'; export interface SourcesCardProps extends CardProps { /** Additional classes for the pagination navigation container. */ className?: string; /** Flag indicating if the pagination is disabled. */ isDisabled?: boolean; /** Label for the English word "of". */ ofWord?: string; /** Accessible label for the pagination component. */ paginationAriaLabel?: string; /** Content rendered inside the paginated card */ sources: { title?: string; link: string; body?: React.ReactNode | string }[]; /** Label for the English word "source" */ sourceWord?: string; /** Plural for sourceWord */ sourceWordPlural?: string; /** Accessible label for the button which moves to the next page. */ toNextPageAriaLabel?: string; /** Accessible label for the button which moves to the previous page. */ toPreviousPageAriaLabel?: string; /** Function called when user clicks to navigate to next page. */ onNextClick?: (event: React.SyntheticEvent, page: number) => void; /** Function called when user clicks to navigate to previous page. */ onPreviousClick?: (event: React.SyntheticEvent, page: number) => void; /** Function called when page is changed. */ onSetPage?: (event: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => void; } const SourcesCard: React.FunctionComponent = ({ className, isDisabled, ofWord = 'of', paginationAriaLabel = 'Pagination', sources, sourceWord = 'source', sourceWordPlural = 'sources', toNextPageAriaLabel = 'Go to next page', toPreviousPageAriaLabel = 'Go to previous page', onNextClick, onPreviousClick, onSetPage, ...props }: SourcesCardProps) => { const [page, setPage] = React.useState(1); const handleNewPage = (_evt: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => { setPage(newPage); onSetPage && onSetPage(_evt, newPage); }; const renderTitle = (title?: string) => { if (title) { return ; } return `Source ${page}`; }; return (
{pluralize(sources.length, sourceWord, sourceWordPlural)} {renderTitle(sources[page - 1].title)} {sources[page - 1].body && ( {sources[page - 1].body} )} {sources.length > 1 && (
)}
); }; export default SourcesCard;