Skip to content

Commit 54ac0d3

Browse files
authored
feat(bundle): update view of text color action item in toolbar (#514)
1 parent 89c9881 commit 54ac0d3

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/bundle/toolbar/ToolbarButtonWithPopupMenu.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ export type MenuItem = {
2626
export type ToolbarButtonWithPopupMenuProps = Omit<
2727
ToolbarBaseProps<ActionStorage> & {
2828
icon: ToolbarIconData;
29+
iconClassName?: string;
30+
chevronIconClassName?: string;
2931
title: string | (() => string);
3032
menuItems: MenuItem[];
33+
/** @default 'classic' */
34+
_selectionType?: 'classic' | 'light';
3135
},
3236
'editor'
3337
>;
@@ -37,8 +41,11 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
3741
focus,
3842
onClick,
3943
icon,
44+
iconClassName,
45+
chevronIconClassName,
4046
title,
4147
menuItems,
48+
_selectionType,
4249
}) => {
4350
const buttonRef = React.useRef<HTMLButtonElement>(null);
4451
const [open, , hide, toggleOpen] = useBooleanState(false);
@@ -48,7 +55,7 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
4855
menuItems.map((i) => ({...i, group: i.group || ''})),
4956
'group',
5057
),
51-
[menuItems, groupBy],
58+
[menuItems],
5259
);
5360

5461
const someActive = menuItems.some(
@@ -64,6 +71,14 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
6471
}
6572
}, [hide, shouldForceHide]);
6673

74+
const [btnView, btnSelected] =
75+
_selectionType === 'light'
76+
? ([
77+
popupOpen ? 'normal' : someActive ? 'flat-action' : 'flat',
78+
popupOpen && someActive,
79+
] as const)
80+
: ([someActive || popupOpen ? 'normal' : 'flat', someActive] as const);
81+
6782
return (
6883
<>
6984
<ActionTooltip
@@ -75,15 +90,15 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
7590
<Button
7691
size="m"
7792
ref={buttonRef}
78-
view={someActive || popupOpen ? 'normal' : 'flat'}
79-
selected={someActive}
93+
view={btnView}
94+
selected={btnSelected}
8095
disabled={everyDisabled}
8196
className={b(null, [className])}
8297
onClick={toggleOpen}
8398
>
84-
<Icon data={icon.data} size={icon.size} />
99+
<Icon data={icon.data} size={icon.size} className={iconClassName} />
85100
{''}
86-
<Icon data={ChevronDown} />
101+
<Icon data={ChevronDown} className={chevronIconClassName} />
87102
</Button>
88103
</ActionTooltip>
89104
<Popup anchorRef={buttonRef} open={popupOpen} onClose={hide}>

src/bundle/toolbar/custom/ToolbarColors.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ $colors: ('gray', 'yellow', 'orange', 'red', 'green', 'blue', 'violet');
22

33
.g-md-toolbar-colors {
44
@each $name in $colors {
5+
&__menu-icon_color_#{$name} {
6+
color: var(--yfm-colorify-#{$name});
7+
}
8+
9+
&__chevron-icon_color_#{$name} {
10+
color: var(--yfm-colorify-#{$name});
11+
}
12+
513
&__item-icon_color_#{$name} {
614
color: var(--yfm-colorify-#{$name});
715
}
816
}
17+
918
&__item-icon_color_default {
1019
color: var(--g-color-text-primary);
1120
}

src/bundle/toolbar/custom/ToolbarColors.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
7777
title={i18n('colorify')}
7878
menuItems={items}
7979
icon={textColorIcon}
80+
_selectionType="light"
81+
iconClassName={b('menu-icon', {color: currentColor})}
82+
chevronIconClassName={b('chevron-icon', {color: currentColor})}
8083
/>
8184
);
8285
};

0 commit comments

Comments
 (0)