-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add an emoji picker #35019
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
feat: add an emoji picker #35019
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
2c189e4
feat: add an emoji picker
pauldambra 49da1b4
Update UI snapshots for `chromium` (16)
github-actions[bot] 1b97dd8
upgrde icons
pauldambra 9dc174d
fix
pauldambra 7708c37
fix
pauldambra 7386c06
Update UI snapshots for `chromium` (16)
github-actions[bot] dd80c4e
Update UI snapshots for `chromium` (15)
github-actions[bot] 2d7130b
fix
pauldambra c73d7a9
fix
pauldambra b80e88c
fix
pauldambra 8482daf
Update UI snapshots for `chromium` (15)
github-actions[bot] cb96f7e
fix
pauldambra 521f203
Update UI snapshots for `chromium` (16)
github-actions[bot] 72484da
Merge branch 'master' into feat/pd/em-pi
pauldambra 45d643b
Merge branch 'master' into feat/pd/em-pi
pauldambra 33f4c54
fix
pauldambra 08c2ce8
Update UI snapshots for `chromium` (16)
github-actions[bot] 21f171f
fix
pauldambra 5df56a4
Merge branch 'master' into feat/pd/em-pi
pauldambra 4023963
fix
pauldambra 688ff7c
fix
pauldambra fc9add5
fix
pauldambra 4970527
fix
pauldambra 4fd06b6
fix
pauldambra d1bc8f1
emoji picker in quick emoji row
pauldambra 2159da0
new icons
pauldambra 1aee986
fix
pauldambra 0c344c4
Update UI snapshots for `chromium` (16)
github-actions[bot] cb38499
Update UI snapshots for `chromium` (15)
github-actions[bot] caea4fd
loading state
pauldambra 7565cd2
put emoji where the cursor is
pauldambra 959d541
Merge branch 'master' into feat/pd/em-pi
pauldambra 5f36d2f
Merge branch 'master' into feat/pd/em-pi
pauldambra 8dd1efd
Merge branch 'master' into feat/pd/em-pi
pauldambra 87f4292
fix
pauldambra affb6a6
fix
pauldambra 9502b7d
Update UI snapshots for `chromium` (2)
github-actions[bot] 610bda8
Update UI snapshots for `chromium` (2)
github-actions[bot] 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
Binary file added
BIN
+2.4 KB
frontend/__snapshots__/lemon-ui-emoji-picker-popover--default--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.37 KB
frontend/__snapshots__/lemon-ui-emoji-picker-popover--default--light.png
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.
Binary file added
BIN
+70.4 KB
frontend/__snapshots__/lemon-ui-emoji-picker-popover--open--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+560 Bytes
(120%)
...pshots__/lemon-ui-lemon-text-area-markdown--empty-lemon-text-markdown--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+521 Bytes
(120%)
...shots__/lemon-ui-lemon-text-area-markdown--empty-lemon-text-markdown--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+572 Bytes
(110%)
...emon-ui-lemon-text-area-markdown--lemon-text-markdown-with-max-length--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+515 Bytes
(110%)
...mon-ui-lemon-text-area-markdown--lemon-text-markdown-with-max-length--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+547 Bytes
(110%)
...ts__/lemon-ui-lemon-text-area-markdown--lemon-text-markdown-with-text--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+513 Bytes
(110%)
...s__/lemon-ui-lemon-text-area-markdown--lemon-text-markdown-with-text--light.png
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
42 changes: 42 additions & 0 deletions
42
frontend/src/lib/components/EmojiPicker/EmojiPickerPopover.stories.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 { Meta, StoryFn, StoryObj } from '@storybook/react' | ||
|
|
||
| import { EmojiPickerPopover } from 'lib/components/EmojiPicker/EmojiPickerPopover' | ||
|
|
||
| type Story = StoryObj<typeof EmojiPickerPopover> | ||
| const meta: Meta<typeof EmojiPickerPopover> = { | ||
| title: 'Lemon UI/Emoji Picker Popover', | ||
| component: EmojiPickerPopover, | ||
| tags: ['autodocs'], | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: 'A component that opens a popover emoji picker.', | ||
| }, | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| onSelect: { | ||
| description: 'The function to run when a user chooses an emoji', | ||
| }, | ||
| defaultOpen: { | ||
| description: 'Whether to start with the popover open - defaults to false', | ||
| }, | ||
| }, | ||
| } | ||
| export default meta | ||
|
|
||
| const BasicTemplate: StoryFn<typeof EmojiPickerPopover> = (props) => { | ||
| return ( | ||
| <div className="w-[325px] h-[370px] border rounded"> | ||
| <EmojiPickerPopover {...props} /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export const Default: Story = BasicTemplate.bind({}) | ||
| Default.args = {} | ||
|
|
||
| export const Open: Story = BasicTemplate.bind({}) | ||
| Open.args = { | ||
| defaultOpen: true, | ||
| } | ||
102 changes: 102 additions & 0 deletions
102
frontend/src/lib/components/EmojiPicker/EmojiPickerPopover.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,102 @@ | ||
| import { | ||
| EmojiPicker, | ||
| EmojiPickerListCategoryHeaderProps, | ||
| EmojiPickerListEmojiProps, | ||
| EmojiPickerListRowProps, | ||
| } from 'frimousse' | ||
| import { LemonButton } from 'lib/lemon-ui/LemonButton' | ||
| import { Popover } from 'lib/lemon-ui/Popover' | ||
| import { useState } from 'react' | ||
| import { IconEmojiAdd } from '@posthog/icons' | ||
|
|
||
| const EmojiPickerCategoryHeader = ({ category, ...props }: EmojiPickerListCategoryHeaderProps): JSX.Element => ( | ||
| <div className="bg-bg-light px-3 pt-3 pb-1.5 font-medium text-neutral-600 text-sm" {...props}> | ||
| {category.label} | ||
| </div> | ||
| ) | ||
|
|
||
| const EmojiPickerEmojiRow = ({ children, ...props }: EmojiPickerListRowProps): JSX.Element => ( | ||
| <div className="scroll-my-1.5 px-1.5" {...props}> | ||
| {children} | ||
| </div> | ||
| ) | ||
|
|
||
| const EmojiPickerEmojiButton = ({ emoji, ...props }: EmojiPickerListEmojiProps): JSX.Element => ( | ||
| <button | ||
| data-attr="emoji-picker-button" | ||
| className="flex items-center justify-center rounded-md text-xl size-8 data-[active]:bg-secondary-3000-hover" | ||
|
pauldambra marked this conversation as resolved.
|
||
| {...props} | ||
| > | ||
| {emoji.emoji} | ||
| </button> | ||
| ) | ||
|
|
||
| export interface EmojiPickerPopoverProps { | ||
| /** | ||
| * The action to take when a user selects an emoji | ||
| * receives the emoji as a string | ||
| */ | ||
| onSelect: (s: string) => void | ||
| /** | ||
| * Whether to start with the popover open or closed | ||
| * Defaults to false (closed) | ||
| */ | ||
| defaultOpen?: boolean | ||
| /** | ||
| * the data-attr to set on the button that opens and closes the popover | ||
| */ | ||
| 'data-attr'?: string | ||
| } | ||
|
|
||
| export function EmojiPickerPopover({ | ||
| onSelect, | ||
| defaultOpen = false, | ||
| 'data-attr': dataAttr, | ||
| }: EmojiPickerPopoverProps): JSX.Element { | ||
| const [emojiPickerOpen, setEmojiPickerOpen] = useState(defaultOpen) | ||
|
|
||
| return ( | ||
| <Popover | ||
| onClickOutside={() => setEmojiPickerOpen(false)} | ||
| // prefer the bottom, but will fall back to other positions based on space | ||
| placement="bottom-start" | ||
| visible={emojiPickerOpen} | ||
| overlay={ | ||
| <EmojiPicker.Root | ||
| className="isolate flex h-[368px] w-fit flex-col bg-bg-light" | ||
| onEmojiSelect={({ emoji }) => { | ||
| onSelect(emoji) | ||
| setEmojiPickerOpen(false) | ||
| }} | ||
| > | ||
| <EmojiPicker.Search className="z-10 mx-2 mt-2 appearance-none rounded bg-fill-input px-2.5 py-2 text-sm border" /> | ||
| <EmojiPicker.Viewport className="relative flex-1 outline-hidden"> | ||
| <EmojiPicker.Loading className="absolute inset-0 flex items-center justify-center text-tertiary text-sm"> | ||
| Loading… | ||
| </EmojiPicker.Loading> | ||
| <EmojiPicker.Empty className="absolute inset-0 flex items-center justify-center text-tertiary text-sm"> | ||
| No emoji found. | ||
| </EmojiPicker.Empty> | ||
| <EmojiPicker.List | ||
| className="select-none pb-1.5" | ||
| components={{ | ||
| CategoryHeader: EmojiPickerCategoryHeader, | ||
| Row: EmojiPickerEmojiRow, | ||
| Emoji: EmojiPickerEmojiButton, | ||
|
pauldambra marked this conversation as resolved.
|
||
| }} | ||
| /> | ||
| </EmojiPicker.Viewport> | ||
| </EmojiPicker.Root> | ||
| } | ||
| > | ||
| <LemonButton | ||
| data-attr={dataAttr} | ||
| icon={<IconEmojiAdd className="text-lg" />} | ||
| onClick={() => { | ||
| setEmojiPickerOpen(!emojiPickerOpen) | ||
| }} | ||
| size="small" | ||
| /> | ||
| </Popover> | ||
| ) | ||
| } | ||
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
70 changes: 70 additions & 0 deletions
70
frontend/src/lib/lemon-ui/LemonTextArea/emojiUsageLogic.ts
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,70 @@ | ||
| import { actions, kea, reducers, path, selectors } from 'kea' | ||
| import { now } from 'lib/dayjs' | ||
|
|
||
| import { permanentlyMount } from 'lib/utils/kea-logic-builders' | ||
|
|
||
| import type { emojiUsageLogicType } from './emojiUsageLogicType' | ||
|
|
||
| export const defaultQuickEmojis = ['💖', '👍', '🤔', '👎', '🌶️'] | ||
|
|
||
| export const emojiUsageLogic = kea<emojiUsageLogicType>([ | ||
| path(['lib', 'lemon-ui', 'LemonTextArea', 'emojiUsage', 'logic']), | ||
| actions({ | ||
| emojiUsed: (emoji: string) => ({ emoji }), | ||
| }), | ||
| reducers({ | ||
| usedEmojis: [ | ||
| {} as Record<string, number[]>, | ||
| { persist: true }, | ||
| { | ||
| emojiUsed: (state, { emoji }) => { | ||
| const currentTime = now().valueOf() | ||
| const thirtyDaysAgo = currentTime - 30 * 24 * 60 * 60 * 1000 | ||
|
|
||
| const newState = { ...state, [emoji]: state[emoji] || [] } | ||
| newState[emoji] = [...newState[emoji], currentTime] | ||
|
|
||
| newState[emoji] = newState[emoji].filter((timestamp: number) => timestamp > thirtyDaysAgo) | ||
|
|
||
| if (newState[emoji].length === 0) { | ||
| delete newState[emoji] | ||
| } else { | ||
| // Limit to max 10 timestamps per emoji to prevent memory issues | ||
| if (newState[emoji].length > 10) { | ||
| newState[emoji] = newState[emoji].slice(-10) | ||
| } | ||
| } | ||
|
|
||
| return newState | ||
| }, | ||
| }, | ||
| ], | ||
| }), | ||
| selectors({ | ||
| favouriteEmojis: [ | ||
| (s) => [s.usedEmojis], | ||
| (usedEmojis): string[] => { | ||
| // Get user's favorite emojis sorted by usage count | ||
| const userFavorites = Object.entries(usedEmojis) | ||
| .map(([emoji, timestamps]) => ({ | ||
| emoji, | ||
| count: timestamps.length, | ||
| })) | ||
| .sort((a, b) => b.count - a.count) // Sort by usage count descending | ||
| .slice(0, 5) // Take top 5 | ||
| .map(({ emoji }) => emoji) // Extract just the emoji strings | ||
|
|
||
| // If we have fewer than 5 favorites, fill with quickEmojis (avoiding duplicates) | ||
| if (userFavorites.length < 5) { | ||
| const remainingSlots = 5 - userFavorites.length | ||
| const availableQuickEmojis = defaultQuickEmojis.filter((emoji) => !userFavorites.includes(emoji)) | ||
| const fillEmojis = availableQuickEmojis.slice(0, remainingSlots) | ||
| return [...userFavorites, ...fillEmojis] | ||
| } | ||
|
|
||
| return userFavorites | ||
| }, | ||
| ], | ||
| }), | ||
| permanentlyMount(), | ||
| ]) |
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
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
Oops, something went wrong.
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.