import { Container } from '@cleartrip/ct-design-container'; import { Typography } from '@cleartrip/ct-design-typography'; import { useStyles } from '@cleartrip/ct-design-style-manager'; import staticBulletedListStyles from './style'; import type { IBulletedListProps } from './type'; /** * BulletedList * * A flexible list renderer that supports ordered (`ol`) and unordered * (`ul`) list markers. Each row shows a marker (number or bullet) * followed by arbitrary content returned from `renderItem`. * * The ordered-list marker width auto-scales with the largest row * number so every digit column lines up — one extra pixel of slot * width per digit so a 10-item list stays aligned with a 100-item * list. * * @example * ```tsx * {item.title}} * /> * ``` */ const BulletedList = ({ list, renderItem, listType = 'ol', styleConfig, }: IBulletedListProps) => { const { itemWrapper: customItemWrapper = [], placeHolder: customPlaceHolder = [], itemContent: customItemContent = [], marker: customMarker = [], } = styleConfig || {}; const maxNumber = list?.length || 0; // Character count of the largest row number — drives the marker // column width so every item's digit group lines up regardless of // 1/2/3-digit transitions. const maxNumberDigits = String(maxNumber).length; // Width of the number column based on the digit count. const numberWidth = maxNumberDigits * 12; const dynamicNumberWidth = useStyles( () => ({ root: { width: numberWidth, }, }), [numberWidth], ); if (!list || list.length === 0) { return null; } return ( <> {list.map((item, index) => ( {listType === 'ol' ? ( {index + 1} . ) : ( {'\u2022'} )} {renderItem(item, index)} ))} ); }; export default BulletedList;