-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add a callback for click link in link-dialog plugin. #335
Add a callback for click link in link-dialog plugin. #335
Conversation
demo code like: export const MdxEditor: React.FC<MdxEditorComponentProps> = ({ content, onEmitChange, onEmitOpen }) => {
const onChange = (aaa: string) => {
if (onEmitChange) onEmitChange(aaa)
}
const allPlugins = () => [
linkDialogPlugin({
onClickLinkCallback: (url: string) => {
onEmitOpen(url)
},
}),
]
return (
<MDXEditor
markdown={content}
onChange={onChange}
plugins={allPlugins()}
/>
)
}
|
Question for you: would it be easier if we have something like this: type LinkPreviewDialogClickHandler = React.MouseEventHandler<HTMLAnchorElement>
// ...
const onLinkPreviewDialogClick$ = Cell<LinkPreviewDialogClickHandler | null>(null)
// ...
<a href={linkDialogState.url} onClick={useCellValue(onLinkPreviewDialogClick$)} Then your code would look like: linkDialogPlugin({
onPreviewDialogLinkClick: (e) => {
e.preventDefault();
onEmitOpen(e.target.url);
},
}), Let me know if this makes sense. |
sorry, @petyosi I tred to use
If I chang it to Meybe just return a url string to callback funtion is more easier. |
🎉 This PR is included in version 2.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I updated your PR to follow the gurx pattern. Your previous implementation was overriding a module-level variable value. Take a look at how it works now - it's great that you're actively contributing to the project, so understanding the internal state management is going to be of good help. |
Add a callback for click link in link-dialog plugin.
So, developers can get the url that user clicked, and do some more actions.