feat: callout improvement (#3090)

This commit is contained in:
Yijing Huang 2023-08-10 07:59:24 -05:00 committed by GitHub
parent 675e23e971
commit 1fad5aa804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 53 deletions

View File

@ -5,6 +5,7 @@ import 'package:appflowy/workspace/application/settings/shortcuts/settings_short
import 'package:appflowy/plugins/document/presentation/editor_plugins/inline_page/inline_page_reference.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/inline_page/inline_page_reference.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@ -185,6 +186,8 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
// OptionAction.moveDown, // OptionAction.moveDown,
]; ];
final calloutBGColor = AFThemeExtension.of(context).calloutBGColor;
final configuration = BlockComponentConfiguration( final configuration = BlockComponentConfiguration(
padding: (_) => const EdgeInsets.symmetric(vertical: 5.0), padding: (_) => const EdgeInsets.symmetric(vertical: 5.0),
); );
@ -250,6 +253,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
), ),
CalloutBlockKeys.type: CalloutBlockComponentBuilder( CalloutBlockKeys.type: CalloutBlockComponentBuilder(
configuration: configuration, configuration: configuration,
defaultColor: calloutBGColor,
), ),
DividerBlockKeys.type: DividerBlockComponentBuilder( DividerBlockKeys.type: DividerBlockComponentBuilder(
configuration: configuration, configuration: configuration,

View File

@ -16,6 +16,8 @@ enum OptionAction {
turnInto, turnInto,
moveUp, moveUp,
moveDown, moveDown,
/// callout background color
color, color,
divider, divider,
align; align;
@ -241,11 +243,12 @@ class ColorOptionAction extends PopoverActionCell {
final bgColor = final bgColor =
node.attributes[blockComponentBackgroundColor] as String?; node.attributes[blockComponentBackgroundColor] as String?;
final selectedColor = bgColor?.toColor(); final selectedColor = bgColor?.toColor();
// get default background color from themeExtension
final defaultColor = AFThemeExtension.of(context).calloutBGColor;
final colors = [ final colors = [
// clear background color. // reset to default background color
FlowyColorOption( FlowyColorOption(
color: Colors.transparent, color: defaultColor,
name: LocaleKeys.document_plugins_optionAction_defaultColor.tr(), name: LocaleKeys.document_plugins_optionAction_defaultColor.tr(),
), ),
...FlowyTint.values.map( ...FlowyTint.values.map(
@ -265,8 +268,7 @@ class ColorOptionAction extends PopoverActionCell {
), ),
onTap: (color, index) async { onTap: (color, index) async {
final transaction = editorState.transaction; final transaction = editorState.transaction;
final backgroundColor = final backgroundColor = color.toHex();
color == Colors.transparent ? null : color.toHex();
transaction.updateNode(node, { transaction.updateNode(node, {
blockComponentBackgroundColor: backgroundColor, blockComponentBackgroundColor: backgroundColor,
}); });

View File

@ -1,4 +1,5 @@
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -26,16 +27,16 @@ class CalloutBlockKeys {
static const String icon = 'icon'; static const String icon = 'icon';
} }
// creating a new callout node // The one is inserted through selection menu
Node calloutNode({ Node calloutNode({
Delta? delta, Delta? delta,
String emoji = '📌', String emoji = '📌',
String backgroundColor = '#F0F0F0', Color? defaultColor,
}) { }) {
final attributes = { final attributes = {
CalloutBlockKeys.delta: (delta ?? Delta()).toJson(), CalloutBlockKeys.delta: (delta ?? Delta()).toJson(),
CalloutBlockKeys.icon: emoji, CalloutBlockKeys.icon: emoji,
CalloutBlockKeys.backgroundColor: backgroundColor, CalloutBlockKeys.backgroundColor: defaultColor?.toHex() ?? '#f2f2f2',
}; };
return Node( return Node(
type: CalloutBlockKeys.type, type: CalloutBlockKeys.type,
@ -43,12 +44,13 @@ Node calloutNode({
); );
} }
// defining the callout block menu item for selection // defining the callout block menu item in selection menu
SelectionMenuItem calloutItem = SelectionMenuItem.node( SelectionMenuItem calloutItem = SelectionMenuItem.node(
name: 'Callout', name: 'Callout',
iconData: Icons.note, iconData: Icons.note,
keywords: ['callout'], keywords: [CalloutBlockKeys.type],
nodeBuilder: (editorState, _) => calloutNode(), nodeBuilder: (editorState, context) =>
calloutNode(defaultColor: AFThemeExtension.of(context).calloutBGColor),
replace: (_, node) => node.delta?.isEmpty ?? false, replace: (_, node) => node.delta?.isEmpty ?? false,
updateSelection: (_, path, __, ___) { updateSelection: (_, path, __, ___) {
return Selection.single(path: path, startOffset: 0); return Selection.single(path: path, startOffset: 0);
@ -59,17 +61,21 @@ SelectionMenuItem calloutItem = SelectionMenuItem.node(
class CalloutBlockComponentBuilder extends BlockComponentBuilder { class CalloutBlockComponentBuilder extends BlockComponentBuilder {
CalloutBlockComponentBuilder({ CalloutBlockComponentBuilder({
this.configuration = const BlockComponentConfiguration(), this.configuration = const BlockComponentConfiguration(),
required this.defaultColor,
}); });
@override @override
final BlockComponentConfiguration configuration; final BlockComponentConfiguration configuration;
final Color defaultColor;
@override @override
BlockComponentWidget build(BlockComponentContext blockComponentContext) { BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node; final node = blockComponentContext.node;
return CalloutBlockComponentWidget( return CalloutBlockComponentWidget(
key: node.key, key: node.key,
node: node, node: node,
defaultColor: defaultColor,
configuration: configuration, configuration: configuration,
showActions: showActions(node), showActions: showActions(node),
actionBuilder: (context, state) => actionBuilder( actionBuilder: (context, state) => actionBuilder(
@ -96,8 +102,11 @@ class CalloutBlockComponentWidget extends BlockComponentStatefulWidget {
super.showActions, super.showActions,
super.actionBuilder, super.actionBuilder,
super.configuration = const BlockComponentConfiguration(), super.configuration = const BlockComponentConfiguration(),
required this.defaultColor,
}); });
final Color defaultColor;
@override @override
State<CalloutBlockComponentWidget> createState() => State<CalloutBlockComponentWidget> createState() =>
_CalloutBlockComponentWidgetState(); _CalloutBlockComponentWidgetState();
@ -128,17 +137,8 @@ class _CalloutBlockComponentWidgetState
// get the background color of the note block from the node's attributes // get the background color of the note block from the node's attributes
Color get backgroundColor { Color get backgroundColor {
final colorString = final colorString =
node.attributes[CalloutBlockKeys.backgroundColor] as String?; node.attributes[CalloutBlockKeys.backgroundColor] as String;
if (colorString == null) { return colorString.toColor();
return Colors.transparent;
}
final brightness = Theme.of(context).brightness;
final bool isDarkMode = brightness == Brightness.dark;
final Color bgColor = colorString.toColor();
return isDarkMode ? bgColor.withOpacity(0.3) : bgColor;
} }
// get the emoji of the note block from the node's attributes or default to '📌' // get the emoji of the note block from the node's attributes or default to '📌'
@ -162,9 +162,9 @@ class _CalloutBlockComponentWidgetState
// the emoji picker button for the note // the emoji picker button for the note
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 6.0, top: 8.0,
left: 2.0, left: 4.0,
right: 2.0, right: 4.0,
), ),
child: EmojiPickerButton( child: EmojiPickerButton(
key: ValueKey( key: ValueKey(
@ -183,7 +183,7 @@ class _CalloutBlockComponentWidgetState
child: buildCalloutBlockComponent(context), child: buildCalloutBlockComponent(context),
), ),
), ),
const VSpace(10), const HSpace(8.0),
], ],
), ),
); );

View File

@ -346,6 +346,7 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
fontSize: FontSizes.s11, fontSize: FontSizes.s11,
fontColor: theme.shader3, fontColor: theme.shader3,
), ),
calloutBGColor: theme.hoverBG3,
caption: _getFontStyle( caption: _getFontStyle(
fontFamily: fontFamily, fontFamily: fontFamily,
fontSize: FontSizes.s11, fontSize: FontSizes.s11,

View File

@ -93,15 +93,15 @@ class DandelionColorScheme extends FlowyColorScheme {
bg2: _black, bg2: _black,
bg3: const Color(0xff4f4f4f), bg3: const Color(0xff4f4f4f),
bg4: const Color(0xff2c144b), bg4: const Color(0xff2c144b),
tint1: const Color(0xff8738F5), tint1: const Color(0x4d9327FF),
tint2: const Color(0xffE6336E), tint2: const Color(0x66FC0088),
tint3: const Color(0xffFF2D9E), tint3: const Color(0x4dFC00E2),
tint4: const Color(0xffE9973E), tint4: const Color(0x80BE5B00),
tint5: const Color(0xffFBF000), tint5: const Color(0x33F8EE00),
tint6: const Color(0xffC0F000), tint6: const Color(0x4d6DC300),
tint7: const Color(0xff15F74E), tint7: const Color(0x5900BD2A),
tint8: const Color(0xff00F0E2), tint8: const Color(0x80008890),
tint9: const Color(0xff00BCF0), tint9: const Color(0x4d0029FF),
main1: _darkMain1, main1: _darkMain1,
main2: const Color(0xffe0196f), main2: const Color(0xffe0196f),
shadow: _black, shadow: _black,

View File

@ -91,15 +91,15 @@ class DefaultColorScheme extends FlowyColorScheme {
bg2: const Color(0xffEDEEF2), bg2: const Color(0xffEDEEF2),
bg3: _darkMain1, bg3: _darkMain1,
bg4: const Color(0xff2C144B), bg4: const Color(0xff2C144B),
tint1: const Color(0xff8738F5), tint1: const Color(0x4d9327FF),
tint2: const Color(0xffE6336E), tint2: const Color(0x66FC0088),
tint3: const Color(0xffFF2D9E), tint3: const Color(0x4dFC00E2),
tint4: const Color(0xffE9973E), tint4: const Color(0x80BE5B00),
tint5: const Color(0xffFBF000), tint5: const Color(0x33F8EE00),
tint6: const Color(0xffC0F000), tint6: const Color(0x4d6DC300),
tint7: const Color(0xff15F74E), tint7: const Color(0x5900BD2A),
tint8: const Color(0xff00F0E2), tint8: const Color(0x80008890),
tint9: const Color(0xff00BCF0), tint9: const Color(0x4d0029FF),
main1: _darkMain1, main1: _darkMain1,
main2: const Color(0xff00B7EA), main2: const Color(0xff00B7EA),
shadow: const Color(0xff0F131C), shadow: const Color(0xff0F131C),

View File

@ -94,15 +94,15 @@ class LavenderColorScheme extends FlowyColorScheme {
bg2: _black, bg2: _black,
bg3: _darkMain1, bg3: _darkMain1,
bg4: const Color(0xff2c144b), bg4: const Color(0xff2c144b),
tint1: const Color(0xff8738F5), tint1: const Color(0x4d9327FF),
tint2: const Color(0xffE6336E), tint2: const Color(0x66FC0088),
tint3: const Color(0xffFF2D9E), tint3: const Color(0x4dFC00E2),
tint4: const Color(0xffE9973E), tint4: const Color(0x80BE5B00),
tint5: const Color(0xffFBF000), tint5: const Color(0x33F8EE00),
tint6: const Color(0xffC0F000), tint6: const Color(0x4d6DC300),
tint7: const Color(0xff15F74E), tint7: const Color(0x5900BD2A),
tint8: const Color(0xff00F0E2), tint8: const Color(0x80008890),
tint9: const Color(0xff00BCF0), tint9: const Color(0x4d0029FF),
main1: _darkMain1, main1: _darkMain1,
main2: _darkMain1, main2: _darkMain1,
shadow: _black, shadow: _black,

View File

@ -22,6 +22,7 @@ class AFThemeExtension extends ThemeExtension<AFThemeExtension> {
final Color toggleOffFill; final Color toggleOffFill;
final Color progressBarBGColor; final Color progressBarBGColor;
final Color toggleButtonBGColor; final Color toggleButtonBGColor;
final Color calloutBGColor;
final TextStyle code; final TextStyle code;
final TextStyle callout; final TextStyle callout;
@ -44,6 +45,7 @@ class AFThemeExtension extends ThemeExtension<AFThemeExtension> {
required this.lightGreyHover, required this.lightGreyHover,
required this.toggleOffFill, required this.toggleOffFill,
required this.textColor, required this.textColor,
required this.calloutBGColor,
required this.code, required this.code,
required this.callout, required this.callout,
required this.caption, required this.caption,
@ -69,6 +71,7 @@ class AFThemeExtension extends ThemeExtension<AFThemeExtension> {
Color? tint8, Color? tint8,
Color? tint9, Color? tint9,
Color? textColor, Color? textColor,
Color? calloutBGColor,
Color? greyHover, Color? greyHover,
Color? greySelect, Color? greySelect,
Color? lightGreyHover, Color? lightGreyHover,
@ -92,6 +95,7 @@ class AFThemeExtension extends ThemeExtension<AFThemeExtension> {
tint8: tint8 ?? this.tint8, tint8: tint8 ?? this.tint8,
tint9: tint9 ?? this.tint9, tint9: tint9 ?? this.tint9,
textColor: textColor ?? this.textColor, textColor: textColor ?? this.textColor,
calloutBGColor: calloutBGColor ?? this.calloutBGColor,
greyHover: greyHover ?? this.greyHover, greyHover: greyHover ?? this.greyHover,
greySelect: greySelect ?? this.greySelect, greySelect: greySelect ?? this.greySelect,
lightGreyHover: lightGreyHover ?? this.lightGreyHover, lightGreyHover: lightGreyHover ?? this.lightGreyHover,
@ -123,6 +127,7 @@ class AFThemeExtension extends ThemeExtension<AFThemeExtension> {
tint8: Color.lerp(tint8, other.tint8, t)!, tint8: Color.lerp(tint8, other.tint8, t)!,
tint9: Color.lerp(tint9, other.tint9, t)!, tint9: Color.lerp(tint9, other.tint9, t)!,
textColor: Color.lerp(textColor, other.textColor, t)!, textColor: Color.lerp(textColor, other.textColor, t)!,
calloutBGColor: Color.lerp(calloutBGColor, other.calloutBGColor, t)!,
greyHover: Color.lerp(greyHover, other.greyHover, t)!, greyHover: Color.lerp(greyHover, other.greyHover, t)!,
greySelect: Color.lerp(greySelect, other.greySelect, t)!, greySelect: Color.lerp(greySelect, other.greySelect, t)!,
lightGreyHover: Color.lerp(lightGreyHover, other.lightGreyHover, t)!, lightGreyHover: Color.lerp(lightGreyHover, other.lightGreyHover, t)!,