Skip to content

Commit 583883c

Browse files
feat(module:affix): support standalone component (#8037)
* build: support standalone label generation * feat(module:affix): support standalone component
1 parent d14869e commit 583883c

File tree

6 files changed

+67
-21
lines changed

6 files changed

+67
-21
lines changed

components/affix/affix.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { Direction, Directionality } from '@angular/cdk/bidi';
7-
import { Platform } from '@angular/cdk/platform';
6+
import { BidiModule, Direction, Directionality } from '@angular/cdk/bidi';
7+
import { Platform, PlatformModule } from '@angular/cdk/platform';
88
import { DOCUMENT } from '@angular/common';
99
import {
1010
AfterViewInit,
@@ -45,6 +45,8 @@ const NZ_AFFIX_DEFAULT_SCROLL_TIME = 20;
4545
@Component({
4646
selector: 'nz-affix',
4747
exportAs: 'nzAffix',
48+
standalone: true,
49+
imports: [BidiModule, PlatformModule],
4850
template: `
4951
<div #fixedEl>
5052
<ng-content></ng-content>

components/affix/affix.module.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { BidiModule } from '@angular/cdk/bidi';
7-
import { PlatformModule } from '@angular/cdk/platform';
8-
import { CommonModule } from '@angular/common';
96
import { NgModule } from '@angular/core';
107

118
import { NzAffixComponent } from './affix.component';
129

1310
@NgModule({
14-
declarations: [NzAffixComponent],
1511
exports: [NzAffixComponent],
16-
imports: [BidiModule, CommonModule, PlatformModule]
12+
imports: [NzAffixComponent]
1713
})
1814
export class NzAffixModule {}

components/affix/doc/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { NzAffixModule } from 'ng-zorro-antd/affix';
1919

2020
## API
2121

22-
### nz-affix
22+
### nz-affix:standalone
2323

2424
| Property | Description | Type | Default | Global Config |
2525
| -------- | ----------- | ---- | ------- | ------------- |

components/affix/doc/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { NzAffixModule } from 'ng-zorro-antd/affix';
2121
## API
2222

2323

24-
### nz-affix
24+
### nz-affix:standalone
2525

2626
| 成员 | 说明 | 类型 | 默认值 | 全局配置 |
2727
| --- | --- | --- | --- | --- |

scripts/site/_site/doc/style/patch.less

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
@media screen and (max-width:767px){
1+
@media screen and (max-width:767px) {
22
.pic-plus img {
33
width: 120px;
44
height: auto;
55
}
66
}
77

8-
.pic-plus > * {
8+
.pic-plus>* {
99
display: inline-block !important;
1010
vertical-align: middle;
1111
}
12+
1213
.pic-plus span {
1314
font-size: 30px;
1415
color: #aaa;
@@ -82,7 +83,8 @@
8283
padding: 24px;
8384
}
8485

85-
body[data-theme='dark'], [data-theme='dark'] * {
86+
body[data-theme='dark'],
87+
[data-theme='dark'] * {
8688
scrollbar-color: #434343 #262626;
8789

8890
&::-webkit-scrollbar {
@@ -94,9 +96,10 @@ body[data-theme='dark'], [data-theme='dark'] * {
9496
}
9597

9698
&::-webkit-scrollbar-thumb {
97-
background-color: #434343;
99+
background-color: #434343;
98100
border-radius: 6px;
99101
border: 2px solid #262626;
102+
100103
:hover {
101104
background-color: #262626;
102105
}
@@ -116,6 +119,11 @@ label {
116119
font-weight: normal;
117120
text-transform: uppercase;
118121

122+
&.standalone {
123+
color: @gold-6;
124+
border: 2px solid @gold-6;
125+
}
126+
119127
&.directive {
120128
color: @magenta-6;
121129
border: 2px solid @magenta-6;
@@ -142,7 +150,7 @@ label {
142150
}
143151

144152
.head-example {
145-
background: rgba(255,255,255,.12) !important;
153+
background: rgba(255, 255, 255, .12) !important;
146154
}
147155

148156
.popover-menu .ant-popover-inner-content #nav a {
@@ -158,7 +166,7 @@ label {
158166
}
159167

160168
.site-page-header-ghost-wrapper {
161-
background-color: rgba(255,255,255,0.08);
169+
background-color: rgba(255, 255, 255, 0.08);
162170
}
163171

164172
.drawer-content-wrapper {
@@ -197,6 +205,7 @@ label {
197205
font-size: 20px;
198206
line-height: 28px;
199207
}
208+
200209
.resource-card-description {
201210
margin: 0 20px 20px 20px;
202211
color: #697b8c;

scripts/site/utils/marked.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,62 @@ renderer.link = function (href, title, text) {
109109
return str;
110110
};
111111

112+
/**
113+
* @param {'component' | 'directive' | 'standalone' | 'service'} label
114+
* @returns {string}
115+
*/
116+
function createLabel(label) {
117+
return `<label class="api-type-label ${label}">${label}</label>`;
118+
}
119+
120+
const STANDALONE_SUFFIX_REGEX = /:standalone$/;
121+
122+
/**
123+
* Clean up special tags such as suffixes.
124+
*
125+
* Currently we have the following tags:
126+
*
127+
* Suffix:
128+
* - `:standalone`: Indicates that the target is a standalone component, directive or pipe.
129+
*
130+
* @param {string} text
131+
*/
132+
function normalizeHead(text) {
133+
return text.replace(STANDALONE_SUFFIX_REGEX, '');
134+
}
135+
136+
/**
137+
* @param {string} text
138+
* @param {number} level
139+
* @returns {string}
140+
*/
112141
renderer.heading = function (text, level) {
113142
const lowerText = text.toLowerCase().replace(/ /g, '-').replace(/\./g, '-').replace(/\?/g, '');
114143
const isMarkedLabel = level === 3 && text.indexOf('nz-') === 0;
115144
const isDirective = text[0] === '[' && text[text.length - 1] === ']';
116145
const isComponent = isMarkedLabel && !isDirective;
146+
const isStandalone = STANDALONE_SUFFIX_REGEX.test(text);
117147
const isService = text.indexOf('Nz') === 0 && text.indexOf('Service') > -1;
118-
const head = `<h${level} id="${lowerText}"><span>${text}</span>`;
148+
const head = `<h${level} id="${lowerText}"><span>${normalizeHead(text)}</span>`;
119149
const link = `<a onclick="window.location.hash = '${lowerText}'" class="anchor">#</a></h${level}>`;
150+
151+
let heading = head;
152+
120153
if (isComponent) {
121-
return head + `<label class="api-type-label component">component</label>` + link;
154+
heading += createLabel('component');
122155
} else if (isDirective) {
123-
return head + `<label class="api-type-label directive">directive</label>` + link;
156+
heading += createLabel('directive');
124157
} else if (isService) {
125-
return head + `<label class="api-type-label service">service</label>` + link;
126-
} else {
127-
return head + link;
158+
heading += createLabel('service');
128159
}
160+
161+
if (isStandalone) {
162+
heading += createLabel('standalone');
163+
}
164+
165+
heading += link;
166+
167+
return heading;
129168
};
130169

131170
renderer.code = function (code, infostring, escaped) {

0 commit comments

Comments
 (0)