@@ -3,15 +3,21 @@ import {
33 useEmojiPicker ,
44 type EmojiMatch ,
55} from '@portabletext/plugin-emoji-picker'
6+ import { usePopover } from '@portabletext/toolbar'
67import { useEffect , useRef } from 'react'
78import { Button } from './primitives/button'
9+ import { Popover } from './primitives/popover'
810
911export function EmojiPickerPlugin ( ) {
1012 const { keyword, matches, selectedIndex, onDismiss, onNavigateTo, onSelect} =
1113 useEmojiPicker ( { matchEmojis} )
1214
15+ if ( keyword . length < 2 ) {
16+ return null
17+ }
18+
1319 return (
14- < EmojiListBox
20+ < EmojiPickerPopover
1521 keyword = { keyword }
1622 matches = { matches }
1723 selectedIndex = { selectedIndex }
@@ -22,20 +28,55 @@ export function EmojiPickerPlugin() {
2228 )
2329}
2430
25- export function EmojiListBox ( props : {
31+ function EmojiPickerPopover ( props : {
2632 keyword : string
2733 matches : Array < EmojiMatch >
2834 selectedIndex : number
2935 onDismiss : ( ) => void
3036 onNavigateTo : ( index : number ) => void
3137 onSelect : ( ) => void
3238} ) {
33- if ( props . keyword . length < 2 ) {
39+ const popover = usePopover ( {
40+ guard : ( ) => true ,
41+ placement : 'top' ,
42+ } )
43+
44+ if ( ! popover . snapshot . matches ( 'active' ) ) {
3445 return null
3546 }
3647
3748 return (
38- < div className = "border border-gray-300 rounded bg-white shadow" >
49+ < Popover
50+ className = "p-0"
51+ isNonModal
52+ triggerRef = { popover . snapshot . context . anchorRef }
53+ crossOffset = { popover . snapshot . context . crossOffset }
54+ offset = { popover . snapshot . context . offset }
55+ placement = { popover . snapshot . context . placement }
56+ isOpen = { props . keyword . length >= 2 }
57+ >
58+ < EmojiListBox
59+ keyword = { props . keyword }
60+ matches = { props . matches }
61+ selectedIndex = { props . selectedIndex }
62+ onDismiss = { props . onDismiss }
63+ onNavigateTo = { props . onNavigateTo }
64+ onSelect = { props . onSelect }
65+ />
66+ </ Popover >
67+ )
68+ }
69+
70+ function EmojiListBox ( props : {
71+ keyword : string
72+ matches : Array < EmojiMatch >
73+ selectedIndex : number
74+ onDismiss : ( ) => void
75+ onNavigateTo : ( index : number ) => void
76+ onSelect : ( ) => void
77+ } ) {
78+ return (
79+ < div className = "rounded" >
3980 { props . matches . length === 0 ? (
4081 < div className = "p-2 flex align-middle gap-2" >
4182 No results found{ ' ' }
0 commit comments