fix: slash menu background color (#2616)

This commit is contained in:
Lucas.Xu
2023-05-26 09:52:47 +08:00
committed by GitHub
parent 70bb7f2ad6
commit 386182e295
15 changed files with 78 additions and 30 deletions

View File

@ -63,13 +63,19 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
// code block
...codeBlockCharacterEvents,
// toggle list
// formatGreaterToToggleList,
// customize the slash menu command
customSlashCommand(
slashMenuItems,
style: styleCustomizer.selectionMenuStyleBuilder(),
),
...standardCharacterShortcutEvents
..removeWhere(
(element) => element == slashCommand,
), // remove the default slash command.
customSlashCommand(slashMenuItems),
// formatGreaterToToggleList,
];
late final showSlashMenu = customSlashCommand(
@ -189,7 +195,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
),
AutoCompletionBlockKeys.type: AutoCompletionBlockComponentBuilder(),
SmartEditBlockKeys.type: SmartEditBlockComponentBuilder(),
// ToggleListBlockKeys.type: ToggleListBlockComponentBuilder(),
ToggleListBlockKeys.type: ToggleListBlockComponentBuilder(),
};
final builders = {

View File

@ -1,3 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra/image.dart';
import 'package:flutter/material.dart';
@ -6,20 +7,21 @@ class SelectableSvgWidget extends StatelessWidget {
super.key,
required this.name,
required this.isSelected,
required this.style,
});
final String name;
final bool isSelected;
final SelectionMenuStyle style;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return svgWidget(
name,
size: const Size.square(18.0),
color: isSelected
? theme.colorScheme.onSurface
: theme.colorScheme.onBackground,
? style.selectionMenuItemSelectedIconColor
: style.selectionMenuItemIconColor,
);
}
}
@ -29,20 +31,21 @@ class SelectableIconWidget extends StatelessWidget {
super.key,
required this.icon,
required this.isSelected,
required this.style,
});
final IconData icon;
final bool isSelected;
final SelectionMenuStyle style;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Icon(
icon,
size: 18.0,
color: isSelected
? theme.colorScheme.onSurface
: theme.colorScheme.onBackground,
? style.selectionMenuItemSelectedIconColor
: style.selectionMenuItemIconColor,
);
}
}

View File

@ -8,9 +8,10 @@ import 'package:flutter/material.dart';
SelectionMenuItem boardMenuItem = SelectionMenuItem(
name: LocaleKeys.document_plugins_referencedBoard.tr(),
icon: (editorState, onSelected) => SelectableSvgWidget(
icon: (editorState, onSelected, style) => SelectableSvgWidget(
name: 'editor/board',
isSelected: onSelected,
style: style,
),
keywords: ['referenced', 'board', 'kanban'],
handler: (editorState, menuService, context) {

View File

@ -10,9 +10,10 @@ import 'package:easy_localization/easy_localization.dart';
SelectionMenuItem boardViewMenuItem(DocumentBloc documentBloc) =>
SelectionMenuItem(
name: LocaleKeys.document_slashMenu_board_createANewBoard.tr(),
icon: (editorState, onSelected) => SelectableSvgWidget(
icon: (editorState, onSelected, style) => SelectableSvgWidget(
name: 'editor/board',
isSelected: onSelected,
style: style,
),
keywords: ['board', 'kanban'],
handler: (editorState, menuService, context) async {

View File

@ -1,3 +1,4 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/divider/divider_node_widget.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
@ -41,9 +42,10 @@ CharacterShortcutEventHandler _convertMinusesToDividerHandler =
SelectionMenuItem dividerMenuItem = SelectionMenuItem(
name: 'Divider',
icon: (editorState, onSelected) => const Icon(
Icons.horizontal_rule,
size: 18.0,
icon: (editorState, onSelected, style) => SelectableIconWidget(
icon: Icons.horizontal_rule,
isSelected: onSelected,
style: style,
),
keywords: ['horizontal rule', 'divider'],
handler: (editorState, _, __) {

View File

@ -7,9 +7,10 @@ import 'emoji_picker.dart';
SelectionMenuItem emojiMenuItem = SelectionMenuItem(
name: 'Emoji',
icon: (editorState, onSelected) => SelectableIconWidget(
icon: (editorState, onSelected, style) => SelectableIconWidget(
icon: Icons.emoji_emotions_outlined,
isSelected: onSelected,
style: style,
),
keywords: ['emoji'],
handler: (editorState, menuService, context) {

View File

@ -8,9 +8,10 @@ import 'package:flutter/material.dart';
SelectionMenuItem gridMenuItem = SelectionMenuItem(
name: LocaleKeys.document_plugins_referencedGrid.tr(),
icon: (editorState, onSelected) => SelectableSvgWidget(
icon: (editorState, onSelected, style) => SelectableSvgWidget(
name: 'editor/board',
isSelected: onSelected,
style: style,
),
keywords: ['referenced', 'grid'],
handler: (editorState, menuService, context) {

View File

@ -10,9 +10,10 @@ import 'package:easy_localization/easy_localization.dart';
SelectionMenuItem gridViewMenuItem(DocumentBloc documentBloc) =>
SelectionMenuItem(
name: LocaleKeys.document_slashMenu_grid_createANewGrid.tr(),
icon: (editorState, onSelected) => SelectableSvgWidget(
icon: (editorState, onSelected, style) => SelectableSvgWidget(
name: 'editor/grid',
isSelected: onSelected,
style: style,
),
keywords: ['grid'],
handler: (editorState, menuService, context) async {

View File

@ -126,7 +126,7 @@ class _ToggleListBlockComponentWidgetState
// build the richtext child
Widget buildToggleListBlockComponent(BuildContext context) {
return Row(
Widget child = Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// the emoji picker button for the note
@ -158,6 +158,16 @@ class _ToggleListBlockComponentWidgetState
),
],
);
if (widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
actionBuilder: widget.actionBuilder!,
child: child,
);
}
return child;
}
Future<void> onCollapsed() async {

View File

@ -124,4 +124,16 @@ class EditorStyleCustomizer {
color: theme.colorScheme.onBackground,
);
}
SelectionMenuStyle selectionMenuStyleBuilder() {
final theme = Theme.of(context);
return SelectionMenuStyle(
selectionMenuBackgroundColor: theme.cardColor,
selectionMenuItemTextColor: theme.colorScheme.onBackground,
selectionMenuItemIconColor: theme.colorScheme.onBackground,
selectionMenuItemSelectedIconColor: theme.colorScheme.onSurface,
selectionMenuItemSelectedTextColor: theme.colorScheme.onSurface,
selectionMenuItemSelectedColor: theme.hoverColor,
);
}
}