@@ -18,6 +18,8 @@ export type ToolbarListButtonData<E> = {
1818 title : string | ( ( ) => string ) ;
1919 withArrow ?: boolean ;
2020 data : ToolbarItemData < E > [ ] ;
21+ alwaysActive ?: boolean ;
22+ hideDisabled ?: boolean ;
2123} ;
2224
2325export type ToolbarListButtonProps < E > = ToolbarBaseProps < E > & ToolbarListButtonData < E > ;
@@ -31,12 +33,14 @@ export function ToolbarListButton<E>({
3133 title,
3234 withArrow,
3335 data,
36+ alwaysActive,
37+ hideDisabled,
3438} : ToolbarListButtonProps < E > ) {
3539 const buttonRef = React . useRef < HTMLButtonElement > ( null ) ;
3640 const [ open , , hide , toggleOpen ] = useBooleanState ( false ) ;
3741
38- const someActive = data . some ( ( item ) => item . isActive ( editor ) ) ;
39- const everyDisabled = data . every ( ( item ) => ! item . isEnable ( editor ) ) ;
42+ const someActive = alwaysActive ? false : data . some ( ( item ) => item . isActive ( editor ) ) ;
43+ const everyDisabled = alwaysActive ? false : data . every ( ( item ) => ! item . isEnable ( editor ) ) ;
4044
4145 const popupOpen = everyDisabled ? false : open ;
4246 const shouldForceHide = open && ! popupOpen ;
@@ -78,35 +82,41 @@ export function ToolbarListButton<E>({
7882 </ Tooltip >
7983 < Popup anchorRef = { buttonRef } open = { popupOpen } onClose = { hide } >
8084 < Menu size = "l" className = { b ( 'menu' ) } >
81- { data . map ( ( { id, title, icon, hotkey, isActive, isEnable, exec, hint} ) => {
82- const titleText = isFunction ( title ) ? title ( ) : title ;
83- const hintText = isFunction ( hint ) ? hint ( ) : hint ;
84- return (
85- < Menu . Item
86- key = { id }
87- active = { isActive ( editor ) }
88- disabled = { ! isEnable ( editor ) }
89- onClick = { ( ) => {
90- hide ( ) ;
91- focus ( ) ;
92- exec ( editor ) ;
93- onClick ?.( id ) ;
94- } }
95- icon = { < Icon data = { icon . data } size = { icon . size ?? 16 } /> }
96- extraProps = { { 'aria-label' : titleText } }
97- >
98- < div className = { b ( 'item' ) } >
99- { titleText }
100- < div className = { b ( 'extra' ) } >
101- { hotkey && < Hotkey value = { hotkey } /> }
102- { hintText && (
103- < HelpPopover className = { b ( 'hint' ) } content = { hintText } />
104- ) }
85+ { data
86+ . map ( ( { id, title, icon, hotkey, isActive, isEnable, exec, hint} ) => {
87+ const titleText = isFunction ( title ) ? title ( ) : title ;
88+ const hintText = isFunction ( hint ) ? hint ( ) : hint ;
89+ const disabled = ! isEnable ( editor ) ;
90+ return hideDisabled && disabled ? null : (
91+ < Menu . Item
92+ key = { id }
93+ active = { isActive ( editor ) }
94+ disabled = { ! isEnable ( editor ) }
95+ onClick = { ( ) => {
96+ hide ( ) ;
97+ focus ( ) ;
98+ exec ( editor ) ;
99+ onClick ?.( id ) ;
100+ } }
101+ icon = { < Icon data = { icon . data } size = { icon . size ?? 16 } /> }
102+ extraProps = { { 'aria-label' : titleText } }
103+ >
104+ < div className = { b ( 'item' ) } >
105+ { titleText }
106+ < div className = { b ( 'extra' ) } >
107+ { hotkey && < Hotkey value = { hotkey } /> }
108+ { hintText && (
109+ < HelpPopover
110+ className = { b ( 'hint' ) }
111+ content = { hintText }
112+ />
113+ ) }
114+ </ div >
105115 </ div >
106- </ div >
107- </ Menu . Item >
108- ) ;
109- } ) }
116+ </ Menu . Item >
117+ ) ;
118+ } )
119+ . filter ( Boolean ) }
110120 </ Menu >
111121 </ Popup >
112122 </ >
0 commit comments