forked from adobe/react-spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmojiPicker.tsx
More file actions
50 lines (46 loc) · 1.7 KB
/
EmojiPicker.tsx
File metadata and controls
50 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use client";
import {Autocomplete, GridLayout, ListBox, ListBoxItem, Select, SelectValue, Size, useFilter, Virtualizer} from 'react-aria-components';
import {Button} from 'vanilla-starter/Button';
import {Popover} from 'vanilla-starter/Popover';
import {SearchField} from 'vanilla-starter/SearchField';
import _emojis from 'emojibase-data/en/compact.json';
import './EmojiPicker.css';
const emojis = _emojis.filter((e) => !e.label.startsWith('regional indicator'));
export function EmojiPicker() {
let {contains} = useFilter({ sensitivity: 'base' });
return (
<Select aria-label="Emoji" className="emoji-picker" defaultValue="🥳">
<Button variant="secondary">
<SelectValue />
</Button>
<Popover placement="bottom" className="emoji-picker-popover">
<Autocomplete filter={contains}>
<SearchField aria-label="Search" placeholder="Search emoji" autoFocus />
<Virtualizer
layout={GridLayout}
layoutOptions={{
minItemSize: new Size(32, 32),
maxItemSize: new Size(32, 32),
minSpace: new Size(4, 4),
preserveAspectRatio: true,
}}>
<ListBox className="emoji-list" items={emojis} aria-label="Emoji list" layout="grid">
{(item) => <EmojiItem id={item.unicode} item={item} />}
</ListBox>
</Virtualizer>
</Autocomplete>
</Popover>
</Select>
);
}
function EmojiItem({ id, item }: { id: string; item: (typeof emojis)[0] }) {
return (
<ListBoxItem
id={id}
value={item}
textValue={item.label + (item.tags || []).join(' ')}
className="emoji-item">
{item.unicode}
</ListBoxItem>
);
}