fix(striker-ui): emphasis header, align header and content in List

main
Tsu-ba-me 2 years ago
parent 6a269a95dc
commit e8d1c64b64
  1. 46
      striker-ui/components/List.tsx

@ -5,14 +5,17 @@ import {
Edit as MUIEditIcon, Edit as MUIEditIcon,
} from '@mui/icons-material'; } from '@mui/icons-material';
import { import {
Box as MUIBox,
List as MUIList, List as MUIList,
ListItem as MUIListItem, ListItem as MUIListItem,
ListItemIcon as MUIListItemIcon, ListItemIcon as MUIListItemIcon,
ListItemProps as MUIListItemProps,
ListProps as MUIListProps, ListProps as MUIListProps,
} 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';
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 Checkbox, { CheckboxProps } from './Checkbox';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
@ -28,6 +31,7 @@ type ListOptionalProps<T = unknown> = {
isAllowEdit?: boolean; isAllowEdit?: boolean;
isAllowEditItem?: boolean; isAllowEditItem?: boolean;
listItemKeyPrefix?: string; listItemKeyPrefix?: string;
listItemProps?: MUIListItemProps;
listProps?: MUIListProps; listProps?: MUIListProps;
onAdd?: IconButtonProps['onClick']; onAdd?: IconButtonProps['onClick'];
onDelete?: IconButtonProps['onClick']; onDelete?: IconButtonProps['onClick'];
@ -74,6 +78,7 @@ const LIST_DEFAULT_PROPS: Required<
isAllowEdit: false, isAllowEdit: false,
isAllowEditItem: undefined, isAllowEditItem: undefined,
listItemKeyPrefix: uuidv4(), listItemKeyPrefix: uuidv4(),
listItemProps: {},
listProps: {}, listProps: {},
onAdd: undefined, onAdd: undefined,
onDelete: undefined, onDelete: undefined,
@ -87,8 +92,12 @@ const List = <T,>({
isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit, isAllowEdit = LIST_DEFAULT_PROPS.isAllowEdit,
isEdit = LIST_DEFAULT_PROPS.isEdit, isEdit = LIST_DEFAULT_PROPS.isEdit,
listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix, listItemKeyPrefix = LIST_DEFAULT_PROPS.listItemKeyPrefix,
listItemProps: {
sx: listItemSx,
...restListItemProps
} = LIST_DEFAULT_PROPS.listItemProps,
listItems, listItems,
listProps = LIST_DEFAULT_PROPS.listProps, listProps: { sx: listSx, ...restListProps } = LIST_DEFAULT_PROPS.listProps,
onAdd, onAdd,
onDelete, onDelete,
onEdit, onEdit,
@ -141,12 +150,16 @@ const List = <T,>({
const headerElement = useMemo( const headerElement = useMemo(
() => () =>
typeof header === 'string' ? ( typeof header === 'string' ? (
<FlexBox <FlexBox row spacing=".3em" sx={{ height: '2.4em' }}>
row
spacing=".3em"
sx={{ height: '2.4em', '& > :first-child': { flexGrow: 1 } }}
>
<BodyText>{header}</BodyText> <BodyText>{header}</BodyText>
<MUIBox
sx={{
borderTopColor: DIVIDER,
borderTopStyle: 'solid',
borderTopWidth: '1px',
flexGrow: 1,
}}
/>
{deleteItemButton} {deleteItemButton}
{editItemButton} {editItemButton}
{addItemButton} {addItemButton}
@ -169,20 +182,33 @@ const List = <T,>({
() => () =>
Object.entries(listItems).map(([key, value]) => ( Object.entries(listItems).map(([key, value]) => (
<MUIListItem <MUIListItem
{...restListItemProps}
key={`${listItemKeyPrefix}-${key}`} key={`${listItemKeyPrefix}-${key}`}
sx={{ paddingLeft: 0, paddingRight: 0 }} sx={{ paddingLeft: 0, paddingRight: 0, ...listItemSx }}
> >
{listItemCheckbox} {listItemCheckbox}
{renderListItem(key, value)} {renderListItem(key, value)}
</MUIListItem> </MUIListItem>
)), )),
[listItemCheckbox, listItemKeyPrefix, listItems, renderListItem], [
listItemCheckbox,
listItemKeyPrefix,
listItems,
listItemSx,
renderListItem,
restListItemProps,
],
); );
return ( return (
<FlexBox spacing={0}> <FlexBox spacing={0}>
{headerElement} {headerElement}
<MUIList {...listProps}>{listItemElements}</MUIList> <MUIList
{...restListProps}
sx={{ paddingBottom: 0, paddingTop: 0, ...listSx }}
>
{listItemElements}
</MUIList>
</FlexBox> </FlexBox>
); );
}; };

Loading…
Cancel
Save