Skip to content

Commit

Permalink
feat(blog): icon to share article by url
Browse files Browse the repository at this point in the history
  • Loading branch information
majahendzel-va committed Jul 17, 2024
1 parent d175132 commit 1554a7c
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
3 changes: 2 additions & 1 deletion apps/blog/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"title": "Share this post",
"twitterAriaLabel": "Share on Twitter",
"facebookAriaLabel": "Share on Facebook",
"linkedInAriaLabel": "Share on LinkedIn"
"linkedInAriaLabel": "Share on LinkedIn",
"urlAriaLabel": "Copy URL"
},
"dynamicTextClamp": {
"readMore": "Read more",
Expand Down
3 changes: 2 additions & 1 deletion apps/blog/src/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"title": "Podziel się artykułem",
"twitterAriaLabel": "Udostępnij na Twitterze",
"facebookAriaLabel": "Udostępnij na Facebooku",
"linkedInAriaLabel": "Udostępnij na LinkedIn"
"linkedInAriaLabel": "Udostępnij na LinkedIn",
"urlAriaLabel": "Skopiuj URL"
},
"dynamicTextClamp": {
"readMore": "Czytaj więcej",
Expand Down
1 change: 1 addition & 0 deletions apps/blog/src/assets/icons/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.url-icon-animated {
animation: icon 1s forwards;
animation-iteration-count: 1;
}

@keyframes icon {
0% {
transform: scale(1);
}
50% {
transform: scale(0.8);
}
100% {
transform: scale(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { Component, computed, input } from '@angular/core';
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
import { NgClass } from '@angular/common';
import {
Component,
computed,
ElementRef,
inject,
input,
Renderer2,
signal,
viewChild,
} from '@angular/core';
import { TranslocoDirective } from '@jsverse/transloco';
import { FastSvgComponent } from '@push-based/ngx-fast-svg';

Expand All @@ -13,16 +24,22 @@ type ShareItem = {
@Component({
standalone: true,
selector: 'al-article-share-icons',
imports: [IconComponent, TranslocoDirective, FastSvgComponent],
imports: [
IconComponent,
TranslocoDirective,
FastSvgComponent,
CdkCopyToClipboard,
NgClass,
],
styleUrls: ['./article-share-icons.component.scss'],
template: `
<div class="flex items-center gap-4">
<span *transloco="let t" class="text-lg font-bold">
<div *transloco="let t" class="flex items-center gap-4">
<span class="text-lg font-bold">
{{ t('articleShareIcons.title') }}
</span>
@for (item of items(); track $index) {
<a
*transloco="let t"
role="button"
[attr.aria-label]="t(item.ariaLabel)"
[href]="item.href"
Expand All @@ -31,6 +48,24 @@ type ShareItem = {
<fast-svg class="text-al-foreground" [name]="item.icon" size="28" />
</a>
}
<a
#copyUrlIcon
role="button"
[attr.aria-label]="t('articleShareIcons.urlAriaLabel')"
[cdkCopyToClipboard]="window.location.href"
(click)="onCopyUrl()"
target="_blank"
>
@if (!isCopyUrlClicked()) {
<fast-svg class="text-al-foreground" [name]="'link'" size="28" />
} @else {
<fast-svg
class="text-al-foreground"
[name]="'circle-check'"
size="28"
/>
}
</a>
</div>
`,
})
Expand All @@ -39,6 +74,12 @@ export class ArticleShareIconsComponent {
title = input.required<string>();
language = input.required<string>();

isCopyUrlClicked = signal(false);
copyUrlIcon = viewChild<ElementRef>('copyUrlIcon');

protected readonly window = window;
private renderer = inject(Renderer2);

readonly items = computed<ShareItem[]>(() => {
const url =
this.language() === 'pl_PL'
Expand All @@ -64,4 +105,27 @@ export class ArticleShareIconsComponent {
},
];
});

onCopyUrl(): void {
this.isCopyUrlClicked.set(true);

if (this.copyUrlIcon()) {
this.renderer.addClass(
this.copyUrlIcon()?.nativeElement,
'url-icon-animated',
);
const handleAnimationEnd = () => {
this.isCopyUrlClicked.set(false);
this.renderer.removeClass(
this.copyUrlIcon()?.nativeElement,
'url-icon-animated',
);
};
this.renderer.listen(
this.copyUrlIcon()?.nativeElement,
'animationend',
handleAnimationEnd,
);
}
}
}
3 changes: 2 additions & 1 deletion libs/blog/shared/ui-icon/src/lib/icon/icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type IconType =
| 'send'
| 'tick'
| 'twitter-x'
| 'youtube';
| 'youtube'
| 'link';

@Component({
selector: 'al-icon',
Expand Down

0 comments on commit 1554a7c

Please sign in to comment.