-
Notifications
You must be signed in to change notification settings - Fork 16.6k
feat(EmojiTextArea): add Slack-like emoji autocomplete component #36417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
331 changes: 331 additions & 0 deletions
331
...frontend/packages/superset-ui-core/src/components/EmojiTextArea/EmojiTextArea.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,331 @@ | ||||||
| /** | ||||||
| * Licensed to the Apache Software Foundation (ASF) under one | ||||||
| * or more contributor license agreements. See the NOTICE file | ||||||
| * distributed with this work for additional information | ||||||
| * regarding copyright ownership. The ASF licenses this file | ||||||
| * to you under the Apache License, Version 2.0 (the | ||||||
| * "License"); you may not use this file except in compliance | ||||||
| * with the License. You may obtain a copy of the License at | ||||||
| * | ||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * Unless required by applicable law or agreed to in writing, | ||||||
| * software distributed under the License is distributed on an | ||||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||
| * KIND, either express or implied. See the License for the | ||||||
| * specific language governing permissions and limitations | ||||||
| * under the License. | ||||||
| */ | ||||||
| import { useState } from 'react'; | ||||||
| import type { Meta, StoryObj } from '@storybook/react'; | ||||||
| import { EmojiTextArea, type EmojiItem } from '.'; | ||||||
|
|
||||||
| const meta: Meta<typeof EmojiTextArea> = { | ||||||
| title: 'Components/EmojiTextArea', | ||||||
| component: EmojiTextArea, | ||||||
| parameters: { | ||||||
| docs: { | ||||||
| description: { | ||||||
| component: ` | ||||||
| A TextArea component with Slack-like emoji autocomplete. | ||||||
|
|
||||||
| ## Features | ||||||
|
|
||||||
| - **Colon prefix trigger**: Type \`:sm\` to see smile emoji suggestions | ||||||
| - **Minimum 2 characters**: Popup only shows after typing 2+ characters (configurable) | ||||||
| - **Smart trigger detection**: Colon must be preceded by whitespace, start of line, or another emoji | ||||||
| - **Prevents accidental selection**: Quick Enter keypress creates newline instead of selecting | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| \`\`\`tsx | ||||||
| import { EmojiTextArea } from '@superset-ui/core/components'; | ||||||
|
|
||||||
| <EmojiTextArea | ||||||
| placeholder="Type :smile: to add emojis..." | ||||||
| onChange={(text) => console.log(text)} | ||||||
| onEmojiSelect={(emoji) => console.log('Selected:', emoji)} | ||||||
| /> | ||||||
| \`\`\` | ||||||
|
|
||||||
| ## Trigger Behavior (Slack-like) | ||||||
|
|
||||||
| The emoji picker triggers in these scenarios: | ||||||
| - \`:sm\` - at the start of text | ||||||
| - \`hello :sm\` - after a space | ||||||
| - \`😀:sm\` - after another emoji | ||||||
|
|
||||||
| It does NOT trigger in: | ||||||
| - \`hello:sm\` - no space before colon | ||||||
| - \`http://example.com\` - colon preceded by letter | ||||||
|
|
||||||
| Try it out below! | ||||||
| `, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| argTypes: { | ||||||
| minCharsBeforePopup: { | ||||||
| control: { type: 'number', min: 1, max: 5 }, | ||||||
| description: 'Minimum characters after colon before showing popup', | ||||||
| defaultValue: 2, | ||||||
| }, | ||||||
| maxSuggestions: { | ||||||
| control: { type: 'number', min: 1, max: 20 }, | ||||||
| description: 'Maximum number of emoji suggestions to show', | ||||||
| defaultValue: 10, | ||||||
| }, | ||||||
| placeholder: { | ||||||
| control: 'text', | ||||||
| description: 'Placeholder text', | ||||||
| }, | ||||||
| rows: { | ||||||
| control: { type: 'number', min: 1, max: 20 }, | ||||||
| description: 'Number of visible rows', | ||||||
| }, | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export default meta; | ||||||
| type Story = StoryObj<typeof EmojiTextArea>; | ||||||
|
|
||||||
| export const Default: Story = { | ||||||
| args: { | ||||||
| placeholder: 'Type :smile: or :thumbsup: to add emojis...', | ||||||
| rows: 4, | ||||||
| style: { width: '100%', maxWidth: 500 }, | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export const WithMinChars: Story = { | ||||||
| args: { | ||||||
| ...Default.args, | ||||||
| minCharsBeforePopup: 3, | ||||||
| placeholder: 'Requires 3 characters after colon (e.g., :smi)', | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export const WithMaxSuggestions: Story = { | ||||||
| args: { | ||||||
| ...Default.args, | ||||||
| maxSuggestions: 5, | ||||||
| placeholder: 'Shows max 5 suggestions', | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export const Controlled: Story = { | ||||||
| render: function ControlledStory() { | ||||||
| const [value, setValue] = useState(''); | ||||||
| const [selectedEmojis, setSelectedEmojis] = useState<EmojiItem[]>([]); | ||||||
|
|
||||||
| return ( | ||||||
| <div style={{ maxWidth: 500 }}> | ||||||
| <EmojiTextArea | ||||||
| value={value} | ||||||
| onChange={setValue} | ||||||
| onEmojiSelect={emoji => setSelectedEmojis(prev => [...prev, emoji])} | ||||||
| placeholder="Type :smile: or :heart: to add emojis..." | ||||||
| rows={4} | ||||||
| style={{ width: '100%' }} | ||||||
| /> | ||||||
| <div style={{ marginTop: 16 }}> | ||||||
| <strong>Current value:</strong> | ||||||
| <pre | ||||||
| style={{ | ||||||
| background: 'var(--ant-color-bg-container)', | ||||||
| padding: 8, | ||||||
| borderRadius: 4, | ||||||
| border: '1px solid var(--ant-color-border)', | ||||||
| whiteSpace: 'pre-wrap', | ||||||
| wordBreak: 'break-word', | ||||||
| }} | ||||||
| > | ||||||
| {value || '(empty)'} | ||||||
| </pre> | ||||||
| </div> | ||||||
| {selectedEmojis.length > 0 && ( | ||||||
| <div style={{ marginTop: 16 }}> | ||||||
| <strong>Selected emojis:</strong> | ||||||
| <div style={{ fontSize: 24, marginTop: 8 }}> | ||||||
| {selectedEmojis.map((e, i) => ( | ||||||
| <span key={i} title={`:${e.shortcode}:`}> | ||||||
| {e.emoji} | ||||||
| </span> | ||||||
| ))} | ||||||
| </div> | ||||||
| </div> | ||||||
| )} | ||||||
| </div> | ||||||
| ); | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export const SlackBehaviorDemo: Story = { | ||||||
| render: function SlackBehaviorDemoStory() { | ||||||
| const examples = [ | ||||||
| { input: ':sm', works: true, desc: 'Start of text' }, | ||||||
| { input: 'hello :sm', works: true, desc: 'After space' }, | ||||||
| { | ||||||
| input: '😀:sm', | ||||||
| works: true, | ||||||
| desc: 'After emoji', | ||||||
| needsEmoji: true, | ||||||
| }, | ||||||
| { input: 'hello:sm', works: false, desc: 'No space before colon' }, | ||||||
| { input: ':s', works: false, desc: 'Only 1 character' }, | ||||||
| ]; | ||||||
|
|
||||||
| return ( | ||||||
| <div style={{ maxWidth: 600 }}> | ||||||
| <h3>Slack-like Trigger Behavior</h3> | ||||||
| <p style={{ color: 'var(--ant-color-text-secondary)' }}> | ||||||
| The emoji picker mimics Slack's behavior. Try these examples: | ||||||
|
||||||
| The emoji picker mimics Slack's behavior. Try these examples: | |
| The emoji picker mimics Slack's behavior. Try these examples: |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The file references
React.FormEventin thehandleSubmitparameter but only importsuseStatefrom 'react' (noReactnamespace). This will cause a TypeScript "React is not defined" type error (or require a separate import) because theReactidentifier is used in a type position without being imported. Import the React namespace alongsideuseStateso theReacttype is available. [type error]Severity Level: Minor⚠️
Why it matters? ⭐
The story uses the
Reactnamespace in a type position:handleSubmit = (e: React.FormEvent) => { ... }.Without importing
React(or importing the FormEvent type directly), TypeScript will complain thatReactis not defined.This is a real type error, not a style nit. Adding
import React, { useState } from 'react';orimport type { FormEvent } from 'react'and adjusting the signature fixes it.Prompt for AI Agent 🤖