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

SF-2193 Add bubble splash effect that can be added to various buttons #2013

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 171 additions & 21 deletions src/SIL.XForge.Scripture/ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/SIL.XForge.Scripture/ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"babel-loader": "^8.3.0",
"chromatic": "^6.17.3",
"codecov": "^3.8.3",
"css-loader": "^6.8.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecation": "^1.3.3",
Expand All @@ -140,7 +141,9 @@
"prettier": "^2.6.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass-loader": "^13.3.2",
"storybook": "^7.0.18",
"style-loader": "^3.3.3",
"ts-mockito": "^2.6.1",
"ts-node": "^10.7.0",
"typescript": "~4.8.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable @angular-eslint/directive-selector */
import { Directive, ElementRef, OnInit, Renderer2 } from '@angular/core';

/**
* Directive to add bubble animation to a button. Inspired by https://codepen.io/nourabusoud/pen/ypZzMM,
* but modified to use an inner `<span>` to attach the pseudo elements to so as not to conflict
* with other styles or components that use `::before` or `::after` such as Angular Material components.
*/
@Directive({
selector: '[sfBubbleButton]'
})
export class BubbleButtonDirective implements OnInit {
cssInnerSpanStyleClass = 'sf-bubble-button-elements';
cssButtonStyleClass = 'sf-bubble-button';
cssButtonAnimationClass = 'sf-bubble-animate';

constructor(private readonly el: ElementRef, private readonly renderer: Renderer2) {}

ngOnInit(): void {
const hostElement = this.el.nativeElement;
const innerSpan = this.renderer.createElement('span');

// Add inner span to host element
this.renderer.addClass(innerSpan, this.cssInnerSpanStyleClass);
this.renderer.appendChild(hostElement, innerSpan);

// Add class and click listener to host element
this.renderer.addClass(hostElement, this.cssButtonStyleClass);
this.renderer.listen(hostElement, 'click', () => {
// Add animation class to inner span
this.addAnimationClass(innerSpan);
});
}

// Adds animation class to the element and removes it after animation is complete
addAnimationClass(el: any): void {
// Reset animation
el.classList.remove(this.cssButtonAnimationClass);

// Timeout needed to restart animation
setTimeout(() => {
el.classList.add(this.cssButtonAnimationClass);
}, 10);
}
}
Loading