|
|
@ -22,6 +22,7 @@ import Checkbox from './Checkbox'; |
|
|
|
import Divider from './Divider'; |
|
|
|
import Divider from './Divider'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import IconButton from './IconButton'; |
|
|
|
import IconButton from './IconButton'; |
|
|
|
|
|
|
|
import Spinner from './Spinner'; |
|
|
|
import { BodyText } from './Text'; |
|
|
|
import { BodyText } from './Text'; |
|
|
|
|
|
|
|
|
|
|
|
const List = forwardRef( |
|
|
|
const List = forwardRef( |
|
|
@ -43,6 +44,7 @@ const List = forwardRef( |
|
|
|
listItemProps: { sx: listItemSx, ...restListItemProps } = {}, |
|
|
|
listItemProps: { sx: listItemSx, ...restListItemProps } = {}, |
|
|
|
listItems, |
|
|
|
listItems, |
|
|
|
listProps: { sx: listSx, ...restListProps } = {}, |
|
|
|
listProps: { sx: listSx, ...restListProps } = {}, |
|
|
|
|
|
|
|
loading, |
|
|
|
onAdd, |
|
|
|
onAdd, |
|
|
|
onDelete, |
|
|
|
onDelete, |
|
|
|
onEdit, |
|
|
|
onEdit, |
|
|
@ -186,48 +188,47 @@ const List = forwardRef( |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const listItemElements = useMemo(() => { |
|
|
|
const listItemElements = useMemo(() => { |
|
|
|
let result = listEmptyElement; |
|
|
|
if (loading) return <Spinner mt={0} />; |
|
|
|
|
|
|
|
|
|
|
|
if (listItems) { |
|
|
|
if (!listItems) return listEmptyElement; |
|
|
|
const entries = Object.entries(listItems); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entries.length > 0) { |
|
|
|
const entries = Object.entries(listItems); |
|
|
|
result = entries.map(([key, value]) => { |
|
|
|
|
|
|
|
const listItem = renderListItem(key, value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
if (entries.length <= 0) return listEmptyElement; |
|
|
|
<MUIListItem |
|
|
|
|
|
|
|
{...restListItemProps} |
|
|
|
return entries.map(([key, value]) => { |
|
|
|
key={`${listItemKeyPrefix}-${key}`} |
|
|
|
const listItem = renderListItem(key, value); |
|
|
|
sx={{ paddingLeft: 0, paddingRight: 0, ...listItemSx }} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{listItemCheckbox( |
|
|
|
|
|
|
|
key, |
|
|
|
|
|
|
|
renderListItemCheckboxState?.call(null, key, value), |
|
|
|
|
|
|
|
getListItemCheckboxProps?.call(null, key, value), |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
{isAllowItemButton ? ( |
|
|
|
|
|
|
|
<ListItemButton |
|
|
|
|
|
|
|
onClick={(...args) => { |
|
|
|
|
|
|
|
onItemClick?.call(null, value, key, ...args); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
sx={{ borderRadius: BORDER_RADIUS }} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{listItem} |
|
|
|
|
|
|
|
</ListItemButton> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
listItem |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</MUIListItem> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return ( |
|
|
|
|
|
|
|
<MUIListItem |
|
|
|
|
|
|
|
{...restListItemProps} |
|
|
|
|
|
|
|
key={`${listItemKeyPrefix}-${key}`} |
|
|
|
|
|
|
|
sx={{ paddingLeft: 0, paddingRight: 0, ...listItemSx }} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{listItemCheckbox( |
|
|
|
|
|
|
|
key, |
|
|
|
|
|
|
|
renderListItemCheckboxState?.call(null, key, value), |
|
|
|
|
|
|
|
getListItemCheckboxProps?.call(null, key, value), |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
{isAllowItemButton ? ( |
|
|
|
|
|
|
|
<ListItemButton |
|
|
|
|
|
|
|
onClick={(...args) => { |
|
|
|
|
|
|
|
onItemClick?.call(null, value, key, ...args); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
sx={{ borderRadius: BORDER_RADIUS }} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{listItem} |
|
|
|
|
|
|
|
</ListItemButton> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
listItem |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</MUIListItem> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}, [ |
|
|
|
}, [ |
|
|
|
listEmptyElement, |
|
|
|
loading, |
|
|
|
listItems, |
|
|
|
listItems, |
|
|
|
|
|
|
|
listEmptyElement, |
|
|
|
renderListItem, |
|
|
|
renderListItem, |
|
|
|
restListItemProps, |
|
|
|
restListItemProps, |
|
|
|
listItemKeyPrefix, |
|
|
|
listItemKeyPrefix, |
|
|
|