Skip to content

Commit

Permalink
feat(menu): 增加 size API
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Sep 1, 2023
1 parent ddd2acf commit 2f09456
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-tables-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

Menu feat: 增加 size API
5 changes: 5 additions & 0 deletions .changeset/green-peas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

Menu feat: 增加 render 和 extraHeader API
5 changes: 5 additions & 0 deletions .changeset/tasty-pets-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/menu": minor
---

feat: 增加 size API
25 changes: 19 additions & 6 deletions packages/ui/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import React, {
import { cx, getPrefixCls } from '@hi-ui/classname'
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@hi-ui/icons'
import { __DEV__ } from '@hi-ui/env'
import { MenuItem } from './MenuItem'
import MenuContext from './context'
import { getAncestorIds } from './util'
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state'
import { HiBaseHTMLProps } from '@hi-ui/core'
import { MenuDataItem, MenuFooterRenderProps } from './types'
import { HiBaseHTMLProps, HiBaseSizeEnum } from '@hi-ui/core'
import Tooltip from '@hi-ui/tooltip'
import { useUncontrolledToggle } from '@hi-ui/use-toggle'
import { getTreeNodesWithChildren } from '@hi-ui/tree-utils'
import { isFunction, isArrayNonEmpty } from '@hi-ui/type-assertion'
import { useResizeObserver } from '@hi-ui/use-resize-observer'
import { useMergeRefs } from '@hi-ui/use-merge-refs'
import { uuid } from '@hi-ui/use-id'
import { MenuDataItem, MenuFooterRenderProps } from './types'
import { MenuItem } from './MenuItem'
import MenuContext from './context'
import { getAncestorIds } from './util'

const MENU_PREFIX = getPrefixCls('menu')

Expand Down Expand Up @@ -61,6 +61,7 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
render,
extraHeader,
onClick,
size = 'lg',
...rest
},
ref
Expand Down Expand Up @@ -230,6 +231,7 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
prefixCls,
className,
`${prefixCls}--${placement}`,
`${prefixCls}--size-${size}`,
mini && `${prefixCls}--mini`,
(expandedType === 'pop' || showAllSubMenus || mini) && `${prefixCls}--popup`
)
Expand Down Expand Up @@ -258,7 +260,13 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
{mergedTagList.map((item, index) => {
return showMini ? (
<Tooltip title={item.title} key={item.id} placement="right">
<MenuItem {...item} level={1} render={renderMenuItemMini} raw={item} />
<MenuItem
{...item}
level={1}
render={renderMenuItemMini}
raw={item}
size={size}
/>
</Tooltip>
) : (
<MenuItem
Expand All @@ -268,6 +276,7 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
key={item.id}
level={1}
raw={item}
size={size}
/>
)
})}
Expand Down Expand Up @@ -368,6 +377,10 @@ export interface MenuProps extends Omit<HiBaseHTMLProps<'div'>, 'onClick'> {
* 额外的头部内容
*/
extraHeader?: React.ReactNode
/**
* 设置菜单项的尺寸
*/
size?: HiBaseSizeEnum
}

if (__DEV__) {
Expand Down
27 changes: 18 additions & 9 deletions packages/ui/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React, { useRef, useContext, forwardRef } from 'react'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { __DEV__ } from '@hi-ui/env'
import { DownOutlined, UpOutlined, RightOutlined } from '@hi-ui/icons'
import MenuContext from './context'
import Popper from '@hi-ui/popper'
import { Expander } from './Expander'
import { isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion'
import { times } from '@hi-ui/array-utils'
import { useMergeRefs } from '@hi-ui/use-merge-refs'
import { HiBaseHTMLProps } from '@hi-ui/core'
import { HiBaseHTMLProps, HiBaseSizeEnum } from '@hi-ui/core'
import { MenuDataItem } from './types'
import MenuContext from './context'
import { Expander } from './Expander'

const MENU_PREFIX = getPrefixCls('menu')

Expand All @@ -35,6 +35,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
hidden = false,
render,
raw,
size = 'lg',
...rest
},
ref
Expand Down Expand Up @@ -165,6 +166,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand All @@ -191,7 +193,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => {
return (
<MenuItem
Expand All @@ -201,6 +203,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
)
})}
Expand All @@ -220,7 +223,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => (
<MenuItem
{...child}
Expand All @@ -229,6 +232,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand All @@ -252,7 +256,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => (
<MenuItem
{...child}
Expand All @@ -261,6 +265,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand All @@ -279,7 +284,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => (
<MenuItem
{...child}
Expand All @@ -288,6 +293,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand Down Expand Up @@ -357,7 +363,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => (
<MenuItem
{...child}
Expand All @@ -366,6 +372,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand All @@ -384,7 +391,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}
}}
>
<ul className={`${prefixCls}-popmenu`}>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
{children!.map((child) => (
<MenuItem
{...child}
Expand All @@ -393,6 +400,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
parentIds={_parentIds}
raw={child}
render={render}
size={size}
/>
))}
</ul>
Expand Down Expand Up @@ -460,6 +468,7 @@ export interface MenuItemProps extends Omit<HiBaseHTMLProps<'li'>, 'id'> {
parentIds?: React.ReactText[]
render?: (node: MenuDataItem) => React.ReactNode
raw?: MenuDataItem
size?: HiBaseSizeEnum
}

if (__DEV__) {
Expand Down
35 changes: 28 additions & 7 deletions packages/ui/menu/src/styles/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ $prefix: '#{$component-prefix}-menu' !default;
color: use-color('gray', 500);
margin-inline-end: use-spacing(4);

svg[class^=hi-v4-icon] {
svg[class^='hi-v4-icon'] {
font-size: use-text-size('lg');
}
}
Expand Down Expand Up @@ -274,18 +274,12 @@ $prefix: '#{$component-prefix}-menu' !default;
.#{$prefix}-item {
&__inner {
box-sizing: border-box;
height: 40px;
display: flex;
align-items: center;
margin-bottom: use-spacing(4);
padding: 0 use-spacing(4) 0 use-spacing(6);
border-radius: use-border-radius('normal');
transition: all 0.3s;

// &--mini {
// justify-content: center;
// }

&--active {
color: use-color-mode('primary');
background-color: use-color-mode('primary', 50);
Expand Down Expand Up @@ -317,4 +311,31 @@ $prefix: '#{$component-prefix}-menu' !default;
}
}
}

&--size-lg {
.#{$prefix}-item {
&__inner {
height: use-height-size(10);
margin-bottom: use-spacing(4);
}
}
}

&--size-md {
.#{$prefix}-item {
&__inner {
height: use-height-size(9);
margin-bottom: use-spacing(2);
}
}
}

&--size-sm {
.#{$prefix}-item {
&__inner {
height: use-height-size(8);
margin-bottom: use-spacing(1);
}
}
}
}
1 change: 1 addition & 0 deletions packages/ui/menu/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './vertical-fat.stories'
export * from './expand-all.stories'
export * from './footer-render.stories'
export * from './render.stories'
export * from './size.stories'

export default {
title: 'Navigation/Menu',
Expand Down
Loading

0 comments on commit 2f09456

Please sign in to comment.