feat: add search functions

pull/103/head
crazywoola 3 years ago
parent bf323dc1be
commit 1778cd2e54

@ -1,13 +1,13 @@
'use client' 'use client'
import data from '@emoji-mart/data' import data from '@emoji-mart/data'
import { init } from 'emoji-mart' import { init, SearchIndex } from 'emoji-mart'
// import AppIcon from '@/app/components/base/app-icon' // import AppIcon from '@/app/components/base/app-icon'
import cn from 'classnames' import cn from 'classnames'
import Divider from '@/app/components/base/divider' import Divider from '@/app/components/base/divider'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import s from './style.module.css' import s from './style.module.css'
import { useState, FC } from 'react' import { useState, FC, ChangeEvent } from 'react'
import { import {
MagnifyingGlassIcon MagnifyingGlassIcon
} from '@heroicons/react/24/outline' } from '@heroicons/react/24/outline'
@ -27,6 +27,16 @@ declare global {
init({ data }) init({ data })
async function search(value: string) {
const emojis = await SearchIndex.search(value) || []
const results = emojis.map((emoji: any) => {
return emoji.skins[0].native
})
console.log(results)
}
const backgroundColors = [ const backgroundColors = [
'#FFEAD5', '#FFEAD5',
'#E4FBCC', '#E4FBCC',
@ -75,7 +85,15 @@ const EmojiPicker: FC<IEmojiPickerProps> = ({
<div className="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none"> <div className="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
<MagnifyingGlassIcon className="w-5 h-5 text-gray-400" aria-hidden="true" /> <MagnifyingGlassIcon className="w-5 h-5 text-gray-400" aria-hidden="true" />
</div> </div>
<input type="search" id="search" className="block w-full p-2 pl-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 " placeholder="Search" /> <input
type="search"
id="search"
className='block w-full h-10 px-3 pl-10 text-sm font-normal bg-gray-100 rounded-lg'
placeholder="Search emojis..."
onChange={(e: ChangeEvent<HTMLInputElement>) => {
search(e.target.value)
}}
/>
</div> </div>
</div> </div>
<Divider className='m-0 mb-3' /> <Divider className='m-0 mb-3' />

Loading…
Cancel
Save