+ props.setSearchInput(event.target.value)}
+ placeholder="Search a Gitmoji by :code:"
+ type="text"
+ value={props.searchInput}
+ />
+
+)
+
+export default Toolbar
diff --git a/src/components/GitmojiList/Toolbar/styles.module.css b/src/components/GitmojiList/Toolbar/styles.module.css
new file mode 100644
index 0000000..9cc43d4
--- /dev/null
+++ b/src/components/GitmojiList/Toolbar/styles.module.css
@@ -0,0 +1,15 @@
+.searchInput {
+ border-radius: 4px;
+ border: 0;
+ box-shadow: 0 2px 4px 0 var(--cardShadow);
+ flex: 1;
+ font-size: 1rem;
+ margin-bottom: 0.5rem;
+ margin-top: 1.5rem;
+ outline: none;
+ padding: 1rem;
+}
+
+.container {
+ display: flex;
+}
diff --git a/src/components/GitmojiList/__tests__/__snapshots__/gitmojiList.spec.js.snap b/src/components/GitmojiList/__tests__/__snapshots__/gitmojiList.spec.js.snap
index 5cd096e..3d61f32 100644
--- a/src/components/GitmojiList/__tests__/__snapshots__/gitmojiList.spec.js.snap
+++ b/src/components/GitmojiList/__tests__/__snapshots__/gitmojiList.spec.js.snap
@@ -2,12 +2,28 @@
exports[`GitmojiList should render the component 1`] = `
+
diff --git a/src/components/GitmojiList/__tests__/gitmojiList.spec.js b/src/components/GitmojiList/__tests__/gitmojiList.spec.js
index 2a4c5fc..ad937e2 100644
--- a/src/components/GitmojiList/__tests__/gitmojiList.spec.js
+++ b/src/components/GitmojiList/__tests__/gitmojiList.spec.js
@@ -8,4 +8,19 @@ describe('GitmojiList', () => {
const wrapper = renderer.create( )
expect(wrapper).toMatchSnapshot()
})
+
+ describe('when user search the bug gitmoji', () => {
+ it('should filter the GitmojiList and find the bug gitmoji', () => {
+ const wrapper = renderer.create( )
+ const instance = wrapper.root
+
+ renderer.act(() => {
+ instance
+ .findByType('input')
+ .props.onChange({ target: { value: 'Bug' } })
+ })
+
+ expect(instance.findAllByType('article').length).toEqual(1)
+ })
+ })
})
diff --git a/src/components/GitmojiList/index.js b/src/components/GitmojiList/index.js
index dab5e1f..6d21aee 100644
--- a/src/components/GitmojiList/index.js
+++ b/src/components/GitmojiList/index.js
@@ -3,6 +3,7 @@ import React, { type Element } from 'react'
import Clipboard from 'clipboard'
import Gitmoji from './Gitmoji'
+import Toolbar from './Toolbar'
import emojiColorsMap from './emojiColorsMap'
type Props = {
@@ -15,6 +16,13 @@ type Props = {
}
const GitmojiList = (props: Props): Element<'div'> => {
+ const [searchInput, setSearchInput] = React.useState(null)
+ const gitmojis = searchInput
+ ? props.gitmojis.filter((gitmoji) =>
+ gitmoji.code.includes(searchInput.toLowerCase())
+ )
+ : props.gitmojis
+
React.useEffect(() => {
const clipboard = new Clipboard(
'.gitmoji-clipboard-emoji, .gitmoji-clipboard-code'
@@ -40,7 +48,7 @@ const GitmojiList = (props: Props): Element<'div'> => {
}, [])
return (
-
+
+
+
+
+
- {props.gitmojis.map((gitmoji, index) => (
-
- ))}
+
+ ))
+ )}
)
}
+
+
+
+ {gitmojis.length === 0 ? (
+