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: support customizing the block icon #274

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

LucasXu0
Copy link
Collaborator

@LucasXu0 LucasXu0 commented Jul 2, 2023

Support customizing the built-in block's icon

Screenshot 2023-07-02 at 12 26 11

Here's the sample code

final iconMap = {
  BulletedListBlockKeys.type: Icons.format_list_bulleted,
  NumberedListBlockKeys.type: Icons.format_list_numbered,
  QuoteBlockKeys.type: Icons.format_quote,
  TodoListBlockKeys.type: Icons.check_box_outline_blank,
};

class CustomBlockIcon extends StatelessWidget {
  const CustomBlockIcon({super.key});

  @override
  Widget build(BuildContext context) {
    final delta = Delta()..insert('Hello World');
    final document = Document.blank()
      ..insert(
        [0],
        [
          bulletedListNode(delta: delta),
          numberedListNode(delta: delta),
          todoListNode(delta: delta, checked: false),
          quoteNode(delta: delta),
        ],
      );

    final customBlockComponentBuilders = {
      ...standardBlockComponentBuilderMap,
      BulletedListBlockKeys.type: BulletedListBlockComponentBuilder(
        iconBuilder: (_, __) => Icon(iconMap[BulletedListBlockKeys.type]),
      ),
      NumberedListBlockKeys.type: NumberedListBlockComponentBuilder(
        iconBuilder: (_, __) => Icon(iconMap[NumberedListBlockKeys.type]),
      ),
      TodoListBlockKeys.type: TodoListBlockComponentBuilder(
        iconBuilder: (_, __) => Icon(iconMap[TodoListBlockKeys.type]),
      ),
      QuoteBlockKeys.type: QuoteBlockComponentBuilder(
        iconBuilder: (_, __) => Icon(iconMap[QuoteBlockKeys.type]),
      ),
    };

    final editorState = EditorState(document: document);
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: SizedBox(
            width: 500,
            child: AppFlowyEditor.custom(
              editorState: editorState,
              blockComponentBuilders: customBlockComponentBuilders,
              commandShortcutEvents: standardCommandShortcutEvents,
              characterShortcutEvents: standardCharacterShortcutEvents,
            ),
          ),
        ),
      ),
    );
  }
}

@codecov
Copy link

codecov bot commented Jul 2, 2023

Codecov Report

Merging #274 (04e9f40) into main (572a174) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #274      +/-   ##
==========================================
+ Coverage   62.56%   62.60%   +0.04%     
==========================================
  Files         245      245              
  Lines       10842    10855      +13     
==========================================
+ Hits         6783     6796      +13     
  Misses       4059     4059              
Impacted Files Coverage Δ
...block_component/bulleted_list_block_component.dart 92.42% <100.00%> (+0.36%) ⬆️
...block_component/numbered_list_block_component.dart 92.85% <100.00%> (+0.79%) ⬆️
...t/quote_block_component/quote_block_component.dart 90.38% <100.00%> (+0.58%) ⬆️
...ist_block_component/todo_list_block_component.dart 86.48% <100.00%> (ø)
...editor/toolbar/desktop/items/icon_item_widget.dart 100.00% <100.00%> (ø)

@LucasXu0 LucasXu0 merged commit 87a1642 into AppFlowy-IO:main Jul 3, 2023
@LucasXu0 LucasXu0 mentioned this pull request Jul 5, 2023
LucasXu0 added a commit to MayurSMahajan/appflowy-editor that referenced this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant