fix(striker-ui): add loading prop to List

main
Tsu-ba-me 1 year ago
parent 71729e3425
commit b5b1e4d6b7
  1. 19
      striker-ui/components/List.tsx
  2. 1
      striker-ui/types/List.d.ts

@ -22,6 +22,7 @@ import Checkbox from './Checkbox';
import Divider from './Divider';
import FlexBox from './FlexBox';
import IconButton from './IconButton';
import Spinner from './Spinner';
import { BodyText } from './Text';
const List = forwardRef(
@ -43,6 +44,7 @@ const List = forwardRef(
listItemProps: { sx: listItemSx, ...restListItemProps } = {},
listItems,
listProps: { sx: listSx, ...restListProps } = {},
loading,
onAdd,
onDelete,
onEdit,
@ -186,13 +188,15 @@ const List = forwardRef(
);
const listItemElements = useMemo(() => {
let result = listEmptyElement;
if (loading) return <Spinner mt={0} />;
if (!listItems) return listEmptyElement;
if (listItems) {
const entries = Object.entries(listItems);
if (entries.length > 0) {
result = entries.map(([key, value]) => {
if (entries.length <= 0) return listEmptyElement;
return entries.map(([key, value]) => {
const listItem = renderListItem(key, value);
return (
@ -221,13 +225,10 @@ const List = forwardRef(
</MUIListItem>
);
});
}
}
return result;
}, [
listEmptyElement,
loading,
listItems,
listEmptyElement,
renderListItem,
restListItemProps,
listItemKeyPrefix,

@ -27,6 +27,7 @@ type ListOptionalProps<T extends unknown = unknown> = {
listItemProps?: import('@mui/material').ListItemProps;
listItems?: Record<string, T>;
listProps?: import('@mui/material').ListProps;
loading?: boolean;
onAdd?: import('../components/IconButton').IconButtonProps['onClick'];
onDelete?: import('../components/IconButton').IconButtonProps['onClick'];
onEdit?: import('../components/IconButton').IconButtonProps['onClick'];

Loading…
Cancel
Save