Skip to content

Commit 19fe6b1

Browse files
committed
Improve MenuList
1 parent 93517ed commit 19fe6b1

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

src/Menu/MenuList.tsx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,27 @@ export interface MenuListProps<
2323
headerIcon?: HI | undefined;
2424
headerAction?: string | React.ReactElement | undefined;
2525
items?: MenuItem<V, I>[] | undefined;
26-
headerProps?: FlexAllProps<'div'> | undefined;
27-
listProps?: FlexAllProps<'div'> | undefined;
26+
headerProps?:
27+
| FlexAllProps<
28+
React.ComponentType<
29+
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
30+
>
31+
>
32+
| undefined;
33+
headerGroupProps?:
34+
| FlexAllProps<
35+
React.ComponentType<
36+
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
37+
>
38+
>
39+
| undefined;
40+
listProps?:
41+
| FlexAllProps<
42+
React.ComponentType<
43+
React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
44+
>
45+
>
46+
| undefined;
2847
onItemSelect?: MenuListItemProps<V, I>['onSelect'] | undefined;
2948
onItemMouseEnter?:
3049
| ((value: MenuListItemProps<V, I>['value'], event: React.MouseEvent<HTMLDivElement>) => void)
@@ -72,16 +91,12 @@ const HeaderRoot = styled((props: React.PropsWithChildren<FlexComponentProps>) =
7291
...rc?.MenuList?.header?.root,
7392
}));
7493

75-
const HeaderTitleContainer = styled((props: React.PropsWithChildren<FlexComponentProps<'div'>>) => {
76-
return <Flex grow alignItems="center" {...props} />;
77-
})(({ theme: { rc }, onClick }) => ({
94+
const HeaderGroup = styled(Flex)(({ theme: { rc }, onClick }) => ({
7895
cursor: onClick ? 'pointer' : undefined,
79-
...rc?.MenuList?.header?.root,
96+
...rc?.MenuList?.header?.group?.root,
8097
}));
8198

82-
const HeaderTitle = styled((props: React.PropsWithChildren<FlexComponentProps>) => {
83-
return <Flex {...props} />;
84-
})(({ theme: { rc } }) => ({
99+
const HeaderTitle = styled(Flex)(({ theme: { rc } }) => ({
85100
fontWeight: 500,
86101
...rc?.MenuList?.header?.title?.root,
87102
}));
@@ -97,6 +112,7 @@ export default function MenuList<
97112
onClose,
98113
items,
99114
headerProps,
115+
headerGroupProps,
100116
listProps,
101117
onItemSelect,
102118
onItemMouseEnter,
@@ -139,9 +155,16 @@ export default function MenuList<
139155

140156
const hasHeader = !!(header || headerIconProps || onBack || headerAction || onClose);
141157

158+
const hasHeaderIcon = !!backIconProps || !!headerIconProps;
159+
160+
const headerGroupFlex =
161+
typeof theme?.header?.group?.flex === 'function'
162+
? theme.header.group.flex({ hasIcon: hasHeaderIcon })
163+
: theme?.header?.group?.flex;
164+
142165
const headerTitleFlex =
143166
typeof theme?.header?.title?.flex === 'function'
144-
? theme.header.title.flex({ hasIcon: !!backIconProps || !!headerIconProps })
167+
? theme.header.title.flex({ hasIcon: hasHeaderIcon })
145168
: theme?.header?.title?.flex;
146169

147170
const listContainerFlex =
@@ -198,7 +221,13 @@ export default function MenuList<
198221
<Root onKeyDown={keyDownHandler} {...rest}>
199222
{hasHeader && (
200223
<HeaderRoot py="xs" pl="s" pr {...theme?.header?.flex} {...headerProps}>
201-
<HeaderTitleContainer grow alignItems="center" onClick={onBack ? backHandler : undefined}>
224+
<HeaderGroup
225+
grow
226+
alignItems="center"
227+
onClick={onBack ? backHandler : undefined}
228+
{...headerGroupFlex}
229+
{...headerGroupProps}
230+
>
202231
{!!backIconProps && <SvgSpriteIcon size="1.5em" {...backIconProps} />}
203232
{!!headerIconProps && <SvgSpriteIcon {...headerIconProps} />}
204233

@@ -210,7 +239,7 @@ export default function MenuList<
210239
>
211240
{header}
212241
</HeaderTitle>
213-
</HeaderTitleContainer>
242+
</HeaderGroup>
214243

215244
{headerActionElement}
216245

src/theme.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ export interface Theme {
287287
| {
288288
root?: CSSProperties | undefined;
289289
flex?: FlexOnlyProps | undefined;
290+
group?:
291+
| {
292+
root?: CSSProperties | undefined;
293+
flex?:
294+
| FlexOnlyProps
295+
| ((options: { hasIcon: boolean }) => FlexOnlyProps)
296+
| undefined;
297+
}
298+
| undefined;
290299
backIcon?: Pick<SvgSpriteIconProps<string>, 'name' | 'size'> | undefined;
291300
closeIcon?: Pick<SvgSpriteIconProps<string>, 'name' | 'size'> | undefined;
292301
title?:

0 commit comments

Comments
 (0)