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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 - Global Ripple #5778

Closed
waterplea opened this issue Oct 27, 2023 · 2 comments 路 Fixed by #5931
Closed

馃殌 - Global Ripple #5778

waterplea opened this issue Oct 27, 2023 · 2 comments 路 Fixed by #5931
Assignees
Labels
feature New feature or request P2 This issue has medium priority

Comments

@waterplea
Copy link
Collaborator

Description

We need a way to enable ripple globally. Probably through CSS selector list or something similar.

@waterplea waterplea added feature New feature or request P2 This issue has medium priority labels Oct 27, 2023
@MillerSvt
Copy link
Collaborator

MillerSvt commented Nov 6, 2023

I have two ideas:

1. Provide tuiGlobalRipple directive that will applied for tui-root, listen mutations, and apply ripple for given selector. Example:

<tui-root tuiGlobalRipple="button,a,.ripple" > ...

This solution allow to apply ripple for any elements (including custom projects elements). But we should develop this directive carefully, for avoid performance regression with large DOM trees.


2. Provide config that contain booleans for enable / disable ripple for certain TUI elements. Example:

@NgModule({
  ...
  providers: [
    ...
    tuiUseRipple({
      button: true,
      link: false,
      default: false,
    }),
  ],
})
export class AppModule {
}

I think this solution more reliable, because of we do not need to listen DOM mutations and care about performance issues. But it require apply directive for each component we want to add ripple.
Also I think, we should provide a way for customize configs, to add some custom components:

type TuiRippleKey = 'button' | 'link' /* ... */;

export interface TuiRippleConfig {
    default: boolean;
    
    [K: TuiRippleKey | string]: boolean
}

export declare function tuiApplyRipple(key: TuiRippleKey | string, element: ElementRef<HTMLElement> /* ... */): void;

// Example typing

const config: TuiRippleConfig = {
    default: true,
    button: false,
    link: true,
    test: false,
};

Developers can apply ripple to theirs components:

export class TestComponent {
  constructor(
    elementRef: ElementRef<HTMLElement>,
    /* ... */
  ) {
    tuiApplyRipple('test', elementRef);
  }
}

@waterplea
Copy link
Collaborator Author

We already have a directive that does the ripple effect. It relies on touchstart, touchend and touchmove events and I believe it should be quite performant, it uses RxJS but it could use some refactoring. We should rework it to PointerEvents so that it is not just touch, some people might want it for clicks too.

It listens to events on the ElementRef. Your idea with a new directive on tui-root is good. We can just call it tuiRipple and put into experimental package, deprecating the current one. Just need to think of a way to customize the color. As for global DI config, it would require a service of some kind which would need to be injected somewhere to start working. I guess directive is cleaner.

I believe we should allow passing the CSS selector rather than a config. It would just listen to all bubbled events inside our directive and when we believe it is time to initiate ripple we can just check for target.closest(OUR_CSS_SELECTORS) to find where we need to initiate it and skip it if it is null. That should not be a problem performance-wise as it will only traverse DOM with a fast native method once per pointerdown event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request P2 This issue has medium priority
Development

Successfully merging a pull request may close this issue.

2 participants