Skip to content

Commit f54e6fa

Browse files
committed
WIP
1 parent 1abc027 commit f54e6fa

File tree

6 files changed

+142
-40
lines changed

6 files changed

+142
-40
lines changed

apps/playground/src/emoji-picker.tsx

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ import {
33
useEmojiPicker,
44
type EmojiMatch,
55
} from '@portabletext/plugin-emoji-picker'
6+
import {usePopover} from '@portabletext/toolbar'
67
import {useEffect, useRef} from 'react'
78
import {Button} from './primitives/button'
9+
import {Popover} from './primitives/popover'
810

911
export 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{' '}

apps/playground/src/feature-flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const defaultEditorFeatureFlags: EditorFeatureFlags = {
2929
imageDeserializerPlugin: false,
3030
htmlDeserializerPlugin: false,
3131
textFileDeserializerPlugin: false,
32-
emojiPickerPlugin: false,
32+
emojiPickerPlugin: true,
3333
codeEditorPlugin: false,
3434
linkPlugin: false,
3535
oneLinePlugin: false,

apps/playground/src/playground-machine.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,19 @@ export const playgroundMachine = setup({
377377
context: ({input}) => ({
378378
editorIdGenerator: input.editorIdGenerator,
379379
featureFlags: defaultPlaygroundFeatureFlags,
380-
value: [],
380+
value: [
381+
{
382+
_type: 'block',
383+
_key: keyGenerator(),
384+
children: [
385+
{
386+
_type: 'span',
387+
_key: keyGenerator(),
388+
text: 'foo\nbar',
389+
},
390+
],
391+
},
392+
],
381393
rangeDecorations: [],
382394
editors: [],
383395
}),

apps/playground/src/primitives/popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const styles = tv({
2828
export function Popover({children, className, ...props}: PopoverProps) {
2929
return (
3030
<AriaPopover
31-
offset={8}
31+
offset={props.offset ?? 8}
3232
{...props}
3333
className={composeRenderProps(className, (className, renderProps) =>
3434
styles({...renderProps, className}),

apps/playground/src/toolbar/toolbar.floating.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function FloatingToolbar() {
99
const toolbarSchema = usePlaygroundToolbarSchema()
1010
const popover = usePopover({
1111
guard: isSelectionExpanded,
12-
placement: 'top',
12+
placement: 'bottom',
1313
})
1414

1515
if (popover.snapshot.matches('inactive')) {
@@ -21,6 +21,7 @@ export function FloatingToolbar() {
2121
isNonModal
2222
triggerRef={popover.snapshot.context.anchorRef}
2323
crossOffset={popover.snapshot.context.crossOffset}
24+
offset={popover.snapshot.context.offset + 8}
2425
placement={popover.snapshot.context.placement}
2526
isOpen={true}
2627
>

0 commit comments

Comments
 (0)