Skip to content
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

feat(example): Copy svg to clipboard #4

Merged
merged 4 commits into from
Feb 28, 2021
Merged

feat(example): Copy svg to clipboard #4

merged 4 commits into from
Feb 28, 2021

Conversation

miles-crighton
Copy link
Contributor

Thanks a bunch for developing this super fun library. While using your repo's example app for a recent project of mine I needed to copy the drawn svg element into Sketch to build out a design.

I thought it'd be super handy to have a copy to clipboard button so that you can copy and paste directly into a design tool like Figma/Sketch. Check out a gif below.

copy-to-clipboard

I tried to make the feature code idiomatic of how you've been building it using your state library (a neat little rabbit hole of investigation) while making sure not to add any extra dependencies.

I wasn't sure precisely whether I could include the async util fn for clipboard copying to the createState object. First I tried simply putting it an action but the proxy to the data was revoked. I then tried using the asyncs example in the docs, but couldn't figure out how to directly invoke the async function using on event chains.

So, I settled on just dispatching the action after the async clipboard utility returned the appropriate message.

I also created a small accessible alert component for letting the user know the result of the copy request. It color adjusts appropriately for light and dark mode.

Hopefully this might be of interest for adding to the example, let me know. If not, thanks again for building these libraries. 👍

@steveruizok
Copy link
Owner

This is excellent! I've improved the copy function a bit so that it clips down to just the current viewBox (with some padding). Otherwise looks great, thank you!

@steveruizok steveruizok merged commit 8766982 into steveruizok:main Feb 28, 2021
@miles-crighton
Copy link
Contributor Author

Neat changes, thanks for merging! 👍

@steveruizok
Copy link
Owner

Also, congrats for giving the state management a try—the docs are somewhat lacking, especially around async stuff. If you're still interested in seeing how it would be done, I'll bring it into the state machine so that we can call it from a keyboard shortcut, too.

@miles-crighton
Copy link
Contributor Author

That'd be great, I was messing around with it for a little while so it'd be cool to see how you'd do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants