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

Svelte: Expose F7 instances through <slot> "let" props #3899

Closed
darrylyeo opened this issue Jun 3, 2021 · 2 comments
Closed

Svelte: Expose F7 instances through <slot> "let" props #3899

darrylyeo opened this issue Jun 3, 2021 · 2 comments

Comments

@darrylyeo
Copy link

darrylyeo commented Jun 3, 2021

Currently, we have to use bind:this along with .instance() to access the internal Framework7 API of several Svelte components. Example from the docs:

<Sheet bind:this={component}>...</Sheet>

<script>
  let component;

  // to get instance in some method
  component.instance()
</script>

I think this boilerplate can be reduced in many cases. I suggest we have the components directly pass the instance as a <slot> prop:

<!-- components/sheet.svelte -->

<script>
    ...
    f7Sheet = f7.sheet.create(params)
</script>

...

<slot sheet={f7Sheet} />

Then we can use the API like this:

<Sheet let:sheet>
    <Button onClick={() => sheet.close()}>Close</Button>
</Sheet>

This can apply to <Actions>, <Messagebar>, <Panel>, <PhotoBrowser>, <Popup>, <Searchbar>, <Sheet>, and many other interactive elements.

@darrylyeo
Copy link
Author

darrylyeo commented Jun 3, 2021

For even more flexibility, the components could also export let the instance e.g. export let f7Sheet so component users can do <Sheet bind:f7Sheet={sheet}>.

@darrylyeo
Copy link
Author

Fantastic! 🎉

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

No branches or pull requests

2 participants