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 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,13 +188,15 @@ const List = forwardRef(
); );
const listItemElements = useMemo(() => { const listItemElements = useMemo(() => {
let result = listEmptyElement; if (loading) return <Spinner mt={0} />;
if (!listItems) return listEmptyElement;
if (listItems) {
const entries = Object.entries(listItems); const entries = Object.entries(listItems);
if (entries.length > 0) { if (entries.length <= 0) return listEmptyElement;
result = entries.map(([key, value]) => {
return entries.map(([key, value]) => {
const listItem = renderListItem(key, value); const listItem = renderListItem(key, value);
return ( return (
@ -221,13 +225,10 @@ const List = forwardRef(
</MUIListItem> </MUIListItem>
); );
}); });
}
}
return result;
}, [ }, [
listEmptyElement, loading,
listItems, listItems,
listEmptyElement,
renderListItem, renderListItem,
restListItemProps, restListItemProps,
listItemKeyPrefix, listItemKeyPrefix,

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

Loading…
Cancel
Save