Find an emoji by name or browse by category, for reactions, statuses and messages.
Yours: 🎉
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { EmojiPicker } from "./ui/uicontext/components/kit/Emoji.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, shadow, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ frame: { display: "grid", gap: space.md, justifyItems: "start" }, panel: { borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.overlay, boxShadow: shadow.md }, picked: { margin: 0, fontSize: font.sm, color: color.muted, minBlockSize: 20 },})const Message = UiSchema.TaggedEnum({ PickedEmoji: { emoji: Schema.String, on: Schema.Boolean } })// Type to search ("party", "ship"), or browse by category; Down moves into the grid, Enter picks the first matchexport const PickAnEmoji = Html.component({ name: "PickAnEmoji", model: Schema.Struct({ mine: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ mine: ["🎉"] }), update: { PickedEmoji: ($, { emoji, on }) => $.evolve({ mine: (all) => (on ? [...all, emoji] : all.filter((e) => e !== emoji)) }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( h.div.attrs(sx(styles.panel)).children(EmojiPicker(h, { props: { mine: model.mine }, onEmit: { Picked: ({ emoji, on }) => Message.PickedEmoji({ emoji, on }) }, })), h.p.attrs({ role: "status", ...sx(styles.picked) }).children(model.mine.length === 0 ? "Nothing picked" : `Yours: ${model.mine.join(" ")}`), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/emoji-pickerUsage
import { EmojiPicker, emojiMatches } from "./ui/uicontext/components/kit/Emoji.ts"const Message = UiSchema.TaggedEnum({ Reacted: { emoji: Schema.String, on: Schema.Boolean } })// the reader's own reactions show chosen; picking one again takes it backexport const ReactionPicker = (h: Html.H<typeof Message.Type>, mine: ReadonlyArray<string>) => EmojiPicker(h, { props: { mine }, onEmit: { Picked: ({ emoji, on }) => Message.Reacted({ emoji, on }) } })// the same names drive ":tada" in a composerexport const firstMatch = emojiMatches("tada")[0]?.emojiAPI reference
EmojiPickerComponent
Props
| Name | Type | Description |
|---|---|---|
mine | string[] | Emoji the reader already used here, shown chosen; picking one again takes it back |
Events
| Event | Payload | Description |
|---|---|---|
Picked | { emoji: string; on: boolean } | The reader picked an emoji: add it (on), or take back one they'd used |
EmojiPanelView function
Options
| Name | Type | Description |
|---|---|---|
queryrequired | string | What's typed in the search field |
categoryrequired | "frequent" | "people" | "nature" | "food" | "activity" | "travel" | "objects" | "symbols" | The category tab that's open while nothing is typed |
mine | string[] | Emoji the reader already used here (their reactions), shown chosen |
searchrequired | (input: InputBuilder<Message>, first: string | undefined) => InputBuilder<Message> | Binds the search field: its input, and Enter to pick the first match |
tabrequired | (button: ButtonBuilder<Message>, category: EmojiCategory) => ButtonBuilder<Message> | Binds a category tab's press |
choicerequired | (button: ButtonBuilder<Message>, emoji: string, on: boolean) => ButtonBuilder<Message> | Binds an emoji's press: the emoji, and whether it adds the reader's (false takes it back) |
Accessibility
- The search field takes focus as the picker opens; Down moves into the grid, the arrows move by row and column, and Enter in the field picks the first match.
- Each emoji is a button named for it (
tada), pressed when it's already yours. Categories are toggle buttons.