Skip to content

Commit 4fa9063

Browse files
authored
feat(docs): added "new" section badge in sidenav (#DS-3386) (#662)
1 parent ea8576c commit 4fa9063

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

apps/docs/src/app/components/sidenav/sidenav.component.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
</kbq-tree-option>
2828

2929
<kbq-tree-option *kbqTreeNodeDef="let node" class="docs-sidenav__item">
30-
{{ node.name[locale()] }}
30+
<div class="layout-row layout-align-start-center">
31+
<div class="layout-margin-right-s">
32+
{{ node.name[locale()] }}
33+
</div>
34+
35+
@if (node.isNew) {
36+
<kbq-badge badgeColor="fade-theme" [compact]="true" [outline]="true">New</kbq-badge>
37+
}
38+
</div>
3139
</kbq-tree-option>
3240
</kbq-tree-selection>
3341
</div>

apps/docs/src/app/components/sidenav/sidenav.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Location, ViewportScroller } from '@angular/common';
22
import { AfterViewInit, ChangeDetectionStrategy, Component, inject, ViewChild, ViewEncapsulation } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { Router, RouterLink } from '@angular/router';
5+
import { KbqBadgeModule } from '@koobiq/components/badge';
56
import { KbqDividerModule } from '@koobiq/components/divider';
67
import { KbqIconModule } from '@koobiq/components/icon';
78
import { KbqScrollbar, KbqScrollbarModule } from '@koobiq/components/scrollbar';
@@ -28,7 +29,8 @@ class TreeNode {
2829
public id: string,
2930
public children: TreeNode[] | null,
3031
public name: Record<DocsLocale, string>,
31-
public type: TreeNodeType
32+
public type: TreeNodeType,
33+
public isNew: boolean = false
3234
) {}
3335
}
3436

@@ -40,6 +42,7 @@ class TreeFlatNode {
4042
expandable: boolean;
4143
parent: any;
4244
type: TreeNodeType;
45+
isNew: boolean;
4346
}
4447

4548
function buildTree(categories: DocCategory[]): TreeNode[] {
@@ -49,7 +52,7 @@ function buildTree(categories: DocCategory[]): TreeNode[] {
4952
data.push(
5053
new TreeNode(
5154
id,
52-
items.map((item) => new TreeNode(item.id, null, item.name, TreeNodeType.Item)),
55+
items.map((item) => new TreeNode(item.id, null, item.name, TreeNodeType.Item, item.isNew)),
5356
name,
5457
TreeNodeType.Category
5558
)
@@ -68,7 +71,8 @@ function buildTree(categories: DocCategory[]): TreeNode[] {
6871
KbqDividerModule,
6972
DocsFooterComponent,
7073
KbqScrollbarModule,
71-
RouterLink
74+
RouterLink,
75+
KbqBadgeModule
7276
],
7377
selector: 'docs-sidenav',
7478
templateUrl: './sidenav.component.html',
@@ -166,6 +170,7 @@ export class DocsSidenavComponent extends DocsLocaleState implements AfterViewIn
166170
flatNode.type = node.type;
167171
flatNode.level = level;
168172
flatNode.expandable = !!node.children;
173+
flatNode.isNew = node.isNew;
169174

170175
return flatNode;
171176
};

apps/docs/src/app/services/documentation-items.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { Injectable } from '@angular/core';
2+
import { DateTime } from 'luxon';
23
import { DocsLocale } from '../constants/locale';
34

5+
const expiresAt = (expiresAt: string) => {
6+
const createdDate = DateTime.fromISO(expiresAt);
7+
if (!createdDate.isValid) {
8+
throw new Error(createdDate.invalidReason);
9+
}
10+
return createdDate.diffNow('days').days > 0;
11+
};
12+
413
export type DocItem = {
514
id: string;
615
name: Record<DocsLocale, string>;
@@ -10,6 +19,11 @@ export type DocItem = {
1019
apiId?: string;
1120
svgPreview?: string;
1221
packageName?: string;
22+
/**
23+
* Indicates whether documentation item as "new".
24+
* Determined by comparing the current date with expiration date.
25+
*/
26+
isNew?: boolean;
1327
};
1428

1529
export type DocCategory = {
@@ -147,7 +161,8 @@ const DOCS: { [key: string]: DocCategory[] } = {
147161
},
148162
svgPreview: 'ag-grid',
149163
hasApi: false,
150-
hasExamples: false
164+
hasExamples: false,
165+
isNew: expiresAt('2025-05-04')
151166
},
152167
{
153168
id: 'alert',
@@ -246,7 +261,8 @@ const DOCS: { [key: string]: DocCategory[] } = {
246261
svgPreview: '',
247262
hasApi: true,
248263
apiId: 'core',
249-
hasExamples: false
264+
hasExamples: false,
265+
isNew: expiresAt('2025-05-04')
250266
},
251267
{
252268
id: 'datepicker',

0 commit comments

Comments
 (0)