-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add copy function #118
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
Conversation
| {props.getActionsComponent(props.message)} | ||
| </Card> | ||
| )} | ||
| {props.getActionsComponent && props.getActionsComponent(props.message)} |
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.
This should not be changed. The component is expected to be several supported actions. Styling should be set here for the container.
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.
If we want to have the border in the messageCanvas, we need to hide it when no button is returned by props.getActionsComponent. Is it ok that I change the type of getActionsComponent from (message: ThreadableMessage) => ReactNode to (message: ThreadableMessage) => ReactNode | undefined?
| if (message.data.text) { | ||
| navigator.clipboard.writeText(message.data.text) | ||
| } |
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.
I think we should indicate the text was copied using tooltip or something similar
| .then(() => { | ||
| setTooltipContent('Copied') | ||
| setTimeout(() => { | ||
| setTooltipContent('Copy') |
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.
| setTooltipContent('Copy') | |
| setTooltipContent('Copy Text') |
| description: { | ||
| component: | ||
| 'The `Message Canvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.', | ||
| 'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. The examples of actions are listed below:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.', |
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.
"The examples of actions are listed below:" > "Listed below are actions you can import from the library to use in your application:"
Or something similar or mentioned somewhere that let's people know we've exposed this action.
| 'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. The examples of actions are listed below:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.', | |
| 'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. Listed below are actions you can import from the library to use in your application:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.', |
| message: ThreadableMessage | ||
| } | ||
|
|
||
| export default function Copy(props: CopyProps) { |
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.
Should we rename this to CopyText instead?
| export default function Copy(props: CopyProps) { | |
| export default function CopyText(props: CopyProps) { |
| /** A function that returns a single React element which contains message actions. For example, this could be a list of buttons for different actions (e.g. copy, delete, save, etc.). The function may also return no element if no actions are applicable or available for a particular message. */ | ||
| getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined |
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.
| /** A function that returns a single React element which contains message actions. For example, this could be a list of buttons for different actions (e.g. copy, delete, save, etc.). The function may also return no element if no actions are applicable or available for a particular message. */ | |
| getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined | |
| /** A function that returns a single React element which may be composed of several actions supported for the message, such as editing, copying, and deleting, etc. | |
| * In case no actions are applicable or available for a particular message, the function may return `undefined`. | |
| * This approach offers flexibility in tailoring message interactions to specific application requirements. | |
| * To define individual message actions, developers can extend the `Action` component's functionality. | |
| * One such example is the CopyText component. | |
| */ | |
| getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined |
| getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined | ||
| } | ||
|
|
||
| export default function MessageCanvas(props: MessageCanvasProps) { |
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.
| export default function MessageCanvas(props: MessageCanvasProps) { | |
| /** | |
| The `MessageCanvas` component serves as a container for displaying messages within a chat interface. | |
| It provides a structured layout for rendering message content along with sender information and timestamp details. | |
| This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application. | |
| */ | |
| export default function MessageCanvas(props: MessageCanvasProps) { |
| tags: ['autodocs'], | ||
| parameters: { | ||
| layout: 'centered', | ||
| docs: { |
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.
I think we should not use this and instead write JsDoc Comments for the component as recommended on Storybook docs
We recommend using JSDoc comments for descriptions, and only use the parameters.docs.description.X properties in situations where comments are not possible to write for some reason, or where you want the description shown in Storybook to be different from the comments. Comments provide a better writing experience as you don’t have to worry about indentation, and they are more discoverable for other developers that are exploring the story/component sources.
https://storybook.js.org/docs/api/doc-block-description#writing-descriptions
| }, | ||
| } | ||
|
|
||
| const baseMessage = { |
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.
I notice a lot of duplicate code in the stories here, is it possible to clean it up using the constants/variables defined here.
| import Copy from '../messageCanvas/actions/copy/copy' | ||
| import MessageSpace from './messageSpace' | ||
|
|
||
| export default { |
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.
Adding description here for each field is not required if we use JsDoc Comments. We can also avoid duplicate things if we define an interface for the shared props between MessageSpace and MessageCanvas, for example,
export interface MessageContainerProps {
/** Profile icon to be shown before sender's name. */
getProfileComponent?: (message: ThreadableMessage) => ReactNode
/** A function that returns a single React element which may be composed of several actions supported for the message, such as editing, copying, and deleting, etc.
* In case no actions are applicable or available for a particular message, the function may return `undefined`.
* This approach offers flexibility in tailoring message interactions to specific application requirements.
* To define individual message actions, developers can extend the `Action` component's functionality.
* One such example is the CopyText component.
*/
getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined
}
export interface MessageCanvasProps extends MessageContainerProps {
/** Message information to be displayed. Please see the `MessageSpace` docs for more information about the `ThreadableMessage` interface. */
message: ThreadableMessage
/** React component to be displayed in the message canvas. */
children: ReactNode
}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.
I will extend MessageContainerProps, but we still need to provide details about ThreadableMessage for messages field
Changes
(I added a note in the
MessageSpace's story and asked people to refer toMessageCanvasfor the usage ofgetActionsComponentandgetProfileComponent. It's showing()={}right now in theMessageSpace's stories. I thought about overwriting the original code, but the message array is quite long and we will have a lot of duplicate code.Screenshots
Video