feat: Enhance EmojiIconPicker with search functionality and keyword support
This commit is contained in:
1 parent
2101080719
commit
a7058c30be
2 files changed
+585
-6
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useState, useId } from 'react'
|
||||
import { useState, useId, useMemo, useEffect } from 'react'
|
||||
import { ChevronDown, ChevronUp } from 'lucide-react'
|
||||
import { haystackForEmoji, matchesEmojiSearch } from './emojiIconPickerKeywords.js'
|
||||
|
||||
/**
|
||||
* Kuratierte Emoji-Gruppen (viele Einzel-Glyphen für breite OS-Unterstützung).
|
||||
@@ -222,10 +223,29 @@ export default function EmojiIconPicker({
|
||||
}) {
|
||||
const uid = useId()
|
||||
const inputId = idProp || `emoji-icon-${uid}`
|
||||
const searchInputId = `${inputId}-picker-search`
|
||||
const [open, setOpen] = useState(defaultExpanded)
|
||||
const [pickerSearch, setPickerSearch] = useState('')
|
||||
const groups =
|
||||
extraGroups.length > 0 ? [...EMOJI_ICON_GROUPS, ...extraGroups] : EMOJI_ICON_GROUPS
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) setPickerSearch('')
|
||||
}, [open])
|
||||
|
||||
const filteredGroups = useMemo(() => {
|
||||
const q = pickerSearch
|
||||
if (!q.trim()) {
|
||||
return groups
|
||||
}
|
||||
return groups
|
||||
.map((g) => ({
|
||||
...g,
|
||||
emojis: g.emojis.filter((em) => matchesEmojiSearch(haystackForEmoji(em, g.label), q))
|
||||
}))
|
||||
.filter((g) => g.emojis.length > 0)
|
||||
}, [groups, pickerSearch])
|
||||
|
||||
const handleInput = (e) => {
|
||||
onChange(e.target.value.slice(0, maxLength))
|
||||
}
|
||||
@@ -308,11 +328,40 @@ export default function EmojiIconPicker({
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: 12,
|
||||
border: '1px solid var(--border)',
|
||||
maxHeight: 'min(72vh, 420px)',
|
||||
maxHeight: 'min(72vh, 460px)',
|
||||
overflowY: 'auto'
|
||||
}}
|
||||
>
|
||||
{groups.map((group, gi) => (
|
||||
<label htmlFor={searchInputId} className="form-label" style={{ marginBottom: 6 }}>
|
||||
In Vorschlägen suchen
|
||||
</label>
|
||||
<input
|
||||
id={searchInputId}
|
||||
type="search"
|
||||
className="form-input"
|
||||
value={pickerSearch}
|
||||
onChange={(e) => setPickerSearch(e.target.value)}
|
||||
placeholder="z. B. rollschuh, karate, apfel…"
|
||||
disabled={disabled}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
inputMode="search"
|
||||
style={{ width: '100%', marginBottom: 12, boxSizing: 'border-box' }}
|
||||
/>
|
||||
{filteredGroups.length === 0 && pickerSearch.trim() && (
|
||||
<p
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: 'var(--text2)',
|
||||
margin: '0 0 12px 0',
|
||||
lineHeight: 1.45
|
||||
}}
|
||||
>
|
||||
Keine Treffer für „{pickerSearch.trim()}“. Andere Begriffe probieren oder oben ein Emoji
|
||||
einfügen (z. B. Win + .).
|
||||
</p>
|
||||
)}
|
||||
{filteredGroups.map((group, gi) => (
|
||||
<div key={`${group.label}-${gi}`} style={{ marginBottom: 14 }}>
|
||||
<div
|
||||
style={{
|
||||
@@ -359,10 +408,11 @@ export default function EmojiIconPicker({
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<p style={{ fontSize: 11, color: 'var(--text3)', margin: 0, lineHeight: 1.5 }}>
|
||||
<p style={{ fontSize: 11, color: 'var(--text3)', margin: '12px 0 0 0', lineHeight: 1.5 }}>
|
||||
Du kannst auch direkt in das Feld tippen oder das Betriebssystem-Emoji-Menü nutzen
|
||||
(z. B. Win + . unter Windows).{' '}
|
||||
<strong>Inline Skating:</strong> Es gibt kein separates Inliner-Emoji; 🛼 (Rollschuh) wird dafür oft genutzt.{' '}
|
||||
(z. B. Win + . unter Windows). Mehrere Wörter verfeinern die Suche: jedes muss in den
|
||||
Stichwörtern vorkommen.{' '}
|
||||
<strong>Inline Skating:</strong> Es gibt kein separates Inliner-Emoji; 🛼 (Rollschuh) wird dafür oft genutzt – Suchbegriffe: rollschuh, inline, inliner.{' '}
|
||||
<strong>Karate / Kampfsport mit Gi:</strong> 🥋 (gemeinsames Unicode-Symbol für u. a. Karate, Judo, Ju-Jitsu).
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user