-
Notifications
You must be signed in to change notification settings - Fork 538
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 #320 from JeevaRamanathan/emoji_picker_current
Emoji picker current
- Loading branch information
Showing
7 changed files
with
393 additions
and
2 deletions.
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
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,12 @@ | ||
import styles from "./app.module.css" | ||
import Emoji from './Emoji'; | ||
import Code from './Code' | ||
export default function App() { | ||
|
||
return ( | ||
<div className={styles.main}> | ||
<Emoji/> | ||
<Code/> | ||
</div> | ||
); | ||
} |
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,62 @@ | ||
import React from 'react'; | ||
import styles from './app.module.css'; | ||
|
||
const obj = ` | ||
**Main Functionalities** | ||
**Copy Block level(div) elements to clipboard** | ||
function copyToClipboard(element) { | ||
// Create a range object that selects the element \n | ||
// to be copied. | ||
const range = document.createRange(); | ||
range.selectNode(element); | ||
// clear current selection | ||
window.getSelection().removeAllRanges(); | ||
// Selects the given range. | ||
window.getSelection().addRange(range); | ||
// Copy the selection to the clipboard. | ||
document.execCommand('copy'); | ||
// Remove the range from the selection. | ||
selection.removeAllRanges(); | ||
} | ||
**Filter emojis based on search value** | ||
emojis.filter((icon) => { | ||
icon.toLowerCase().includes(searchValue.toLowerCase()) | ||
}) | ||
**axios to call API** | ||
axios.get(__url__) | ||
.then(response => { | ||
// Handle response | ||
}); | ||
`; | ||
|
||
const Code = () => { | ||
return ( | ||
<div className={styles.container}> | ||
<pre> | ||
<code> | ||
{obj.split('\n').map((line, index) => { | ||
if (line.trim().startsWith('//')) { | ||
return <span key={index} className={styles.comments}>{line}</span>; | ||
} | ||
else if(line.trim().startsWith('**')){ | ||
return <b key={index}>{line}</b>; | ||
} | ||
return <div key={index}>{line}</div>; | ||
})} | ||
</code> | ||
</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Code; |
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,125 @@ | ||
import { useEffect, useState } from 'react'; | ||
import styles from './app.module.css'; | ||
import axios from 'axios'; | ||
|
||
const access_key = 'eb3aa13df1b14cc7bc614fc2d7f894f41b09d68a'; | ||
const Emoji = () => { | ||
const [emojis, setEmojis] = useState([]); | ||
const [filteredEmojis, setFilteredEmojis] = useState([]); | ||
const [search, setSearch] = useState(''); | ||
const [toastMessage, setToastMessage] = useState(''); | ||
const [category, setCategory] = useState([]); | ||
|
||
useEffect(() => { | ||
loadAllEmojis(); | ||
loadCategories(); | ||
window.scrollTo(0,0); | ||
}, []); | ||
|
||
const loadAllEmojis = () => { | ||
axios.get(`https://emoji-api.com/emojis?access_key=${access_key}`).then((res) => { | ||
setEmojis(res.data); | ||
setFilteredEmojis(res.data); | ||
}); | ||
}; | ||
|
||
const loadCategories = () => { | ||
axios.get(`https://emoji-api.com/categories?access_key=${access_key}`).then((res) => { | ||
setCategory(res.data); | ||
}); | ||
}; | ||
|
||
const getIconTitle = (title) => { | ||
const [_, ...value] = title.split(' '); | ||
return value.join(' '); | ||
}; | ||
|
||
const onChange = (e) => { | ||
let searchValue = e.target.value; | ||
setSearch(searchValue); | ||
let filteredIcons = emojis.filter((icon) => | ||
icon.unicodeName.toLowerCase().includes(searchValue.trim().toLowerCase()) | ||
); | ||
setFilteredEmojis(filteredIcons); | ||
}; | ||
|
||
const categoryChange = (e) => { | ||
setSearch(''); | ||
setFilteredEmojis([]); | ||
setEmojis([]); | ||
if (e.target.value == 'all') { | ||
loadAllEmojis(); | ||
} else { | ||
axios.get(`https://emoji-api.com/categories/${e.target.value}?access_key=${access_key}`).then((res) => { | ||
setEmojis(res.data); | ||
setFilteredEmojis(res.data); | ||
}); | ||
} | ||
}; | ||
|
||
const copyToClipBoard = (id) => { | ||
let range = document.createRange(); | ||
range.selectNode(document.getElementById(id)); | ||
window.getSelection().removeAllRanges(); // clear current selection | ||
window.getSelection().addRange(range); // to select text | ||
document.execCommand('copy'); | ||
window.getSelection().removeAllRanges(); // to deselect | ||
setToastMessage('Copied Successfully!'); | ||
setTimeout(() => { | ||
setToastMessage(''); | ||
}, 1500); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={styles.topSection}> | ||
<div> | ||
<select className={styles.select} onChange={categoryChange}> | ||
<option>all</option> | ||
{category.map((item) => { | ||
return <option value={item.slug}>{item.slug.replace('-', ' ')}</option>; | ||
})} | ||
</select> | ||
</div> | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="Search" | ||
onChange={onChange} | ||
value={search} | ||
className={styles.inputField} | ||
></input> | ||
</div> | ||
<div | ||
className={`${styles.copyText} ${ | ||
filteredEmojis == null || filteredEmojis?.length === 0 ? styles.hidden : '' | ||
}`} | ||
> | ||
Click on an Emoji to Copy | ||
</div> | ||
</div> | ||
<div className={styles.container}> | ||
{filteredEmojis?.length == 0 && search.trim() == '' && ( | ||
<div className={styles.loaderContainer}> | ||
<div className={styles.loader}></div> | ||
</div> | ||
)} | ||
{filteredEmojis?.map((icon, index) => ( | ||
<span | ||
className={styles.iconContainer} | ||
key={index} | ||
onClick={() => copyToClipBoard(icon.unicodeName + '_' + index)} | ||
> | ||
<span className={styles.icon} title={getIconTitle(icon.unicodeName)} id={icon.unicodeName + '_' + index}> | ||
{icon.character} | ||
</span> | ||
</span> | ||
))} | ||
</div> | ||
|
||
{toastMessage && <div className={styles.toast}>{toastMessage}</div>} | ||
</> | ||
); | ||
}; | ||
|
||
export default Emoji; |
Oops, something went wrong.