From e8d1c64b64e70e2d525a015823f3d305b9362fdf Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 8 Sep 2022 17:33:38 -0400 Subject: [PATCH] fix(striker-ui): emphasis header, align header and content in List --- striker-ui/components/List.tsx | 46 ++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/striker-ui/components/List.tsx b/striker-ui/components/List.tsx index cf3df300..0bc3e30c 100644 --- a/striker-ui/components/List.tsx +++ b/striker-ui/components/List.tsx @@ -5,14 +5,17 @@ import { Edit as MUIEditIcon, } from '@mui/icons-material'; import { + Box as MUIBox, List as MUIList, ListItem as MUIListItem, ListItemIcon as MUIListItemIcon, + ListItemProps as MUIListItemProps, ListProps as MUIListProps, } from '@mui/material'; import { FC, ReactNode, useMemo } from 'react'; import { v4 as uuidv4 } from 'uuid'; -import { BLUE, GREY, RED } from '../lib/consts/DEFAULT_THEME'; + +import { BLUE, DIVIDER, GREY, RED } from '../lib/consts/DEFAULT_THEME'; import Checkbox, { CheckboxProps } from './Checkbox'; import FlexBox from './FlexBox'; @@ -28,6 +31,7 @@ type ListOptionalProps = { isAllowEdit?: boolean; isAllowEditItem?: boolean; listItemKeyPrefix?: string; + listItemProps?: MUIListItemProps; listProps?: MUIListProps; onAdd?: IconButtonProps['onClick']; onDelete?: IconButtonProps['onClick']; @@ -74,6 +78,7 @@ const LIST_DEFAULT_PROPS: Required< isAllowEdit: false, isAllowEditItem: undefined, listItemKeyPrefix: uuidv4(), + listItemProps: {}, listProps: {}, onAdd: undefined, onDelete: undefined, @@ -87,8 +92,12 @@ const List = ({ isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit, isEdit = LIST_DEFAULT_PROPS.isEdit, listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix, + listItemProps: { + sx: listItemSx, + ...restListItemProps + } = LIST_DEFAULT_PROPS.listItemProps, listItems, - listProps = LIST_DEFAULT_PROPS.listProps, + listProps: { sx: listSx, ...restListProps } = LIST_DEFAULT_PROPS.listProps, onAdd, onDelete, onEdit, @@ -141,12 +150,16 @@ const List = ({ const headerElement = useMemo( () => typeof header === 'string' ? ( - :first-child': { flexGrow: 1 } }} - > + {header} + {deleteItemButton} {editItemButton} {addItemButton} @@ -169,20 +182,33 @@ const List = ({ () => Object.entries(listItems).map(([key, value]) => ( {listItemCheckbox} {renderListItem(key, value)} )), - [listItemCheckbox, listItemKeyPrefix, listItems, renderListItem], + [ + listItemCheckbox, + listItemKeyPrefix, + listItems, + listItemSx, + renderListItem, + restListItemProps, + ], ); return ( {headerElement} - {listItemElements} + + {listItemElements} + ); };