-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #604 from systemli/feat/emoji-picker
✨ Add emoji picker to message form
- Loading branch information
Showing
5 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,3 @@ | ||
export interface Emoji { | ||
native: string | ||
} |
This file contains 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 React, { FC } from 'react' | ||
import data from '@emoji-mart/data' | ||
import Picker from '@emoji-mart/react' | ||
import { Emoji } from './Emoji' | ||
import { Box, IconButton, Popper } from '@mui/material' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faSmile } from '@fortawesome/free-solid-svg-icons' | ||
import palette from '../../theme/palette' | ||
|
||
interface Props { | ||
onChange: (emoji: Emoji) => void | ||
} | ||
|
||
const EmojiPicker: FC<Props> = ({ onChange }) => { | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null) | ||
|
||
const handleChange = (emoji: Emoji) => { | ||
onChange(emoji) | ||
setAnchorEl(null) | ||
} | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(anchorEl ? null : event.currentTarget) | ||
event.stopPropagation() | ||
} | ||
|
||
const open = Boolean(anchorEl) | ||
const id = open ? 'simple-popper' : undefined | ||
|
||
return ( | ||
<Box> | ||
<IconButton component="span" onClick={handleClick} style={{ marginRight: '8px' }}> | ||
<FontAwesomeIcon color={palette.primary['main']} icon={faSmile} size="xs" /> | ||
</IconButton> | ||
<Popper anchorEl={anchorEl} id={id} open={open}> | ||
<Picker data={data} onClickOutside={() => setAnchorEl(null)} onEmojiSelect={handleChange} theme="light" /> | ||
</Popper> | ||
</Box> | ||
) | ||
} | ||
|
||
export default EmojiPicker |
This file contains 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 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