-
-
Notifications
You must be signed in to change notification settings - Fork 623
feat: Add Emoji Picker Option #854
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
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
57a3198
shows the emojis, keyboard navigation yet to be setup
hunxjunedo 4890198
fixed lint and styled emoji picker
hunxjunedo 9ace67d
added support for keyboard shortcuts, and cleanup
hunxjunedo 9f122b4
add more reasonable color to emojiMenu
hunxjunedo 5795d62
added emoji option to slashmenu
hunxjunedo 02318b8
optimized emojipicker for slower network
hunxjunedo 4da8fd7
finally made the emoji menu accessible through the slash menu
hunxjunedo 6de43ab
cleanup and add comments
hunxjunedo 15bf3df
add the appropriate typescript code, removed ts errors
hunxjunedo d7f248b
added dark mode, moved styles to css file
hunxjunedo b8d08ea
fixed lint
hunxjunedo 9f0051a
resolve conflict
hunxjunedo 6114681
Started refactor
matthewlipski 1f19707
added the empji item to slash menu and setup onclick, only eng locale…
hunxjunedo 1c0fd74
get the emoji.tsx to render the emoji inline
hunxjunedo 1941739
add option to show or hide emoji suggestion menu
hunxjunedo 873176b
added locales and fixed type issue
hunxjunedo e62f21c
generalize emojimenu component and move dependencies to react dir
hunxjunedo 3fa4920
create a new dir inlineContent and retent at and structure it
hunxjunedo b0a2186
Added grid suggestion menu to component context + refactor
matthewlipski c75a5f6
Merge branch 'refs/heads/main' into hunxjunedo-main
matthewlipski da5ee45
Updated package lock
matthewlipski 92358e2
Small fixes
matthewlipski 5986300
unlink columns length from css, and a new prop gridCols
hunxjunedo 449825d
More cleanup & implemented PR feedback
matthewlipski d82fb81
Change emojis to use text instead of custom IC & fixed styles
matthewlipski e72af9d
Added empty grid items and loaders
matthewlipski 6446f22
Small fix
matthewlipski f0e776f
Added docs & small fixes
matthewlipski ff3f3b9
Small dep array fix
matthewlipski 853b948
Implemented PR feedback
matthewlipski 956045b
Added `openSuggestionMenu` docs
matthewlipski 23f8e2d
Added e2e tests
matthewlipski fe625d5
Updated snapshots
matthewlipski 3f030db
Fully split regular & grid suggestion menu code
matthewlipski 9438dc9
Implemented remaining feedback and updated tests
matthewlipski 8d5fc1d
Added `emojiPicker` to `BlockNoteViewProps` docs
matthewlipski 5a882dd
Updated tests
matthewlipski d2cf8b1
Updated screenshots
matthewlipski 0e29580
Updated docs
matthewlipski 583e37f
Cleaned up merge
matthewlipski 33ab57b
Added missing files
matthewlipski 7a17b42
Small fix + regen files
matthewlipski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Grid Suggestion Menus | ||
description: In addition to displaying Suggestion Menus as stacks, BlockNote also supports displaying them as grids. | ||
imageTitle: Grid Suggestion Menus | ||
--- | ||
|
||
import { Example } from "@/components/example"; | ||
|
||
# Grid Suggestion Menus | ||
|
||
Grid Suggestion Menus appear when the user enters a trigger character, and text after the character is used to filter the menu items. | ||
|
||
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. | ||
|
||
## Emoji Picker | ||
|
||
The Emoji Picker is a Grid Suggestion Menu that opens with the `:` character (or when selecting emoji item in the Slash Menu). | ||
|
||
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. | ||
|
||
<img | ||
style={{ maxWidth: "400px" }} | ||
src="/img/screenshots/emoji_picker.png" | ||
alt="image" | ||
/> | ||
|
||
### Changing Emoji Picker Columns | ||
|
||
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. | ||
|
||
<Example name="ui-components/suggestion-menus-emoji-picker-columns" /> | ||
|
||
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. | ||
|
||
### Replacing the Emoji Picker Component | ||
|
||
You can replace the React component used for the Emoji Picker with your own, as you can see in the demo below. | ||
|
||
<Example name="ui-components/suggestion-menus-emoji-picker-component" /> | ||
|
||
Again, we add a `GridSuggestionMenuController` component with `triggerCharacter={":"}` and set `emojiPicker={false}` to replace the default Emoji Picker. | ||
|
||
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. | ||
|
||
## Creating additional Grid Suggestion Menus | ||
|
||
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. | ||
|
||
<Example name="ui-components/suggestion-menus-grid-mentions" /> | ||
|
||
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
examples/03-ui-components/08-suggestion-menus-emoji-picker-columns/.bnexample.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"playground": true, | ||
"docs": true, | ||
"author": "yousefed", | ||
"tags": [ | ||
"Intermediate", | ||
"Blocks", | ||
"UI Components", | ||
"Suggestion Menus", | ||
"Emoji Picker" | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/03-ui-components/08-suggestion-menus-emoji-picker-columns/App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import "@blocknote/core/fonts/inter.css"; | ||
import { | ||
GridSuggestionMenuController, | ||
useCreateBlockNote, | ||
} from "@blocknote/react"; | ||
import { BlockNoteView } from "@blocknote/mantine"; | ||
import "@blocknote/mantine/style.css"; | ||
|
||
export default function App() { | ||
// Creates a new editor instance. | ||
const editor = useCreateBlockNote({ | ||
initialContent: [ | ||
{ | ||
type: "paragraph", | ||
content: "Welcome to this demo!", | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "Press the ':' key to open the Emoji Picker", | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "There are now 5 columns instead of 10", | ||
}, | ||
{ | ||
type: "paragraph", | ||
}, | ||
], | ||
}); | ||
|
||
// Renders the editor instance. | ||
return ( | ||
<BlockNoteView editor={editor} emojiPicker={false}> | ||
<GridSuggestionMenuController | ||
triggerCharacter={":"} | ||
// Changes the Emoji Picker to only have 5 columns. | ||
columns={5} | ||
minQueryLength={2} | ||
/> | ||
</BlockNoteView> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/03-ui-components/08-suggestion-menus-emoji-picker-columns/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changing Emoji Picker Columns | ||
|
||
In this example, we change the Emoji Picker to display 5 columns instead of 10. | ||
|
||
**Try it out:** Press the ":" key to open the Emoji Picker! | ||
|
||
**Relevant Docs:** | ||
|
||
- [Changing Emoji Picker Columns](/docs/ui-components/suggestion-menus#changing-emoji-picker-columns) | ||
- [Editor Setup](/docs/editor-basics/setup) |
14 changes: 14 additions & 0 deletions
14
examples/03-ui-components/08-suggestion-menus-emoji-picker-columns/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html lang="en"> | ||
<head> | ||
<script> | ||
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> | ||
</script> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Changing Emoji Picker Columns</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./main.tsx"></script> | ||
</body> | ||
</html> |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
examples/03-ui-components/08-suggestion-menus-emoji-picker-columns/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@blocknote/example-suggestion-menus-emoji-picker-columns", | ||
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
"private": true, | ||
"version": "0.12.4", | ||
"scripts": { | ||
"start": "vite", | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"lint": "eslint . --max-warnings 0" | ||
}, | ||
"dependencies": { | ||
"@blocknote/core": "latest", | ||
"@blocknote/react": "latest", | ||
"@blocknote/ariakit": "latest", | ||
"@blocknote/mantine": "latest", | ||
"@blocknote/shadcn": "latest", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.25", | ||
"@types/react-dom": "^18.0.9", | ||
"@vitejs/plugin-react": "^4.0.4", | ||
"eslint": "^8.10.0", | ||
"vite": "^4.4.8" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"../../../.eslintrc.js" | ||
] | ||
}, | ||
"eslintIgnore": [ | ||
"dist" | ||
] | ||
} |
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
examples/03-ui-components/09-suggestion-menus-emoji-picker-component/.bnexample.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"playground": true, | ||
"docs": true, | ||
"author": "yousefed", | ||
"tags": [ | ||
"Intermediate", | ||
"UI Components", | ||
"Suggestion Menus", | ||
"Emoji Picker", | ||
"Appearance & Styling" | ||
] | ||
} |
71 changes: 71 additions & 0 deletions
71
examples/03-ui-components/09-suggestion-menus-emoji-picker-component/App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import "@blocknote/core/fonts/inter.css"; | ||
import { | ||
DefaultReactGridSuggestionItem, | ||
GridSuggestionMenuController, | ||
GridSuggestionMenuProps, | ||
useCreateBlockNote, | ||
} from "@blocknote/react"; | ||
import { BlockNoteView } from "@blocknote/mantine"; | ||
import "@blocknote/mantine/style.css"; | ||
|
||
import "./styles.css"; | ||
|
||
// Custom component to replace the default Emoji Picker. | ||
function CustomEmojiPicker( | ||
props: GridSuggestionMenuProps<DefaultReactGridSuggestionItem> | ||
) { | ||
return ( | ||
<div | ||
className={"emoji-picker"} | ||
style={ | ||
{ gridTemplateColumns: `repeat(${props.columns || 1}, 1fr)` } as any | ||
}> | ||
{props.items.map((item, index) => ( | ||
<div | ||
className={`emoji-picker-item${ | ||
props.selectedIndex === index ? " selected" : "" | ||
}`} | ||
onClick={() => { | ||
props.onItemClick?.(item); | ||
}}> | ||
{item.icon} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default function App() { | ||
// Creates a new editor instance. | ||
const editor = useCreateBlockNote({ | ||
initialContent: [ | ||
{ | ||
type: "paragraph", | ||
content: "Welcome to this demo!", | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "Press the ':' key to open the Emoji Picker", | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "It's been replaced with a custom component", | ||
}, | ||
{ | ||
type: "paragraph", | ||
}, | ||
], | ||
}); | ||
|
||
// Renders the editor instance. | ||
return ( | ||
<BlockNoteView editor={editor} emojiPicker={false}> | ||
<GridSuggestionMenuController | ||
triggerCharacter={":"} | ||
gridSuggestionMenuComponent={CustomEmojiPicker} | ||
columns={10} | ||
minQueryLength={2} | ||
/> | ||
</BlockNoteView> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/03-ui-components/09-suggestion-menus-emoji-picker-component/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Replacing Emoji Picker Component | ||
|
||
In this example, we replace the default Emoji Picker component with a basic custom one. | ||
|
||
**Try it out:** Press the ":" key to see the new Emoji Picker! | ||
|
||
**Relevant Docs:** | ||
|
||
- [Replacing the Emoji Picker Component](/docs/ui-components/suggestion-menus#replacing-the-emoji-picker-component) | ||
- [Editor Setup](/docs/editor-basics/setup) |
14 changes: 14 additions & 0 deletions
14
examples/03-ui-components/09-suggestion-menus-emoji-picker-component/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html lang="en"> | ||
<head> | ||
<script> | ||
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> | ||
</script> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Replacing Emoji Picker Component</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./main.tsx"></script> | ||
</body> | ||
</html> |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
examples/03-ui-components/09-suggestion-menus-emoji-picker-component/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@blocknote/example-suggestion-menus-emoji-picker-component", | ||
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
"private": true, | ||
"version": "0.12.4", | ||
"scripts": { | ||
"start": "vite", | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"lint": "eslint . --max-warnings 0" | ||
}, | ||
"dependencies": { | ||
"@blocknote/core": "latest", | ||
"@blocknote/react": "latest", | ||
"@blocknote/ariakit": "latest", | ||
"@blocknote/mantine": "latest", | ||
"@blocknote/shadcn": "latest", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.25", | ||
"@types/react-dom": "^18.0.9", | ||
"@vitejs/plugin-react": "^4.0.4", | ||
"eslint": "^8.10.0", | ||
"vite": "^4.4.8" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"../../../.eslintrc.js" | ||
] | ||
}, | ||
"eslintIgnore": [ | ||
"dist" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.