|
|
@ -11,6 +11,8 @@ import { |
|
|
|
ListItemIcon as MUIListItemIcon, |
|
|
|
ListItemIcon as MUIListItemIcon, |
|
|
|
ListItemProps as MUIListItemProps, |
|
|
|
ListItemProps as MUIListItemProps, |
|
|
|
ListProps as MUIListProps, |
|
|
|
ListProps as MUIListProps, |
|
|
|
|
|
|
|
SxProps, |
|
|
|
|
|
|
|
Theme, |
|
|
|
} from '@mui/material'; |
|
|
|
} from '@mui/material'; |
|
|
|
import { FC, ReactNode, useMemo } from 'react'; |
|
|
|
import { FC, ReactNode, useMemo } from 'react'; |
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
@ -18,18 +20,19 @@ import { v4 as uuidv4 } from 'uuid'; |
|
|
|
import { BLUE, DIVIDER, GREY, RED } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
import { BLUE, DIVIDER, GREY, RED } from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
import Checkbox, { CheckboxProps } from './Checkbox'; |
|
|
|
import Checkbox, { CheckboxProps } from './Checkbox'; |
|
|
|
import FlexBox from './FlexBox'; |
|
|
|
import FlexBox, { FlexBoxProps } from './FlexBox'; |
|
|
|
import IconButton, { IconButtonProps } from './IconButton'; |
|
|
|
import IconButton, { IconButtonProps } from './IconButton'; |
|
|
|
import { BodyText } from './Text'; |
|
|
|
import { BodyText } from './Text'; |
|
|
|
|
|
|
|
|
|
|
|
type ListOptionalProps<T = unknown> = { |
|
|
|
type ListOptionalProps<T = unknown> = { |
|
|
|
header?: ReactNode; |
|
|
|
header?: ReactNode; |
|
|
|
isEdit?: boolean; |
|
|
|
|
|
|
|
isAllowAddItem?: boolean; |
|
|
|
isAllowAddItem?: boolean; |
|
|
|
isAllowCheckItem?: boolean; |
|
|
|
isAllowCheckItem?: boolean; |
|
|
|
isAllowDelete?: boolean; |
|
|
|
isAllowDelete?: boolean; |
|
|
|
isAllowEdit?: boolean; |
|
|
|
isAllowEdit?: boolean; |
|
|
|
isAllowEditItem?: boolean; |
|
|
|
isAllowEditItem?: boolean; |
|
|
|
|
|
|
|
isEdit?: boolean; |
|
|
|
|
|
|
|
isScroll?: boolean; |
|
|
|
listItemKeyPrefix?: string; |
|
|
|
listItemKeyPrefix?: string; |
|
|
|
listItemProps?: MUIListItemProps; |
|
|
|
listItemProps?: MUIListItemProps; |
|
|
|
listProps?: MUIListProps; |
|
|
|
listProps?: MUIListProps; |
|
|
@ -40,9 +43,10 @@ type ListOptionalProps<T = unknown> = { |
|
|
|
renderListItem?: (key: string, value: T) => ReactNode; |
|
|
|
renderListItem?: (key: string, value: T) => ReactNode; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
type ListProps<T = unknown> = ListOptionalProps<T> & { |
|
|
|
type ListProps<T = unknown> = FlexBoxProps & |
|
|
|
listItems: Record<string, T>; |
|
|
|
ListOptionalProps<T> & { |
|
|
|
}; |
|
|
|
listItems: Record<string, T>; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const LIST_DEFAULT_PROPS: Required< |
|
|
|
const LIST_DEFAULT_PROPS: Required< |
|
|
|
Omit< |
|
|
|
Omit< |
|
|
@ -71,12 +75,13 @@ const LIST_DEFAULT_PROPS: Required< |
|
|
|
| 'onItemCheckboxChange' |
|
|
|
| 'onItemCheckboxChange' |
|
|
|
> = { |
|
|
|
> = { |
|
|
|
header: undefined, |
|
|
|
header: undefined, |
|
|
|
isEdit: false, |
|
|
|
|
|
|
|
isAllowAddItem: undefined, |
|
|
|
isAllowAddItem: undefined, |
|
|
|
isAllowCheckItem: undefined, |
|
|
|
isAllowCheckItem: undefined, |
|
|
|
isAllowDelete: undefined, |
|
|
|
isAllowDelete: undefined, |
|
|
|
isAllowEdit: false, |
|
|
|
isAllowEdit: false, |
|
|
|
isAllowEditItem: undefined, |
|
|
|
isAllowEditItem: undefined, |
|
|
|
|
|
|
|
isEdit: false, |
|
|
|
|
|
|
|
isScroll: false, |
|
|
|
listItemKeyPrefix: uuidv4(), |
|
|
|
listItemKeyPrefix: uuidv4(), |
|
|
|
listItemProps: {}, |
|
|
|
listItemProps: {}, |
|
|
|
listProps: {}, |
|
|
|
listProps: {}, |
|
|
@ -91,6 +96,7 @@ const List = <T,>({ |
|
|
|
header, |
|
|
|
header, |
|
|
|
isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit, |
|
|
|
isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit, |
|
|
|
isEdit = LIST_DEFAULT_PROPS.isEdit, |
|
|
|
isEdit = LIST_DEFAULT_PROPS.isEdit, |
|
|
|
|
|
|
|
isScroll = LIST_DEFAULT_PROPS.isScroll, |
|
|
|
listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix, |
|
|
|
listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix, |
|
|
|
listItemProps: { |
|
|
|
listItemProps: { |
|
|
|
sx: listItemSx, |
|
|
|
sx: listItemSx, |
|
|
@ -108,6 +114,8 @@ const List = <T,>({ |
|
|
|
isAllowCheckItem = isAllowEdit, |
|
|
|
isAllowCheckItem = isAllowEdit, |
|
|
|
isAllowDelete = isAllowEdit, |
|
|
|
isAllowDelete = isAllowEdit, |
|
|
|
isAllowEditItem = isAllowEdit, |
|
|
|
isAllowEditItem = isAllowEdit, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...rootProps |
|
|
|
}: ListProps<T>): ReturnType<FC<ListProps<T>>> => { |
|
|
|
}: ListProps<T>): ReturnType<FC<ListProps<T>>> => { |
|
|
|
const addItemButton = useMemo( |
|
|
|
const addItemButton = useMemo( |
|
|
|
() => |
|
|
|
() => |
|
|
@ -199,13 +207,17 @@ const List = <T,>({ |
|
|
|
restListItemProps, |
|
|
|
restListItemProps, |
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
const listScrollSx: SxProps<Theme> | undefined = useMemo( |
|
|
|
|
|
|
|
() => (isScroll ? { maxHeight: '100%', overflowY: 'scroll' } : undefined), |
|
|
|
|
|
|
|
[isScroll], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<FlexBox spacing={0}> |
|
|
|
<FlexBox spacing={0} {...rootProps}> |
|
|
|
{headerElement} |
|
|
|
{headerElement} |
|
|
|
<MUIList |
|
|
|
<MUIList |
|
|
|
{...restListProps} |
|
|
|
{...restListProps} |
|
|
|
sx={{ paddingBottom: 0, paddingTop: 0, ...listSx }} |
|
|
|
sx={{ paddingBottom: 0, paddingTop: 0, ...listScrollSx, ...listSx }} |
|
|
|
> |
|
|
|
> |
|
|
|
{listItemElements} |
|
|
|
{listItemElements} |
|
|
|
</MUIList> |
|
|
|
</MUIList> |
|
|
|