import React from 'react'; import type { DefinitionListItemProps, DefinitionListProps, IconData, LabelProps, } from '@gravity-ui/uikit'; import {ClipboardButton, DefinitionList, Flex, Icon, Label, Text} from '@gravity-ui/uikit'; import {cn} from '../../utils/cn'; import i18n from './i18n'; import './YDBDefinitionList.scss'; const b = cn('ydb-definition-list'); export type YDBDefinitionListItem = { name: string; content: React.ReactNode; copyText?: string | number; note?: DefinitionListItemProps['note']; }; export interface YDBDefinitionListHeaderLabel { id: string; value: React.ReactNode; icon?: IconData; theme?: LabelProps['theme']; } interface YDBDefinitionListProps extends Omit { title?: React.ReactNode; titleSuffix?: {title: React.ReactNode; copyText?: string}; titleSeparator?: React.ReactNode; items: YDBDefinitionListItem[]; headerLabels?: YDBDefinitionListHeaderLabel[]; iconSize?: number; labelSize?: LabelProps['size']; footer?: React.ReactNode; compact?: boolean; nameMaxWidth?: DefinitionListProps['nameMaxWidth'] | 'auto'; wrapperClassName?: string; dataQa?: string; } /** DefinitionList with predefined styles and layout */ export function YDBDefinitionList({ title, titleSuffix, titleSeparator = '•', headerLabels, iconSize = 12, labelSize = 'xs', footer, items, compact, nameMaxWidth = 220, className, wrapperClassName, dataQa, ...restProps }: YDBDefinitionListProps) { const hasHeader = Boolean(title || titleSuffix || (headerLabels && headerLabels.length)); const renderHeader = () => { if (!hasHeader) { return null; } return ( {title && ( {title} {titleSuffix && ( {titleSeparator} {titleSuffix.title} {titleSuffix.copyText && ( )} )} )} {headerLabels && headerLabels.length > 0 && ( {headerLabels.map((label) => ( ))} )} ); }; const renderContent = () => { if (items.length) { const definitionListProps = nameMaxWidth === 'auto' ? restProps : {...restProps, nameMaxWidth}; return ( {items.map((item, index) => { const {name, content, copyText, ...rest} = item; let normalizedCopyText: string | undefined; if (typeof copyText === 'string') { normalizedCopyText = copyText || undefined; } else if (typeof copyText === 'number') { normalizedCopyText = String(copyText); } return ( ); })} ); } return i18n('no-data'); }; const renderFooter = () => { if (!footer) { return null; } return
{footer}
; }; return ( {renderHeader()} {renderContent()} {renderFooter()} ); }