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: Pass plugin values to Tippy props #152

Open
baleeds opened this issue Mar 5, 2024 · 7 comments
Open

Feature: Pass plugin values to Tippy props #152

baleeds opened this issue Mar 5, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@baleeds
Copy link

baleeds commented Mar 5, 2024

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[X] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

In Tippy, if you add a plugin, that plugin now accepts a value on the TippyProps matching that plugin name. Helipopper does allow adding plugins, but there doesn't appear to be a way to pass those plugin values into the TippyProps from the TippyDirective.

This means that the plugin strategy for Tippy is handicapped in a way that is preventing me from solving a problem.

Expected behavior

Ideally, there would be an input like [tpPluginValues]="{ myPlugin: 123 }" that would pass these values into the TippyProps. I do understand that there could be some annoyances if somebody names their plugin the same thing as a "core" tippy prop, but this is how the Tippy plugins work.

What is the motivation / use case for changing the behavior?

I'm trying to write a plugin for a "singletonGroup" which allows only one Tippy to be open per group key. I can't pass the group key into the plugin though. Plugins are useful for the maintainer of helipopper because people can extend the library with bespoke functionality.

Environment


Angular version: 17


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version:   
- Platform:  

Others:

@NetanelBasal
Copy link
Member

You're welcome to create a PR. We can use inputs or DI to pass it.

@NetanelBasal NetanelBasal added the enhancement New feature or request label Mar 6, 2024
@baleeds
Copy link
Author

baleeds commented Mar 6, 2024

I'm clear on how to use inputs to pass it in. Not sure how DI would work, could you explain a bit more before I get started?

Something like this?
https://github.com/ngneat/helipopper/blob/master/projects/ngneat/helipopper/src/lib/tippy.directive.ts#L99C5-L99C63

@NetanelBasal
Copy link
Member

The real question is whether you expect the plugin to apply globally to all instances or just a specific one?

@baleeds
Copy link
Author

baleeds commented Mar 6, 2024

Well, you can provide a default value for the plugin which would then apply globally. What I'm trying to do is create a plugin that exists for all instances, but only takes effect for instances that have a specific prop value.

Sort of like this code from the Tippy docs:

import tippy, {followCursor} from 'tippy.js';

tippy(targets, {
  followCursor: true,
  plugins: [followCursor],
});

In this scenario, you can provide the followCursor plugin but set followCursor to false and it wouldn't apply to this instance.

@NetanelBasal
Copy link
Member

So we could add the plugins at the config label and expose additional input that will apply it as in your example.

@baleeds
Copy link
Author

baleeds commented Mar 7, 2024

So we could add the plugins at the config label and expose additional input that will apply it as in your example.

Correct, that would be my aim.

The plugin values exist at the top level of the TippyProps. The structure of a TippyInstance looks like this:

{
    "id": 21,
    "popperInstance": ...,
    "state": ...,
    "props": {
    	"appendTo": body,
    	"delay": 300,
    	"followCursor": true,
    	...
    },
    ...
}

That means that the functionality in the TippyDirective is going to be spreading these "plugin" values into the tippy props directly. The question then becomes, should this @Input() be named something specific to plugins, or generic to tippy props?

Here's what the usage could look like:

<app-my-thing [tp]="tippyTemplate" [tpPluginValues]="{ followCursor: true }">

or

<app-my-thing [tp]="tippyTemplate" [tpTippyProps]="{ followCursor: true }">

@NetanelBasal
Copy link
Member

tpTippyProps If it goes to tippy props

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