|
|
|
@ -8,6 +8,7 @@ import { |
|
|
|
|
Box as MUIBox, |
|
|
|
|
List as MUIList, |
|
|
|
|
ListItem as MUIListItem, |
|
|
|
|
ListItemButton, |
|
|
|
|
ListItemIcon as MUIListItemIcon, |
|
|
|
|
SxProps, |
|
|
|
|
Theme, |
|
|
|
@ -23,7 +24,7 @@ import { |
|
|
|
|
} from 'react'; |
|
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
|
|
|
|
|
|
import { BLUE, GREY, RED } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
import { BLUE, BORDER_RADIUS, GREY, RED } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
import Checkbox from './Checkbox'; |
|
|
|
|
import Divider from './Divider'; |
|
|
|
@ -36,6 +37,7 @@ const List = forwardRef( |
|
|
|
|
{ |
|
|
|
|
allowCheckAll: isAllowCheckAll = false, |
|
|
|
|
allowEdit: isAllowEdit = false, |
|
|
|
|
allowItemButton: isAllowItemButton = false, |
|
|
|
|
edit: isEdit = false, |
|
|
|
|
flexBoxProps, |
|
|
|
|
header, |
|
|
|
@ -53,6 +55,7 @@ const List = forwardRef( |
|
|
|
|
onEdit, |
|
|
|
|
onAllCheckboxChange, |
|
|
|
|
onItemCheckboxChange, |
|
|
|
|
onItemClick, |
|
|
|
|
renderListItem = (key) => <BodyText>{key}</BodyText>, |
|
|
|
|
renderListItemCheckboxState, |
|
|
|
|
scroll: isScroll = false, |
|
|
|
@ -203,7 +206,10 @@ const List = forwardRef( |
|
|
|
|
const entries = Object.entries(listItems); |
|
|
|
|
|
|
|
|
|
if (entries.length > 0) { |
|
|
|
|
result = entries.map(([key, value]) => ( |
|
|
|
|
result = entries.map(([key, value]) => { |
|
|
|
|
const listItem = renderListItem(key, value); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<MUIListItem |
|
|
|
|
{...restListItemProps} |
|
|
|
|
key={`${listItemKeyPrefix}-${key}`} |
|
|
|
@ -213,22 +219,36 @@ const List = forwardRef( |
|
|
|
|
key, |
|
|
|
|
renderListItemCheckboxState?.call(null, key, value), |
|
|
|
|
)} |
|
|
|
|
{renderListItem(key, value)} |
|
|
|
|
{isAllowItemButton ? ( |
|
|
|
|
<ListItemButton |
|
|
|
|
onClick={(...args) => { |
|
|
|
|
onItemClick?.call(null, value, key, ...args); |
|
|
|
|
}} |
|
|
|
|
sx={{ borderRadius: BORDER_RADIUS }} |
|
|
|
|
> |
|
|
|
|
{listItem} |
|
|
|
|
</ListItemButton> |
|
|
|
|
) : ( |
|
|
|
|
listItem |
|
|
|
|
)} |
|
|
|
|
</MUIListItem> |
|
|
|
|
)); |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
}, [ |
|
|
|
|
listEmptyElement, |
|
|
|
|
listItemCheckbox, |
|
|
|
|
listItemKeyPrefix, |
|
|
|
|
listItems, |
|
|
|
|
listItemSx, |
|
|
|
|
renderListItem, |
|
|
|
|
renderListItemCheckboxState, |
|
|
|
|
restListItemProps, |
|
|
|
|
listItemKeyPrefix, |
|
|
|
|
listItemSx, |
|
|
|
|
listItemCheckbox, |
|
|
|
|
renderListItemCheckboxState, |
|
|
|
|
isAllowItemButton, |
|
|
|
|
onItemClick, |
|
|
|
|
]); |
|
|
|
|
const listScrollSx: SxProps<Theme> | undefined = useMemo( |
|
|
|
|
() => (isScroll ? { maxHeight: '100%', overflowY: 'scroll' } : undefined), |
|
|
|
|