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

Feature Request: Svelte support #93

Open
VisionaryAppDev opened this issue Jul 21, 2022 · 3 comments
Open

Feature Request: Svelte support #93

VisionaryAppDev opened this issue Jul 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@VisionaryAppDev
Copy link

Hello everyone,
I have tried this package before on NuxtJS and it's working perfect. I do like it a lot and thinking of using this package again with SvelteKit, but it seem like it isn't supported at the moment. So, will img-comparison-slider support Svelte anything soon? Or is there a way I can make it working with Svelte at the moment? Thanks.

@sneas
Copy link
Owner

sneas commented Jul 22, 2022

Hi @VisionaryAppDev, it seems like img-comparison-slider somewhat works in Svelte out of the box. By somewhat I mean it doesn't support any component's attribute except "value". I guess there is something to do with the Svelte's attribute binding system. But there is a way to set custom attribute via bind:this. Check out the example I created https://github.com/sneas/img-comparison-slider-svelte

The trick is:

  1. Install img-comparison-slider https://github.com/sneas/img-comparison-slider-svelte/blob/main/package.json#L21
  2. Import img-comparison-slider in main.js https://github.com/sneas/img-comparison-slider-svelte/blob/main/src/main.js#L2
  3. Use the component https://github.com/sneas/img-comparison-slider-svelte/blob/main/src/App.svelte#L16-L27

Pay attention how I set up custom direction attribute with the help of the binder and onMount function. You might want to do the same for other attributes if needed.

@sneas sneas added the enhancement New feature or request label Jul 22, 2022
@VisionaryAppDev
Copy link
Author

Thank a lot @sneas. From your trick, I have managed to get it working with SvelteKit now.

custom attribute via bind:this

For SvelteKit, I could assign it directly. Not sure if it is a SvelteKit thing as I am also new to Svelte. Please check it here https://github.com/VisionaryAppDev/img-comparison-slider-svelte-kit/blob/master/src/routes/index.svelte

@sneas
Copy link
Owner

sneas commented Jul 22, 2022

Looks great, @VisionaryAppDev. I'm happy your way is working because it seems cleaner. I'm also new to Svelte :)

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

No branches or pull requests

2 participants