@@ -35,7 +35,7 @@ import {
3535 type ContextMenuSwitchItem ,
3636} from './type' ;
3737
38- export type { IconSpaceMode } from '@/Menu' ;
38+ export type { IconAlign , IconSpaceMode } from '@/Menu' ;
3939
4040const EmptyMenuItem = memo ( ( ) => {
4141 const { t } = useTranslation ( common ) ;
@@ -117,22 +117,36 @@ const renderItemContent = (
117117 iconNode ?: ReactNode ,
118118) => {
119119 const label = getItemLabel ( item ) ;
120+ const desc = 'desc' in item ? item . desc : undefined ;
120121 const extra = 'extra' in item ? item . extra : undefined ;
121122 const indicatorOnRight = options ?. indicatorOnRight ;
123+ const alignStart = Boolean ( desc ) && options ?. iconAlign === 'start' ;
122124 const hasCustomIcon = iconNode !== undefined && ! indicatorOnRight ;
123125 const hasIcon = hasCustomIcon ? Boolean ( iconNode ) : Boolean ( item . icon ) ;
124126 const shouldRenderIcon = hasCustomIcon
125127 ? Boolean ( options ?. reserveIconSpace || iconNode )
126128 : Boolean ( hasIcon || options ?. reserveIconSpace ) ;
127129
130+ const labelNode = desc ? (
131+ < div className = { styles . labelGroup } >
132+ < span className = { styles . label } > { label } </ span >
133+ < span className = { styles . desc } > { desc } </ span >
134+ </ div >
135+ ) : (
136+ < span className = { styles . label } > { label } </ span >
137+ ) ;
138+
128139 return (
129- < div className = { styles . itemContent } >
140+ < div className = { cx ( styles . itemContent , alignStart && styles . itemContentAlignStart ) } >
130141 { shouldRenderIcon ? (
131- < span aria-hidden = { ! hasIcon } className = { styles . icon } >
142+ < span
143+ aria-hidden = { ! hasIcon }
144+ className = { cx ( styles . icon , alignStart && styles . iconAlignStart ) }
145+ >
132146 { hasCustomIcon ? iconNode : hasIcon ? renderIcon ( item . icon , 'small' ) : null }
133147 </ span >
134148 ) : null }
135- < span className = { styles . label } > { label } </ span >
149+ { labelNode }
136150 { extra ? < span className = { styles . extra } > { extra } </ span > : null }
137151 { indicatorOnRight && iconNode ? iconNode : null }
138152 { options ?. submenu ? (
@@ -165,6 +179,7 @@ export const renderContextMenuItems = (
165179 keyPath : string [ ] = [ ] ,
166180 options ?: RenderOptions ,
167181) : ReactNode [ ] => {
182+ const iconAlign = options ?. iconAlign ;
168183 const iconSpaceMode = options ?. iconSpaceMode ?? 'global' ;
169184 const reserveIconSpace =
170185 options ?. reserveIconSpace ?? hasAnyIcon ( items , iconSpaceMode === 'global' ) ;
@@ -199,7 +214,11 @@ export const renderContextMenuItems = (
199214 label = { labelText }
200215 onCheckedChange = { ( checked ) => checkboxItem . onCheckedChange ?.( checked ) }
201216 >
202- { renderItemContent ( checkboxItem , { indicatorOnRight, reserveIconSpace } , indicator ) }
217+ { renderItemContent (
218+ checkboxItem ,
219+ { iconAlign, indicatorOnRight, reserveIconSpace } ,
220+ indicator ,
221+ ) }
203222 </ ContextMenu . CheckboxItem >
204223 ) ;
205224 }
@@ -221,7 +240,7 @@ export const renderContextMenuItems = (
221240 label = { labelText }
222241 onCheckedChange = { switchItem . onCheckedChange }
223242 >
224- { renderItemContent ( switchItem , { reserveIconSpace } ) }
243+ { renderItemContent ( switchItem , { iconAlign , reserveIconSpace } ) }
225244 </ ContextMenuSwitchItemInternal >
226245 ) ;
227246 }
@@ -248,6 +267,7 @@ export const renderContextMenuItems = (
248267 ) : null }
249268 { group . children
250269 ? renderContextMenuItems ( group . children , nextKeyPath , {
270+ iconAlign,
251271 iconSpaceMode,
252272 indicatorOnRight : groupIndicatorOnRight ,
253273 reserveIconSpace : groupReserveIconSpace ,
@@ -274,6 +294,7 @@ export const renderContextMenuItems = (
274294 label = { labelText }
275295 >
276296 { renderItemContent ( submenu , {
297+ iconAlign,
277298 reserveIconSpace,
278299 submenu : true ,
279300 } ) }
@@ -288,7 +309,10 @@ export const renderContextMenuItems = (
288309 >
289310 < ContextMenu . Popup className = { styles . popup } >
290311 { submenu . children && submenu . children . length > 0 ? (
291- renderContextMenuItems ( submenu . children , nextKeyPath , { iconSpaceMode } )
312+ renderContextMenuItems ( submenu . children , nextKeyPath , {
313+ iconAlign,
314+ iconSpaceMode,
315+ } )
292316 ) : (
293317 < EmptyMenuItem />
294318 ) }
@@ -313,7 +337,7 @@ export const renderContextMenuItems = (
313337 label = { labelText }
314338 onClick = { ( event ) => invokeItemClick ( menuItem , nextKeyPath , event ) }
315339 >
316- { renderItemContent ( menuItem , { reserveIconSpace } ) }
340+ { renderItemContent ( menuItem , { iconAlign , reserveIconSpace } ) }
317341 </ ContextMenu . Item >
318342 ) ;
319343 } ) ;
0 commit comments