feat(Reactions): added new Reactions component#197
Conversation
|
Preview is ready. |
|
@Ruminat Let's simplify the API, currently it looks a bit hard to understand and it stores the state in multiple places ( // Do not extend whole PaletteOption, only pick needed props. This makes refactor easier
interface ReactionsItem extends Pick<PaletteOption, 'value' | 'content' | 'title'> {
count: number;
selected?: boolean;
}
interface ReactionsProps {
// This would map into Palette props (options and value depending on selected states) and create buttons if count > 0
reactions: ReactionsItem[];
// User should handle this callback and change reactions array
onToggle?: (reaction: ReactionsItem) => void;
// Extract tooltip render to dedicated prop and pass whole reaction item
// No other tooltip props needed for the sake of simplicty
renderTooltipContent?: (reaction: ReactionsItem) => React.ReactNode;
// Keep only columns. Other Palette props are useless
columns?: number;
// Rest props
// ...
}The only source of state is now the |
Yeah, I like that solution, I'll change the code accordingly |
|
@amje I started implementing your solution and encountered a problem: let's say you have three reactions: 😊, 👍 and 😢 So I guess we have to use 2 states here |
|
I've also noticed this comment: // Extract tooltip render to dedicated prop and pass whole reaction item
// No other tooltip props needed for the sake of simplictyTooltip is a little bit harder than just rendering content, tooltip has the following type: export interface ReactionTooltipProps
extends Pick<PopoverProps, 'strategy' | 'placement' | 'modifiers'> {
/**
* Tooltip's content.
*/
content: React.ReactNode;
/**
* Tooltip content's HTML class attribute.
*/
className?: string;
/**
* Fires when the `onMouseLeave` callback is called.
* Usage example:
* you have some popup inside a tooltip, you hover on it, you don't want the tooltip to be closed because of that.
*/
canClosePopup?: () => boolean;
}
|
|
@amje ping |
1 similar comment
|
@amje ping |
@Ruminat Don't see a problem here. Having predefined order is good. GitHub reactions work exactly like so |
You are trying to fix those issues implementing extra stuff in the component that not needed. It's better to have simple and robust API that would work predictable. |
|
@amje I simplified |
|
@amje ping |
|
@Ruminat As we discussed eariler, let's implement the following API: interface Reaction {
value: string; // Unique identifier of reaction
content: React.ReactNode; // Reaction's content
title?: string; // Alternative content via browser's tooltip
}
interface ReactionState {
value: string;
selected?: boolean;
count?: number;
}
interface ReactionsProps extends QAProps, DOMProps {
reactions: Reaction[]; // <-- Keep all data in single array
reactionsState?: ReactionState[]; // <-- Keep all state in place
onToggle?: (value: string) => void; // User should update reactionsState in this callback
// Other props
readOnly?: boolean; // Instead of disabling buttons and coloring them to gray we hide palette trigger and ignore hover/click events
paletteProps?: Pick<PaletteProps, 'columns' | 'rowClassName' | 'optionClassName'> // Only pick props related to view
}It's robust, simple and easy to understand. |
|
@amje I implemented your suggested API |
|
@amje I also added
What do you think? |
|
I also added myself as owner of |
|
@amje ping |
1 similar comment
|
@amje ping |
|
@amje ping |
1 similar comment
|
@amje ping |
|
@amje ping |
Reactions component
A component for managing users' reactions: