Skip to content

Commit

Permalink
feat(blog): icon to share article by url (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
majahendzel-va committed Jul 22, 2024
1 parent 3c3af74 commit 419b04c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 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,8 +1,9 @@
import { Component, computed, input } from '@angular/core';
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
import { Component, computed, input, signal } from '@angular/core';
import { TranslocoDirective } from '@jsverse/transloco';
import { FastSvgComponent } from '@push-based/ngx-fast-svg';

import { IconComponent, IconType } from '@angular-love/blog/shared/ui-icon';
import { IconType } from '@angular-love/blog/shared/ui-icon';

type ShareItem = {
href: string;
Expand All @@ -13,16 +14,16 @@ type ShareItem = {
@Component({
standalone: true,
selector: 'al-article-share-icons',
imports: [IconComponent, TranslocoDirective, FastSvgComponent],
imports: [TranslocoDirective, FastSvgComponent, CdkCopyToClipboard],
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,19 +32,46 @@ type ShareItem = {
<fast-svg class="text-al-foreground" [name]="item.icon" size="28" />
</a>
}
<a
role="button"
[attr.aria-label]="t('articleShareIcons.urlAriaLabel')"
[class.url-icon-animated]="animating()"
[cdkCopyToClipboard]="articleUrl()"
(click)="animating.set(true)"
(animationend)="animating.set(false)"
target="_blank"
>
<fast-svg
name="link"
class="text-al-foreground"
[class.!hidden]="animating()"
size="28"
/>
<fast-svg
name="circle-check"
class="text-al-foreground"
[class.!hidden]="!animating()"
size="28"
/>
</a>
</div>
`,
})
export class ArticleShareIconsComponent {
slug = input.required<string>();
title = input.required<string>();
language = input.required<string>();
readonly slug = input.required<string>();
readonly title = input.required<string>();
readonly language = input.required<string>();

readonly animating = signal(false);

readonly articleUrl = computed(() =>
this.language() === 'pl_PL'
? `https://angular.love/${this.slug()}`
: `https://angular.love/en/${this.slug()}`,
);

readonly items = computed<ShareItem[]>(() => {
const url =
this.language() === 'pl_PL'
? `https://angular.love/${this.slug()}`
: `https://angular.love/en/${this.slug()}`;
const url = this.articleUrl();
const text = encodeURIComponent(this.title());

return [
Expand Down

0 comments on commit 419b04c

Please sign in to comment.