From 5e611e7d51a8cad3697a381612225b0d12879d55 Mon Sep 17 00:00:00 2001 From: HyperLifelll9 Date: Thu, 7 Dec 2023 17:05:43 +0800 Subject: [PATCH] feat(module:pipes): make the css-unit pipe support more units (#8260) --- components/pipes/demo/css-unit.md | 4 ++-- components/pipes/nz-css-unit.pipe.ts | 13 +------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/components/pipes/demo/css-unit.md b/components/pipes/demo/css-unit.md index ee4e2c9344..d85676f290 100644 --- a/components/pipes/demo/css-unit.md +++ b/components/pipes/demo/css-unit.md @@ -9,7 +9,7 @@ title: Css 单位 -警告:在 `v17.0.0` 中被弃用,请使用 Angular 内置语法替代,例如: +提示:如果条件允许,我们更推荐使用 Angular 内置语法,例如: ```html
px
@@ -21,7 +21,7 @@ Css 单位 Css unit -WARNING: Deprecated in `v17.0.0`, please use angular's built-in syntax instead, eg: +Tip: If possible, we prefer to use Angular's built-in syntax, for example: ```html
px
diff --git a/components/pipes/nz-css-unit.pipe.ts b/components/pipes/nz-css-unit.pipe.ts index f1ff8838d9..e38c51668a 100644 --- a/components/pipes/nz-css-unit.pipe.ts +++ b/components/pipes/nz-css-unit.pipe.ts @@ -5,23 +5,12 @@ import { Pipe, PipeTransform } from '@angular/core'; -/** - * @deprecated v17.0.0 - Use angular's built-in syntax instead - */ @Pipe({ name: 'nzToCssUnit', standalone: true }) export class NzToCssUnitPipe implements PipeTransform { transform(value: number | string, defaultUnit: string = 'px'): string { - const absoluteLengthUnit = ['cm', 'mm', 'Q', 'in', 'pc', 'pt', 'px']; - const relativeLengthUnit = ['em', 'ex', 'ch', 'rem', '1h', 'vw', 'vh', 'vmin', 'vmax']; - const percentagesUnit = ['%']; - const listOfUnit = [...absoluteLengthUnit, ...relativeLengthUnit, ...percentagesUnit]; - let unit = 'px'; - if (listOfUnit.some(u => u === defaultUnit)) { - unit = defaultUnit; - } - return typeof value === 'number' ? `${value}${unit}` : `${value}`; + return typeof value === 'number' ? `${value}${defaultUnit}` : value; } }