-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4320] dev: propel emoji reaction component #7741
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f201c63
dev: animated counter added to propel
anmolsinghbhatia 26c1ab6
chore: animated counter story added
anmolsinghbhatia 60b9a0c
chore: propel config updated
anmolsinghbhatia e38e764
chore: code refactor
anmolsinghbhatia 6d3f934
dev: emoji reaction and renderer component added to propel
anmolsinghbhatia 722b026
dev: emoji reaction story added
anmolsinghbhatia d4cdb1f
chore: propel config updated
anmolsinghbhatia 2887cb1
chore: code refactor
anmolsinghbhatia 5a883ed
fix: format error
anmolsinghbhatia 154cc77
Merge branch 'preview' of github.com:makeplane/plane into dev-propel-…
sriramveeraghanta fe570f2
chore: lint error resolved
sriramveeraghanta 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
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 |
|---|---|---|
|
|
@@ -2532,4 +2532,4 @@ | |
| "close_button": "Закрыть панель навигации", | ||
| "outline_floating_button": "Открыть структуру" | ||
| } | ||
| } | ||
| } | ||
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
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
49 changes: 49 additions & 0 deletions
49
packages/propel/src/emoji-reaction/emoji-reaction-picker.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,49 @@ | ||
| import { useState } from "react"; | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { SmilePlus } from "lucide-react"; | ||
| import { stringToEmoji } from "../emoji-icon-picker"; | ||
| import { EmojiReactionPicker } from "./emoji-reaction-picker"; | ||
|
|
||
| const meta: Meta<typeof EmojiReactionPicker> = { | ||
| title: "EmojiReactionPicker", | ||
| component: EmojiReactionPicker, | ||
| parameters: { | ||
| layout: "centered", | ||
| }, | ||
| tags: ["autodocs"], | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof EmojiReactionPicker>; | ||
|
|
||
| const EmojiPickerDemo = (args: React.ComponentProps<typeof EmojiReactionPicker>) => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [selectedEmoji, setSelectedEmoji] = useState<string | null>(null); | ||
|
|
||
| return ( | ||
| <div className="space-y-4 p-4"> | ||
| <EmojiReactionPicker | ||
| {...args} | ||
| isOpen={isOpen} | ||
| handleToggle={setIsOpen} | ||
| onChange={(emoji) => { | ||
| setSelectedEmoji(emoji); | ||
| console.log("Selected emoji:", emoji); | ||
| }} | ||
| label={ | ||
| <span className={`flex items-center justify-center rounded-md px-2 size-8 text-xl`}> | ||
| {selectedEmoji ? stringToEmoji(selectedEmoji) : <SmilePlus className="h-6 text-custom-text-100" />} | ||
| </span> | ||
| } | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| render: (args) => <EmojiPickerDemo {...args} />, | ||
| args: { | ||
| closeOnSelect: true, | ||
| searchPlaceholder: "Search emojis...", | ||
| }, | ||
| }; | ||
84 changes: 84 additions & 0 deletions
84
packages/propel/src/emoji-reaction/emoji-reaction-picker.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,84 @@ | ||
| import React, { useMemo, useCallback } from "react"; | ||
| import { EmojiRoot } from "../emoji-icon-picker/emoji/emoji"; | ||
| import { emojiToString } from "../emoji-icon-picker/helper"; | ||
| import { Popover } from "../popover"; | ||
| import { cn } from "../utils/classname"; | ||
| import { convertPlacementToSideAndAlign, type TPlacement, type TSide, type TAlign } from "../utils/placement"; | ||
|
|
||
| export interface EmojiReactionPickerProps { | ||
| isOpen: boolean; | ||
| handleToggle: (value: boolean) => void; | ||
| buttonClassName?: string; | ||
| closeOnSelect?: boolean; | ||
| disabled?: boolean; | ||
| dropdownClassName?: string; | ||
| label: React.ReactNode; | ||
| onChange: (emoji: string) => void; | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| placement?: TPlacement; | ||
| searchDisabled?: boolean; | ||
| searchPlaceholder?: string; | ||
| side?: TSide; | ||
| align?: TAlign; | ||
| } | ||
|
|
||
| export const EmojiReactionPicker: React.FC<EmojiReactionPickerProps> = (props) => { | ||
| const { | ||
| isOpen, | ||
| handleToggle, | ||
| buttonClassName, | ||
| closeOnSelect = true, | ||
| disabled = false, | ||
| dropdownClassName, | ||
| label, | ||
| onChange, | ||
| placement = "bottom-start", | ||
| searchDisabled = false, | ||
| searchPlaceholder = "Search", | ||
| side = "bottom", | ||
| align = "start", | ||
| } = props; | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // side and align calculations | ||
| const { finalSide, finalAlign } = useMemo(() => { | ||
| if (placement) { | ||
| const converted = convertPlacementToSideAndAlign(placement); | ||
| return { finalSide: converted.side, finalAlign: converted.align }; | ||
| } | ||
| return { finalSide: side, finalAlign: align }; | ||
| }, [placement, side, align]); | ||
|
|
||
| const handleEmojiChange = useCallback( | ||
| (value: string) => { | ||
| const emoji = emojiToString(value); | ||
| onChange(emoji); | ||
| if (closeOnSelect) handleToggle(false); | ||
| }, | ||
| [onChange, closeOnSelect, handleToggle] | ||
| ); | ||
|
|
||
| return ( | ||
| <Popover open={isOpen} onOpenChange={handleToggle}> | ||
| <Popover.Button className={cn("outline-none", buttonClassName)} disabled={disabled}> | ||
| {label} | ||
| </Popover.Button> | ||
| <Popover.Panel | ||
| positionerClassName="z-50" | ||
| className={cn( | ||
| "w-80 bg-custom-background-100 rounded-md border-[0.5px] border-custom-border-300 overflow-hidden", | ||
| dropdownClassName | ||
| )} | ||
| side={finalSide} | ||
| align={finalAlign} | ||
| sideOffset={8} | ||
| > | ||
| <div className="h-80 overflow-hidden overflow-y-auto"> | ||
| <EmojiRoot | ||
| onChange={handleEmojiChange} | ||
| searchPlaceholder={searchPlaceholder} | ||
| searchDisabled={searchDisabled} | ||
| /> | ||
| </div> | ||
| </Popover.Panel> | ||
| </Popover> | ||
| ); | ||
| }; | ||
32 changes: 32 additions & 0 deletions
32
packages/propel/src/emoji-reaction/emoji-reaction.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,32 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { EmojiReaction } from "./emoji-reaction"; | ||
|
|
||
| const meta: Meta<typeof EmojiReaction> = { | ||
| title: "EmojiReaction", | ||
| component: EmojiReaction, | ||
| parameters: { | ||
| layout: "centered", | ||
| }, | ||
| tags: ["autodocs"], | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof EmojiReaction>; | ||
|
|
||
| export const Single: Story = { | ||
| args: { | ||
| emoji: "👍", | ||
| count: 5, | ||
| reacted: false, | ||
| users: ["User 1", "User 2", "User 3"], | ||
| }, | ||
| }; | ||
|
|
||
| export const Reacted: Story = { | ||
| args: { | ||
| emoji: "❤️", | ||
| count: 12, | ||
| reacted: true, | ||
| users: ["User 1", "User 2", "User 3", "User 4", "User 5", "User 6"], | ||
| }, | ||
| }; |
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,182 @@ | ||
| import * as React from "react"; | ||
| import { Plus } from "lucide-react"; | ||
| import { AnimatedCounter } from "../animated-counter"; | ||
| import { stringToEmoji } from "../emoji-icon-picker"; | ||
| import { Tooltip } from "../tooltip"; | ||
| import { cn } from "../utils"; | ||
|
|
||
| export interface EmojiReactionType { | ||
| emoji: string; | ||
| count: number; | ||
| reacted?: boolean; | ||
| users?: string[]; | ||
| } | ||
|
|
||
| export interface EmojiReactionProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
| emoji: string; | ||
| count: number; | ||
| reacted?: boolean; | ||
| users?: string[]; | ||
| onReactionClick?: (emoji: string) => void; | ||
| className?: string; | ||
| showCount?: boolean; | ||
| size?: "sm" | "md" | "lg"; | ||
| } | ||
|
|
||
| export interface EmojiReactionGroupProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| reactions: EmojiReactionType[]; | ||
| onReactionClick?: (emoji: string) => void; | ||
| onAddReaction?: () => void; | ||
| className?: string; | ||
| showAddButton?: boolean; | ||
| maxDisplayUsers?: number; | ||
| size?: "sm" | "md" | "lg"; | ||
| } | ||
|
|
||
| export interface EmojiReactionButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
| onAddReaction?: () => void; | ||
| className?: string; | ||
| size?: "sm" | "md" | "lg"; | ||
| } | ||
|
|
||
| const sizeClasses = { | ||
| sm: { | ||
| button: "px-2 py-1 text-xs gap-1", | ||
| emoji: "text-sm", | ||
| count: "text-xs", | ||
| addButton: "h-6 w-6", | ||
| addIcon: "h-3 w-3", | ||
| }, | ||
| md: { | ||
| button: "px-2.5 py-1.5 text-sm gap-1.5", | ||
| emoji: "text-base", | ||
| count: "text-sm", | ||
| addButton: "h-7 w-7", | ||
| addIcon: "h-3.5 w-3.5", | ||
| }, | ||
| lg: { | ||
| button: "px-3 py-2 text-base gap-2", | ||
| emoji: "text-lg", | ||
| count: "text-base", | ||
| addButton: "h-8 w-8", | ||
| addIcon: "h-4 w-4", | ||
| }, | ||
| }; | ||
|
|
||
| const EmojiReaction = React.forwardRef<HTMLButtonElement, EmojiReactionProps>( | ||
| ( | ||
| { emoji, count, reacted = false, users = [], onReactionClick, className, showCount = true, size = "md", ...props }, | ||
| ref | ||
| ) => { | ||
| const sizeClass = sizeClasses[size]; | ||
|
|
||
| const handleClick = () => { | ||
| onReactionClick?.(emoji); | ||
| }; | ||
|
|
||
| const tooltipContent = React.useMemo(() => { | ||
| if (!users.length) return null; | ||
|
|
||
| const displayUsers = users.slice(0, 5); | ||
| const remainingCount = users.length - displayUsers.length; | ||
|
|
||
| return ( | ||
| <div className="text-xs"> | ||
| <div className="font-medium mb-1">{stringToEmoji(emoji)}</div> | ||
| <div> | ||
| {displayUsers.join(", ")} | ||
| {remainingCount > 0 && ` and ${remainingCount} more`} | ||
| </div> | ||
| </div> | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| }, [emoji, users]); | ||
|
|
||
| const button = ( | ||
| <button | ||
| ref={ref} | ||
| onClick={handleClick} | ||
| className={cn( | ||
| "inline-flex items-center rounded-full border transition-all duration-200 hover:scale-105", | ||
| "focus:outline-none focus:ring-2 focus:ring-custom-primary-100/20 focus:ring-offset-1", | ||
| sizeClass.button, | ||
| reacted | ||
| ? "bg-custom-primary-100/10 border-custom-primary-100 text-custom-primary-100" | ||
| : "bg-custom-background-100 border-custom-border-200 text-custom-text-300 hover:border-custom-border-300 hover:bg-custom-background-90", | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <span className={sizeClass.emoji}>{emoji}</span> | ||
| {showCount && count > 0 && <AnimatedCounter count={count} size={size} className={sizeClass.count} />} | ||
| </button> | ||
| ); | ||
|
|
||
| if (tooltipContent && users.length > 0) { | ||
| return <Tooltip tooltipContent={tooltipContent}>{button}</Tooltip>; | ||
| } | ||
|
|
||
| return button; | ||
| } | ||
| ); | ||
|
|
||
| const EmojiReactionButton = React.forwardRef<HTMLButtonElement, EmojiReactionButtonProps>( | ||
| ({ onAddReaction, className, size = "md", ...props }, ref) => { | ||
| const sizeClass = sizeClasses[size]; | ||
|
|
||
| return ( | ||
| <button | ||
| ref={ref} | ||
| onClick={onAddReaction} | ||
| className={cn( | ||
| "inline-flex items-center justify-center rounded-full border border-dashed border-custom-border-300", | ||
| "bg-custom-background-100 text-custom-text-400 transition-all duration-200", | ||
| "hover:border-custom-primary-100 hover:text-custom-primary-100 hover:bg-custom-primary-100/5", | ||
| "focus:outline-none focus:ring-2 focus:ring-custom-primary-100/20 focus:ring-offset-1", | ||
| sizeClass.addButton, | ||
| className | ||
| )} | ||
| title="Add reaction" | ||
| {...props} | ||
| > | ||
| <Plus className={sizeClass.addIcon} /> | ||
| </button> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| const EmojiReactionGroup = React.forwardRef<HTMLDivElement, EmojiReactionGroupProps>( | ||
| ( | ||
| { | ||
| reactions, | ||
| onReactionClick, | ||
| onAddReaction, | ||
| className, | ||
| showAddButton = true, | ||
| maxDisplayUsers = 5, | ||
| size = "md", | ||
| ...props | ||
| }, | ||
| ref | ||
| ) => ( | ||
| <div ref={ref} className={cn("flex flex-wrap items-center gap-2", className)} {...props}> | ||
| {reactions.map((reaction, index) => ( | ||
| <EmojiReaction | ||
| key={`${reaction.emoji}-${index}`} | ||
| emoji={reaction.emoji} | ||
| count={reaction.count} | ||
| reacted={reaction.reacted} | ||
| users={reaction.users?.slice(0, maxDisplayUsers)} | ||
| onReactionClick={onReactionClick} | ||
| size={size} | ||
| /> | ||
| ))} | ||
| {showAddButton && <EmojiReactionButton onAddReaction={onAddReaction} size={size} />} | ||
| </div> | ||
| ) | ||
| ); | ||
|
|
||
| EmojiReaction.displayName = "EmojiReaction"; | ||
| EmojiReactionButton.displayName = "EmojiReactionButton"; | ||
| EmojiReactionGroup.displayName = "EmojiReactionGroup"; | ||
|
|
||
| export { EmojiReaction, EmojiReactionButton, EmojiReactionGroup }; | ||
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,10 @@ | ||
| export { EmojiReaction, EmojiReactionGroup, EmojiReactionButton } from "./emoji-reaction"; | ||
| export type { | ||
| EmojiReactionProps, | ||
| EmojiReactionGroupProps, | ||
| EmojiReactionButtonProps, | ||
| EmojiReactionType, | ||
| } from "./emoji-reaction"; | ||
|
|
||
| export { EmojiReactionPicker } from "./emoji-reaction-picker"; | ||
| export type { EmojiReactionPickerProps } from "./emoji-reaction-picker"; |
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.
Uh oh!
There was an error while loading. Please reload this page.