Skip to content

Commit c70bb79

Browse files
feat(blog): tooltip for difficulty level (#298)
1 parent bc5383b commit c70bb79

File tree

17 files changed

+309
-4
lines changed

17 files changed

+309
-4
lines changed

apps/blog/src/assets/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@
9191
"difficulty": {
9292
"beginner": "Beginner",
9393
"intermediate": "Intermediate",
94-
"advanced": "Advanced"
94+
"advanced": "Advanced",
95+
"tooltipBeginner": "Fundamental concepts, basic syntax, and simple projects.",
96+
"tooltipIntermediate": "More complex features, intermediate concepts, performance, and best practices.",
97+
"tooltipAdvanced": "Advanced topics, architecture, scalability, and professional development practices."
9598
},
9699
"tableOfContents": {
97100
"title": "Table of Contents"

apps/blog/src/assets/i18n/pl.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@
9494
"difficulty": {
9595
"beginner": "Początkujący",
9696
"intermediate": "Średnio zaawansowany",
97-
"advanced": "Zaawansowany"
97+
"advanced": "Zaawansowany",
98+
"tooltipBeginner": "Podstawowe pojęcia, podstawowa składnia oraz proste projekty.",
99+
"tooltipIntermediate": "Bardziej zaawansowane funkcje, performance oraz najlepsze praktyki.",
100+
"tooltipAdvanced": "Jeżeli jest potrzebna jeszcze jakaś informacja czy design, proszę o znak"
98101
},
99102
"tableOfContents": {
100103
"title": "Spis treści"

apps/blog/src/styles.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
@use '@angular/cdk';
22
@include cdk.a11y-visually-hidden();
3+
4+
@import '@angular/cdk/overlay-prebuilt.css';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { inject, Pipe, PipeTransform } from '@angular/core';
2+
import { TranslocoService } from '@jsverse/transloco';
3+
import { map, Observable } from 'rxjs';
4+
5+
@Pipe({
6+
name: 'difficultyLevelTooltip',
7+
standalone: true,
8+
})
9+
export class DifficultyLevelPipe implements PipeTransform {
10+
private readonly _translocoService = inject(TranslocoService);
11+
transform(difficultyLevel: number): Observable<string> {
12+
return this._translocoService.langChanges$.pipe(
13+
map(() => {
14+
switch (difficultyLevel) {
15+
case 0:
16+
return this._translocoService.translate(
17+
'difficulty.tooltipBeginner',
18+
);
19+
case 1:
20+
return this._translocoService.translate(
21+
'difficulty.tooltipIntermediate',
22+
);
23+
case 2:
24+
return this._translocoService.translate(
25+
'difficulty.tooltipAdvanced',
26+
);
27+
default:
28+
return this._translocoService.translate(
29+
'difficulty.tooltipIntermediate',
30+
);
31+
}
32+
}),
33+
);
34+
}
35+
}

libs/blog/shared/ui-difficulty/src/lib/ui-difficulty.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgClass } from '@angular/common';
1+
import { AsyncPipe, NgClass } from '@angular/common';
22
import {
33
ChangeDetectionStrategy,
44
Component,
@@ -7,14 +7,20 @@ import {
77
} from '@angular/core';
88
import { TranslocoDirective } from '@jsverse/transloco';
99

10+
import { TooltipDirective } from '@angular-love/ui-tooltip';
11+
12+
import { DifficultyLevelPipe } from './difficulty-level.pipe';
13+
1014
export type UiDifficulty = 'beginner' | 'intermediate' | 'advanced';
1115

1216
@Component({
1317
selector: 'al-difficulty',
1418
standalone: true,
1519
template: `
1620
<div
21+
alTooltip
1722
class="text-al-foreground/90 flex items-center overflow-hidden text-sm"
23+
[tooltipText]="difficultyLevel() | difficultyLevelTooltip | async"
1824
>
1925
<!-- Left Block -->
2026
<div
@@ -78,7 +84,13 @@ export type UiDifficulty = 'beginner' | 'intermediate' | 'advanced';
7884
</div>
7985
`,
8086
changeDetection: ChangeDetectionStrategy.OnPush,
81-
imports: [NgClass, TranslocoDirective],
87+
imports: [
88+
NgClass,
89+
TranslocoDirective,
90+
TooltipDirective,
91+
DifficultyLevelPipe,
92+
AsyncPipe,
93+
],
8294
})
8395
export class UiDifficultyComponent {
8496
readonly difficulty = input.required<UiDifficulty>();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "al",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "al",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ui-tooltip
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test ui-tooltip` to execute the unit tests.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'ui-tooltip',
4+
preset: '../../../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../../../coverage/libs/blog/shared/ui-tooltip',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "ui-tooltip",
3+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/blog/shared/ui-tooltip/src",
5+
"prefix": "al",
6+
"projectType": "library",
7+
"tags": ["scope:client", "type:ui"],
8+
"targets": {
9+
"test": {
10+
"executor": "@nx/jest:jest",
11+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
12+
"options": {
13+
"jestConfig": "libs/blog/shared/ui-tooltip/jest.config.ts"
14+
}
15+
},
16+
"lint": {
17+
"executor": "@nx/eslint:lint"
18+
}
19+
}
20+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/ui-tooltip/ui-tooltip.component';
2+
export * from './lib/ui-tooltip/tooltip.directive';

0 commit comments

Comments
 (0)