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

main
Tsu-ba-me 1 year ago
parent 71729e3425
commit b5b1e4d6b7
  1. 73
      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,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,

@ -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