@@ -5,7 +5,7 @@ import {Colors} from '../../../extensions';
55import { i18n } from '../../../i18n/menubar' ;
66import { ToolbarBaseProps } from '../../../toolbar' ;
77import { icons } from '../../config/icons' ;
8- import { ToolbarButtonWithPopupMenu } from '../ToolbarButtonWithPopupMenu' ;
8+ import { MenuItem , ToolbarButtonWithPopupMenu } from '../ToolbarButtonWithPopupMenu' ;
99
1010import './ToolbarColors.scss' ;
1111
@@ -16,29 +16,32 @@ export type ToolbarColorsProps = Omit<ToolbarBaseProps<never>, 'editor'> & {
1616 active ?: boolean ;
1717 enable ?: boolean ;
1818 currentColor ?: string ;
19+ withDefault ?: boolean ;
1920 exec ( color : string ) : void ;
2021} ;
2122
2223export const ToolbarColors : React . FC < ToolbarColorsProps > = ( props ) => {
23- const { exec, onClick, enable, currentColor} = props ;
24+ const { exec, onClick, enable, currentColor, withDefault} = props ;
25+ const isDefault = currentColor === undefined ;
26+
2427 const onItemClick = ( color : string ) => ( ) => {
25- exec ( color ) ;
26- onClick ?.( 'colorify' , { color} ) ;
28+ // do not exec when current color is default and clicked to default item
29+ if ( ! ( isDefault && color === '' ) ) exec ( color ) ;
30+ onClick ?.( 'colorify' , { color : color === '' ? 'default' : color } ) ;
2731 } ;
2832
2933 const items = [
30- Colors . Black ,
3134 Colors . Gray ,
3235 Colors . Yellow ,
3336 Colors . Orange ,
3437 Colors . Red ,
3538 Colors . Green ,
3639 Colors . Blue ,
3740 Colors . Violet ,
38- ] . map ( ( color ) => ( {
41+ ] . map < MenuItem > ( ( color ) => ( {
3942 id : color ,
4043 icon : textColorIcon . data ,
41- size : textColorIcon . size ?? 16 ,
44+ iconSize : textColorIcon . size ?? 16 ,
4245 text : i18n ( `colorify__color_${ color } ` ) ,
4346 iconClassname : b ( 'item-icon' , { color} ) ,
4447 action : {
@@ -50,6 +53,24 @@ export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
5053 group : i18n ( `colorify__group_text` ) ,
5154 } ) ) ;
5255
56+ if ( withDefault ) {
57+ items . unshift ( {
58+ id : 'default' ,
59+ icon : textColorIcon . data ,
60+ iconSize : textColorIcon . size ?? 16 ,
61+ text : i18n ( `colorify__color_default` ) ,
62+ iconClassname : b ( 'item-icon' , { color : 'default' } ) ,
63+ group : i18n ( `colorify__group_text` ) ,
64+ ignoreActive : true ,
65+ action : {
66+ run : onItemClick ( '' ) ,
67+ isEnable : ( ) => Boolean ( enable ) ,
68+ isActive : ( ) => isDefault ,
69+ meta ( ) { } ,
70+ } ,
71+ } ) ;
72+ }
73+
5374 return (
5475 < ToolbarButtonWithPopupMenu
5576 { ...props }
0 commit comments