Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundle): update view of text color action item in toolbar #514

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/bundle/toolbar/ToolbarButtonWithPopupMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export type MenuItem = {
export type ToolbarButtonWithPopupMenuProps = Omit<
ToolbarBaseProps<ActionStorage> & {
icon: ToolbarIconData;
iconClassName?: string;
chevronIconClassName?: string;
title: string | (() => string);
menuItems: MenuItem[];
/** @default 'classic' */
_selectionType?: 'classic' | 'light';
},
'editor'
>;
Expand All @@ -37,8 +41,11 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
focus,
onClick,
icon,
iconClassName,
chevronIconClassName,
title,
menuItems,
_selectionType,
}) => {
const buttonRef = React.useRef<HTMLButtonElement>(null);
const [open, , hide, toggleOpen] = useBooleanState(false);
Expand All @@ -48,7 +55,7 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
menuItems.map((i) => ({...i, group: i.group || ''})),
'group',
),
[menuItems, groupBy],
[menuItems],
);

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

const [btnView, btnSelected] =
_selectionType === 'light'
? ([
popupOpen ? 'normal' : someActive ? 'flat-action' : 'flat',
popupOpen && someActive,
] as const)
: ([someActive || popupOpen ? 'normal' : 'flat', someActive] as const);

return (
<>
<ActionTooltip
Expand All @@ -75,15 +90,15 @@ export const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProp
<Button
size="m"
ref={buttonRef}
view={someActive || popupOpen ? 'normal' : 'flat'}
selected={someActive}
view={btnView}
selected={btnSelected}
disabled={everyDisabled}
className={b(null, [className])}
onClick={toggleOpen}
>
<Icon data={icon.data} size={icon.size} />
<Icon data={icon.data} size={icon.size} className={iconClassName} />
{''}
<Icon data={ChevronDown} />
<Icon data={ChevronDown} className={chevronIconClassName} />
</Button>
</ActionTooltip>
<Popup anchorRef={buttonRef} open={popupOpen} onClose={hide}>
Expand Down
9 changes: 9 additions & 0 deletions src/bundle/toolbar/custom/ToolbarColors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ $colors: ('gray', 'yellow', 'orange', 'red', 'green', 'blue', 'violet');

.g-md-toolbar-colors {
@each $name in $colors {
&__menu-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}

&__chevron-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}

&__item-icon_color_#{$name} {
color: var(--yfm-colorify-#{$name});
}
}

&__item-icon_color_default {
color: var(--g-color-text-primary);
}
Expand Down
3 changes: 3 additions & 0 deletions src/bundle/toolbar/custom/ToolbarColors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const ToolbarColors: React.FC<ToolbarColorsProps> = (props) => {
title={i18n('colorify')}
menuItems={items}
icon={textColorIcon}
_selectionType="light"
iconClassName={b('menu-icon', {color: currentColor})}
chevronIconClassName={b('chevron-icon', {color: currentColor})}
/>
);
};
Loading