Skip to content

Commit 00ed925

Browse files
griest024xelaint
andauthored
feat(dgeni): add deprecated field to API doc (#3543)
--------- Co-authored-by: xelaint <xelaint@gmail.com>
1 parent e78100d commit 00ed925

10 files changed

Lines changed: 169 additions & 2 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
@use 'sass:map';
2+
@use 'theme' as daff-theme;
3+
@use 'utilities' as daff;
4+
5+
// stylelint-disable selector-class-pattern
6+
@mixin type-theming($color, $opacity: 0.1) {
7+
background: rgba($color, $opacity);
8+
color: $color;
9+
}
10+
11+
@mixin daffio-api-item-label-theme($theme) {
12+
$primary: daff-theme.daff-map-get($theme, primary);
13+
$secondary: daff-theme.daff-map-get($theme, secondary);
14+
$tertiary: daff-theme.daff-map-get($theme, tertiary);
15+
$critical: daff-theme.daff-map-get($theme, critical);
16+
$base: daff-theme.daff-map-get($theme, 'core', 'base');
17+
$base-contrast: daff-theme.daff-map-get(
18+
daff-theme.$theme,
19+
'core',
20+
'base-contrast'
21+
);
22+
$type: daff-theme.daff-map-get($theme, 'core', 'type');
23+
24+
.daffio-docs-api-item-label {
25+
&.class {
26+
@include type-theming(daff-theme.daff-color($primary));
27+
}
28+
29+
&.type-alias {
30+
@include type-theming(daff-theme.daff-color($secondary));
31+
}
32+
33+
&.interface {
34+
@include type-theming(daff-theme.daff-color($tertiary));
35+
}
36+
37+
&.const {
38+
@include type-theming(
39+
daff-theme.daff-illuminate($base-contrast, $secondary, 3)
40+
);
41+
}
42+
43+
&.enum {
44+
@include type-theming(
45+
daff-theme.daff-illuminate($base-contrast, $primary, 3)
46+
);
47+
}
48+
49+
&.package {
50+
@include type-theming(
51+
daff-theme.daff-illuminate($base-contrast, daff-theme.$daff-yellow, 3)
52+
);
53+
}
54+
55+
&.function {
56+
@include type-theming(
57+
daff-theme.daff-illuminate($base-contrast, $tertiary, 3)
58+
);
59+
}
60+
61+
&.deprecated {
62+
@include daff-theme.light($type) {
63+
@include type-theming(daff-theme.daff-color($critical, 70));
64+
}
65+
66+
@include daff-theme.dark($type) {
67+
@include type-theming(daff-theme.daff-color($critical, 40), 0.15);
68+
}
69+
}
70+
}
71+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@use '../../../../../scss/type-descriptors/mixins' as type-mixin;
2+
@use 'utilities' as daff;
3+
4+
:host {
5+
display: block;
6+
border-radius: 0.25rem;
7+
font-family: daff.$font-family-mono;
8+
font-size: 0.625rem;
9+
line-height: 0.875rem;
10+
padding: 0.25rem 0.5rem;
11+
text-transform: uppercase;
12+
}
13+
14+
15+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
HostBinding,
5+
Input,
6+
} from '@angular/core';
7+
8+
export type DaffioDocsApiItemLabelType = 'class' | 'type-alias' | 'interface' | 'const' | 'enum' | 'package' | 'function' | 'deprecated';
9+
10+
export enum DaffioDocsApiItemLabelTypeEnum {
11+
Class = 'class',
12+
TypeAlias = 'type-alias',
13+
Interface = 'interface',
14+
Const = 'const',
15+
Enum = 'enum',
16+
Package = 'package',
17+
Function = 'function',
18+
Deprecated = 'deprecated',
19+
}
20+
21+
@Component({
22+
selector: 'daffio-docs-api-item-label',
23+
template: '<ng-content></ng-content>',
24+
styleUrl: './api-item-label.component.scss',
25+
changeDetection: ChangeDetectionStrategy.OnPush,
26+
})
27+
export class DaffioDocsApiItemLabelComponent {
28+
@Input() type: DaffioDocsApiItemLabelType;
29+
30+
@HostBinding('class.daffio-docs-api-item-label') hostClass = true;
31+
32+
/* eslint-disable quote-props */
33+
@HostBinding('class') get class() {
34+
return {
35+
'class': this.type === DaffioDocsApiItemLabelTypeEnum.Class,
36+
'type-alias': this.type === DaffioDocsApiItemLabelTypeEnum.TypeAlias,
37+
'interface': this.type === DaffioDocsApiItemLabelTypeEnum.Interface,
38+
'const': this.type === DaffioDocsApiItemLabelTypeEnum.Const,
39+
'enum': this.type === DaffioDocsApiItemLabelTypeEnum.Enum,
40+
'package': this.type === DaffioDocsApiItemLabelTypeEnum.Package,
41+
'function': this.type === DaffioDocsApiItemLabelTypeEnum.Function,
42+
'deprecated': this.type === DaffioDocsApiItemLabelTypeEnum.Deprecated,
43+
};
44+
}
45+
}

apps/daffio/src/app/docs/api/components/fragments/api-base-content/api-base-content.component.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
@if (child()) {
2-
<h3 [attr.id]="doc().slug">{{doc().name}}</h3>
2+
<div class="daffio-docs-api-base-content__title">
3+
<h3 [attr.id]="doc().slug">{{doc().name}}</h3>
4+
@if (doc().deprecated) {
5+
<daffio-docs-api-item-label type="deprecated">Deprecated</daffio-docs-api-item-label>
6+
}
7+
</div>
38
} @else {
4-
<h1 [attr.id]="doc().slug">{{doc().name}}</h1>
9+
<div class="daffio-docs-api-base-content__title">
10+
<h1 [attr.id]="doc().slug">{{doc().name}}</h1>
11+
@if (doc().deprecated) {
12+
<daffio-docs-api-item-label type="deprecated">Deprecated</daffio-docs-api-item-label>
13+
}
14+
</div>
515
}
616
<p [innerHTML]="doc().importExample | safe"></p>
717
<div [innerHTML]="doc().description | safe"></div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@use '../../../../../../scss/type-descriptors/mixins' as type-mixin;
2+
3+
.daffio-docs-api-base-content {
4+
&__title {
5+
display: flex;
6+
align-items: center;
7+
flex-wrap: wrap;
8+
gap: 0.75rem;
9+
margin-bottom: 1rem;
10+
11+
> * {
12+
margin: 0;
13+
}
14+
}
15+
}

apps/daffio/src/app/docs/api/components/fragments/api-base-content/api-base-content.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import {
1111

1212
import { DaffioSafeHtmlPipe } from '../../../../../core/html-sanitizer/safe.pipe';
1313
import { DaffioDocsApiDynamicContent } from '../../../dynamic-content/dynamic-content.type';
14+
import { DaffioDocsApiItemLabelComponent } from '../../api-item-label/api-item-label.component';
1415

1516
@Component({
1617
selector: 'daffio-docs-api-base-content',
1718
templateUrl: './api-base-content.component.html',
19+
styleUrl: './api-base-content.component.scss',
1820
changeDetection: ChangeDetectionStrategy.OnPush,
1921
imports: [
2022
DaffioSafeHtmlPipe,
23+
DaffioDocsApiItemLabelComponent,
2124
],
2225
})
2326
export class DaffioDocsApiBaseContentComponent implements DaffioDocsApiDynamicContent<DaffApiDocBase> {

apps/daffio/src/scss/component-themes.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@use '../app/docs/api/components/fragments/api-type-content/api-type-content-theme' as api-type-content;
1818
@use '../app/docs/api/components/method-block/method-block-theme' as api-method-block;
1919
@use '../app/docs/api/components/fragments/api-directive-content/api-directive-content-theme' as api-directive-content;
20+
@use '../app/docs/api/components/api-item-label/api-item-label-theme' as api-item-label;
2021

2122
@mixin component-themes($theme) {
2223
@include simple-footer.daffio-simple-footer-theme($theme);
@@ -38,4 +39,5 @@
3839
@include api-type-content.daffio-api-type-content-theme($theme);
3940
@include api-method-block.daffio-method-block-theme($theme);
4041
@include api-directive-content.daffio-api-directive-content-theme($theme);
42+
@include api-item-label.daffio-api-item-label-theme($theme);
4143
}

libs/docs-utils/src/doc/api/base.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export interface DaffApiDocBase extends DaffDoc {
1818
sourceApiBlock: DaffDocsRenderedContent;
1919
slug: string;
2020
name: string;
21+
deprecated: string;
2122
}

libs/docs-utils/src/doc/api/type.type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ export interface DaffDocsApiTypeProperty extends Pick<PropertyMemberDoc, MemberF
1919
decorators: Array<DaffDocsApiDecorator>;
2020
description: DaffDocsRenderedContent;
2121
type: DaffDocsRenderedContent;
22+
deprecated: string;
2223
}
2324

2425
export interface DaffDocsApiTypeMethod extends Pick<MethodMemberDoc, MemberFields | 'typeParameters'> {
2526
decorators: Array<DaffDocsApiDecorator>;
2627
parameterDocs: Array<DaffDocsApiFunctionParam>;
2728
description: DaffDocsRenderedContent;
2829
type: DaffDocsRenderedContent;
30+
deprecated: string;
2931
}
3032

3133
export interface DaffDocsApiHeritageInfo extends Pick<HeritageInfo, 'text'> {}

tools/dgeni/src/transforms/daffodil-api-package/processors/role.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class RoleProcessor implements FilterableProcessor {
6868
'sourceApiBlock',
6969
'slug',
7070
'name',
71+
'deprecated',
7172
],
7273
{
7374
description: this.markdownSerialize,
@@ -127,6 +128,7 @@ export class RoleProcessor implements FilterableProcessor {
127128
'isOptional',
128129
'isGetAccessor',
129130
'isSetAccessor',
131+
'deprecated',
130132
],
131133
{
132134
decorators: arraySerializer(this.decoratorSerialize),
@@ -156,6 +158,7 @@ export class RoleProcessor implements FilterableProcessor {
156158
'isOptional',
157159
'isGetAccessor',
158160
'isSetAccessor',
161+
'deprecated',
159162
],
160163
{
161164
decorators: arraySerializer(this.decoratorSerialize),

0 commit comments

Comments
 (0)