From 0593338b0140726fa147d04391842679759cd43c Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 28 Sep 2022 22:17:37 -0400 Subject: [PATCH] fix(striker-ui): add scroll CSS and expose root props in List --- striker-ui/components/List.tsx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/striker-ui/components/List.tsx b/striker-ui/components/List.tsx index 0bc3e30c..9898c369 100644 --- a/striker-ui/components/List.tsx +++ b/striker-ui/components/List.tsx @@ -11,6 +11,8 @@ import { ListItemIcon as MUIListItemIcon, ListItemProps as MUIListItemProps, ListProps as MUIListProps, + SxProps, + Theme, } from '@mui/material'; import { FC, ReactNode, useMemo } from 'react'; 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 Checkbox, { CheckboxProps } from './Checkbox'; -import FlexBox from './FlexBox'; +import FlexBox, { FlexBoxProps } from './FlexBox'; import IconButton, { IconButtonProps } from './IconButton'; import { BodyText } from './Text'; type ListOptionalProps = { header?: ReactNode; - isEdit?: boolean; isAllowAddItem?: boolean; isAllowCheckItem?: boolean; isAllowDelete?: boolean; isAllowEdit?: boolean; isAllowEditItem?: boolean; + isEdit?: boolean; + isScroll?: boolean; listItemKeyPrefix?: string; listItemProps?: MUIListItemProps; listProps?: MUIListProps; @@ -40,9 +43,10 @@ type ListOptionalProps = { renderListItem?: (key: string, value: T) => ReactNode; }; -type ListProps = ListOptionalProps & { - listItems: Record; -}; +type ListProps = FlexBoxProps & + ListOptionalProps & { + listItems: Record; + }; const LIST_DEFAULT_PROPS: Required< Omit< @@ -71,12 +75,13 @@ const LIST_DEFAULT_PROPS: Required< | 'onItemCheckboxChange' > = { header: undefined, - isEdit: false, isAllowAddItem: undefined, isAllowCheckItem: undefined, isAllowDelete: undefined, isAllowEdit: false, isAllowEditItem: undefined, + isEdit: false, + isScroll: false, listItemKeyPrefix: uuidv4(), listItemProps: {}, listProps: {}, @@ -91,6 +96,7 @@ const List = ({ header, isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit, isEdit = LIST_DEFAULT_PROPS.isEdit, + isScroll = LIST_DEFAULT_PROPS.isScroll, listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix, listItemProps: { sx: listItemSx, @@ -108,6 +114,8 @@ const List = ({ isAllowCheckItem = isAllowEdit, isAllowDelete = isAllowEdit, isAllowEditItem = isAllowEdit, + + ...rootProps }: ListProps): ReturnType>> => { const addItemButton = useMemo( () => @@ -199,13 +207,17 @@ const List = ({ restListItemProps, ], ); + const listScrollSx: SxProps | undefined = useMemo( + () => (isScroll ? { maxHeight: '100%', overflowY: 'scroll' } : undefined), + [isScroll], + ); return ( - + {headerElement} {listItemElements}