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: custom slash menu text style #862

Merged
merged 1 commit into from
Aug 9, 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: 14 additions & 11 deletions lib/src/editor/selection_menu/selection_menu_item_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appflowy_editor/src/editor_state.dart';
import 'package:appflowy_editor/src/editor/selection_menu/selection_menu_service.dart';
import 'package:appflowy_editor/src/editor/selection_menu/selection_menu_widget.dart';
import 'package:appflowy_editor/src/editor_state.dart';
import 'package:flutter/material.dart';

class SelectionMenuItemWidget extends StatefulWidget {
Expand Down Expand Up @@ -32,6 +32,7 @@ class _SelectionMenuItemWidgetState extends State<SelectionMenuItemWidget> {
@override
Widget build(BuildContext context) {
final style = widget.selectionMenuStyle;
final isSelected = widget.isSelected || _onHover;
return Container(
padding: const EdgeInsets.fromLTRB(8.0, 5.0, 8.0, 5.0),
child: SizedBox(
Expand All @@ -53,16 +54,18 @@ class _SelectionMenuItemWidgetState extends State<SelectionMenuItemWidget> {
)
: WidgetStateProperty.all(Colors.transparent),
),
label: Text(
widget.item.name,
textAlign: TextAlign.left,
style: TextStyle(
color: (widget.isSelected || _onHover)
? style.selectionMenuItemSelectedTextColor
: style.selectionMenuItemTextColor,
fontSize: 12.0,
),
),
label: widget.item.nameBuilder
?.call(widget.item.name, style, isSelected) ??
Text(
widget.item.name,
textAlign: TextAlign.left,
style: TextStyle(
color: (widget.isSelected || _onHover)
? style.selectionMenuItemSelectedTextColor
: style.selectionMenuItemTextColor,
fontSize: 12.0,
),
),
onPressed: () {
widget.item.handler(
widget.editorState,
Expand Down
13 changes: 13 additions & 0 deletions lib/src/editor/selection_menu/selection_menu_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ typedef SelectionMenuItemHandler = void Function(
BuildContext context,
);

typedef SelectionMenuItemNameBuilder = Widget Function(
String name,
SelectionMenuStyle style,
bool isSelected,
);

/// Selection Menu Item
class SelectionMenuItem {
SelectionMenuItem({
required String Function() getName,
required this.icon,
required this.keywords,
required SelectionMenuItemHandler handler,
this.nameBuilder,
}) : _getName = getName {
this.handler = (editorState, menuService, context) {
if (deleteSlash) {
Expand All @@ -35,6 +42,7 @@ class SelectionMenuItem {
bool onSelected,
SelectionMenuStyle style,
) icon;
final SelectionMenuItemNameBuilder? nameBuilder;

String get name => _getName();

Expand Down Expand Up @@ -94,6 +102,7 @@ class SelectionMenuItem {
bool onSelected,
SelectionMenuStyle style,
)? iconBuilder,
SelectionMenuItemNameBuilder? nameBuilder,
bool Function(EditorState editorState, Node node)? insertBefore,
bool Function(EditorState editorState, Node node)? replace,
Selection? Function(
Expand All @@ -109,6 +118,7 @@ class SelectionMenuItem {

return SelectionMenuItem(
getName: getName,
nameBuilder: nameBuilder,
icon: (editorState, onSelected, style) {
if (iconData != null) {
return Icon(
Expand Down Expand Up @@ -217,6 +227,7 @@ class SelectionMenuWidget extends StatefulWidget {
required this.itemCountFilter,
required this.deleteSlashByDefault,
this.singleColumn = false,
this.nameBuilder,
});

final List<SelectionMenuItem> items;
Expand All @@ -234,6 +245,8 @@ class SelectionMenuWidget extends StatefulWidget {
final bool deleteSlashByDefault;
final bool singleColumn;

final SelectionMenuItemNameBuilder? nameBuilder;

@override
State<SelectionMenuWidget> createState() => _SelectionMenuWidgetState();
}
Expand Down
Loading