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

use:popper action (instead of component based API) #1

Open
FezVrasta opened this issue Apr 20, 2020 · 2 comments
Open

use:popper action (instead of component based API) #1

FezVrasta opened this issue Apr 20, 2020 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@FezVrasta
Copy link
Member

FezVrasta commented Apr 20, 2020

The existing <Popper /> component doesn't feel right, it does absolutely nothing, if not allow the consumers to pass props down and retrieve the result.

The README example could be written as follows and everything would still work:

<Popper
  reference={referenceElement}
  popper={popperElement}
  options={popperOptions}
  bind:styles
  bind:attributes
/>

<button bind:this={referenceElement}>Reference Element</button>
<div
  bind:this={popperElement}
  class="tooltip"
  style={css(styles.popper)}
  {...attributes.popper}>
  Popper Element
  <div bind:this={arrowElement} class="arrow" style={css(styles.arrow)} />
</div>

A cleaner approach could be the use:action API.

<script>
  let styles = {};
  let attributes = {};
</script>

<button
  use:popper={{ popperElement, options }}
  on:popperUpdate={evt => {
    styles = evt.detail.styles;
    attributes = evt.detail.attributes;
  }}
>
  Reference Element
</button>

Here's a basic example:
https://codesandbox.io/s/trusting-butterfly-704gd?file=/popperAction.js

Thoughts?

@FezVrasta FezVrasta added the help wanted Extra attention is needed label Apr 20, 2020
@bryanmylee
Copy link

I just found out about this issue, and I’ve actually just published a package that uses two actions to attach Popper!

https://github.com/bryanmylee/svelte-popperjs

The idea is to wrap both actions in an object such that there is some shared state, then attach Popper there.

For my package, I have a createPopperActions function which returns two functions – refAction and popperAction, that are used on the reference and popper element.

popperAction takes the popper options config object, and while it doesn’t emit any event to update styles or attributes yet, that is definitely a possibility.

Perhaps that could be of some help!

@bryanmylee
Copy link

bryanmylee commented Jul 14, 2020

<script>
  import { createPopperActions } from ‘svelte-popperjs’;
  const [ popperRef, popperContent ] = createPopperActions();
</script>

<button use:popperRef>
  Reference Element
</button>
<div use:popperContent={{ placement: ‘right’ }}>
  Popper Element
</div>

Here’s an example of how my package is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants