Skip to content

Commit d897307

Browse files
feat: Add Emoji Picker Option (#854)
* shows the emojis, keyboard navigation yet to be setup * fixed lint and styled emoji picker * added support for keyboard shortcuts, and cleanup * add more reasonable color to emojiMenu * added emoji option to slashmenu * optimized emojipicker for slower network * finally made the emoji menu accessible through the slash menu * cleanup and add comments * add the appropriate typescript code, removed ts errors * added dark mode, moved styles to css file * fixed lint * resolve conflict * Started refactor * added the empji item to slash menu and setup onclick, only eng locale for now * get the emoji.tsx to render the emoji inline * add option to show or hide emoji suggestion menu * added locales and fixed type issue * generalize emojimenu component and move dependencies to react dir * create a new dir inlineContent and retent at and structure it * Added grid suggestion menu to component context + refactor * Updated package lock * Small fixes * unlink columns length from css, and a new prop gridCols * More cleanup & implemented PR feedback * Change emojis to use text instead of custom IC & fixed styles * Added empty grid items and loaders * Small fix * Added docs & small fixes * Small dep array fix * Implemented PR feedback * Added `openSuggestionMenu` docs * Added e2e tests * Updated snapshots * Fully split regular & grid suggestion menu code * Implemented remaining feedback and updated tests * Added `emojiPicker` to `BlockNoteViewProps` docs * Updated tests * Updated screenshots * Updated docs * Added missing files * Small fix + regen files --------- Co-authored-by: Matthew Lipski <[email protected]> Co-authored-by: Matthew Lipski <[email protected]>
1 parent 762b569 commit d897307

File tree

138 files changed

+2642
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2642
-403
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: Grid Suggestion Menus
3+
description: In addition to displaying Suggestion Menus as stacks, BlockNote also supports displaying them as grids.
4+
imageTitle: Grid Suggestion Menus
5+
---
6+
7+
import { Example } from "@/components/example";
8+
9+
# Grid Suggestion Menus
10+
11+
Grid Suggestion Menus appear when the user enters a trigger character, and text after the character is used to filter the menu items.
12+
13+
Grid Suggestion Menus are similar to regular Suggestion Menus, but results are organized in a grid, and users can use all arrow keys (including left, right) on their keyboard to navigate the results.
14+
15+
## Emoji Picker
16+
17+
The Emoji Picker is a Grid Suggestion Menu that opens with the `:` character (or when selecting emoji item in the Slash Menu).
18+
19+
It only displays once the user types 2 non-whitespace characters a query, to minimize cases where the user only wants to enter the `:` character.
20+
21+
<img
22+
style={{ maxWidth: "400px" }}
23+
src="/img/screenshots/emoji_picker.png"
24+
alt="image"
25+
/>
26+
27+
### Changing Emoji Picker Columns
28+
29+
By default, the Emoji Picker is rendered with 10 columns, but you can change this to any amount. In the demo below, the Emoji Picker is changed to only display 5 columns.
30+
31+
<Example name="ui-components/suggestion-menus-emoji-picker-columns" />
32+
33+
Passing `emojiPicker={false}` to `BlockNoteView` tells BlockNote not to show the default Emoji Picker. Adding the `GridSuggestionMenuController` with `triggerCharacter={":"}` and `columns={5}` tells BlockNote to show one with 5 columns instead.
34+
35+
### Replacing the Emoji Picker Component
36+
37+
You can replace the React component used for the Emoji Picker with your own, as you can see in the demo below.
38+
39+
<Example name="ui-components/suggestion-menus-emoji-picker-component" />
40+
41+
Again, we add a `GridSuggestionMenuController` component with `triggerCharacter={":"}` and set `emojiPicker={false}` to replace the default Emoji Picker.
42+
43+
Now, we also pass a component to its `gridSuggestionMenuComponent` prop. The `gridSuggestionMenuComponent` we pass is responsible for rendering the filtered items. The `GridSuggestionMenuController` controls its position and visibility (below the trigger character), and it also determines which items should be shown. Since we don't specify which items to show (the `getItems` prop isn't defined), it will use the default items for a grid, which are the emojis.
44+
45+
## Creating additional Grid Suggestion Menus
46+
47+
You can add additional Grid Suggestion Menus to the editor, which can use any trigger character. The demo below adds an example Grid Suggestion Menu for mentions, where each item is the first character of the user's name, and opens with the `@` character.
48+
49+
<Example name="ui-components/suggestion-menus-grid-mentions" />
50+
51+
Changing the column count in the new Grid Suggestion Menu, or the component used to render it, is done the same way as for the [Emoji Picker](/docs/advanced/grid-suggestion-menus#emoji-picker). For more information about how the mentions elements work, see [Custom Inline Content](/docs/custom-schemas/custom-inline-content).

docs/pages/docs/editor-basics/setup.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export type BlockNoteViewProps = {
9696
linkToolbar?: boolean;
9797
sideMenu?: boolean;
9898
slashMenu?: boolean;
99+
emojiPicker?: boolean;
99100
filePanel?: boolean;
100101
tableHandles?: boolean;
101102
children?:
@@ -120,6 +121,8 @@ export type BlockNoteViewProps = {
120121

121122
`slashMenu`: Whether the [Slash Menu](/docs/ui-components/suggestion-menus#slash-menu) should be enabled.
122123

124+
`emojiPicker`: Whether the [Emoji Picker](/docs/ui-components/suggestion-menus#emoji-picker) should be enabled.
125+
123126
`filePanel`: Whether the File Toolbar should be enabled.
124127

125128
`tableHandles`: Whether the Table Handles should be enabled.

docs/pages/docs/ui-components/suggestion-menus.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Passing `slashMenu={false}` to `BlockNoteView` tells BlockNote not to show the d
3131

3232
`getItems` should return the items that need to be shown in the Slash Menu, based on a `query` entered by the user (anything the user types after the `triggerCharacter`).
3333

34-
### Replacing the Suggestion Menu Component
34+
### Replacing the Slash Menu Component
3535

36-
You can replace the React component used for the Suggestion Menu with your own, as you can see in the demo below.
36+
You can replace the React component used for the Slash Menu with your own, as you can see in the demo below.
3737

3838
<Example name="ui-components/suggestion-menus-slash-menu-component" />
3939

@@ -48,3 +48,24 @@ You can add additional Suggestion Menus to the editor, which can use any trigger
4848
<Example name="custom-schema/suggestion-menus-mentions" />
4949

5050
Changing the items in the new Suggestion Menu, or the component used to render it, is done the same way as for the [Slash Menu](/docs/ui-components/suggestion-menus#slash-menu). For more information about how the mentions elements work, see [Custom Inline Content](/docs/custom-schemas/custom-inline-content).
51+
52+
## Additional Features
53+
54+
BlockNote offers a few other features for working with Suggestion Menus which may fit your use case.
55+
56+
### Opening Suggestion Menus Programmatically
57+
58+
While suggestion menus are generally meant to be opened when the user presses a trigger character, you may also want to open them from code. To do this, you can use the following editor method:
59+
60+
```typescript
61+
openSuggestionMenu(triggerCharacter: string): void;
62+
63+
// Usage
64+
editor.openSuggestionMenu("/");
65+
```
66+
67+
### Waiting for a Query
68+
69+
You may want to hold off displaying a Suggestion Menu unless you're certain that the user actually wants to open the menu and not just enter the trigger character. In this case, you should use the `minQueryLength` prop for `SuggestionMenuController`, which takes a number.
70+
71+
The number indicates how many characters the user query needs to have before the menu is shown. When greater than 0, it also prevents the menu from displaying if the user enters a space immediately after the trigger character.
279 KB
Loading
273 KB
Loading

examples/03-ui-components/07-suggestion-menus-slash-menu-component/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
display: flex;
1010
flex-direction: column;
1111
gap: 8px;
12+
height: fit-content;
13+
max-height: 100%;
14+
15+
overflow: auto;
1216

1317
padding: 8px;
1418

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"playground": true,
3+
"docs": true,
4+
"author": "yousefed",
5+
"tags": [
6+
"Intermediate",
7+
"Blocks",
8+
"UI Components",
9+
"Suggestion Menus",
10+
"Emoji Picker"
11+
]
12+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import "@blocknote/core/fonts/inter.css";
2+
import {
3+
GridSuggestionMenuController,
4+
useCreateBlockNote,
5+
} from "@blocknote/react";
6+
import { BlockNoteView } from "@blocknote/mantine";
7+
import "@blocknote/mantine/style.css";
8+
9+
export default function App() {
10+
// Creates a new editor instance.
11+
const editor = useCreateBlockNote({
12+
initialContent: [
13+
{
14+
type: "paragraph",
15+
content: "Welcome to this demo!",
16+
},
17+
{
18+
type: "paragraph",
19+
content: "Press the ':' key to open the Emoji Picker",
20+
},
21+
{
22+
type: "paragraph",
23+
content: "There are now 5 columns instead of 10",
24+
},
25+
{
26+
type: "paragraph",
27+
},
28+
],
29+
});
30+
31+
// Renders the editor instance.
32+
return (
33+
<BlockNoteView editor={editor} emojiPicker={false}>
34+
<GridSuggestionMenuController
35+
triggerCharacter={":"}
36+
// Changes the Emoji Picker to only have 5 columns.
37+
columns={5}
38+
minQueryLength={2}
39+
/>
40+
</BlockNoteView>
41+
);
42+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changing Emoji Picker Columns
2+
3+
In this example, we change the Emoji Picker to display 5 columns instead of 10.
4+
5+
**Try it out:** Press the ":" key to open the Emoji Picker!
6+
7+
**Relevant Docs:**
8+
9+
- [Changing Emoji Picker Columns](/docs/ui-components/suggestion-menus#changing-emoji-picker-columns)
10+
- [Editor Setup](/docs/editor-basics/setup)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html lang="en">
2+
<head>
3+
<script>
4+
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
5+
</script>
6+
<meta charset="UTF-8" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>Changing Emoji Picker Columns</title>
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="./main.tsx"></script>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)